-------------------------------------------------------------------------------
function start(level)
	if not current_player then
		Console:pushText('Please, input player...')
	end
	
	current_player.gameState:clear()
	path_manager:clear()

	if not level or not levels_index_map[level] then
		Console:pushText('Unknown Level')
		return
	end
	
	-- удаляем все окна
	PopUpScreensMgr:destroyAll()
	current_scene = nil
	local levelClassName = levels_index_map[level]
	local levelName = string.sub(levelClassName, 3)
	local tag = getLevelsGameStateTag(levelName)

	-- Добавляем режим игры
	if HasGameState(PLAY_MODE, tag) == false then
		SetGameState(PLAY_MODE, EPlayMode.CASUAL, tag)
		Helpers.SaveObjectToGameState(PLAY_MODE_PARAMETERS, EPlayModeDefaultParameters[EPlayMode.CASUAL], tag)
	end
	
	-- init levelName
	startLevel( levelClassName )

	Console:pushText('Loading level '..levelName)
end
Console:registerCommand('start'):setAction('start')
-------------------------------------------------------------------------------

function loadlevel(level)
	if not current_player then
		Console:pushText('Please, input player...')
	end

	if not level or not levels_index_map[level] then
		Console:pushText('Unknown Level')
		return
	end

	local levelClassName = levels_index_map[level]
	local levelName = string.sub(levelClassName, 3)
	local tag = getLevelsGameStateTag(levelName)
	local gameState	= current_player.gameState

	-- Добавляем режим игры
	if gameState:hasState(PLAY_MODE, tag) == false then
		SetGameState(PLAY_MODE, EPlayMode.CASUAL, tag)
		Helpers.SaveObjectToGameState(PLAY_MODE_PARAMETERS, EPlayModeDefaultParameters[EPlayMode.CASUAL], tag)
	end

	if not current_scene then
		-- удаляем все окна
		PopUpScreensMgr:destroyAll()
	end
	
	local levelClassName = levels_index_map[level]
	startLevel( levelClassName )

	Console:pushText('Loading level '..levelName)
end
Console:registerCommand('loadlevel'):setAction('loadlevel')
-------------------------------------------------------------------------------

function mm()
	exitToMainMenu()
end
Console:registerCommand('mm'):setAction('mm')
-------------------------------------------------------------------------------

function levelId(level)
	if not current_scene then
		Console:pushText('Scene not found...')
		return 
	end
	
	local level_name = current_scene:getPlayField().name
	
	for i, v in pairs(levels_index_map) do
		if v == 'l_'..level_name then
			Console:pushText('Level id is ' .. i)
			return 
		end
	end
end
Console:registerCommand('levelId'):setAction('levelId')
-------------------------------------------------------------------------------

function findTool(tool_name)
	if not current_scene then
		Console:pushText('Scene not found')
		return 
	end

	if tool_name == nil or tool_name == '' then
		Console:pushText('No tool name')
		return 
	end

	if not current_scene:getPlayField():getInventory().tools[tool_name] then
		Console:pushText('There is no such tool')
		return  
	end
	
	current_scene:getPlayField():findTool(tool_name, true)
	Console:pushText(tool_name..' found')
end
Console:registerCommand('findTool'):setAction('findTool')
-------------------------------------------------------------------------------

function reparseStrings()
	StringManager:loadStrings(STRINGS_FILE_PATH, false)
	
	Console:pushText('StringManager update strings from '..STRINGS_FILE_PATH)
end
Console:registerCommand('reparseStrings'):setAction('reparseStrings')
-------------------------------------------------------------------------------

local generateSavePath = function (path)
	local ext = ExtractFileExtention(path)
	local name = ExtractFileName(path)
	local path = GetParentFolderPath(path)
	local new_path = path..'\\'..name..'___save.'..ext

	return new_path
end
-------------------------------------------------------------------------------
local CONSOLE_SAVE_LAST_TAG = 'ConsoleSaveLastTag'

function saveState(index)
	if current_player then
		local state = current_player.gameState
		local path  = generateSavePath( state:getPath() )
		if index then
			path, _ = string.gsub (path, '.xml', ' '..index..'.xml')
		end
		--local tag = current_scene:getPlayField().is_collectors_edition and EGameStateTag.CE or EGameStateTag.SE
		local tag = getDefaultGameStateTag()
		state:setState(CONSOLE_SAVE_LAST_TAG, tag, EGameStateTag.GENERAL)
		path_manager:saveToGameState(tag, state)
		state:save(path)
		Console:pushText('Save state in path "'..path..'"')
		
	else
		Console:pushText('Active player is not exists...')
	end
