--============================================================================
--  mainloop.lua
--  Copyright (c) 2009, Bamtang Games. All Rights Reserved.
------------------------------------------------------------------------------

gMaxLengthUserName = 7;

gDifferencesLevel = 0;
gPuzzleLevel = 0;
gCoordinatesLevel = 0;
gScrambleLevel = 0;

gMapLevel = 1;
gLocked1 = false;
gLocked2 = false;
gLocked3 = false;
gRoomComplete1 = false;
gRoomComplete2 = false;
gRoomComplete3 = false;
gRoomAllPuzzlesComplete1 = false;
gRoomAllPuzzlesComplete2 = false;
gRoomAllPuzzlesComplete3 = false;
gScene = "scene1";

if gLocalizedPath == nil then
    DebugOut("[ERROR] gLocalizedPath not defined!");
    gLocalizedPath = "loc/en/";
end

function SendGameMessage(msg)
    if msg == "quit" then
        QuitToMainMenu();
    end
end

SplashNoAbortStyle = { parent=DefaultStyle, disableAbort=true; };
SplashNormalStyle = { parent=DefaultStyle, disableAbort=false; };

-- Main game loop
function Main()
    if gswtDebug == 0 then
        SetDefaultStyle(SplashNoAbortStyle);
        DisplaySplash("", "images/esrb_splash_screen", 4000);

        SetDefaultStyle(SplashNormalStyle);
        DisplaySplash("", "images/portal", 4000);
        DisplaySplash("", "images/VsluSoft.jpg", 4000);
        DisplaySplash("images/intro02.swf", "images/bamtang", 4000);
    end

    DoModal("scripts/loading.lua");

    if gswtDebug == 0 then
        DoModal("scripts/disclaimer.lua");
    end

    -- If there is no login user, pop a dialog that lets the user create one
    if GetNumUsers() == 0 then
        gEnterNameValue = "";
        name = DoModal("scripts/registeruser.lua");
        if name ~= nil then
            CreateNewUser(name);
        end
    end

    -- Push the game selection screen
    while true do
        -- DoMainWindow will exit only if there are NO windows pushed on the stack, so
        -- a PopModal()/PushModal() combination will not cause this to loop.
        DoMainWindow("scripts/mainmenu.lua");
    end
end

-- Return a function to be executed in a thread
return Main
