otclient-redemption/modules/client/client.lua

83 lines
2 KiB
Lua
Raw Permalink Normal View History

local musicFilename = 'sounds/startup'
local musicChannel = nil
if g_sounds then
musicChannel = g_sounds.getChannel(SoundChannels.Music)
end
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
function startup()
2022-04-29 23:14:24 -03:00
if musicChannel then
musicChannel:enqueue(musicFilename, 3)
2022-04-29 23:14:24 -03:00
connect(g_game, {
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,\nthus the performance will be really bad.\nPlease 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)
msgbox.onOk = function()
EnterGame.firstShow()
end
2022-04-29 23:14:24 -03:00
else
EnterGame.firstShow()
end
if g_app.hasUpdater() and g_sounds then
g_sounds.setAudioEnabled(g_settings.getBoolean('enableAudio'))
end
end
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
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
end