-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
362 lines (205 loc) · 6.13 KB
/
Copy pathinit.lua
File metadata and controls
362 lines (205 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local os = _tl_compat and _tl_compat.os or os; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table; love.filesystem.setRequirePath(love.filesystem.getRequirePath() .. ";?.lua;?/init.lua;scenes/nback3/?.lua")
require("globals")
require("menu-main")
require("common")
require("help")
require("languageselector")
require("love")
require("nbtypes")
require("pviewer")
require("tiledbackground")
local inspect = require("inspect")
local timer = require("Timer").new()
local keyconfig = require("keyconfig")
local i18n = require("i18n")
local linesbuf = require("kons").new()
local cam = require("camera").new()
local profiCam = require("camera").new()
local screenMode = "win"
local Resizable = {}
local to_resize = {}
function dispatchWindowResize(neww, newh)
for _, v in ipairs(to_resize) do
if v and v.resize then v:resize(neww, newh) end
end
end
local function quit()
SETTINGS.firstRun = false
writeSettings()
end
function loadLocales()
local files = love.filesystem.getDirectoryItems(SCENEPREFIX .. "locales")
print("locale files", inspect(files))
for _, v in ipairs(files) do
i18n.loadFile("locales/" .. v, function(path)
local chunk, errmsg = love.filesystem.load(SCENEPREFIX .. path)
if not chunk then
error(errmsg)
end
return chunk
end)
end
end
function setupLocale(locale)
print("setupLocale", locale)
i18n.setLocale(locale)
end
function bindKeys()
local kc = keyconfig
kc.bind("keypressed", { key = "2" }, function(sc)
linesbuf.show = not linesbuf.show
return false, sc
end, "show or hide debug output", "linesbufftoggle")
end
local subInitCounter = 0
function subInit()
bindKeys()
nback:init(SAVE_NAME)
pviewer:init(SAVE_NAME)
help:init()
print('main menu', mainMenu)
mainMenu:init()
mainMenu:clear()
mainMenu:addItem(i18n("mainMenu.play"), nback)
mainMenu:addItem(i18n("mainMenu.viewProgress"), pviewer)
mainMenu:addItem(i18n("mainMenu.help"), help)
if not ON_ANDROID then
mainMenu:addItem(i18n("mainMenu.exit"), function() love.event.quit() end)
end
subInitCounter = subInitCounter + 1
print('subInitCounter', subInitCounter)
end
local function init()
SETTINGS = readSettings()
print('settings:', inspect(SETTINGS))
loadLocales()
print("arg", inspect(arg))
local locale = "en"
if arg[1] then
locale = string.match(arg[1], "locale=(%S+)") or "en"
end
if SETTINGS.firstRun or PREVENTIVE_FIRST_RUN then
languageSelector = require("languageselector").new()
end
setupLocale(locale)
math.randomseed(os.time())
love.window.setTitle("nback")
subInit()
table.insert(to_resize, nback)
table.insert(to_resize, mainMenu)
table.insert(to_resize, pviewer)
table.insert(to_resize, help)
table.insert(to_resize, languageSelector)
table.insert(to_resize, tiledback)
if ON_ANDROID then
love.window.setMode(0, 0, { fullscreen = true })
cam = require("camera").new()
screenMode = "fs"
dispatchWindowResize(love.graphics.getDimensions())
end
linesbuf.show = false
end
function update(dt)
if languageSelector then
languageSelector:update(dt)
if languageSelector.locale then
setupLocale(languageSelector.locale)
subInit()
languageSelector = nil
end
else
mainMenu:update(dt)
timer:update(dt)
end
linesbuf:update()
end
local function keypressed(scancode)
if languageSelector and languageSelector.keypressed then
languageSelector:keypressed(scancode)
else
keyconfig.keypressed(scancode)
mainMenu:keypressed(scancode)
end
end
local function keyreleased(key)
mainMenu:keyreleased(key)
end
local function draw()
if languageSelector then
tiledback:draw()
languageSelector:draw()
else
cam:attach()
mainMenu:draw()
cam:detach()
end
linesbuf:pushi("FPS %d", love.timer.getFPS())
linesbuf:draw()
love.timer.sleep(0.01)
end
local function wheelmoved(_, y)
if y == 1 then
profiCam:zoom(0.98)
elseif y == -1 then
profiCam:zoom(1.02)
end
end
local function mousemoved(x, y, dx, dy, istouch)
if love.keyboard.isDown("lshift") and love.mouse.isDown(1) then
profiCam:move(-dx, -dy)
end
if languageSelector then
languageSelector:mousemoved(x, y, dx, dy, istouch)
else
mainMenu:mousemoved(x, y, dx, dy, istouch)
end
end
local function mousepressed(x, y, button, istouch)
if languageSelector then
languageSelector:mousepressed(x, y, button, istouch)
else
mainMenu:mousepressed(x, y, button, istouch)
end
end
local function mousereleased(x, y, button, istouch)
if languageSelector then
else
mainMenu:mousereleased(x, y, button, istouch)
end
end
local function touchpressed(id, x, y, dx, dy, pressure)
if languageSelector then
languageSelector:touchpressed(id, x, y)
else
mainMenu:touchpressed(id, x, y, dx, dy, pressure)
end
end
local function touchreleased(id, x, y, dx, dy, pressure)
if languageSelector then
languageSelector:touchreleased(id, x, y)
else
mainMenu:touchreleased(id, x, y, dx, dy, pressure)
end
end
local function touchmoved(id, x, y, dx, dy, pressure)
if languageSelector then
languageSelector:touchmoved(id, x, y)
else
mainMenu:touchmoved(id, x, y, dx, dy, pressure)
end
end
return {
init = init,
quit = quit,
draw = draw,
update = update,
keypressed = keypressed,
keyreleased = keyreleased,
mousemoved = mousemoved,
wheelmoved = wheelmoved,
mousereleased = mousereleased,
mousepressed = mousepressed,
touchpressed = touchpressed,
touchreleased = touchreleased,
touchmoved = touchmoved,
}