-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.lua
286 lines (283 loc) · 9.59 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
-- # ____ __ __ #
-- # / __ \__ ______ _/ /__________ ______/ /__ #
-- # / / / / / / / __ `/ __/ ___/ __ `/ ___/ //_/ #
-- # / /_/ / /_/ / /_/ / /_/ / / /_/ / /__/ ,< #
-- # \___\_\__,_/\__,_/\__/_/ \__,_/\___/_/|_| #
-- # #
-- Quatrack is a music game
-- Creating issue on github is welcomed
-- Some coding style:
-- 1. I made a framework called Zenitha, *most* code in Zenitha are not directly relevant to game;
-- 2. "xxx" are texts for reading by player, 'xxx' are string values just used in program;
-- 3. Some goto statement are used for better performance. All goto-labes have detailed names so don't be afraid;
-- 4. Except "gcinfo" function of lua itself, other "gc" are short for "graphics";
-------------------------------------------------------------
-- Load Zenitha
require("Zenitha")
DEBUG.checkLoadTime("Load Zenitha")
--------------------------------------------------------------
-- Global Vars Declaration
VERSION=require"version"
FNNS=SYSTEM:find'\79\83'-- What does FNSF stand for? IDK so don't ask me lol
SFXPACKS={}
VOCPACKS={}
FIRSTLAUNCH=false
--------------------------------------------------------------
-- System setting
math.randomseed(os.time()*626)
love.setDeprecationOutput(false)
love.keyboard.setTextInput(false)
--------------------------------------------------------------
-- Create directories
for _,v in next,{'conf','record','replay','cache','lib','songs'} do
local info=love.filesystem.getInfo(v)
if not info then
love.filesystem.createDirectory(v)
elseif info.type~='directory' then
love.filesystem.remove(v)
love.filesystem.createDirectory(v)
end
end
--------------------------------------------------------------
-- Load modules
CHAR=require'assets.char'
require'assets.gameTables'
require'assets.gameFuncs'
DEBUG.checkLoadTime("Load Assets")
--------------------------------------------------------------
-- Config Zenitha
STRING.install()
ZENITHA.setAppName('Quatrack')
ZENITHA.setVersionText(VERSION.string)
ZENITHA.setFirstScene('load')
function ZENITHA.globalEvent.drawCursor(_,x,y)
if not SETTINGS.sysCursor then
GC.setColor(1,1,1)
GC.setLineWidth(2)
GC.translate(x,y)
GC.rotate(love.timer.getTime()%6.283185307179586)
GC.circle('line',0,0,10)
if love.mouse.isDown(1) then GC.circle('line',0,0,6) end
if love.mouse.isDown(2) then GC.circle('fill',0,0,4) end
if love.mouse.isDown(3) then GC.line(-6,-6,6,6) GC.line(-6,6,6,-6) end
GC.setColor(1,1,1,.626)
GC.line(0,-20,0,20)
GC.line(-20,0,20,0)
end
end
local _keyDown_orig=ZENITHA.globalEvent.keyDown
function ZENITHA.globalEvent.keyDown(key,isRep)
if _keyDown_orig(key,isRep) then return true end
if key=='f11' then
SETTINGS.fullscreen=not SETTINGS.fullscreen
saveSettings()
return true
end
end
ZENITHA.setDebugInfo{
{"Cache",gcinfo},
{"Tasks",TASK.getCount},
{"Audios",love.audio.getSourceCount},
}
do-- OnFocus
local function task_autoSoundOff()
while true do
coroutine.yield()
local v=love.audio.getVolume()
love.audio.setVolume(math.max(v-.05,0))
if v==0 then return end
end
end
local function task_autoSoundOn()
while true do
coroutine.yield()
local v=love.audio.getVolume()
if v<SETTINGS.mainVol then
love.audio.setVolume(math.min(v+.05,SETTINGS.mainVol,1))
else
return
end
end
end
function ZENITHA.globalEvent.focus(f)
if f then
applyFPS(SCN.cur=='game')
love.timer.step()
if SETTINGS.autoMute then
TASK.removeTask_code(task_autoSoundOff)
TASK.new(task_autoSoundOn)
end
else
if SETTINGS.slowUnfocus then
ZENITHA.setMaxFPS(math.min(SETTINGS.maxFPS,90))
ZENITHA.setDrawFreq(15)
end
if SETTINGS.autoMute then
TASK.removeTask_code(task_autoSoundOn)
TASK.new(task_autoSoundOff)
end
end
end
end
function ZENITHA.globalEvent.drawSysInfo()
if not SETTINGS.powerInfo then return end
GC.translate(SCR.safeX,0)
GC.setColor(0,0,0,.26)
GC.rectangle('fill',0,0,107,26)
local state,pow=love.system.getPowerInfo()
if state~='unknown' then
GC.setLineWidth(2)
if state=='nobattery' then
GC.setColor(1,1,1)
GC.line(74,5,100,22)
elseif pow then
if state=='charging' then GC.setColor(0,1,0)
elseif pow>50 then GC.setColor(1,1,1)
elseif pow>26 then GC.setColor(1,1,0)
elseif pow==26 then GC.setColor(.5,0,1)
else GC.setColor(1,0,0)
end
GC.rectangle('fill',76,6,pow*.22,14)
if pow<100 then
FONT.set(15,'_basic')
GC.shadedPrint(pow,88,5,'center',1,8)
end
end
GC.rectangle('line',74,4,26,18)
GC.rectangle('fill',102,6,2,14)
end
FONT.set(25,'_basic')
GC.print(os.date("%H:%M"),3,0,nil,.9)
end
FONT.setDefaultFallback('symbols')
FONT.setDefaultFont('norm')
FONT.setFallback('mono','norm')
FONT.load{
mono='assets/font/monospaced.ttf',
bold='assets/font/Inter-ExtraBold.otf',
norm='assets/font/Inter-Regular.otf',
thin='assets/font/Inter-SemiBold.otf',
symbols='assets/font/symbols.otf',
}
SCR.setSize(1280,720)
BGM.setDefault('title')
BGM.setMaxSources(5)
VOC.setDiversion(.62)
WIDGET._prototype.button.sound_press='button'
WIDGET._prototype.checkBox.sound_on='check'
WIDGET._prototype.checkBox.sound_off='uncheck'
WIDGET._prototype.selector.sound_press='selector'
WIDGET._prototype.listBox.sound_select='click'
WIDGET._prototype.inputBox.sound_input='hit5'
WIDGET._prototype.inputBox.sound_bksp='hit3'
WIDGET._prototype.inputBox.sound_bksp='hold1'
WIDGET._prototype.inputBox.sound_clear='hold4'
WIDGET._prototype.textBox.sound_clear='hold4'
WIDGET._prototype.slider.numFontType='norm'
WIDGET._prototype.slider_fill.lineWidth=2
WIDGET._prototype.switch.labelPos='left'
WIDGET._prototype.button.lineWidth=2
WIDGET._prototype.button_fill.textColor=TABLE.copy(COLOR.D)
LANG.add{
zh='assets/language/lang_zh.lua',
en='assets/language/lang_en.lua',
}
LANG.setDefault('zh')
--[Attention] Not loading IMG/SFX/BGM files here, just read file paths
IMG.init{
logo_full='assets/image/logo_full.png',
logo_color='assets/image/logo_color.png',
z={
character='assets/image/z_character.png',
screen1='assets/image/z_screen1.png',
screen2='assets/image/z_screen2.png',
particle1='assets/image/z_particle1.png',
particle2='assets/image/z_particle2.png',
particle3='assets/image/z_particle3.png',
particle4='assets/image/z_particle4.png',
}
}
SFX.load((function()
local path='assets/effect/chiptune/'
local L={}
for _,v in next,love.filesystem.getDirectoryItems(path) do
if FILE.isSafe(path..v) then
L[v:sub(1,-5)]=path..v
end
end
return L
end)())
BGM.load((function()
local L={}
for _,v in next,love.filesystem.getDirectoryItems('assets/music') do
if FILE.isSafe('assets/music/'..v) then
L[v:sub(1,-5)]='assets/music/'..v
end
end
return L
end)())
VOC.init{}
DEBUG.checkLoadTime("Configuring Zenitha")
--------------------------------------------------------------
-- Load SOURCE ONLY resources
SHADER={}
for _,v in next,love.filesystem.getDirectoryItems('assets/shader') do
if FILE.isSafe('assets/shader/'..v) then
local name=v:sub(1,-6)
SHADER[name]=love.graphics.newShader('assets/shader/'..name..'.glsl')
end
end
for _,v in next,love.filesystem.getDirectoryItems('assets/background') do
if FILE.isSafe('assets/background/'..v) and v:sub(-3)=='lua' then
local name=v:sub(1,-5)
BG.add(name,require('assets/background/'..name))
end
end
for _,v in next,love.filesystem.getDirectoryItems('assets/scene') do
if FILE.isSafe('assets/scene/'..v) then
local sceneName=v:sub(1,-5)
SCN.add(sceneName,require('assets/scene/'..sceneName))
end
end
DEBUG.checkLoadTime("Load SDs+BGs+SCNs")
--------------------------------------------------------------
-- Load settings and statistics
local setting=FILE.load('conf/settings','-json -canskip')
if setting then
for k,v in next,setting do SETTINGS.__data[k]=v end
end
for k,v in next,SETTINGS.__data do
SETTINGS.__data[k]=nil
SETTINGS[k]=v
end
TABLE.update(STAT,loadFile('conf/data','-canSkip') or {})
local savedKey=loadFile('conf/key','-canSkip')
if savedKey then
KEY_MAP=savedKey
KEY_MAP_inv:_update()
end
--------------------------------------------------------------
-- First start
FIRSTLAUNCH=STAT.run==0
if FIRSTLAUNCH and MOBILE then
SETTINGS.cleanCanvas=true
SETTINGS.scaleX=1.3
SETTINGS.trackW=1.3
end
-- Update savedata
do
SETTINGS.drawRate=SETTINGS.drawRate or SETTINGS.frameMul
STAT.hits=nil
SETTINGS.frameMul=nil
love.filesystem.remove('progress')
if STAT.version~=VERSION.code or not love.filesystem.getInfo('songs/readme.txt','file') then
love.filesystem.write('songs/readme.txt',love.filesystem.read('assets/language/readme.txt'))
STAT.version=VERSION.code
saveStats()
end
end
DEBUG.checkLoadTime("Load savedata")
--------------------------------------------------------------
DEBUG.logLoadTime()
--------------------------------------------------------------
-- Apply system setting