-
Notifications
You must be signed in to change notification settings - Fork 3
/
__types.lua
4658 lines (4525 loc) · 294 KB
/
__types.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
-- Playdate SDK Annotations
-- SDK Version: 2.6.0
-- Generated by Benjamin Dumke-von der Ehe
-- https://github.com/balpha/playdate-types
-------------------------------------------
---@meta
---@type pd_playdate_lib
playdate = playdate
---@type pd_json_lib
json = json
---@alias pd_pattern integer[]
---@type table<string, pd_text_alignment>
kTextAlignment = kTextAlignment
import = require
---@alias pd_font_family table<pd_font_variant, pd_font>
---@alias pd_font_family_paths table<pd_font_variant, string>
---@alias pd_source pd_fileplayer | pd_sampleplayer | pd_synth | pd_instrument
---@alias pd_effect pd_bitcrusher | pd_twopolefilter | pd_onepolefilter | pd_ringmod | pd_overdrive | pd_delayline
-- not completely foolproof, but this hack should catch some accidental assignments to read-only properties
---@class READONLY_number : number
---@class READONLY_boolean : boolean
---@class READONLY_pd_size : pd_size
---@class READONLY_pd_point : pd_point
---@class pd_event
---@field step number
---@field value number
---@field interpolate boolean? -- ?
---@class pd_line_collision_info
---@field sprite pd_sprite
---@field entryPoint pd_point
---@field exitPoint pd_point
---@field ti1 number
---@field ti2 number
---@class pd_sprite_collision_info
---@field sprite pd_sprite
---@field other pd_sprite
---@field type pd_collision_type
---@field overlaps boolean
---@field ti number
---@field move pd_vector2D
---@field normal pd_vector2D
---@field touch pd_point
---@field spriteRect pd_rect
---@field otherRect pd_rect
---@field bounce pd_point?
---@field slide pd_point?
---@class pd_note_table
---@field step number
---@field note number
---@field length number
---@field velocity number
---@class pd_stats_table
---@field kernel number
---@field serial number
---@field game number
---@field GC number
---@field wifi number
---@field audio number
---@field trace number
---@field idle number
---@class pd_UNDOCUMENTED
---@class pd_button
---@class pd_text_alignment
---@class pd_flip
---@class pd_image_flip
---@class pd_color
---@class pd_dither_type
---@class pd_draw_mode
---@class pd_language
---@class pd_filemode
---@class pd_line_cap_style
---@class pd_polygon_fill_rule
---@class pd_stroke_location
---@class pd_font_variant
---@class pd_capitalization
---@class pd_collision_type
---@class pd_sound_format
---@class pd_waveform
---@class pd_lfo_type
---@class pd_sound_filter
---@class pd_wrap_mode
---@class pd_seek_mode
---@class pd_time_table
---@field year number
---@field month number
---@field day number
---@field weekday number
---@field hour number
---@field minute number
---@field second number
---@field millisecond number
---@class pd_file_time_table
---@field year number
---@field month number
---@field day number
---@field hour number
---@field minute number
---@field second number
---@class pd_input_handler
--- Called immediately after the player presses the A Button.
---@field AButtonDown nil | (fun())
--- Called after the A Button is held down for one second. This can be used for secondary actions (e.g., displaying a game world map, changing weapons).
---@field AButtonHeld nil | (fun())
--- Called immediately after the player releases the A Button.
---@field AButtonUp nil | (fun())
--- Called immediately after the player presses the B Button.
---@field BButtonDown nil | (fun())
--- Called after the B Button is held down for one second. This can be used for secondary actions (e.g., displaying a game world map, changing weapons).
---@field BButtonHeld nil | (fun())
--- Called immediately after the player releases the B Button.
---@field BButtonUp nil | (fun())
--- Called immediately after the player presses the down direction on the d-pad.
---@field downButtonDown nil | (fun())
--- Called immediately after the player releases the down direction on the d-pad.
---@field downButtonUp nil | (fun())
--- Called immediately after the player presses the left direction on the d-pad.
---@field leftButtonDown nil | (fun())
--- Called immediately after the player releases the left direction on the d-pad.
---@field leftButtonUp nil | (fun())
--- Called immediately after the player presses the right direction on the d-pad.
---@field rightButtonDown nil | (fun())
--- Called immediately after the player releases the right direction on the d-pad.
---@field rightButtonUp nil | (fun())
--- Called immediately after the player presses the up direction on the d-pad.
---@field upButtonDown nil | (fun())
--- Called immediately after the player releases the up direction on the d-pad.
---@field upButtonUp nil | (fun())
--- For playdate.cranked(), `change` is the angle change in degrees. `acceleratedChange` is `change` multiplied by a value that increases as the crank moves faster, similar to the way mouse acceleration works. Negative values are anti-clockwise.
---@field cranked nil | (fun(change: number, acceleratedChange: number))
---@class pd_metadata
--- A unique identifier for your game, in reverse DNS notation.
---@field bundleID string
--- A game version number, formatted any way you wish, that is displayed to players. It is not used to compute when updates should occur.
---@field version string
--- A monotonically-increasing integer value used to indicate a unique version of your game. This can be set using an automated build process like Continuous Integration to avoid having to set the value by hand.
---@field buildNumber integer
--- A directory of images that will be used by the launcher.
---@field imagePath string
--- Optional. Should point to the path of a short audio file to be played as the game launch animation is taking place.
---@field launchSoundPath string?
--- Optional. A content warning that displays when the user launches your game for the first time. The user will have the option of backing out and not launching your game if they choose.
---@field contentWarning string?
--- Optional. A second content warning that displays on a second screen when the user launches your game for the first time. The user will have the option of backing out and not launching your game if they choose. Note: contentWarning2 will only display if a contentWarning attribute is also specified.
---@field contentWarning2 string?
---@class tablelib
--- Returns the first index of `element` in the given array-style table. If the table does not contain `element`, the function returns nil.
---@field indexOfElement fun(table: table, element: any): number?
--- Returns the size of the given table as multiple values (`arrayCount`, `hashCount`).
---@field getsize fun(table: table): (number, number)
--- Returns a new Lua table with the array and hash parts preallocated to accommodate `arrayCount` and `hashCount` elements respectively.
---
--- If you can make a decent estimation of how big your table will need to be, table.create() can be much more efficient than the alternative, especially in loops. For example, if you know your array is always going to contain approximately ten elements, say myArray = table.create( 10, 0 ) instead of myArray = {}.
---@field create fun(arrayCount: number, hashCount: number): table
--- shallowcopy returns a shallow copy of the `source` table. If a `destination` table is provided, it copies the contents of `source` into `destination` and returns `destination`. The copy will contain references to any nested tables.
---@field shallowcopy fun(source: table, destination?: table): table
--- deepcopy returns a deep copy of the `source` table. The copy will contain copies of any nested tables.
---@field deepcopy fun(source: table): table
---@class pd_playdate_lib
--- Returns two values, the current API version of the Playdate runtime and the minimum API version supported by the runtime.
---@field apiVersion fun(): (number, number)
--- The playdate.metadata table contains the values in the current game’s pdxinfo file, keyed by variable name. To retrieve the version number of the game, for example, you would use playdate.metadata.version.
---
--- Changing values in this table at run time has no effect.
---@field metadata pd_metadata
--- Implement this callback and Playdate OS will call it once per frame. This is the place to put the main update-and-draw code for your game. Playdate will attempt to call this function by default 30 times per second; that value can be changed by calling playdate.display.setRefreshRate().
---
--- If your update() function takes too long to execute, Playdate OS may not be able to call it as often as specified by the current refresh rate. In this case, Playdate OS will simply try and call it as often as it can, with a not-to-exceed rate of playdate.display.getRefreshRate() frames per second.
---@field update nil | (fun())
--- Suspends callbacks to playdate.update() for the specified number of milliseconds.
---
--- playdate.wait() is ideal for pausing game execution to, for example, show a message to the player. Because .update() will not be called, the screen will freeze during .wait(). Audio will continue to play. Animation during this wait period is possible, but you will need to explicitly call playdate.display.flush() once per frame.
--- While timers should pause during playdate.wait() (assuming playdate.timer.updateTimers() and playdate.frameTimer.updateTimers() are invoked during playdate.update()), animators will `not` pause during playdate.wait(). Be sure to account for this in your code.
---@field wait fun(milliseconds: number)
--- Stops per-frame callbacks to playdate.update(). Useful in conjunction with playdate.display.flush() if your program only does things in response to button presses.
---@field stop fun()
--- Resumes per-frame callbacks to playdate.update().
---@field start fun()
--- Reinitializes the Playdate runtime and restarts the currently running game. The optional string arg passed in is available after restart in playdate.argv as if it had been passed in on the command line when launching the simulator.
---@field restart fun(arg?: string)
--- Called when the player chooses to exit the game via the System Menu or Menu button.
---@field gameWillTerminate nil | (fun())
--- Called before the device goes to low-power sleep mode because of a low battery.
---@field deviceWillSleep nil | (fun())
--- If your game is running on the Playdate when the device is locked, this function will be called. Implementing this function allows your game to take special action when the Playdate is locked, e.g., saving state.
---@field deviceWillLock nil | (fun())
--- If your game is running on the Playdate when the device is unlocked, this function will be called.
---@field deviceDidUnlock nil | (fun())
--- Called before the system pauses the game. (In the current version of Playdate OS, this only happens when the device’s Menu button is pushed.) Implementing these functions allows your game to take special action when it is paused, e.g., updating the menu image.
---@field gameWillPause nil | (fun())
--- Called before the system resumes the game.
---@field gameWillResume nil | (fun())
--- Returns a playdate.menu object. Use this to add your custom menu items.
---@field getSystemMenu fun(): pd_menu
---@field menu pd_menu_lib
--- While the game is paused it can optionally provide an image to be displayed alongside the System Menu. Use this function to set that image.
---
--- `image` should be a 400 x 240 pixel playdate.graphics.image. All important content should be in the left half of the image in an area 200 pixels wide, as the menu will obscure the rest. The right side of the image will be visible briefly as the menu animates in and out.
---
--- Optionally, `xOffset` can be provided which must be a number between 0 and 200 and will cause the menu image to animate to a position offset left by `xOffset` pixels as the menu is animated in.
---
--- To remove a previously-set menu image, pass nil for the `image` argument.
---@field setMenuImage fun(image: pd_image, xOffset?: number)
--- Returns the current language of the system, which will be one of the constants `playdate.graphics.font.kLanguageEnglish` or `playdate.graphics.font.kLanguageJapanese`.
---@field getSystemLanguage fun(): pd_language
--- Returns `true` if the user has checked the "Reduce Flashing" option in Playdate Settings; `false` otherwise. Games should read this value and, if `true`, avoid visuals that could be problematic for people with sensitivities to flashing lights or patterns.
---@field getReduceFlashing fun(): boolean
--- Returns `true` if the user has checked the "Upside Down" option in Playdate Settings; `false` otherwise. (Upside Down mode can be convenient for players wanting to hold Playdate upside-down so they can use their left hand to operate the crank.)
---
--- Typically your game doesn’t need to anything in regards to this setting. But it is available in case your game wants to take some special actions, display special instructions, etc.
---
--- Reported d-pad directions are flipped when in Upside Down mode — RIGHT will be reported as LEFT, UP as DOWN, etc. — so that the d-pad will make sense to a user holding Playdate upside-down. However, the A and B buttons — since they are still labeled as "A" and "B" — retain their normal meanings and will be reported as usual.
---@field getFlipped fun(): boolean
--- The accelerometer is off by default, to save a bit of power. If you will be using the accelerometer in your game, you’ll first need to call playdate.startAccelerometer() then wait for the next update cycle before reading its values. If you won’t be using the accelerometer again for a while, calling playdate.stopAccelerometer() will put it back into a low-power idle state.
---@field startAccelerometer fun()
--- Puts the accelerometer into a low-power idle state. (Though, to be honest, the accelerometer draws so little power when it’s running you’d never notice the difference.)
---@field stopAccelerometer fun()
--- If the accelerometer has been turned on with playdate.startAccelerometer(), returns the x, y, and z values from the accelerometer as a list. Positive x points right, positive y points to the bottom of the screen, and positive z points through the screen away from the viewer. For example, with the device held upright this function returns the values (0,1,0). With it flat on its back, it returns (0,0,1).
---@field readAccelerometer fun(): (number, number, number)
--- Returns true if the accelerometer is currently running.
---@field accelerometerIsRunning fun(): boolean
--- Returns true if `button` is currently being pressed.
---
--- `button` should be one of the constants:
---
--- `playdate.kButtonA`
---
--- `playdate.kButtonB`
---
--- `playdate.kButtonUp`
---
--- `playdate.kButtonDown`
---
--- `playdate.kButtonLeft`
---
--- `playdate.kButtonRight`
---
--- Or one of the strings "a", "b", "up", "down", "left", "right".
---@field buttonIsPressed fun(button: pd_button): boolean
--- Returns true for `just one update cycle` if `button` was pressed. buttonJustPressed will not return true again until the button is released and pressed again. This is useful for, say, a player "jump" action, so the jump action is taken only once and not on every single update.
---
--- `button` should be one of the constants listed in playdate.buttonIsPressed()
---@field buttonJustPressed fun(button: pd_button): boolean
--- Returns true for `just one update cycle` if `button` was released. buttonJustReleased will not return true again until the button is pressed and released again.
---
--- `button` should be one of the constants listed in playdate.buttonIsPressed()
---@field buttonJustReleased fun(button: pd_button): boolean
--- Returns the above data in one call, with multiple return values (`current`, `pressed`, `released`) containing bitmasks indicating which buttons are currently down, and which were pressed and released since the last update. For example, if the d-pad left button and the A button are both down, the `current` value will be (`playdate.kButtonA`|`playdate.kButtonLeft`).
---@field getButtonState fun(): (integer, integer, integer)
--- When set, button up/down events on the D pad and the A and B buttons are added to a list instead of simply polled at the beginning of a frame, allowing the code to handle multiple taps on a given button in a single frame. At the default 30 FPS, a queue size of 5 should be adequate. At lower frame rates/longer frame times, the queue size should be extended until all button presses are caught. Additionally, when the button queue is enabled the button callbacks listed below are passed the event time as an argument.
---@field setButtonQueueSize fun(size: number)
--- Called immediately after the player presses the A Button.
---@field AButtonDown nil | (fun())
--- Called after the A Button is held down for one second. This can be used for secondary actions (e.g., displaying a game world map, changing weapons).
---@field AButtonHeld nil | (fun())
--- Called immediately after the player releases the A Button.
---@field AButtonUp nil | (fun())
--- Called immediately after the player presses the B Button.
---@field BButtonDown nil | (fun())
--- Called after the B Button is held down for one second. This can be used for secondary actions (e.g., displaying a game world map, changing weapons).
---@field BButtonHeld nil | (fun())
--- Called immediately after the player releases the B Button.
---@field BButtonUp nil | (fun())
--- Called immediately after the player presses the down direction on the d-pad.
---@field downButtonDown nil | (fun())
--- Called immediately after the player releases the down direction on the d-pad.
---@field downButtonUp nil | (fun())
--- Called immediately after the player presses the left direction on the d-pad.
---@field leftButtonDown nil | (fun())
--- Called immediately after the player releases the left direction on the d-pad.
---@field leftButtonUp nil | (fun())
--- Called immediately after the player presses the right direction on the d-pad.
---@field rightButtonDown nil | (fun())
--- Called immediately after the player releases the right direction on the d-pad.
---@field rightButtonUp nil | (fun())
--- Called immediately after the player presses the up direction on the d-pad.
---@field upButtonDown nil | (fun())
--- Called immediately after the player releases the up direction on the d-pad.
---@field upButtonUp nil | (fun())
--- Returns a boolean indicating whether or not the crank is folded into the unit.
---
--- If your game requires the crank and :isCrankDocked() is true, you can use a crank alert to notify the user that the crank should be extended.
---@field isCrankDocked fun(): boolean
--- Returns the absolute position of the crank (in degrees). Zero is pointing straight up parallel to the device. Turning the crank clockwise (when looking at the right edge of an upright device) increases the angle, up to a maximum value 359.9999. The value then resets back to zero as the crank continues its rotation.
---
--- local crankPosition = playdate.getCrankPosition()
---@field getCrankPosition fun(): number
--- Returns two values, `change` and `acceleratedChange`. `change` represents the angle change (in degrees) of the crank since the last time this function (or the playdate.cranked() callback) was called. Negative values are anti-clockwise. `acceleratedChange` is change multiplied by a value that increases as the crank moves faster, similar to the way mouse acceleration works.
---
--- local change, acceleratedChange = playdate.getCrankChange()
---@field getCrankChange fun(): (number, number)
--- Returns the number of "ticks" — whose frequency is defined by the value of `ticksPerRevolution` — the crank has turned through since the last time this function was called. Tick boundaries are set at absolute positions along the crank’s rotation. Ticks can be positive or negative, depending upon the direction of rotation.
---
--- For example, say you have a movie player and you want your movie to advance 6 frames for every one revolution of the crank. Calling playdate.getCrankTicks(6) during each update will give you a return value of 1 as the crank turns past each 60 degree increment. (Since we passed in a 6, each tick represents 360 ÷ 6 = 60 degrees.) So getCrankTicks(6) will return a 1 as the crank turns past the 0 degree absolute position, the 60 degree absolute position, and so on for the 120, 180, 240, and 300 degree positions. Otherwise, 0 will be returned. (-1 will be returned if the crank moves past one of these mentioned positions while going in a backward direction.)
---
--- You must import `CoreLibs/crank` to use getCrankTicks().
--- Example: Reading crank input using getCrankTicks
--- import "CoreLibs/crank"
---
--- local ticksPerRevolution = 6
---
--- function playdate.update()
--- local crankTicks = playdate.getCrankTicks(ticksPerRevolution)
---
--- if crankTicks == 1 then
--- print("Forward tick")
--- elseif crankTicks == -1 then
--- print("Backward tick")
--- end
--- end
---@field getCrankTicks fun(ticksPerRevolution: number): number
--- For playdate.cranked(), `change` is the angle change in degrees. `acceleratedChange` is `change` multiplied by a value that increases as the crank moves faster, similar to the way mouse acceleration works. Negative values are anti-clockwise.
---@field cranked nil | (fun(change: number, acceleratedChange: number))
--- This function, if defined, is called when the crank is docked.
---@field crankDocked nil | (fun())
--- This function, if defined, is called when the crank is undocked.
---@field crankUndocked nil | (fun())
--- `True` disables the default crank docking/undocking sound effects. `False` re-enables them. Useful if the crank sounds seem out-of-place in your game.
---
--- When your game terminates, crank sounds will automatically be re-enabled.
---@field setCrankSoundsDisabled fun(disable: boolean)
---@field inputHandlers pd_inputHandlers_lib
--- `True` disables the 3 minute auto-lock feature. `False` re-enables it and resets the timer back to 3 minutes.
---
--- Auto-lock will automatically be re-enabled when your game terminates.
--- If disabling auto-lock, developers should look for opportunities to re-enable auto-lock when appropriate. (For example, if your game is an MP3 audio player, auto-lock could be re-enabled when the user pauses the audio.)
---@field setAutoLockDisabled fun(disable: boolean)
--- Returns the number of milliseconds the game has been `active` since launched.
---@field getCurrentTimeMilliseconds fun(): number
--- Resets the high-resolution timer.
---@field resetElapsedTime fun()
--- Returns the number of seconds since playdate.resetElapsedTime() was called. The value is a floating-point number with microsecond accuracy.
---@field getElapsedTime fun(): number
--- Returns the number of seconds and milliseconds elapsed since midnight (hour 0), January 1 2000 UTC, as a list: `(seconds, milliseconds)`. This function is suitable for seeding the random number generator:
---
--- Sample code for seeding the random number generator
--- math.randomseed(playdate.getSecondsSinceEpoch())
---@field getSecondsSinceEpoch fun(): (number, number)
--- Returns a table with values for the local time, accessible via the following keys:
---
--- `year`: 4-digit year (until 10,000 AD)
---
--- `month`: month of the year, where 1 is January and 12 is December
---
--- `day`: day of the month, 1 - 31
---
--- `weekday`: day of the week, where 1 is Monday and 7 is Sunday
---
--- `hour`: 0 - 23
---
--- `minute`: 0 - 59
---
--- `second`: 0 - 59 (or 60 on a leap second)
---
--- `millisecond`: 0 - 999
---@field getTime fun(): pd_time_table
--- Returns a table in the same format as playdate.getTime(), but in GMT rather than local time.
---@field getGMTTime fun(): pd_time_table
--- Returns the number of seconds and milliseconds between midnight (hour 0), January 1 2000 UTC and `time`, specified in local time, as a list: `(seconds, milliseconds)`.
---
--- `time` should be a table of the same format as the one returned by playdate.getTime().
---@field epochFromTime fun(time: pd_time_table): (number, number)
--- Returns the number of seconds and milliseconds between midnight (hour 0), January 1 2000 UTC and `time`, specified in GMT time, as a list: `(seconds, milliseconds)`.
---
--- `time` should be a table of the same format as the one returned by playdate.getTime().
---@field epochFromGMTTime fun(time: pd_time_table): (number, number)
--- Converts the epoch to a local date and time table, in the same format as the table returned by playdate.getTime().
---@field timeFromEpoch fun(seconds: number, milliseconds: number): pd_time_table
--- Converts the epoch to a GMT date and time table, in the same format as the table returned by playdate.getTime().
---@field GMTTimeFromEpoch fun(seconds: number, milliseconds: number): pd_time_table
--- Returns true if the user has set the 24-Hour Time preference in the Settings program.
---@field shouldDisplay24HourTime fun(): boolean
--- If the simulator is launched from the command line, any extra arguments passed there are available in the playdate.argv array.
---@field argv string[]
--- `flag` determines whether or not the print() function adds a newline to the end of the printed text. Default is `true`.
---@field setNewlinePrinted fun(flag: boolean)
--- Calculates the current frames per second and draws that value at `x, y`.
---@field drawFPS fun(x: number, y: number)
--- Returns the `measured, actual` refresh rate in frames per second. This value may be different from the `specified` refresh rate (see playdate.display.getRefreshRate()) by a little or a lot depending upon how much calculation is being done per frame.
---@field getFPS fun(): number
--- Returns a table containing percentages of time spent in each system task over the last interval, if more than zero. Possible keys are
---
--- kernel
---
--- serial
---
--- game
---
--- GC
---
--- wifi
---
--- audio
---
--- trace
---
--- idle
---
--- playdate.getStats() only functions on a Playdate device. In the Simulator, this function returns nil.
---@field getStats fun(): pd_stats_table
--- setStatsInterval() sets the length of time for each sample frame of runtime stats. Set `seconds` to zero to disable stats collection.
---@field setStatsInterval fun(seconds: number)
---@field display pd_display_lib
---@field easingFunctions pd_easingFunctions_lib
---@field datastore pd_datastore_lib
---@field file pd_file_lib
---@field geometry pd_geometry_lib
---@field graphics pd_graphics_lib
---@field keyboard pd_keyboard_lib
---@field math pd_math_lib
---@field pathfinder pd_pathfinder_lib
--- Returns a table holding booleans with the following keys:
---
--- `charging`: The battery is actively being charged
---
--- `USB`: There is a powered USB cable connected
---
--- `screws`: There is 5V being applied to the corner screws (via the dock, for example)
---@field getPowerStatus fun(): table
--- Returns a value from 0-100 denoting the current level of battery charge. 0 = empty; 100 = full.
---@field getBatteryPercentage fun(): number
--- Returns the battery’s current voltage level.
---@field getBatteryVoltage fun(): number
--- This variable—not a function, so don’t invoke with `()`—it is set to 1 when running inside of the Simulator and is `nil` otherwise.
---@field isSimulator boolean
---@field simulator pd_simulator_lib
--- Clears the simulator console.
---@field clearConsole fun()
--- Sets the color of the playdate.debugDraw() overlay image. Values are in the range 0-1.
---@field setDebugDrawColor fun(r: number, g: number, b: number, a: number)
--- Lets you act on keyboard keypresses when running in the Simulator ONLY. These can be useful for adding debugging functions that can be enabled via your keyboard.
---
--- It is possible test a game on Playdate hardware and trap computer keyboard keypresses if you are using the Simulator’s Control Device with Simulator option.
---
--- key is a string containing the character pressed or released on the keyboard. Note that:
---
--- The key in question needs to have a textual representation or these functions will not be called. For instance, alphanumeric keys will call these functions; keyboard directional arrows will not.
---
--- If the keypress in question is already in use by the Simulator for another purpose (say, to control the d-pad or A/B buttons), these functions will not be called.
---
--- If `key` is an alphabetic character, the value will always be lowercase, even if the user deliberately typed an uppercase character.
---@field keyPressed nil | (fun(key: string))
--- Lets you act on keyboard key releases when running in the Simulator ONLY. These can be useful for adding debugging functions that can be enabled via your keyboard.
---@field keyReleased nil | (fun(key: string))
--- Called immediately after playdate.update(), any drawing performed during this callback is overlaid on the display in 50% transparent red (or another color selected with playdate.setDebugDrawColor()).
---
--- White pixels are drawn in the debugDrawColor. Black pixels are transparent.
---@field debugDraw nil | (fun())
---@field sound pd_sound_lib
---@field string pd_string_lib
---@field timer pd_timer_lib
---@field frameTimer pd_frameTimer_lib
---@field ui pd_ui_lib
--- Called when a msg <text> command is received on the serial port. The text following the command is passed to the function as the string `message`.
---
--- Running !msg <message> in the simulator Lua console sends the command to the device if one is connected, otherwise it sends it to the game running in the simulator.
---@field serialMessageReceived nil | (fun(message: string))
--- If `flag` is false, automatic garbage collection is disabled and the game should manually collect garbage with Lua’s collectgarbage() function.
---@field setCollectsGarbage fun(flag: boolean)
--- Force the Lua garbage collector to run for at least `ms` milliseconds every frame, so that garbage doesn’t pile up and cause the game to run out of memory and stall in emergency garbage collection. The default value is 1 millisecond.
---
--- If your game isn’t generating a lot of garbage, it might be advantageous to set a smaller minimum GC time, granting more CPU bandwidth to your game.
---@field setMinimumGCTime fun(ms: number)
--- When the amount of used memory is less than min (scaled from 0-1, as a percentage of total system memory), the system will only run the collector for the minimum GC time, as set by playdate.setGCScaling(), every frame. If the used memory is more than max, the system will spend all free time running the collector. Between the two, the time used by the garbage collector is scaled proportionally.
---
--- For example, if the scaling is set to a min of 0.4 and max of 0.7, and memory is half full, the collector will run for the minimum GC time plus 1/3 of whatever time is left before the next frame (because (0.5 - 0.4) / (0.7 - 0.4) = 1/3).
---
--- The default behavior is a scaling of (0.0, 1.0). If set to (0.0, 0.0), the system will use all available extra time each frame running GC.
---@field setGCScaling fun(min: number, max: number)
---@field kButtonA pd_button
---@field kButtonB pd_button
---@field kButtonUp pd_button
---@field kButtonDown pd_button
---@field kButtonLeft pd_button
---@field kButtonRight pd_button
---@class pd_json_lib
--- Takes the JSON encoded string and converts it to a Lua table.
---
--- Equivalent to playdate->json->decode() in the C API.
---@field decode fun(string: string)
--- Reads the given playdate.file.file object or the file at the given path and converts it to a Lua table.
---@field decodeFile (fun(file: pd_file_file)) | (fun(path: string))
--- Returns a string containing the JSON representation of the passed-in Lua table.
---@field encode fun(table: table): string
--- Returns a string containing the JSON representation of a Lua table, with human-readable formatting.
---@field encodePretty fun(table: table): string
--- Encodes the Lua table table to JSON and writes it to the given playdate.file.file object or the given path. If pretty is true, the output is formatted to make it human-readable. Otherwise, no additional whitespace is added.
---
--- For a very simple way to serialize a table to a file, see playdate.datastore.
---@field encodeToFile (fun(file: pd_file_file, pretty?: boolean, table?: table)) | (fun(path: string, pretty?: boolean, table?: table))
---@class pd_menu_lib : pd_menu
---@field item pd_item_lib
---@class pd_menu
--- `title` will be the title displayed by the menu item.
---@field addMenuItem fun(self: pd_menu, title: string, callback: fun())
--- Creates a new menu item that can be checked or unchecked by the player.
---
--- `title` will be the title displayed by the menu item.
---
--- `initialValue` can be set to true or false, indicating the checked state of the menu item. Optional, defaults to false.
---
--- If this menu item is interacted with while the system menu is open, `callback` will be called when the menu is closed, before playdate.gameWillResume is called. The callback function will be passed one argument, a boolean value, indicating the current value of the menu item.
---
--- If the returned playdate.menu.item is nil, a second errorMessage return value will indicate the reason the operation failed.
---
--- Playdate OS allows a maximum of three custom menu items to be added to the System Menu.
---@field addCheckmarkMenuItem fun(self: pd_menu, title: string, initialValue?: number, callback?: fun(boolean)): pd_item
--- Creates a menu item that allows the player to cycle through a set of options.
---
--- `title` will be the title displayed by the menu item.
---
--- `options` should be an array-style table of strings representing the states the menu item can have. Due to limited horizontal space, the option strings and title should be kept short for this type of menu item.
---
--- `initialValue` can optionally be set to any of the values in the options array.
---
--- If the value of this menu item is changed while the system menu is open, `callback` will be called when the menu is closed, before playdate.gameWillResume is called. The callback function will be passed one string argument indicating the currently selection option.
---
--- If the returned playdate.menu.item is nil, a second errorMessage return value will indicate the reason the operation failed.
---
--- Playdate OS allows a maximum of three custom menu items to be added to the System Menu.
---@field addOptionsMenuItem fun(self: pd_menu, title: string, options: string[], initalValue?: string, callback?: fun(string)): pd_item
--- Returns an array-style table containing all playdate.menu.items your game has added to the menu.
---@field getMenuItems fun(self: pd_menu): pd_item[]
--- Removes the specified playdate.menu.item from the menu.
---@field removeMenuItem fun(self: pd_menu, menuItem: pd_item)
--- Removes from the referenced menu object all playdate.menu.items added by your game.
---
--- Items that were added to the System Menu by the operating system cannot be removed by this operation, or any other.
---@field removeAllMenuItems fun(self: pd_menu)
---@class pd_inputHandlers_lib
--- Pushes a new input handler onto the stack.
---
--- `handler:` A table containing one or more custom input functions.
---
--- `masksPreviousHandlers:` If true, input functions not defined in `handler` will not be called. If missing or false, the previously-pushed input handler tables will be searched for input functions missing from `handler`, cascading down to the default playdate table.
---@field push fun(handler: pd_input_handler, masksPreviousHandlers?: boolean)
--- Pops the last input handler off of the stack.
---@field pop fun()
---@class pd_display_lib
--- Sets the desired refresh rate in frames per second. The default is 30 fps, which is a recommended figure that balances animation smoothness with performance and power considerations. Maximum is 50 fps.
---
--- If `rate` is 0, playdate.update() is called as soon as possible. Since the display refreshes line-by-line, and unchanged lines aren’t sent to the display, the update cycle will be faster than 30 times a second but at an indeterminate rate. playdate.getCurrentTimeMilliseconds() should then be used as a steady time base.
---
--- Equivalent to playdate->display->setRefreshRate() in the C API.
---@field setRefreshRate fun(rate: number)
--- Returns the specified refresh rate in frames per second. See also playdate.getFPS() for `measured, actual` frame rate.
---@field getRefreshRate fun(): number
--- Sends the contents of the frame buffer to the display immediately. Useful if you have called playdate.stop() to disable update callbacks in, say, the case where your app updates the display only in reaction to button presses.
---@field flush fun()
--- Returns the height the Playdate display, taking the current display scale into account; e.g., if the scale is 2, the values returned will be based off of a 200 x 120-pixel screen rather than the native 400 x 240. (See playdate.display.setScale().)
---
--- Equivalent to playdate->display->getHeight() in the C API.
---@field getHeight fun(): number
--- Returns the width the Playdate display, taking the current display scale into account; e.g., if the scale is 2, the values returned will be based off of a 200 x 120-pixel screen rather than the native 400 x 240. (See playdate.display.setScale().)
---
--- Equivalent to playdate->display->getWidth() in the C API.
---@field getWidth fun(): number
--- Returns the values `(width, height)` describing the Playdate display size. Takes the current display scale into account; e.g., if the scale is 2, the values returned will be based off of a 200 x 120-pixel screen rather than the native 400 x 240. (See playdate.display.setScale().)
---@field getSize fun(): (number, number)
--- Returns the values `(x, y, width, height)` describing the Playdate display size. Takes the current display scale into account; e.g., if the scale is 2, the values returned will be based off of a 200 x 120-pixel screen rather than the native 400 x 240. (See playdate.display.setScale().)
---@field getRect fun(): pd_rect
--- Sets the display scale factor. Valid values for `scale` are 1, 2, 4, and 8.
---
--- The top-left corner of the frame buffer is scaled up to fill the display; e.g., if the scale is set to 4, the pixels in rectangle [0,100] x [0,60] are drawn on the screen as 4 x 4 squares.
---
--- Equivalent to playdate->display->setScale() in the C API.
---@field setScale fun(scale: number)
--- Gets the display scale factor. Valid values for `scale` are 1, 2, 4, and 8.
---@field getScale fun(): number
--- If the argument passed to setInverted() is true, the frame buffer will be drawn inverted (everything onscreen that was black will now be white, etc.)
---
--- Equivalent to playdate->display->setInverted() in the C API.
---@field setInverted fun(flag: boolean)
--- Returns the current value of the display invert flag.
---@field getInverted fun(): boolean
--- Adds a mosaic effect to the display. Valid `x` and `y` values are between 0 and 3, inclusive.
---
--- Equivalent to playdate->display->setMosaic() in the C API.
---@field setMosaic fun(x: number, y: number)
--- Returns the current mosaic effect settings as multiple values (`x`, `y`).
---@field getMosaic fun(): (number, number)
--- Offsets the entire display by `x`, `y`. Offset values can be negative. The "exposed" part of the display is black or white, according to the value set in playdate.graphics.setBackgroundColor(). This is an efficient way to make a "shake" effect without redrawing anything.
---
--- This function is different from playdate.graphics.setDrawOffset().
---
--- Equivalent to playdate->display->setOffset() in the C API.
---
--- Example: A screen shake effect using setOffset
--- -- You can copy and paste this example directly as your main.lua file to see it in action
--- import "CoreLibs/graphics"
--- import "CoreLibs/timer"
---
--- -- This function relies on the use of timers, so the timer core library
--- -- must be imported, and updateTimers() must be called in the update loop
--- local function screenShake(shakeTime, shakeMagnitude)
--- -- Creating a value timer that goes from shakeMagnitude to 0, over
--- -- the course of 'shakeTime' milliseconds
--- local shakeTimer = playdate.timer.new(shakeTime, shakeMagnitude, 0)
--- -- Every frame when the timer is active, we shake the screen
--- shakeTimer.updateCallback = function(timer)
--- -- Using the timer value, so the shaking magnitude
--- -- gradually decreases over time
--- local magnitude = math.floor(timer.value)
--- local shakeX = math.random(-magnitude, magnitude)
--- local shakeY = math.random(-magnitude, magnitude)
--- playdate.display.setOffset(shakeX, shakeY)
--- end
--- -- Resetting the display offset at the end of the screen shake
--- shakeTimer.timerEndedCallback = function()
--- playdate.display.setOffset(0, 0)
--- end
--- end
---
--- function playdate.update()
--- playdate.timer.updateTimers()
--- if playdate.buttonJustPressed(playdate.kButtonA) then
--- -- Shake the screen for 500ms, with the screen
--- -- shaking around by about 5 pixels on each side
--- screenShake(500, 5)
--- end
---
--- -- A circle to be able to view what the shaking looks like
--- playdate.graphics.fillCircleAtPoint(200, 120, 10)
--- end
---@field setOffset fun(x: number, y: number)
--- getOffset() returns the current display offset as multiple values (`x`, `y`).
---@field getOffset fun(): (number, number)
--- Flips the display on the x or y axis, or both.
---
--- Function arguments are booleans, and in Lua 0 evaluates to true.
---
--- Equivalent to playdate->display->setFlipped() in the C API.
---@field setFlipped fun(x: number, y: number)
--- The simplest method for putting an image on the display. Copies the contents of the image at `path` directly to the frame buffer. The image must be 400x240 pixels with no transparency.
---
--- Loading an image via playdate.graphics.image.new() and drawing it at a desired coordinate with playdate.graphics.image:draw() offers more flexibility.
---@field loadImage fun(path: string)
---@class pd_easingFunctions_lib
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field linear fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inQuad fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outQuad fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inOutQuad fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outInQuad fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inCubic fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outCubic fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inOutCubic fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outInCubic fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inQuart fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outQuart fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inOutQuart fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outInQuart fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inQuint fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outQuint fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inOutQuint fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outInQuint fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inSine fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outSine fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inOutSine fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outInSine fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field inExpo fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---
--- `p` - period parameter
---
--- `s` - amount of "overshoot"
---@field outExpo fun(t: number, b: number, c: number, d: number): number
--- `t` is elapsed time
---
--- `b` is the beginning value
---
--- `c` is the change (or end value - start value)
---
--- `d` is the duration
---
--- `a` - amplitude
---