-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathscene.lua
2881 lines (2581 loc) · 108 KB
/
scene.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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local scene = {}
window_dir = 0
mask_shader = pcallNewShader[[
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
vec4 tx = Texel(texture, texture_coords).rgba;
if (tx.rgb == vec3(0.0) || tx.a == 0) {
// a discarded pixel wont be applied as the stencil.
discard;
}
return vec4(1.0);
}
]]
paletteshader_0 = pcallNewShader[[
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
vec4 texturecolor = Texel(texture, texture_coords);
texturecolor = texturecolor * color;
number r = texturecolor.r;
number g = texturecolor.g;
number b = texturecolor.b;
return vec4(r, g, b, texturecolor.a);
}
]]
xwxShader = pcallNewShader[[
extern number time;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec2 newCoord = texture_coords;
float amt = 0.4;
newCoord.x = newCoord.x - (amt/2) + (fract(sin(dot(vec2(texture_coords.y, time), vec2(12.9898,78.233))) * 43758.5453) * amt/2);
vec4 pixel = Texel(texture, newCoord ); //This is the current pixel color
return pixel * color;
}
]]
--local paletteshader_autumn = love.graphics.newShader("paletteshader_autumn.txt")
--local paletteshader_dunno = love.graphics.newShader("paletteshader_dunno.txt")
local shader_zawarudo = pcallNewShader("shader_pucker.txt")
local level_shader = paletteshader_0
local doin_the_world = false
local shader_time = 0
local particle_timers = {}
local canv = love.graphics.newCanvas(love.graphics.getWidth(), love.graphics.getHeight())
local last_width,last_height = love.graphics.getWidth(),love.graphics.getHeight()
local viewport
local displaywords = false
local stack_box, stack_font
local pathlock_box, pathlock_font
local initialwindoposition
stopwatch = nil
drag_units = {}
mous_for_drag_unit = {}
initialxy_for_drag_unit = {}
local sessionseed
local buttons = {}--{"resume", "editor", "exit", "restart"}
local darken = nil
local button_last_y = 0
pause = false
selected_pause_button = 1
doing_rhythm_turn = false
function scene.load()
sessionseed = math.random(0,100000000)/100000000
repeat_timers = {}
key_down = {}
selector_open = false
stack_box = {x = 0, y = 0, scale = 0, units = {}, enabled = false}
pathlock_box = {x = 0, y = 0, scale = 0, enabled = false}
stack_font = love.graphics.newFont(12)
stack_font:setFilter("nearest","nearest")
pathlock_font = love.graphics.newFont(16)
drag_units = {}
mous_for_drag_unit = {}
initialxy_for_drag_unit = {}
scene.resetStuff()
local now = os.time(os.date("*t"))
presence = {
state = "ingame",
details = "playing the gam",
largeImageKey = "cover",
largeimageText = "bab be u",
smallImageKey = "icon",
smallImageText = "bab",
startTimestamp = now
}
nextPresenceUpdate = 0
if level_name then
presence["details"] = "playing level: "..level_name
end
mouse_grabbed = false
love.mouse.setGrabbed(false)
-- mobile buttons
local screenwidth = love.graphics.getWidth()
local screenheight = love.graphics.getHeight()
local twelfth = screenwidth/12
mobile_controls_activekeys = "wasd"
gooi.newButton({text = "",x = 10*twelfth,y = screenheight-3*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(0,-1,mobile_controls_activekeys) end):setBGImage(sprites["ui/arrow up"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 11*twelfth,y = screenheight-2*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(1,0,mobile_controls_activekeys) end):setBGImage(sprites["ui/arrow right"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 10*twelfth,y = screenheight-1*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(0,1,mobile_controls_activekeys) end):setBGImage(sprites["ui/arrow down"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 9*twelfth,y = screenheight-2*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(-1,0,mobile_controls_activekeys) end):setBGImage(sprites["ui/arrow left"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 11*twelfth,y = screenheight-3*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(1,-1,mobile_controls_activekeys) end):setBGImage(sprites["ui/arrow ur"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 11*twelfth,y = screenheight-1*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(1,1,mobile_controls_activekeys) end):setBGImage(sprites["ui/arrow dr"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 9*twelfth,y = screenheight-1*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(-1,1,mobile_controls_activekeys) end):setBGImage(sprites["ui/arrow dl"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 9*twelfth,y = screenheight-3*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(-1,-1,mobile_controls_activekeys) end):setBGImage(sprites["ui/arrow ul"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 10*twelfth,y = screenheight-2*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(0,0,mobile_controls_activekeys) end):setBGImage(sprites["ui/square"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 9.25*twelfth,y = 0.25*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(0, 0, "undo") end):setBGImage(sprites["ui/undo"]):bg({0, 0, 0, 0})
gooi.newButton({text = "",x = 10.75*twelfth,y = 0.25*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) scene.resetStuff() end):setBGImage(sprites["ui/reset"]):bg({0, 0, 0, 0})
mobile_controls_timeless = gooi.newButton({text = "",x = 10*twelfth,y = 1.5*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c) doOneMove(0, 0, "e") end):setBGImage(sprites["ui/timestop"]):bg({0, 0, 0, 0})
mobile_controls_p1 = gooi.newButton({text = "",x = 9*twelfth,y = screenheight-4.15*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c)
mobile_controls_activekeys = "wasd"
mobile_controls_p1:setBounds(9*twelfth, screenheight-4.15*twelfth)
mobile_controls_p2:setBounds(10*twelfth, screenheight-4.25*twelfth)
mobile_controls_p3:setBounds(11*twelfth, screenheight-4.25*twelfth)
end):setBGImage(sprites["ui_1"]):bg({0, 0, 0, 0})
mobile_controls_p2 = gooi.newButton({text = "",x = 10*twelfth,y = screenheight-4.25*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c)
mobile_controls_activekeys = "udlr"
mobile_controls_p1:setBounds(9*twelfth, screenheight-4.25*twelfth)
mobile_controls_p2:setBounds(10*twelfth, screenheight-4.15*twelfth)
mobile_controls_p3:setBounds(11*twelfth, screenheight-4.25*twelfth)
end):setBGImage(sprites["ui_2"]):bg({0, 0, 0, 0})
mobile_controls_p3 = gooi.newButton({text = "",x = 11*twelfth,y = screenheight-4.25*twelfth,w = twelfth,h = twelfth,group = "mobile-controls"}):onPress(function(c)
mobile_controls_activekeys = "numpad"
mobile_controls_p1:setBounds(9*twelfth, screenheight-4.25*twelfth)
mobile_controls_p2:setBounds(10*twelfth, screenheight-4.25*twelfth)
mobile_controls_p3:setBounds(11*twelfth, screenheight-4.15*twelfth)
end):setBGImage(sprites["ui_3"]):bg({0, 0, 0, 0})
stopwatch = {visible = false, big = {rotation=0}, small = {rotation=0}}
gooi.setGroupVisible("mobile-controls", is_mobile)
pause = false
scene.selecting = false
scene.buildUI()
end
function scene.buildUI()
-- darken is a UI element so that it can take focus from all UI underneath it
darken = ui.component.new():setColor(0, 0, 0, 0.5):setSize(love.graphics.getWidth(), love.graphics.getHeight()):setFill(true)
buttons = {}
if not options then
scene.addButton("resume", function() pause = false end)
scene.addButton("restart", function() pause = false; scene.resetStuff() end)
scene.addButton("editor", function() new_scene = editor; load_mode = "edit" end)
scene.addButton("options", function() options = true; scene.buildUI() end)
scene.addButton("exit to " .. escResult(false), function() escResult(true) end)
else
buildOptions()
end
local ox, oy = love.graphics.getWidth()/2, buttons[1]:getHeight()*3
for _,button in ipairs(buttons) do
local width, height = button:getSize()
button:setPos(ox - width/2, oy)
oy = oy + height + 10
end
button_last_y = oy
end
function scene.addButton(text, func)
local button = ui.menu_button.new(text, #buttons%2+1, func)
table.insert(buttons, button)
return button
end
function scene.addOption(id, name, options, changed)
local option = 1
for i,v in ipairs(options) do
if settings[id] == v[2] then
option = i
end
end
scene.addButton(name .. ": " .. options[option][1], function()
settings[id] = options[(((option-1)+1)%#options)+1][2]
saveAll()
if changed then
changed(settings[id])
end
scene.buildUI()
end)
end
function scene.update(dt)
mouse_X = love.mouse.getX()
mouse_Y = love.mouse.getY()
--mouse_movedX = love.mouse.getX() - love.graphics.getWidth()*0.5
--mouse_movedY = love.mouse.getY() - love.graphics.getHeight()*0.5
sound_volume = {}
scene.checkInput()
updateCursors()
updateDragabl()
mouse_oldX = mouse_X
mouse_oldY = mouse_Y
if pause then dt = 0 end
if xwxShader then
xwxShader:send("time", dt) -- send delta time to the shader
end
--TODO: PERFORMANCE: If many things are producing particles, it's laggy as heck.
scene.doPassiveParticles(dt, ":)", "bonus", 0.25, 1, 1, {2, 4})
scene.doPassiveParticles(dt, "un:)", "unwin", 0.25, 1, 1, {1, 2})
scene.doPassiveParticles(dt, "nxt", "nxt", 0.25, 1, 1, {0, 3})
scene.doPassiveParticles(dt, ":o", "bonus", 0.5, 0.8, 1, {4, 1})
scene.doPassiveParticles(dt, "qt", "love", 0.25, 0.5, 1, {4, 2})
scene.doPassiveParticles(dt, "slep", "slep", 1, 0.33, 1, {0, 3})
scene.doPassiveParticles(dt, "thonk", "thonk", 0.25, 0.5, 1, {0, 3})
scene.doPassiveParticles(dt, "tryagain", "bonus", 0.25, 0.25, 1, {3, 3})
doReplay(dt)
if rules_with and rules_with["rythm"] then
doRhythm()
end
updateCamera()
end
function updateCamera()
if units_by_name and units_by_name["camra"] and #units_by_name["camra"] > 0 then
local camera = units_by_name["camra"][1]
local vx, vy, vw, vh = camera.special.camera.x, camera.special.camera.y, camera.special.camera.w, camera.special.camera.h
local function updateCamPos()
end
local function setViewport(v)
if not v then
viewport = {
x = camera.x - vx - (vw - 1)/2,
y = camera.y - vy - (vh - 1)/2,
w = vw,
h = vh,
last_cam_x = camera.x,
last_cam_y = camera.y,
}
else
local x = math.floor(v.x + v.w/2)
local y = math.floor(v.y + v.h/2)
moveUnit(camera, x, y, nil, false)
v.last_cam_x = camera.x
v.last_cam_y = camera.y
viewport = v
end
end
if not viewport or camera.x ~= last_cam_x or camera.y ~= last_cam_y then
setViewport()
end
if rules_with then
local stalking = {}
local stalk_rules = matchesRule(camera, "stalk", nil)
for _,match in ipairs(stalk_rules) do
table.insert(stalking, match[2])
end
if #stalking > 0 then
local full_rect
for _,stalkee in ipairs(stalking) do
local stalk_rect = {}
stalk_rect.x1 = stalkee.draw.x - vx - (vw - 1)/2
stalk_rect.y1 = stalkee.draw.y - vy - (vh - 1)/2
stalk_rect.x2 = stalk_rect.x1 + vw
stalk_rect.y2 = stalk_rect.y1 + vh
if not full_rect then
full_rect = stalk_rect
else
full_rect.x1 = math.min(full_rect.x1, stalk_rect.x1)
full_rect.y1 = math.min(full_rect.y1, stalk_rect.y1)
full_rect.x2 = math.max(full_rect.x2, stalk_rect.x2)
full_rect.y2 = math.max(full_rect.y2, stalk_rect.y2)
end
end
if full_rect then
setViewport{
x = full_rect.x1,
y = full_rect.y1,
w = full_rect.x2 - full_rect.x1,
h = full_rect.y2 - full_rect.y1,
}
return
end
end
end
else
viewport = nil
end
end
function doRhythm()
if replay_playback then return false end
if love.timer.getTime() > (rhythm_time + rhythm_interval) then
if not pause and not past_playback then
rhythm_time = rhythm_time + rhythm_interval
doMovement(0, 0, "rythm")
end
end
end
function doReplay(dt)
if not replay_playback then return false end
if love.timer.getTime() > (replay_playback_time + replay_playback_interval) then
if not pause and not replay_pause and not past_playback then
replay_playback_time = replay_playback_time + replay_playback_interval
doReplayTurn(replay_playback_turn)
replay_playback_turn = replay_playback_turn + 1
else
replay_playback_time = love.timer.getTime()
end
end
return true
end
function doReplayTurn(turn)
if (replay_playback_turns == nil) then
replay_playback_string_parts = replay_playback_string:split("|")
replay_playback_turns = replay_playback_string_parts[1]:split(";")
if (replay_playback_string_parts[2] ~= nil) then
local ok, loaded_rng_cache = serpent.load(love.data.decode("string", "base64", replay_playback_string_parts[2]))
if (not ok) then
print("Serpent error while loading:", ok, fullDump(loaded_rng_cache))
end
rng_cache = loaded_rng_cache
end
end
local turn_string = replay_playback_turns[turn]
if (turn_string == nil or turn_string == "") then
replay_playback = false
print("Finished playback at turn: "..tostring(turn))
return
end
local turn_parts = turn_string:split(",")
x, y, key = tonumber(turn_parts[1]), tonumber(turn_parts[2]), turn_parts[3]
if (key == "clikt") then
last_click_button = 1
playSound("clicc")
elseif (key == "anti clikt") then
last_click_button = 2
playSound("anti clicc")
end
if (key:sub(1, 4) == "drag") then
last_click_button = 1
drag_units = {}
local drag_units_data = key:sub(6):split(":")
for _,drag_unit_data in ipairs(drag_units_data) do
local dudparts = drag_unit_data:split("@")
local did, dx, dy = tonumber(dudparts[1]), tonumber(dudparts[2])-0.5, tonumber(dudparts[3])-0.5
if did~= nil then
local unit = units_by_id[did] or cursors_by_id[did]
if unit ~= nil then
--hack for unit tests mode - draw doesn't exist so we'll just... pretend
if (unit.draw == nil) then
unit.draw = {}
end
unit.draw.x = dx;
unit.draw.y = dy;
table.insert(drag_units, unit);
end
end
end
finishDragabl();
drag_units = {}
key = "drag"
end
if (x == nil or y == nil) then
replay_playback = false
print("Finished playback at turn: "..tostring(turn))
return
else
if (turn_parts[4] ~= nil) then
local ok, cursor_table = serpent.load(love.data.decode("string", "base64", turn_parts[4]))
if (not ok) then
print("Serpent error while loading:", ok, fullDump(cursor_table))
else
for i,coords in ipairs(cursor_table) do
local cursor = cursors[i]
if (cursor == nil) then
--print("Couldn't find cursor while doing replay, halp")
else
cursor.x = coords[1]
cursor.y = coords[2]
if (not unit_tests) then
local screenx, screeny = gameTileToScreen(cursor.x+0.5, cursor.y+0.5)
cursor.screenx = screenx
cursor.screeny = screeny
end
end
end
end
end
doOneMove(x, y, key)
end
end
function string:split(sSeparator, nMax, bRegexp)
assert(sSeparator ~= '')
assert(nMax == nil or nMax >= 1)
local aRecord = {}
if self:len() > 0 then
local bPlain = not bRegexp
nMax = nMax or -1
local nField, nStart = 1, 1
local nFirst,nLast = self:find(sSeparator, nStart, bPlain)
while nFirst and nMax ~= 0 do
aRecord[nField] = self:sub(nStart, nFirst-1)
nField = nField+1
nStart = nLast+1
nFirst,nLast = self:find(sSeparator, nStart, bPlain)
nMax = nMax-1
end
aRecord[nField] = self:sub(nStart)
end
return aRecord
end
function scene.resetStuff(forTime)
if not forTime then
pastClear()
end
timeless = false
clear()
if not is_mobile then
love.mouse.setCursor(empty_cursor)
end
--love.mouse.setGrabbed(true)
resetMusic(map_music, 0.9)
rules_with = nil --fix for thicc/rotatabl persisting through restart since we check a couple of rules in createUnit. doesn't seem to break anything?
loadMap()
clearRules()
parseRules()
updateGroup()
calculateLight()
updateUnits(true)
updatePortals()
miscUpdates(true)
thiccBlock(true)
next_levels, next_level_objs = getNextLevels()
first_turn = false
window_dir = 0
if playing_world then
saveWorld()
end
selectLastLevels()
end
function scene.keyPressed(key, isrepeat)
if isrepeat then
return
end
last_input_time = love.timer.getTime()
if key == "escape" then
--[[local current_level = level_name
if readSaveFile(level_name, "won") then
current_level = current_level.." (won) "
end
if readSaveFile(level_name, "clear") then
current_level = current_level.." (cleared) "
end
if readSaveFile(level_name, "complete") then
current_level = current_level.." (complete) "
end
if readSaveFile(level_name, "bonus") then
current_level = current_level.." (bonused) "
end
local tfs = readSaveFile(level_name, "transform")
if tfs then
current_level = current_level.." (transformed into " .. fullDump(tfs) .. ") "
end
ui.overlay.confirm({
text = current_level .. "\r\n\r\n" .. (spookmode and "G̴͔̭͇͎͕͔ͪ̾ͬͦ̇͑͋͟͡o̵̸͓̠̦̱̭̘͍̱͑̃̀ͅ ̱̫͉̆͐̇ͥ̽͆͂͑̿͜b̸̵͈̼̜̅͗̄̆ͅa͚̠͚̣̺̗͖͈̓̿̈́͆͐̉ͯ̀̚c͉̜̙̤͍̞̳̬ͪ̇k̙͙̼̀̓̂̑̈́̌ͯ̕͢ͅ ̶̛̠̹̈̒ͫ͐t̙͉͍͚̠̗̰͗͊͛ͫ͒ͥ̏ͫ͢͜ȍ̙͙̪̬̎̊ͫͭͫ͗̔̚ ̴̪͖͔̖̙̬͍̥ͪ̾̾͂͂l̪͉͙̪̩͙̎̏͌̽ͤ̈́̀͜͠e̡͓͍͉̖̤ͬ̓̏ͥͫ̀ͅv̱͈͍̞̼̀͋̂̃͋́̚͠ͅḛ̷̷̱̿͂l̢̮͇̫̗͍̱͈̟͌̐̎̑̈́ ̵̠͖̣̟̲̖̇̈̓ͭͫ͠s͚̝̻ͤ̓̀̀e̅͑̐̄͏̤̫̕͠lͨ͋͌ͤͩ̋̓͏̘̼̠̪̖͓͔̹e̵͖̤̒͒ͥ̓ͬ̓͘c͖͈̏̄̐̅̎ͨ͢ṫ͔̥͓̊̌̓̇ọ̞̤͔̩̒͗ͨ́̓͟ŗ̖͉̹̻̮̬̦͌̿͂?̶̡͈̫̗̈́̒̎̃̎̓" or "Go back to "..escResult(false).."?"),
okText = "Yes",
cancelText = spookmode and "Yes" or "Cancel",
ok = function()
escResult(true)
end
})
return]]
pause = not pause
selected_pause_button = 1
end
if key == "g" and (key_down["lctrl"] or key_down["rctrl"]) then
settings["grid_lines"] = not settings["grid_lines"]
saveAll()
end
if pause then
scene.selecting = true
--[[if key == "w" or key == "up" or key == "i" or key == "kp8" then
selected_pause_button = selected_pause_button - 1
if selected_pause_button < 1 then
selected_pause_button = #buttons
end
elseif key == "s" or key == "down" or key == "k" or key == "kp2" then
selected_pause_button = selected_pause_button + 1
if selected_pause_button > #buttons then
selected_pause_button = 1
end
elseif key == "return" or key == "space" or key == "kpenter" then
handlePauseButtonPressed(selected_pause_button)
end]]
else
scene.selecting = false
local do_turn_now = false
if (key == "w" or key == "a" or key == "s" or key == "d") then
if not repeat_timers["wasd"] or repeat_timers["wasd"] > 30 then
repeat_timers["wasd"] = 30
elseif repeat_timers["wasd"] <= 30 then
do_turn_now = true
repeat_timers["wasd"] = 0
end
elseif (key == "up" or key == "down" or key == "left" or key == "right") then
if not repeat_timers["udlr"] or repeat_timers["udlr"] > 30 then
repeat_timers["udlr"] = 30
elseif repeat_timers["udlr"] <= 30 then
do_turn_now = true
repeat_timers["udlr"] = 0
end
elseif (key == "i" or key == "j" or key == "k" or key == "l") then
if not repeat_timers["ijkl"] or repeat_timers["ijkl"] > 30 then
repeat_timers["ijkl"] = 30
elseif repeat_timers["ijkl"] <= 30 then
do_turn_now = true
repeat_timers["ijkl"] = 0
end
elseif (key == "kp1" or
key == "kp2" or
key == "kp3" or
key == "kp4" or
key == "kp5" or
key == "kp6" or
key == "kp7" or
key == "kp8" or
key == "kp9") then
if not repeat_timers["udlr"] then
do_turn_now = true
repeat_timers["numpad"] = 0
end
elseif (key == "z" or key == "q" or key == "backspace" or key == "kp0" or key == "o") then
if not repeat_timers["undo"] then
do_turn_now = true
repeat_timers["undo"] = 0
end
end
if rules_with and rules_with["rythm"] then
if key == "+" or key == "=" then
rhythm_interval = rhythm_interval * 0.8
elseif key == "-" or key == "_" then
rhythm_interval = rhythm_interval / 0.8
end
end
--print(rhythm_interval)
for _,v in ipairs(repeat_keys) do
if v == key then
do_turn_now = true
repeat_timers[v] = 0
end
end
if key == "r" then
if not currently_winning or not key_down["lctrl"] then
scene.resetStuff()
elseif not RELEASE_BUILD and world_parent == "officialworlds" then
local file = love.filesystem.getSource() .. "/" .. getWorldDir() .. "/" .. level_filename .. ".replay"
local f = io.open(file, "w"); f:write(official_replay_string); f:close()
print("Replay successfully saved to " .. getWorldDir() .. "/" .. level_filename .. ".replay")
end
end
-- Replay keys
if key == "f12" then
if not replay_playback then
tryStartReplay()
else
replay_playback = false
end
end
if replay_playback and not pause then
if key == "+" or key == "=" or key == "w" or key == "up" then
replay_playback_interval = replay_playback_interval * 0.8
elseif key == "-" or key == "_" or key == "s" or key == "down" then
replay_playback_interval = replay_playback_interval / 0.8
elseif key == "0" or key == ")" then
replay_playback_interval = 0.3
elseif key == "space" then
replay_pause = not replay_pause
elseif key == "z" or key == "q" or key == "backspace" or key == "kp0" or key == "o" or key == "a" or key == "left" then
replay_pause = true
if replay_playback_turn > 1 then
replay_playback_turn = replay_playback_turn - 1
doOneMove(0,0,"undo")
end
print(replay_playback_turn)
elseif key == "d" or key == "right" then
doReplayTurn(replay_playback_turn)
replay_playback_turn = replay_playback_turn + 1
elseif key == "e" then
replay_playback_interval = 0
end
end
if key == "e" and not currently_winning and not replay_playback then
doOneMove(0, 0, "e")
end
if key == "f" and not currently_winning and not replay_playback then
doOneMove(0, 0, "f")
end
if key == "tab" then
displaywords = true
end
if key == "y" and hasU("swan") and units_by_name["swan"] then
playSound("honk"..love.math.random(1,6))
end
most_recent_key = key
key_down[key] = true
if (do_turn_now) then
scene.checkInput()
end
end
end
function tryStartReplay(instant)
scene.resetStuff()
local dir = getWorldDir() .. "/"
local full_dir = getWorldDir(true) .. "/"
if love.filesystem.getInfo(dir .. level_filename .. ".replay") then
replay_playback_string = love.filesystem.read(dir .. level_filename .. ".replay")
replay_playback = true
print("Started replay from: "..dir .. level_filename .. ".replay")
elseif love.filesystem.getInfo(full_dir .. level_name .. ".replay") then
replay_playback_string = love.filesystem.read(full_dir .. level_name .. ".replay")
replay_playback = true
print("Started replay from: "..full_dir .. level_name .. ".replay")
elseif love.filesystem.getInfo("levels/" .. level_filename .. ".replay") then
replay_playback_string = love.filesystem.read("levels/" .. level_filename .. ".replay")
replay_playback = true
print("Started replay from: ".."levels/" .. level_filename .. ".replay")
elseif love.filesystem.getInfo("levels/" .. level_name .. ".replay") then
replay_playback_string = love.filesystem.read("levels/" .. level_name .. ".replay")
replay_playback = true
print("Started replay from: ".."levels/" .. level_name .. ".replay")
else
print("Failed to find replay: ".. dir .. level_filename .. ".replay")
end
if instant then
local turn = 1
while replay_playback do
doReplayTurn(turn)
turn = turn + 1
end
end
end
--TODO: Releasing a key could signal to instantly run input under certain circumstances.
--UPDATE: I tested it and it didn't help (the keyReleased function never got called before the 30ms elapsed). I have no idea why.
function scene.keyReleased(key)
for _,v in ipairs(repeat_keys) do
if v == key then
repeat_timers[v] = nil
end
end
if key == "tab" then
displaywords = false
end
if key == "z" or key == "q" or key == "backspace" or key == "kp0" or key == "o" then
UNDO_DELAY = settings["input_delay"]
end
--[[local do_turn_now = false
print(key)
if key == "w" or key == "s" and not key_down["a"] and not key_down["d"] then
print(repeat_timers["wasd"])
if repeat_timers["wasd"] <= 30 then
do_turn_now = true
repeat_timers["wasd"] = 0
end
elseif key == "a" or key == "d" and not key_down["w"] and not key_down["s"] then
if repeat_timers["wasd"] <= 30 then
do_turn_now = true
repeat_timers["wasd"] = 0
end
elseif key == "up" or key == "down" and not key_down["left"] and not key_down["right"] then
if repeat_timers["udlr"] <= 30 then
do_turn_now = true
repeat_timers["udlr"] = 0
end
elseif key == "left" or key == "right" and not key_down["up"] and not key_down["down"] then
if repeat_timers["udlr"] <= 30 then
do_turn_now = true
repeat_timers["udlr"] = 0
end
end
if (do_turn_now) then
print("asdf")
scene.checkInput()
end]]--
key_down[key] = false
end
function scene.getTransform()
local transform = love.math.newTransform()
local roomwidth = mapwidth * TILE_SIZE
local roomheight = mapheight * TILE_SIZE
local screenwidth = love.graphics.getWidth() * (is_mobile and 0.75 or 1)
local screenheight = love.graphics.getHeight()
local targetwidth = (mapwidth + 4) * TILE_SIZE
local targetheight = (mapheight + 4) * TILE_SIZE
if viewport then
--local camera = units_by_name["camra"][1]
--local vx, vy, vw, vh = camera.special.camera.x, camera.special.camera.y, camera.special.camera.w, camera.special.camera.h
local scale = math.min(screenwidth / (viewport.w * TILE_SIZE), screenheight / (viewport.h * TILE_SIZE))
local scaledwidth = screenwidth * (1/scale)
local scaledheight = screenheight * (1/scale)
--transform:translate(scaledwidth / 2 - roomwidth / 2, scaledheight / 2 - roomheight / 2)
--transform:translate((camera.x - vx + 0.5) * TILE_SIZE, (camera.y - vy + 0.5) * TILE_SIZE)
transform:scale(scale, scale)
transform:translate(-(viewport.x + viewport.w/2) * TILE_SIZE, -(viewport.y + viewport.h/2) * TILE_SIZE)
transform:translate(scaledwidth/2, scaledheight/2)
else
if settings["int_scaling"] then
targetwidth = roomwidth
targetheight = roomheight
end
local scale = 1
if settings["int_scaling"] then
local scales = {0.25, 0.375, 0.5, 0.75, 1, 2, 3, 4}
scale = scales[1]
for _,s in ipairs(scales) do
if screenwidth >= roomwidth * s and screenheight >= roomheight * s then
scale = s
else break end
end
else
scale = math.min(screenwidth / targetwidth, screenheight / targetheight)
end
local scaledwidth = screenwidth * (1/scale)
local scaledheight = screenheight * (1/scale)
transform:scale(scale, scale)
transform:translate(scaledwidth / 2 - roomwidth / 2, scaledheight / 2 - roomheight / 2)
end
if shake_dur > 0 and not outerlvl.cool then
local range = 1
transform:translate(math.random(-range, range), math.random(-range, range))
end
return transform
end
--TODO: PERFORMANCE: Calling hasProperty once per frame means that we have to index rules, check conditions, etc. with O(m*n) performance penalty. But, the results of these calls do not change until a new turn or undo. So, we can cache the values of these calls in a global table and dump the table whenever the turn changes for a nice and easy performance boost.
--(Though this might not be true for mice, which can change their position mid-frame?? Also for other meta stuff (like windo)? Until there's mouse conditional rules or meta stuff in a puzzle IDK how this should actually work or be displayed. Just keep that in mind tho.)
function scene.draw(dt)
if pause then dt = 0 end
local draw_empty = rules_with["no1"] ~= nil
local start_time = love.timer.getTime()
-- reset canvas if the screen size has changed
if love.graphics.getWidth() ~= last_width or love.graphics.getHeight() ~= last_height then
last_width = love.graphics.getWidth()
last_height = love.graphics.getHeight()
canv = love.graphics.newCanvas(love.graphics.getWidth(), love.graphics.getHeight())
end
love.graphics.setCanvas{canv, stencil=true}
love.graphics.setShader()
--background color
local bg_color = {getPaletteColor(1, 0)}
if timeless then bg_color = {getPaletteColor(0, 0)}
elseif rainbowmode then bg_color = {hslToRgb(love.timer.getTime()/6%1, .2, .2, .9), 1} end
love.graphics.setColor(bg_color[1], bg_color[2], bg_color[3], bg_color[4])
-- fill the background with the background color
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
local roomwidth = mapwidth * TILE_SIZE
local roomheight = mapheight * TILE_SIZE
love.graphics.push()
love.graphics.applyTransform(scene.getTransform())
love.graphics.setColor(getPaletteColor(0,3))
love.graphics.printf(next_level_name, 0, -14, roomwidth)
local lvl_color = {getPaletteColor(0, 4)}
--[[if hasProperty(outerlvl,"tranz") then
love.graphics.draw(sprites["overlay/trans"], 0, 0, 0, roomwidth / sprites["overlay/trans"]:getWidth(), roomheight / sprites["overlay/trans"]:getHeight())
end
if hasProperty(outerlvl,"gay") then
table.insert(outerlvl.overlay, "gay")
end]]
-- Lvl be colors
if hasProperty(outerlvl,"rave") then
lvl_color = {hslToRgb((love.timer.getTime()/3+#undo_buffer/45)%1, 0.1, 0.1, .9), 1}
elseif hasProperty(outerlvl,"colrful") or rainbowmode then
lvl_color = {hslToRgb(love.timer.getTime()/6%1, .1, .1, .9), 1}
elseif (hasProperty(outerlvl,"reed") and hasProperty(outerlvl,"whit")) or hasProperty(outerlvl,"pinc") then
lvl_color = {getPaletteColor(4, 1)}
elseif (hasProperty(outerlvl,"grun") and hasProperty(outerlvl,"whit")) then
lvl_color = {getPaletteColor(5, 3)}
elseif hasProperty(outerlvl,"whit") then
lvl_color = {getPaletteColor(0, 3)}
elseif (hasProperty(outerlvl,"bleu") and hasProperty(outerlvl,"reed")) or hasProperty(outerlvl,"purp") then
lvl_color = {getPaletteColor(3, 1)}
elseif (hasProperty(outerlvl,"reed") and hasProperty(outerlvl,"grun")) or hasProperty(outerlvl,"yello") then
lvl_color = {getPaletteColor(2, 4)}
elseif (hasProperty(outerlvl,"reed") and hasProperty(outerlvl,"yello")) or hasProperty(outerlvl,"orang") then
lvl_color = {getPaletteColor(2, 3)}
elseif (hasProperty(outerlvl,"bleu") and hasProperty(outerlvl,"grun")) or hasProperty(outerlvl,"cyeann") then
lvl_color = {getPaletteColor(1, 4)}
elseif hasProperty(outerlvl,"reed") then
lvl_color = {getPaletteColor(2, 2)}
elseif hasProperty(outerlvl,"bleu") then
lvl_color = {getPaletteColor(1, 3)}
elseif hasProperty(outerlvl,"grun") then
lvl_color = {getPaletteColor(5, 2)}
elseif hasProperty(outerlvl,"cyeann") then
lvl_color = {getPaletteColor(1, 4)}
elseif hasProperty(outerlvl,"blacc") then
lvl_color = {getPaletteColor(0, 4)}
end
love.graphics.setColor(lvl_color[1], lvl_color[2], lvl_color[3], lvl_color[4])
if not (level_destroyed or hasProperty(outerlvl, "stelth")) then
local flyenes = countProperty(outerlvl,"flye")
local mapy = 0 - math.sin(love.timer.getTime())*5*flyenes
love.graphics.rectangle("fill", 0, mapy, roomwidth, roomheight)
if level_background_sprite ~= nil and level_background_sprite ~= "" and sprites[level_background_sprite] then
love.graphics.setColor(1, 1, 1)
local sprite = sprites[level_background_sprite]
love.graphics.draw(sprite, 0, 0, 0, 1, 1, 0, 0)
end
end
if settings["grid_lines"] then
love.graphics.setLineWidth(1)
local r,g,b,a = getPaletteColor(0,1)
love.graphics.setColor(r,g,b,0.3)
for i=1,mapwidth-1 do
love.graphics.line(i*TILE_SIZE,0,i*TILE_SIZE,roomheight)
end
for i=1,mapheight-1 do
love.graphics.line(0,i*TILE_SIZE,roomwidth,i*TILE_SIZE)
end
end
local function drawUnit(unit, drawx, drawy, rotation, loop)
if unit.name == "no1" and not (draw_empty and validEmpty(unit)) then return end
local brightness = 1
if ((rules_with["wurd"] and hasRule(unit,"be","wurd")) or (rules_with["anti wurd"] and hasRule(unit,"be","anti wurd"))) and not unit.active and not level_destroyed and not (unit.fullname == "prop") then
brightness = 0.33
end
if (unit.name == "steev") and not hasU(unit) then
brightness = 0.33
end
if unit.name == "casete" and not hasProperty(unit, "nogo") then
brightness = 0.5
end
if timeless and not hasProperty(unit,"zawarudo") and not (unit.type == "txt") then
brightness = 0.33
end
if unit.fullname == "txt_now" then
if doing_past_turns then
unit.sprite = {"txt/latr"}
else
unit.sprite = {"txt/now"}
end
end
if unit.rave then
-- print("unit " .. unit.name .. " is rave")
local ravespeed = 0.75
if settings["epileptic"] then
ravespeed = 7.5
end
local newcolor = hslToRgb((love.timer.getTime()/ravespeed+#undo_buffer/45+unit.x/18+unit.y/18)%1, .5, .5, 1)
newcolor[1] = newcolor[1]*255
newcolor[2] = newcolor[2]*255
newcolor[3] = newcolor[3]*255
unit.color_override = newcolor
elseif unit.colrful or rainbowmode then
-- print("unit " .. unit.name .. " is colourful or rainbowmode")
local newcolor = hslToRgb((love.timer.getTime()/15+#undo_buffer/45+unit.x/18+unit.y/18)%1, .5, .5, 1)
newcolor[1] = newcolor[1]*255
newcolor[2] = newcolor[2]*255
newcolor[3] = newcolor[3]*255
unit.color_override = newcolor
end
local wobble_suffix = unit.wobble and ("_" .. (unit.frame + anim_stage) % 3 + 1) or ""
local sprite = sprites[unit.sprite[1]]
--no tweening empty for now - it's buggy!
--TODO: it's still a little buggy if you push/pull empties.
if (unit.name == "no1") then
--drawx = unit.x
--drawy = unit.y
--rotation = math.rad((unit.dir - 1) * 45)
unit.draw.scalex = 1
unit.draw.scaley = 1
end
local function setColor(color)
color = type(color[1]) == "table" and color[1] or color
if #color == 3 then
if color[1] then
color = {color[1]/255, color[2]/255, color[3]/255, 1}
else
color = {1,1,1,1}
end
else
local palette = current_palette
if current_palette == "default" and unit.wobble then
palette = "baba"
end
color = {getPaletteColor(color[1], color[2], palette)}