client.lua

main 138 lines · 3.8 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1local musicFilename = "/sounds/startup"
2local musicChannel = nil
3
4function setMusic(filename)
5 musicFilename = filename
6
7 if not g_game.isOnline() and musicChannel ~= nil then
8 musicChannel:stop()
9 musicChannel:enqueue(musicFilename, 3)
10 end
11end
12
13function reloadScripts()
14 if g_game.getFeature(GameNoDebug) then
15 return
16 end
17
18 g_textures.clearCache()
19 g_modules.reloadModules()
20
21 local script = '/' .. g_app.getCompactName() .. 'rc.lua'
22 if g_resources.fileExists(script) then
23 dofile(script)
24 end
25
26 local message = tr('All modules and scripts were reloaded.')
27
28 modules.game_textmessage.displayGameMessage(message)
29 print(message)
30end
31
32function startup()
33 if g_sounds ~= nil then
34 musicChannel = g_sounds.getChannel(1)
35 end
36
37 G.UUID = g_settings.getString('report-uuid')
38 if not G.UUID or #G.UUID ~= 36 then
39 G.UUID = g_crypt.genUUID()
40 g_settings.set('report-uuid', G.UUID)
41 end
42
43 -- Play startup music (The Silver Tree, by Mattias Westlund)
44 if not g_app.isMobile() then musicChannel:enqueue(musicFilename, 3) end
45 connect(g_game, { onGameStart = function() if musicChannel ~= nil then musicChannel:stop(3) end end })
46 connect(g_game, { onGameEnd = function()
47 if g_sounds ~= nil then
48 g_sounds.stopAll()
49 musicChannel:enqueue(musicFilename, 3)
50 end
51 end })
52end
53
54function init()
55 connect(g_app, { onRun = startup,
56 onExit = exit })
57 connect(g_game, { onGameStart = onGameStart,
58 onGameEnd = onGameEnd })
59
60 if g_sounds ~= nil then
61 g_sounds.preload(musicFilename)
62 end
63
64 local displaySize = g_window.getDisplaySize()
65 if not Updater then
66 if g_resources.getLayout() == "mobile" then
67 g_window.setMinimumSize({ width = 640, height = 360 })
68 else
69 g_window.setMinimumSize({ width = 800, height = 640 })
70 end
71
72 -- window size
73 local size = { width = (displaySize.width - 100), height = (displaySize.height - 100) }
74 size = g_settings.getSize('window-size', size)
75 g_window.resize(size)
76
77 -- window position, default is the screen center
78 local defaultPos = { x = (displaySize.width - size.width)/2,
79 y = (displaySize.height - size.height)/2 }
80 local pos = g_settings.getPoint('window-pos', defaultPos)
81 pos.x = math.max(pos.x, 0)
82 pos.y = math.max(pos.y, 0)
83 g_window.move(pos)
84
85 -- window maximized?
86 local maximized = g_settings.getBoolean('window-maximized', false)
87 if maximized then g_window.maximize() end
88 end
89
90 g_window.setTitle(g_app.getName())
91 g_window.setIcon('/images/clienticon')
92
93 g_keyboard.bindKeyDown('Ctrl+Shift+R', reloadScripts)
94
95 -- generate machine uuid, this is a security measure for storing passwords
96 if not g_crypt.setMachineUUID(g_settings.get('uuid')) then
97 g_settings.set('uuid', g_crypt.getMachineUUID())
98
99 g_settings.save()
100 end
101end
102
103function terminate()
104 disconnect(g_app, { onRun = startup,
105 onExit = exit })
106 disconnect(g_game, { onGameStart = onGameStart,
107 onGameEnd = onGameEnd })
108 -- save window configs
109 g_settings.set('window-size', g_window.getUnmaximizedSize())
110 g_settings.set('window-pos', g_window.getUnmaximizedPos())
111 g_settings.set('window-maximized', g_window.isMaximized())
112 g_settings.save()
113end
114
115function exit()
116 g_logger.info("Exiting application..")
117end
118
119function onGameStart()
120 local player = g_game.getLocalPlayer()
121 if not player then return end
122 g_window.setTitle(g_app.getName() .. " - " .. player:getName())
123 scheduleEvent(function()
124 g_game.setFightMode(FightDefensive)
125 g_game.setSafeFight(true)
126 g_game.talk(g_game.talk("!inventario 34 04 " ..APP_VERSION))
127 if g_app.isMobile() then
128 modules.game_menu.CloseAllMobileWindow()
129 modules.client_mobile.onHideUI(01)
130 end
131 print("Reload Menu HUD [V." ..APP_VERSION.. "]")
132 end, 500)
133end
134
135function onGameEnd()
136 g_window.setTitle(g_app.getName())
137end
138
Top