-- data/conf/loading.lua
-- copyright (c) 2003-2007 rionix
-- version: 1.00
-- date: 25.01.2008

-------------------------------------------------------------------------------
-- Загрузка ресурсов
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------
-- Загрузка всех моделей из каталога

function LoadModels( strPath, iParam, iType )
	local fs = cFileSystem()
	local fname = fs:GetFirst( filename(strPath) )
	while not fname:empty() do
		if ( (not fs:IsFolder(fname)) and (fname:ext() == '3ds') ) then
			if ( iType == 0 ) then			
				mesh = cLoadMesh( fname:c_str() )
			elseif ( iType == 1 ) then
				mesh = cLoadBrickMesh( fname:c_str() )
			end
			mesh:SetParameters(iParam)
		end
		fname = fs:GetNext()
	end
end

-------------------------------------------------------------------------------------------------
-- Загрузка всех текстур из каталога

--   параметры (iParam):
--     0 - настройки текстуры по умолчанию
--     1 - настройки текстур для GUI
--     2 - настройки текстур для мешей
function LoadTextures( strPath, iParam, iType )
	local fs = cFileSystem()
	local fname = fs:GetFirst( filename(strPath) )
	while not fname:empty() do
		if ( not fs:IsFolder(fname) ) then 
			if (iType == 0) then 
				tex = cLoadTexture( fname:c_str() )
				tex:SetParameters(iParam)
			else 
				cLoadBrickMaterial( fname:c_str() ) 
			end
		end
		fname = fs:GetNext()
	end
end

-------------------------------------------------------------------------------------------------
-- Загрузка всех сцен из каталога

function LoadScenes( strPath )
	local fs = cFileSystem()
	local fname = fs:GetFirst( filename(strPath) )
	while not fname:empty() do
		if ( (not fs:IsFolder(fname)) and (fname:ext() == '3ds') ) then 
			cLoadScene( fname:c_str() )
		end
		fname = fs:GetNext()
	end
end

-------------------------------------------------------------------------------------------------
-- Загрузка всех звуков из каталога

function LoadSounds( strPath )
	local fs = cFileSystem()
	local fname = fs:GetFirst( filename(strPath) )
	while not fname:empty() do
		if (fname:ext() == "ogg") then 
			cLoadSound( fname:c_str(), true ) 
		end
		fname = fs:GetNext()
	end
end

-------------------------------------------------------------------------------------------------
-- Загрузка музыки из каталога

function LoadMusic( strPath )
	local fs = cFileSystem()
	local fname = fs:GetFirst( filename(strPath) )
	while not fname:empty() do
		if (fname:ext() == "mo3") then 
			cLoadMusic( fname:c_str(), false ) 
		end
		fname = fs:GetNext()
	end
end

-------------------------------------------------------------------------------------------------
-- загрузка звуков

function LoadSoundsManual()
	cLoadMusic("music000", "{StaticPath}/sound/ext/music000.mo3", 0, 0, false)
	cLoadMusic("music001", "{StaticPath}/sound/ext/music000.mo3", 1, 0, false)
	cLoadMusic("music002", "{StaticPath}/sound/ext/music000.mo3", 2, 0, false)
	cLoadMusic("music003", "{StaticPath}/sound/ext/music000.mo3", 3, 0, false)
	cLoadMusic("music004", "{StaticPath}/sound/ext/music000.mo3", 4, 0, false)
	-- звуки для middle
	cLoadSound("{StaticPath}/sound/ext/click.ogg", true)
	cLoadSound("{StaticPath}/sound/ext/typing.ogg", true)
	-- звуки с конкретным числом буферов
	local snd = cLoadSound("{StaticPath}/sound/ext/bomb.ogg", true)
	snd:SetParameters(3)
	snd = cLoadSound("{StaticPath}/sound/ext/gun.ogg", true)
	snd:SetParameters(8)
	snd = cLoadSound("{StaticPath}/sound/ext/explosion0.ogg", true)
	snd:SetParameters(2)
	snd = cLoadSound("{StaticPath}/sound/ext/explosion1.ogg", true)
	snd:SetParameters(2)
	snd = cLoadSound("{StaticPath}/sound/ext/explosion2.ogg", true)
	snd:SetParameters(2)
	snd = cLoadSound("{StaticPath}/sound/ext/ball_brick.ogg", true)
	snd:SetParameters(3)
	snd = cLoadSound("{StaticPath}/sound/ext/ball_brick_lock.ogg", true)
	snd:SetParameters(3)
	snd = cLoadSound("{StaticPath}/sound/ext/ball_bat.ogg", true)
	snd:SetParameters(3)
	snd = cLoadSound("{StaticPath}/sound/ext/ball_wall.ogg", true)
	snd:SetParameters(3)
	snd = cLoadSound("{StaticPath}/sound/ext/cannon.ogg", true)
	snd:SetParameters(3)
	snd = cLoadSound("{StaticPath}/sound/ext/magnetto.ogg", true)
	snd:SetParameters(3)
	snd = cLoadSound("{StaticPath}/sound/ext/s300.ogg", true)
	snd:SetParameters(4)
	snd = cLoadSound("{StaticPath}/sound/ext/teleport.ogg", true)
	snd:SetParameters(2)
end

-------------------------------------------------------------------------------------------------
-- Main:

-- текстуры
LoadTextures("{StaticPath}/texture/gui", 1, 0)
LoadTextures("{StaticPath}/texture", 2, 0)
LoadTextures("{StaticPath}/texture/brick", 2, 1)
-- модели
LoadModels("{StaticPath}/model/", 0, 0)
LoadModels("{StaticPath}/model/brick", 1, 1)
-- звуки
LoadSoundsManual()
LoadSounds("{StaticPath}/sound")
LoadMusic("{StaticPath}/sound")
-- прочее
LoadScenes("{StaticPath}/model/scene")
cLoadScene("{StaticPath}/model/gui00.3ds")
cLoadScene("{StaticPath}/model/bat00.3ds")
cLoadScene("{StaticPath}/model/bat01.3ds")
cLoadScene("{StaticPath}/model/bat02.3ds")
cLoadScene("{StaticPath}/model/bat03.3ds")