-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
497 lines (416 loc) · 11 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
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
PLUMINO_VERSION = {9, 1}
PLUMINO_VERSION_CODENAME = 'Replay Update'
PLUMINO_DEV_BUILD = false
window = {}
window.w, window.h, window.mode = love.window.getMode()
MAX_FPS = 60
local next_time = love.timer.getTime()
modeNames = {
"marathon",
"20g_marathon",
"sprint",
"ionlysprint",
"sinemarathon",
"testmode",
"squirrel",
"marathon_nodelays",
"beat"
}
-- EDIT THIS TABLE TO LOAD MORE MODES.
rotationSystems = {
"ars",
"srs",
"ors",
"flashlight",
"incremental",
"h",
"bruh"
}
-- EDIT THIS TABLE TO LOAD ROTATION SYSTEMS.
randomisers = {
"tgm",
"onlyi",
"bag",
"memoryless"
}
-- EDIT THIS TABLE TO LOAD RANDOMISERS.
pluginNames = {
"mix"
}
-- you know the drill
CLEAR_SHADER_ON_DRAW = false
autoShaderDefs = {
{'frag', 'f_bw'},
{'frag', 'f_nop'},
{'frag', 'f_hell'},
{'frag', 'f_yes'},
{'frag', 'f_pixel'},
{'frag', 'f_yesno'},
{'vert', 'v_yes'},
{'vert', 'v_nop'},
{'vert', 'v_tan'}
}
manualShaderDefs = {
wibbry = {'frag/f_yes.frag', 'vert/v_yes.vert'}
}
piece = {}
json = require "lib/json"
inspect = require "lib/inspect"
require "util"
require "stuff/skin"
require "game"
require "stuff/ui"
require "states/options/main"
local logistatus, logierr = pcall(function() logitech = require "lib/logitech" end) -- experimental
local libstatus, liberr = pcall(function() discord = require "lib/discordRPC" end)
if logistatus then
logitech = require "lib/logitech"
else
print("[WARNING!] Could not load Logitech lighting library: "..logierr)
print("[WARNING!] This is normal if using the .love file.")
end
if libstatus then
discord = require "lib/discordRPC"
else
print("[WARNING!] Could not load Discord rich presence: "..liberr)
print("[WARNING!] This is normal if using the .love file.")
end
local presence = {}
function updatePresence(p)
presence = p
nextPresence = 0
end
local nextPresence = 0
game.font = {
big = love.graphics.newFont("assets/font/standard.ttf", 36),
std = love.graphics.newFont("assets/font/standard.ttf", 14),
med = love.graphics.newFont("assets/font/standard.ttf", 20),
med2 = love.graphics.newFont("assets/font/standard.ttf", 24),
med3 = love.graphics.newFont("assets/font/standard.ttf", 26)
}
game.gfx = {
intro = "arikek.png",
title = "title.png",
dev = "dev.png",
poweredby = "poweredby.png",
logo = "logo.png"
}
game.background = {
"bg1.png",
"bg2.png",
"bg3.png",
"bg4.png",
"bg5.png",
"bg6.png",
"bg7.png",
"bg8.png",
"bg9.png",
"bg10.png",
"bg11.png",
"bg12.png",
"bg13.png"
}
game.bgm = {
"bgm1.ogg"
}
game.mino = {
"1.png",
"2.png",
"2_alt.png",
"3.png",
"agc.png",
"flat.png",
"flat_bright.png"
}
game.minoName = {
"Default",
"Bricks",
"Bricks (alternate)",
"Retro",
"Classic",
"Flat (dark)",
"Flat (bright)"
}
modes = {}
plugins = {}
rotations = {}
randomiser = {}
shaders = {}
currentShader = nil
local shaderTimeStart = love.timer.getTime()
shaderTime = 0
game.config = {
currentShader = nil
}
game.sfx = {
ready = "ready.wav",
go = "go.wav",
credit = "credit.wav",
lock = "lock.wav",
gameover = "gameover.wav",
levelup = "levelup.ogg"
}
game.clearaudio = {
"1.wav", "2.wav", "3.wav", "4.wav"
}
game.skins = {
"Default"
}
game.skinIndex = 1
screen = love.graphics.newCanvas() -- testing this
screenX = 0
screenY = 0
screenCol = {1, 1, 1, 1}
controller = false
controllers = love.joystick.getJoysticks()
function doControllerCheck()
local c, cs = false, love.joystick.getJoysticks()
for i, pad in ipairs(cs) do
c = true
print(('Found a controller: %s'):format(pad:getName()))
end
print(('Controller status: %s'):format(tostring(c)))
controller, controllers = c, cs
end
doControllerCheck()
love.joystickadded, love.joystickremoved = doControllerCheck, doControllerCheck
function game:switchState(name, args)
if not game.states[name] then
error("Could not switch to state "..name)
end
if game.state and game.state.stop then
game.state:stop()
end
game.stateName = name
game.state = game.states[name]
if game.state.init then
game.state:init(args)
end
-- RESET THE SCREEN VARIABLES
screenX = 0
screenY = 0
screenCol = {1, 1, 1, 1}
love.window.setTitle("Plumino²: "..name)
end
function game:setShader(name)
if name == nil then
currentShader = nil
return
end
if not shaders[name] then
error('Cannot find shader '..name)
end
currentShader = name
end
local files = {
"game",
"menu",
"splash",
"title",
"credits",
"keyconfig",
"options",
"controllerconfig",
"replay"
}
gameToLogitechKeys = {
up = "ARROW_UP",
down = "ARROW_DOWN",
left = "ARROW_LEFT",
right = "ARROW_RIGHT",
["return"] = "ENTER"
}
local threadCode = [[
require 'love.timer'
local keys, gameToLogitechKeys = ...
for j, i in pairs(keys) do
local key = gameToLogitechKeys[i] or i:upper()
print(('[Thread] Setting %s to on'):format(key))
love.thread.getChannel('lights'):push({key, 100, 100, 100})
love.timer.sleep(0.2)
end
]]
startupLightEffectThread = love.thread.newThread(threadCode)
function killLighting()
if not logitech then return end
for _, i in pairs(logitech.keys) do
logitech.setLightingForKey(i, 0, 0, 0)
end
end
function love.load(args)
if discord then
discord.initialize("585884186188054535", true) -- DISCORD RICH PRESENCE
end
for _, i in pairs(files) do -- handle state loading
game.states[i] = require("./states/"..i)
end
for _, i in pairs(modeNames) do -- handle mode loading
modes[i] = require("./mode/"..i)
end
for _, i in pairs(rotationSystems) do -- handle rotsys loading
require("./rotsys/"..i)
end
for _, i in pairs(randomisers) do -- handle randomiser loading
require("./randomiser/"..i)
end
for _, i in pairs(autoShaderDefs) do -- handle shader loading
shaders[i[2]] = love.graphics.newShader(i[1]..'/'..i[2]..'.'..i[1])
end
for i, j in pairs(manualShaderDefs) do
shaders[i] = love.graphics.newShader(unpack(j))
end
for _, i in pairs(pluginNames) do
plugins[i] = require('./plugins/'..i)
plugins[i].enabled = false
end
-- SKIN SYSTEM GOES HERE
for p, f in pairs(game.gfx) do -- handle gfx loading
game.gfx[p] = love.graphics.newImage("assets/gfx/"..f)
end
local fs = love.filesystem.getDirectoryItems('assets/skins')
for _, i in ipairs(fs) do
print('found skin: '..i)
if i ~= 'Default' then
table.insert(game.skins, i)
end
end
skin:load('Default')
local runInputConfig = false
if love.filesystem then
local c, e = love.filesystem.read("keys.psv")
if c == nil then
print('Input file load failed. Sending player to configurator.')
runInputConfig = true
else
local t = json.decode(c)
game.keyMap = deepcopy(t)
end
local p, r = love.filesystem.read('controller.psv')
if p == nil then
print('Controller input load failed. Ignoring.')
else
local t = json.decode(p)
game.controllerMap = deepcopy(t)
end
local n, m = love.filesystem.read('config.json')
if n == nil then
print('Config load failed. Ignoring.')
else
local t = json.decode(n)
game.config = t
end
end
if logitech then
logitech.init()
love.timer.sleep(0.1) -- give it a sec to init
print('[Logitech] Initialised successfully? '..tostring(logitech.initialised))
startupLightEffectThread:start(game.keyMap, gameToLogitechKeys)
end
if args[1] then
game:switchState('replay', {args[1], true})
return
end
if runInputConfig then
game:switchState("keyconfig", {"splash"})
else
game:switchState("splash")
end
game:setShader(game.config.currentShader)
end
function love.update(dt)
shaderTime = love.timer.getTime() - shaderTimeStart
if shaders[currentShader] and shaders[currentShader]:hasUniform('time') then
shaders[currentShader]:send('time', shaderTime)
end
local lightMessage = love.thread.getChannel('lights'):pop()
if lightMessage and logitech then
logitech.setLightingForKey(unpack(lightMessage))
end
if game.playing and game.replayMode then
game:updateReplayKeys()
end
game:updateKeys()
game:checkJustPressed()
game:doInput()
if game.state and game.state.update then
game.state:update(dt)
end
if discord then
if game.mode and game.mode.getPresenceText then
presence.largeImageText = game.mode:getPresenceText()
end
if nextPresence < love.timer.getTime() then
discord.updatePresence(presence)
nextPresence = love.timer.getTime() + 2.0
end
discord.runCallbacks()
end
next_time = next_time + 1/MAX_FPS
end
function love.quit()
if discord then
discord.shutdown()
end
if logitech then
print('[Logitech] Shutting down.')
logitech.shutdown()
end
end
if discord then
function discord.ready(uid, uname, discrim, avy)
print(string.format("[Discord RPC] Ready! Logged in as %s#%s (%s).", uname, discrim, uid))
end
end
function love.draw()
if CLEAR_SHADER_ON_DRAW then
love.graphics.setShader()
end
love.graphics.setCanvas(screen)
love.graphics.clear()
love.graphics.setBlendMode("alpha")
if game.state and game.state.draw then
game.state:draw()
end
love.graphics.setFont(game.font.med)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print(tostring(love.timer.getFPS()).."/"..MAX_FPS.." FPS", 0, 0)
if shaders[currentShader] then
love.graphics.setShader(shaders[currentShader])
end
love.graphics.setCanvas()
love.graphics.setColor(unpack(screenCol))
love.graphics.setBlendMode("alpha", "premultiplied")
love.graphics.draw(screen, screenX, screenY)
local current_time = love.timer.getTime()
if next_time <= current_time then
next_time = current_time
return
end
love.timer.sleep(next_time - current_time)
end
function love.keypressed(k, sc, r)
--game:keyDown(k, sc, r)
game:replayKeyDown(k, sc, r)
if game.state and game.state.keyDown then
game.state:keyDown(k, sc, r)
end
game:doAltInput()
end
function love.gamepadpressed(p, b)
if game.state and game.state.padDown then
game.state:padDown(b)
end
game:doAltInput()
end
function love.gamepadreleased(p, b)
if game.state and game.state.padUp then
game.state:padUp(b)
end
end
function love.keyreleased(k, sc)
--game:keyUp(k, sc)
game:replayKeyUp(k, sc)
if game.state and game.state.keyUp then
game.state:keyUp(k, sc)
end
end