2013-01-18 23:39:11 +01:00
local musicFilename = " /sounds/startup "
2013-01-16 19:46:42 +01:00
local musicChannel = g_sounds.getChannel ( 1 )
2011-12-03 22:41:37 +01:00
2013-01-16 19:46:42 +01:00
function setMusic ( filename )
2012-08-26 11:10:48 +02:00
musicFilename = filename
if not g_game.isOnline ( ) then
2013-01-16 19:46:42 +01:00
musicChannel : stop ( )
musicChannel : enqueue ( musicFilename , 3 )
2012-08-26 11:10:48 +02:00
end
end
2013-01-16 19:46:42 +01:00
function reloadScripts ( )
2013-03-01 09:46:55 +01:00
g_textures.clearCache ( )
2012-06-26 00:13:30 +02:00
g_modules.reloadModules ( )
2013-01-27 10:44:15 +01:00
local script = ' / ' .. g_app.getCompactName ( ) .. ' rc '
if g_resources.fileExists ( script ) then
dofile ( script )
end
2012-04-26 21:54:16 +02:00
local message = tr ( ' All modules and scripts were reloaded. ' )
2012-07-24 07:30:08 +02:00
2012-07-26 11:12:20 +02:00
modules.game_textmessage . displayGameMessage ( message )
2012-04-26 21:54:16 +02:00
print ( message )
2012-03-18 14:34:39 +01:00
end
2013-01-16 19:46:42 +01:00
function startup ( )
2012-08-19 16:30:57 +02:00
-- Play startup music (The Silver Tree, by Mattias Westlund)
2013-01-16 19:46:42 +01:00
musicChannel : enqueue ( musicFilename , 3 )
connect ( g_game , { onGameStart = function ( ) musicChannel : stop ( 3 ) end } )
connect ( g_game , { onGameEnd = function ( )
g_sounds.stopAll ( )
musicChannel : enqueue ( musicFilename , 3 )
end } )
2012-08-19 16:30:57 +02:00
-- Check for startup errors
local errtitle = nil
local errmsg = nil
if g_graphics.getRenderer ( ) : lower ( ) : match ( ' gdi generic ' ) then
errtitle = tr ( ' Graphics card driver not detected ' )
errmsg = tr ( ' No graphics card detected, everything will be drawn using the CPU, \n thus the performance will be really bad. \n Please update your graphics driver to have a better performance. ' )
end
-- Show entergame
if errmsg or errtitle then
local msgbox = displayErrorBox ( errtitle , errmsg )
msgbox.onOk = function ( ) EnterGame.firstShow ( ) end
else
EnterGame.firstShow ( )
end
end
2013-01-16 19:46:42 +01:00
function init ( )
2013-02-10 05:54:20 +01:00
connect ( g_app , { onRun = startup ,
2013-02-10 04:17:20 +01:00
onExit = exit } )
2013-02-18 17:16:22 +01:00
2012-01-06 10:35:48 +01:00
g_window.setMinimumSize ( { width = 600 , height = 480 } )
2012-08-26 11:10:48 +02:00
g_sounds.preload ( musicFilename )
2011-12-30 07:36:10 +01:00
2011-12-30 05:50:19 +01:00
-- initialize in fullscreen mode on mobile devices
if g_window.getPlatformType ( ) == " X11-EGL " then
2011-12-30 07:05:32 +01:00
g_window.setFullscreen ( true )
2011-12-30 05:50:19 +01:00
else
2012-01-06 09:48:59 +01:00
-- window size
local size = { width = 800 , height = 600 }
2012-06-26 00:13:30 +02:00
size = g_settings.getSize ( ' window-size ' , size )
2012-01-03 02:32:34 +01:00
g_window.resize ( size )
2012-01-06 09:48:59 +01:00
-- window position, default is the screen center
2012-01-03 02:32:34 +01:00
local displaySize = g_window.getDisplaySize ( )
2012-02-05 23:42:35 +01:00
local defaultPos = { x = ( displaySize.width - size.width ) / 2 ,
y = ( displaySize.height - size.height ) / 2 }
2012-06-26 00:13:30 +02:00
local pos = g_settings.getPoint ( ' window-pos ' , defaultPos )
2013-01-16 19:46:42 +01:00
pos.x = math.max ( pos.x , 0 )
pos.y = math.max ( pos.y , 0 )
2012-01-03 02:32:34 +01:00
g_window.move ( pos )
2012-01-06 09:48:59 +01:00
-- window maximized?
2012-06-26 00:13:30 +02:00
local maximized = g_settings.getBoolean ( ' window-maximized ' , false )
2012-01-06 09:48:59 +01:00
if maximized then g_window.maximize ( ) end
2011-12-30 05:50:19 +01:00
end
2011-12-30 07:36:10 +01:00
2013-01-16 19:46:42 +01:00
g_window.setTitle ( g_app.getName ( ) )
2013-01-18 23:39:11 +01:00
g_window.setIcon ( ' /images/clienticon ' )
2013-01-16 19:46:42 +01:00
-- poll resize events
g_window.poll ( )
2012-02-20 03:27:08 +01:00
2013-01-16 19:46:42 +01:00
g_keyboard.bindKeyDown ( ' Ctrl+Shift+R ' , reloadScripts )
2013-01-26 17:38:48 +01:00
-- generate machine uuid, this is a security measure for storing passwords
if not g_crypt.setMachineUUID ( g_configs.get ( ' uuid ' ) ) then
2013-01-29 14:50:24 +01:00
g_configs.set ( ' uuid ' , g_crypt.getMachineUUID ( ) )
2013-01-26 17:38:48 +01:00
g_configs.save ( )
2013-02-10 05:54:20 +01:00
end
2012-01-06 10:35:48 +01:00
end
2013-01-16 19:46:42 +01:00
function terminate ( )
2013-02-10 05:54:20 +01:00
disconnect ( g_app , { onRun = startup ,
2013-02-10 04:17:20 +01:00
onExit = exit } )
2012-01-17 06:36:25 +01:00
-- save window configs
2012-06-26 00:13:30 +02:00
g_settings.set ( ' window-size ' , g_window.getUnmaximizedSize ( ) )
g_settings.set ( ' window-pos ' , g_window.getUnmaximizedPos ( ) )
g_settings.set ( ' window-maximized ' , g_window.isMaximized ( ) )
2012-08-15 01:58:25 +02:00
2013-01-17 15:23:01 +01:00
local protocolVersion = g_game.getProtocolVersion ( )
if protocolVersion ~= 0 then
g_settings.set ( ' protocol-version ' , protocolVersion )
2013-02-10 05:59:55 +01:00
end
2011-12-03 22:41:37 +01:00
end
2013-02-10 05:28:47 +01:00
function exit ( )
g_logger.info ( " Exiting application.. " )
2013-02-10 04:17:20 +01:00
end