2025-01-28 20:49:56 +01:00
local musicFilename = ' sounds/startup '
2021-04-02 21:35:34 +02:00
local musicChannel = nil
2022-08-17 12:51:56 -03:00
if g_sounds then
musicChannel = g_sounds.getChannel ( SoundChannels.Music )
end
2011-12-03 19:41:37 -02:00
2013-01-16 16:46:42 -02:00
function setMusic ( filename )
2022-04-29 23:14:24 -03:00
musicFilename = filename
2012-08-26 06:10:48 -03:00
2022-04-29 23:14:24 -03:00
if not g_game.isOnline ( ) then
musicChannel : stop ( )
musicChannel : enqueue ( musicFilename , 3 )
end
2012-08-26 06:10:48 -03:00
end
2013-01-16 16:46:42 -02:00
function startup ( )
2022-04-29 23:14:24 -03:00
if musicChannel then
2021-04-02 21:35:34 +02:00
musicChannel : enqueue ( musicFilename , 3 )
2022-04-29 23:14:24 -03:00
connect ( g_game , {
2022-08-17 12:51:56 -03:00
onGameStart = function ( )
musicChannel : stop ( 3 )
end
2022-04-29 23:14:24 -03:00
} )
connect ( g_game , {
onGameEnd = function ( )
g_sounds.stopAll ( )
musicChannel : enqueue ( musicFilename , 3 )
end
} )
end
-- 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 (
2023-05-11 11:38:24 -03:00
' 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. ' )
2022-04-29 23:14:24 -03:00
end
-- Show entergame
if errmsg or errtitle then
local msgbox = displayErrorBox ( errtitle , errmsg )
2022-08-17 12:51:56 -03:00
msgbox.onOk = function ( )
EnterGame.firstShow ( )
end
2022-04-29 23:14:24 -03:00
else
EnterGame.firstShow ( )
end
2025-05-19 17:34:54 -04:00
if g_app.hasUpdater ( ) and g_sounds then
g_sounds.setAudioEnabled ( g_settings.getBoolean ( ' enableAudio ' ) )
end
2012-08-19 11:30:57 -03:00
end
2013-01-16 16:46:42 -02:00
function init ( )
2023-05-11 11:38:24 -03:00
if g_app.hasUpdater ( ) then
connect ( g_app , {
onUpdateFinished = startup ,
} )
2022-04-29 23:14:24 -03:00
else
2023-05-11 11:38:24 -03:00
connect ( g_app , {
onRun = startup ,
} )
2022-04-29 23:14:24 -03:00
end
2023-05-11 11:38:24 -03:00
if musicChannel then
g_sounds.preload ( musicFilename )
2022-04-29 23:14:24 -03:00
end
2012-01-06 07:35:48 -02:00
end
2013-01-16 16:46:42 -02:00
function terminate ( )
2023-05-11 11:38:24 -03:00
if g_app.hasUpdater ( ) then
disconnect ( g_app , {
onUpdateFinished = startup ,
} )
else
disconnect ( g_app , {
onRun = startup ,
} )
end
2022-08-17 12:51:56 -03:00
end