-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
executable file
·329 lines (273 loc) · 7.3 KB
/
main.lua
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
require 'retina'
local loader = require 'loader'
local processor = require 'gamesystem.imageprocessthread'
DEBUG = true
PROFILING = false
if DEBUG and PROFILING then
ProFi = require 'ProFi'
ProFi:start()
end
option = {
uifps = 30,
uidt = 1/30,
seperateUI = true,
shaderquality = 'HIGH',
texturequality = 'HIGH',
language = 'English',
retina = 1,
simplestencil = true,
}
hotkey = {
editor = 'p',
inventory = 'q',
run = 'lshift',
sneak = 'lctrl',
brief = 'b',
profile = 'i',
lli = 'l',
menu = 'escape',
cellphone = 'c',
}
gamesys = {}
function gamesys.push(sys,transtime)
table.insert(gamesys,sys)
loveframes.anim:easy(gamesys,'transtime',1,0,transtime)
sys.host = gamesys
end
function gamesys.pop(transtime)
-- loveframes.anim:easy(gamesys,'transtime',1,0,transtime)
-- sys.host = nil
return table.remove(gamesys,sys)
end
function gamesys.top()
return gamesys[#gamesys]
end
function gamesys.update(dt)
if gamesys.transtime > 0 and gamesys[#gamesys-1] then
gamesys[#gamesys-1]:update(dt)
end
gamesys[#gamesys]:update(dt)
end
function gamesys.draw()
if gamesys.transtime > 0 and gamesys[#gamesys-1] then
gamesys[#gamesys-1]:draw()
end
gamesys[#gamesys]:draw()
end
require 'middleclass'
local waits = require 'library.trigger'
local shader = require 'shader'
local graphics = require 'library.graphics'
sound = require 'library.sound'
Stateful = require"stateful"
local localization = require 'library.localization'
local essential = require 'library.essential'
local hotkey = require 'library.hotkey'
local img = essential.getImageTable()
local lfs = love.filesystem
local function _iterateAsset(f)
if lfs.isFile(f) then
if string.sub(f,#f-3) == '.png' then
--loader.newImage(img,f,f)
loader.newImage(img,f,f)
return
end
elseif lfs.isDirectory(f) then
for i,v in ipairs(lfs.enumerate(f)) do
_iterateAsset(f..'/'..v)
end
end
end
local function enumerateAssets()
local assetfolder = {'asset','animation','doodad','item','unit','dot.png','worldmap.png'}
while #assetfolder>0 do
local f = table.remove(assetfolder)
_iterateAsset(f)
end
end
local modalBackground
local finishedLoading
function love.load()
love.physics.setMeter(1)
graphics.load()
assert(graphics.canvas)
-- UI init --
if love.filesystem.isFile'option' then
local f = love.filesystem.read('option')
f = json.decode(f)
-- assert(f)
if f then essential.load(f) end
end
if love.filesystem.isFile'hotkey' then
local f = love.filesystem.read('hotkey')
f = json.decode(f)
-- assert(f)
if f then hotkey.load(f) end
end
if love.filesystem.isFile'graphics' then
local f = love.filesystem.read('graphics')
f = json.decode(f)
-- assert(f)
if f then graphics.load(f) end
end
localization.setLocalization(option.language)
require 'library.mathematic'
require 'ai'
require 'gameobject'
serial = require 'gamesystem.serial'
require 'gamesystem.controller'
require 'gamesystem.inventory'
require 'gamesystem.interactfunc'
essential.setTextureQuality()
shader.setQuality()
-- initFont()
sound.load()
require 'loveframes'
-- preload all files
enumerateAssets()
loader.start(function()
finishedLoading = true
end)
-- load the examples menu
local splash = true
local intro = true
-- load the sin selector menu
local mainmenu = require 'gamesystem.mainmenu'
if splash then
local splashscreen = require 'gamesystem.splashscreen'
splashscreen:load()
splashscreen.OnFinish = function()
if intro then
local intro = require 'gamesystem.intro'
intro:load()
intro.OnFinish = function()
mainmenu:loadmain()
gamesys.push(mainmenu)
end
gamesys.push(intro)
else
mainmenu:loadmain()
gamesys.push(mainmenu)
end
end
gamesys.push(splashscreen)
else
mainmenu:loadmain()
gamesys.push(mainmenu)
end
if DEBUG then
loveframes.config["DEBUG"] = true
else
loveframes.config["DEBUG"] = false
end
loveframes.config["DEBUG"] = false
-- loveframes.debug.SkinSelector()
-- loveframes.debug.ExamplesMenu()
-- gra.setBackgroundColor(255,255,255,0)
modalBackground = loveframes.Create'frame'
modalBackground:setSize(screen.width,screen.height)
modalBackground:setPos(0,0)
modalBackground:SetVisible(false)
modalBackground.gaussianblur_intensity = 10
love.graphics.setIcon(requireImage'icon.png')
sound.playMusic('sound/music/adagio.ogg')
end
function love.mousepressed(x, y, button)
if option.retina then
x,y = x/option.retina,y/option.retina
end
gamesys[#gamesys]:mousepressed(x,y,button)
loveframes.mousepressed(x, y, button)
end
local mouseposition = love.mouse.getPosition
function love.mouse.getPosition()
local x,y = mouseposition()
if option.retina then
x,y = x/option.retina,y/option.retina
end
return x,y
end
function love.mousereleased(x, y, button)
if option.retina then
x,y = x/option.retina,y/option.retina
end
gamesys[#gamesys]:mousereleased(x,y,button)
loveframes.mousereleased(x, y, button)
end
function love.keypressed(key, unicode)
gamesys[#gamesys]:keypressed(key,unicode)
loveframes.keypressed(key, unicode)
if key == "`" then
local debug = loveframes.config["DEBUG"]
if debug == true then
loveframes.config["DEBUG"] = false
else
loveframes.config["DEBUG"] = true
end
end
end
function love.keyreleased(key)
gamesys[#gamesys]:keyreleased(key)
loveframes.keyreleased(key)
end
local ui_elapse = 0
local refreshUI = true
function love.update(dt)
if not finishedLoading then
loader.update() -- You must do this on each iteration until all resources are loaded
end
processor.update()
waits.update()
if option.seperateUI then
ui_elapse = ui_elapse + dt
if ui_elapse > option.uidt then
loveframes.update(ui_elapse)
ui_elapse = ui_elapse - option.uidt
refreshUI = true
end
else
loveframes.update(dt)
end
gamesys.update(dt)
sound.cleanUp()
-- print(processor.getPercent())
end
function love.draw()
if loveframes.modalobject then
-- filters.gaussianblur.conf(modalBackground)
-- filters.gaussianblur.predraw(modalBackground)
end
gamesys.draw()
if loveframes.modalobject then
-- filters.gaussianblur.postdraw(modalBackground)
end
if option.seperateUI then
if refreshUI then
graphics.canvas.c:clear()
gra.setColor(255,255,255)
gra.setCanvas(graphics.canvas.c)
loveframes.draw()
gra.setCanvas()
refreshUI = false
end
gra.setColor(255,255,255)
gra.setBlendMode'premultiplied'
gra.draw(graphics.canvas.c)
gra.setBlendMode'alpha'
else
gra.setColor(255,255,255)
loveframes.draw()
end
gra.setColor(0, 0, 0, 255)
pn("Press \"`\" to toggle debug mode.", 210, 7)
gra.setColor(255, 255, 255, 255)
pn("Press \"`\" to toggle debug mode.", 210, 5)
if not finishedLoading then
gra.setFont(font.smallfont)
local percent = 0
if loader.resourceCount ~= 0 then percent = loader.loadedCount / loader.resourceCount end
gra.print(("Loading Assets.. %d%%"):format(percent*100), 100, 100)
end
local fps = love.timer.getFPS()
gra.setCaption(string.format(LocalizedString"Path of Eternity Privilege Zero // frame time: %.2fms (%d fps).", 1000/fps, fps))
end