end
Console:registerCommand('saveState'):setAction('saveState')
-------------------------------------------------------------------------------

function restoreState(index)
	if current_player then
		local state = current_player.gameState
		local path  = generateSavePath( state:getPath() )
		if index then
			path, _ = string.gsub (path, '.xml', ' '..index..'.xml')
		end
		if state:load(path) then
			Console:pushText('state is load in path "'..path..'"')
			
			-- удаляем все окна
			PopUpScreensMgr:destroyAll()
			current_scene = nil

			local tag = state:getState(CONSOLE_SAVE_LAST_TAG, EGameStateTag.GENERAL):get(0)			
			local level_to_load, last_visited_scene = getLevelToLoad(tag)
			if last_visited_scene then
				startLevel(level_to_load)
			end
		else
			Console:pushText('state is NOT load in path "'..path..'"')
		end
	else
		Console:pushText('Active player is not exists...')
	end
end
Console:registerCommand('restoreState'):setAction('restoreState')
-------------------------------------------------------------------------------

function outro()
	if current_player then
		createOutroScreen()
		Console:pushText('Outro started...')
	else
		Console:pushText('Active player is not exists...')
	end
end
Console:registerCommand('outro'):setAction('outro')
-------------------------------------------------------------------------------

function intro()
	if current_player then
		createIntroScreen()
		Console:pushText('Intro started...')
	else
		Console:pushText('Active player is not exists...')
	end
end
Console:registerCommand('intro'):setAction('intro')
-------------------------------------------------------------------------------

-- Way Manager ---------------------------------------------
function cleargraph(params)
	path_manager.unresolved_dependencies = {}
	path_manager.current_node= nil
	path_manager.root_node = nil
end
Console:registerCommand('cleargraph'):setAction('cleargraph')
-------------------------------------------------------------------------------
function graphsize(params)
	Console:pushText('Current graph size is: '..path_manager:getGraphSize())
end
Console:registerCommand('graphsize'):setAction('graphsize')
-------------------------------------------------------------------------------
function printgraph(params)
	path_manager:printGraph()
end
Console:registerCommand('printgraph'):setAction('printgraph')
-------------------------------------------------------------------------------
function shot(x)
	saveFramebufferToFile(x)
	print("saved screenshot to " .. x)
end
Console:registerCommand('shot'):setAction('shot')
-------------------------------------------------------------------------------
function debugLocalization(bActive)
	if bActive then
		bActive = string.lower(bActive)

		if bActive ~= 'true' and bActive ~= 'false' then
			Console:pushText('wrong argument: "'..bActive..'"')
		else
			bDebugLocalization = toboolean(bActive)
			Console:pushText('debug_localization: "'..tostring(bDebugLocalization == true)..'"')
		end
	else
		Console:pushText('debug_localization: "'..tostring(bDebugLocalization == true)..'"')
	end
end
Console:registerCommand('debug_localization'):setAction('debugLocalization')
-------------------------------------------------------------------------------
function addnote(note_id)
	--if note_id == all then addallnotes mode

    if not current_scene then
        Console:pushText('Scene not found.')
        return 
    end

	local notesPath
	if IsLevelCollectorsEdition(current_scene:getPlayField().name) then
		notesPath = NOTES_FOLDER_CE
	else
		notesPath = NOTES_FOLDER
	end

	local addNotesCount = 0
    local noteFiles = getResourceFolderFiles(notesPath)
    for i = 0, noteFiles:size() - 1 do
        local id   = ExtractFileName(noteFiles:get(i))
		if (note_id == "all" or note_id == id) and not HasGameState('PageSlot', id) then
			AddUniqueGameState('PageSlot', id)
			addNotesCount = addNotesCount + 1
		end
    end
    
	Console:pushText(addNotesCount.." note(s) added")
end

function addallnotes()
	addnote("all")
end

