dofile ('Data/Scripts/Common/Console.lua')

-------------------------------------------------------------------------------
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)
	end

	PopUpScreensMgr:destroyAll()
	current_scene = nil
	
	local levelClassName = levels_index_map[level]
	startLevel( levelClassName )

	Console:pushText('Loading level '..levelName)	
end
-------------------------------------------------------------------------------
function addphoto(photo_id)
	--if note_id == all then addallnotes mode

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

	local photosPath
	if IsLevelCollectorsEdition(current_scene:getPlayField().name) then
		photosPath = PHOTOS_FOLDER_CE
	else
		photosPath = PHOTOS_FOLDER
	end

	local addPhotossCount = 1
    local photoFiles = getResourceFolderFiles(photosPath)
    for i = 0, photoFiles:size() - 1 do
        local id  = string.sub(ExtractFileName(photoFiles:get(i)), 7)
		if (photo_id == "all" or photo_id == id) and not HasGameState('PhotoGallerySlot', id) then
			AddUniqueGameState('PhotoGallerySlot', id)
			AddUniqueGameState('GalleryType_' .. id, 'photo')
			addPhotossCount = addPhotossCount + 1
		end
    end
    
	Console:pushText(addPhotossCount.." photos(s) added")
end

function addallphoto()
	addphoto("all")
end

Console:registerCommand('addphoto'):setAction('addphoto')
Console:registerCommand('addallphoto'):setAction('addallphoto')
-------------------------------------------------------------------------------
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/match3/'),
							getResourceFolderFiles('Data/Scripts/match3/field/'),
							getResourceFolderFiles('Data/Scripts/match3/field/ability/'),
							getResourceFolderFiles('Data/Scripts/match3/panel/'),
							getResourceFolderFiles('Data/Scripts/match3/help/'),
							getResourceFolderFiles('Data/Scripts/Action/'),
							getResourceFolderFiles('Data/Scripts/Labyrinth/'),
							getResourceFolderFiles('Data/Scripts/InGameEditor/'),
							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 
		filename = filename or ''
		return 'File '..filename..' was not found.'
end
-------------------------------------------------------------------------------
function addalltasks()
	if not current_scene then
		Console:pushText('Scene not found')
		return 
	end

	current_scene:getGameTasksTracker():addAllTasks()
	Console:pushText('All tasks found')
end
Console:registerCommand('addalltasks'):setAction('addalltasks')
-------------------------------------------------------------------------------
function finishalltasks()
	if not current_scene then
		Console:pushText('Scene not found')
		return 
	end

	current_scene:getGameTasksTracker():finishAllTasks()
	Console:pushText('All tasks finished')
end
Console:registerCommand('finishalltasks'):setAction('finishalltasks')
-------------------------------------------------------------------------------
