local isRegisterScenes = false

function RegisterScenes()
    if isRegisterScenes then
        return
    end
    isRegisterScenes = true
    
    local qt = 'quest'
    local ho = 'hidden_object'
    local hp = 'hidden_picture'
    local mg = 'mini_game'
    
    local function RegisterLevelEx(level_info, level_type, is_collectors)
        local INFO_NAME   = 1
        local INFO_PARENT = 2
        local INFO_MODE   = 3
        
        local sc_p          
        local mg_p          
        local res_sc_p   
        local res_mg_p      
        local sounds_sc_p
        local sounds_mg_p
        
        if is_collectors then
            sc_p            = 'data/ExtraContent/Scripts/scenes/'
            mg_p            = 'data/ExtraContent/Scripts/minigames/'
            res_sc_p        = 'data/ExtraContent/Texture/Scenes/'
            res_mg_p        = 'data/ExtraContent/Texture/Minigames/'
            sounds_sc_p     = 'data/ExtraContent/Sound/Scenes/'
            sounds_mg_p     = 'data/ExtraContent/Sound/minigames/'
        else
            sc_p            = 'data/Scripts/scenes/'
            mg_p            = 'data/Scripts/minigames/'
            res_sc_p        = 'data/Texture/Scenes/'
            res_mg_p        = 'data/Texture/Minigames/'
            sounds_sc_p     = 'data/Sound/Scenes/'
            sounds_mg_p     = 'data/Sound/minigames/'
        end
        
        sc_p        = level_type~=mg and sc_p        or mg_p
        res_sc_p    = level_type~=mg and res_sc_p    or res_mg_p
        sounds_sc_p = level_type~=mg and sounds_sc_p or sounds_mg_p
        
        local level_postfix    = {[qt]='',      [ho]='ho',  [mg]='mg', [hp]='hp' }
        local name_postfix     = {[qt]='',      [ho]='_ho', [mg]='',   [hp]='_hp'}
        local res_dir          = {[qt]='main/', [ho]='ho/', [mg]='',   [hp]='hp/'}
        local level_ce_postfix = {[false]='', [true]='_ce'}
        
        if  level_type == ho or
            level_type == hp
        then
            level_info[INFO_PARENT] = level_info[INFO_PARENT] or level_info[INFO_NAME]
        end
        
        local base_name = level_info[INFO_NAME]
		local level_index = string.gsub(base_name, '^0*(%d+).*', '%1') .. level_postfix[level_type]
		local parent_name = level_info[INFO_PARENT] and 'l_'..level_info[INFO_PARENT] or nil
		local mode = level_info[INFO_MODE] or level_type
		
		if levels_index_map then
		    local index_post = 1
		    local qt_start_char = string.byte('a')
		    local index_post_char
		    local index = level_index
		    
            while( levels_index_map[index .. level_ce_postfix[is_collectors]] ) do
                index_post_char = level_type==qt and string.char(qt_start_char+index_post-1) or tostring(index_post)
                index = level_index .. index_post_char
                
                index_post = index_post+1
            end
            
            level_index = index .. level_ce_postfix[is_collectors]
        end
        
        local level_name = 'l_'..base_name .. name_postfix[level_type]
		
		RegisterLevel(level_index, level_name, sc_p..base_name..'/'..base_name .. name_postfix[level_type] ..'.lua', res_sc_p..base_name..'/'..res_dir[level_type], mode, parent_name)
		
		levels[level_name].level_type = level_type
		levels[level_name].sounds_path = sounds_sc_p..base_name..'/'
        if is_collectors then
            levels[level_name].collectors_edition = true
        end
    end
    
    local function RegisterLevels(levels, level_type, is_collectors)
        for i,level_info in ipairs(levels) do
            RegisterLevelEx(level_info, level_type, is_collectors)
        end
    end
    
    -- register all levels
	local quest_levels =
	{
		{'01_dock'},
		{'01a_dock_boat'},
		{'02_legran_gate'},
		{'03_yard'},
		{'04_guest_room'},
		{'05_office'},
		{'06_garden'},
		{'07_shed'},
		{'08_street'},
		{'08a_street_pavilion'},
		{'09_doctor'},
		{'10_hotel'},
		{'11_corridor'},
		{'12_grannies_room'},
		{'13_junk_shop'},
	}
	
	local ho_levels =
	{
	    {'09_doctor'},
	    {'11_corridor'},
	    {'14_village'},
	}
	
	local hp_levels =
	{
	    {'06_garden'},
	}
	
	local mg_levels =
	{
	    {'01_Box',      '01a_dock_boat',  qt},
	    {'02_Lock',     '02_legran_gate', qt},
	    {'05_Majong',   '05_office',      qt},
	    {'09_Blood',   	'09_doctor',      qt},
	    {'06_Ship',    	'06_garden'      ,qt},
	    {'11_Vitraj',   '11_corridor',    qt},
	}
	
	RegisterLevels(quest_levels, qt, false)
	RegisterLevels(ho_levels,    ho, false)
	RegisterLevels(hp_levels,    hp, false)
	RegisterLevels(mg_levels,    mg, false)


    if IsCollectorsEdition() then
        local quest_levels =
	    {
	    }
	    
	    local ho_levels =
	    {
	    
	    }
	    
	    local hp_levels =
        {
            
        }
	
	    local mg_levels =
	    {
	    }
        
        RegisterLevels(quest_levels, qt, true)
	    RegisterLevels(ho_levels,    ho, true)
	    RegisterLevels(hp_levels,    hp, true)
	    RegisterLevels(mg_levels,    mg, true)
    end
end