Console:registerCommand('addnote'):setAction('addnote')
Console:registerCommand('addallnotes'):setAction('addallnotes')
-------------------------------------------------------------------------------
function redofile(filename)       
		local vecFiles = {  getResourceFolderFiles('Data/Scripts/'), 
							getResourceFolderFiles('Data/Scripts/Screens/'), 
							getResourceFolderFiles('Data/Scripts/Comics/'),
							getResourceFolderFiles('Data/Scripts/HOLogic/'), 
							getResourceFolderFiles('Data/Scripts/Utils/'),
							getResourceFolderFiles('Data/Scripts/Tools/'),
							getResourceFolderFiles('Data/Scripts/Hint/'),
							getResourceFolderFiles('Data/Scripts/Common/'),
							getResourceFolderFiles('Data/Scripts/Common/Achievments/'),
							getResourceFolderFiles('Data/Scripts/Common/Collect/'),
							getResourceFolderFiles('Data/Scripts/Common/Comics/'),
							getResourceFolderFiles('Data/Scripts/Common/Hint/'),
							getResourceFolderFiles('Data/Scripts/Common/HOLogic/'),
							getResourceFolderFiles('Data/Scripts/Common/Screens/'),
							getResourceFolderFiles('Data/Scripts/Common/Tools/'),
							getResourceFolderFiles('Data/Scripts/Common/Utils/'),
						 }
		for _, vec in ipairs(vecFiles) do
			for i = 0, vec:size() - 1 do
				if filename == ExtractFileName(vec:get(i)) then
					dofile(vec:get(i))
					Console:pushText('File '..vec:get(i)..' was reread.') 
					return
				end
			end
		end 
		return 'File '..filename..' was not found.'
end
Console:registerCommand('redofile'):setAction('redofile')
-------------------------------------------------------------------------------
function lang(id)
	if id then
		if string.sub(id, 1, 2) == "ru" then
			STRINGS_FILE_PATH = STRINGS_FILE_PATH_RU
		elseif string.sub(id, 1, 3) == "eng" then
			STRINGS_FILE_PATH = STRINGS_FILE_PATH_ENG
		else
			Console:pushText("wrong lang param. use ru or eng to change language. use no params to switch ru/eng.")
			return
		end
	else
		if STRINGS_FILE_PATH == STRINGS_FILE_PATH_ENG then
			STRINGS_FILE_PATH = STRINGS_FILE_PATH_RU
		else
			STRINGS_FILE_PATH = STRINGS_FILE_PATH_ENG
		end
	end
		
	StringManager:loadStrings(STRINGS_FILE_PATH, false)
	
	Console:pushText('StringManager update strings from '..STRINGS_FILE_PATH)
end
Console:registerCommand('lang'):setAction('lang')
local lang_command = Console:getCommand('lang')
if lang_command then
	lang_command:addPossibleParam("ru")
	lang_command:addPossibleParam("eng")
end
-------------------------------------------------------------------------------
function autoplay(mode, period)
	if current_scene and current_scene.getAutoPlayer and current_scene:getAutoPlayer() then
		local autoplayer = current_scene:getAutoPlayer()
		autoplayer:setStepPeriod(tonumber(period) or 0.2)
		if mode == "0" then
			autoplayer:stop()
			SetGameState('AUTOPLAY', '0')
		elseif mode == "1" then
			autoplayer:setReloadMode(false)
			autoplayer:setDestroySceneOnReload(false)
			autoplayer:start()
			SetGameState('AUTOPLAY', '1')
		elseif mode == "2" then
			autoplayer:setReloadMode(true)
			autoplayer:setDestroySceneOnReload(false)
			autoplayer:start()
			SetGameState('AUTOPLAY', '2')
		elseif mode == "3" then
			autoplayer:setReloadMode(true)
			autoplayer:setDestroySceneOnReload(true)
			autoplayer:start()
			SetGameState('AUTOPLAY', '3')
		else
			Console:pushText("use autoplay 0|1|2 <time (0.2 by default)>")
		end
	else
		Console:pushText("error initialisation autoplay function")
	end
end
Console:registerCommand("autoplay"):setAction("autoplay")
-------------------------------------------------------------------------------
function cleanpanel(params)
	if current_scene then
		current_scene:getPanel():setMode(EPanelMode.CLEAN)
	end
end
Console:registerCommand('cleanpanel'):setAction('cleanpanel')
-------------------------------------------------------------------------------
function unlockachievments()
    if not current_scene then
        Console:pushText('Scene not found...')
        return 
    end

    local achievments = current_scene:getAchievmentsManager():getAchievments()
    for _, achievment in pairs(achievments) do
        achievment:setCompleted(true)
        achievment:setUnlocked(true)
    end
end
Console:registerCommand('unlockachievments'):setAction('unlockachievments')
-------------------------------------------------------------------------------
function quit()
	Application:getPlatform():exit()
end
Console:registerCommand('quit'):setAction('quit')
-------------------------------------------------------------------------------