isaacscript-common 12.6.1 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +116 -37
- package/dist/isaacscript-common.lua +631 -184
- package/dist/src/features/customStage/backdrop.lua +4 -4
- package/dist/src/features/customStage/versusScreen.lua +2 -2
- package/dist/src/features/deployJSONRoom.d.ts +0 -11
- package/dist/src/features/deployJSONRoom.d.ts.map +1 -1
- package/dist/src/features/deployJSONRoom.lua +10 -74
- package/dist/src/features/extraConsoleCommands/listCommands.lua +2 -2
- package/dist/src/features/firstLast.lua +8 -8
- package/dist/src/features/setHotkey.d.ts +42 -0
- package/dist/src/features/setHotkey.d.ts.map +1 -0
- package/dist/src/features/setHotkey.lua +104 -0
- package/dist/src/functions/array.lua +2 -2
- package/dist/src/functions/cards.lua +2 -2
- package/dist/src/functions/collectibles.lua +2 -2
- package/dist/src/functions/dimensions.lua +2 -2
- package/dist/src/functions/emptyRoom.d.ts +8 -0
- package/dist/src/functions/emptyRoom.d.ts.map +1 -0
- package/dist/src/functions/emptyRoom.lua +74 -0
- package/dist/src/functions/enums.d.ts.map +1 -1
- package/dist/src/functions/enums.lua +3 -3
- package/dist/src/functions/gridEntities.lua +2 -2
- package/dist/src/functions/gridIndex.d.ts +10 -0
- package/dist/src/functions/gridIndex.d.ts.map +1 -0
- package/dist/src/functions/gridIndex.lua +32 -0
- package/dist/src/functions/log.d.ts.map +1 -1
- package/dist/src/functions/log.lua +9 -8
- package/dist/src/functions/logEntities.d.ts.map +1 -1
- package/dist/src/functions/logEntities.lua +17 -9
- package/dist/src/functions/pills.lua +4 -4
- package/dist/src/functions/roomShape.d.ts +6 -1
- package/dist/src/functions/roomShape.d.ts.map +1 -1
- package/dist/src/functions/roomShape.lua +3 -0
- package/dist/src/functions/roomShapeWalls.d.ts +20 -0
- package/dist/src/functions/roomShapeWalls.d.ts.map +1 -0
- package/dist/src/functions/roomShapeWalls.lua +285 -0
- package/dist/src/functions/rooms.d.ts +7 -0
- package/dist/src/functions/rooms.d.ts.map +1 -1
- package/dist/src/functions/rooms.lua +16 -5
- package/dist/src/functions/set.d.ts +7 -0
- package/dist/src/functions/set.d.ts.map +1 -1
- package/dist/src/functions/set.lua +10 -0
- package/dist/src/functions/sprites.lua +2 -2
- package/dist/src/functions/trinkets.lua +2 -2
- package/dist/src/functions/utils.d.ts +18 -12
- package/dist/src/functions/utils.d.ts.map +1 -1
- package/dist/src/functions/utils.lua +26 -14
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.lua +29 -5
- package/dist/src/initFeatures.lua +3 -3
- package/dist/src/interfaces/Corner.d.ts +8 -0
- package/dist/src/interfaces/Corner.d.ts.map +1 -1
- package/dist/src/objects/roomShapeCorners.d.ts +6 -1
- package/dist/src/objects/roomShapeCorners.d.ts.map +1 -1
- package/dist/src/objects/roomShapeCorners.lua +71 -14
- package/package.json +2 -2
- package/src/features/customStage/backdrop.ts +3 -3
- package/src/features/customStage/versusScreen.ts +2 -2
- package/src/features/deployJSONRoom.ts +8 -98
- package/src/features/extraConsoleCommands/listCommands.ts +2 -2
- package/src/features/firstLast.ts +8 -8
- package/src/features/setHotkey.ts +144 -0
- package/src/functions/array.ts +2 -2
- package/src/functions/cards.ts +2 -2
- package/src/functions/collectibles.ts +2 -2
- package/src/functions/dimensions.ts +2 -2
- package/src/functions/emptyRoom.ts +85 -0
- package/src/functions/enums.ts +4 -3
- package/src/functions/gridEntities.ts +2 -2
- package/src/functions/gridIndex.ts +40 -0
- package/src/functions/log.ts +9 -10
- package/src/functions/logEntities.ts +25 -9
- package/src/functions/pills.ts +4 -4
- package/src/functions/roomShape.ts +6 -1
- package/src/functions/roomShapeWalls.ts +359 -0
- package/src/functions/rooms.ts +22 -3
- package/src/functions/set.ts +12 -0
- package/src/functions/sprites.ts +2 -2
- package/src/functions/trinkets.ts +2 -2
- package/src/functions/utils.ts +20 -14
- package/src/index.ts +4 -1
- package/src/initFeatures.ts +2 -2
- package/src/interfaces/Corner.ts +9 -0
- package/src/objects/roomShapeCorners.ts +74 -16
- package/dist/src/features/registerHotkey.d.ts +0 -23
- package/dist/src/features/registerHotkey.d.ts.map +0 -1
- package/dist/src/features/registerHotkey.lua +0 -93
- package/src/features/registerHotkey.ts +0 -124
|
@@ -2,10 +2,12 @@ import { RoomShape } from "isaac-typescript-definitions";
|
|
|
2
2
|
import { CornerType } from "../enums/CornerType";
|
|
3
3
|
import { Corner } from "../interfaces/Corner";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The locations of the corners for each room shape.
|
|
7
|
+
*
|
|
8
|
+
* Note that these corner locations are not accurate for the Mother Boss Room and the Home closet
|
|
9
|
+
* rooms. (Those rooms have custom shapes.)
|
|
10
|
+
*/
|
|
9
11
|
export const ROOM_SHAPE_CORNERS: {
|
|
10
12
|
readonly [key in RoomShape]: readonly Corner[];
|
|
11
13
|
} = {
|
|
@@ -13,18 +15,22 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
13
15
|
[RoomShape.SHAPE_1x1]: [
|
|
14
16
|
{
|
|
15
17
|
type: CornerType.TOP_LEFT,
|
|
18
|
+
gridIndex: 0,
|
|
16
19
|
position: Vector(60, 140),
|
|
17
20
|
},
|
|
18
21
|
{
|
|
19
22
|
type: CornerType.TOP_RIGHT,
|
|
23
|
+
gridIndex: 14,
|
|
20
24
|
position: Vector(580, 140),
|
|
21
25
|
},
|
|
22
26
|
{
|
|
23
27
|
type: CornerType.BOTTOM_LEFT,
|
|
28
|
+
gridIndex: 120,
|
|
24
29
|
position: Vector(60, 420),
|
|
25
30
|
},
|
|
26
31
|
{
|
|
27
32
|
type: CornerType.BOTTOM_RIGHT,
|
|
33
|
+
gridIndex: 134,
|
|
28
34
|
position: Vector(580, 420),
|
|
29
35
|
},
|
|
30
36
|
],
|
|
@@ -33,18 +39,22 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
33
39
|
[RoomShape.IH]: [
|
|
34
40
|
{
|
|
35
41
|
type: CornerType.TOP_LEFT,
|
|
42
|
+
gridIndex: 30,
|
|
36
43
|
position: Vector(60, 220),
|
|
37
44
|
},
|
|
38
45
|
{
|
|
39
46
|
type: CornerType.TOP_RIGHT,
|
|
47
|
+
gridIndex: 44,
|
|
40
48
|
position: Vector(580, 220),
|
|
41
49
|
},
|
|
42
50
|
{
|
|
43
51
|
type: CornerType.BOTTOM_LEFT,
|
|
52
|
+
gridIndex: 90,
|
|
44
53
|
position: Vector(60, 340),
|
|
45
54
|
},
|
|
46
55
|
{
|
|
47
56
|
type: CornerType.BOTTOM_RIGHT,
|
|
57
|
+
gridIndex: 104,
|
|
48
58
|
position: Vector(580, 340),
|
|
49
59
|
},
|
|
50
60
|
],
|
|
@@ -53,18 +63,22 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
53
63
|
[RoomShape.IV]: [
|
|
54
64
|
{
|
|
55
65
|
type: CornerType.TOP_LEFT,
|
|
66
|
+
gridIndex: 4,
|
|
56
67
|
position: Vector(220, 140),
|
|
57
68
|
},
|
|
58
69
|
{
|
|
59
70
|
type: CornerType.TOP_RIGHT,
|
|
71
|
+
gridIndex: 10,
|
|
60
72
|
position: Vector(420, 140),
|
|
61
73
|
},
|
|
62
74
|
{
|
|
63
75
|
type: CornerType.BOTTOM_LEFT,
|
|
76
|
+
gridIndex: 124,
|
|
64
77
|
position: Vector(220, 420),
|
|
65
78
|
},
|
|
66
79
|
{
|
|
67
80
|
type: CornerType.BOTTOM_RIGHT,
|
|
81
|
+
gridIndex: 130,
|
|
68
82
|
position: Vector(420, 420),
|
|
69
83
|
},
|
|
70
84
|
],
|
|
@@ -73,18 +87,22 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
73
87
|
[RoomShape.SHAPE_1x2]: [
|
|
74
88
|
{
|
|
75
89
|
type: CornerType.TOP_LEFT,
|
|
90
|
+
gridIndex: 0,
|
|
76
91
|
position: Vector(60, 140),
|
|
77
92
|
},
|
|
78
93
|
{
|
|
79
94
|
type: CornerType.TOP_RIGHT,
|
|
95
|
+
gridIndex: 14,
|
|
80
96
|
position: Vector(580, 140),
|
|
81
97
|
},
|
|
82
98
|
{
|
|
83
99
|
type: CornerType.BOTTOM_LEFT,
|
|
100
|
+
gridIndex: 225,
|
|
84
101
|
position: Vector(60, 700),
|
|
85
102
|
},
|
|
86
103
|
{
|
|
87
104
|
type: CornerType.BOTTOM_RIGHT,
|
|
105
|
+
gridIndex: 239,
|
|
88
106
|
position: Vector(580, 700),
|
|
89
107
|
},
|
|
90
108
|
],
|
|
@@ -93,18 +111,22 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
93
111
|
[RoomShape.IIV]: [
|
|
94
112
|
{
|
|
95
113
|
type: CornerType.TOP_LEFT,
|
|
114
|
+
gridIndex: 4,
|
|
96
115
|
position: Vector(220, 140),
|
|
97
116
|
},
|
|
98
117
|
{
|
|
99
118
|
type: CornerType.TOP_RIGHT,
|
|
119
|
+
gridIndex: 10,
|
|
100
120
|
position: Vector(420, 140),
|
|
101
121
|
},
|
|
102
122
|
{
|
|
103
123
|
type: CornerType.BOTTOM_LEFT,
|
|
124
|
+
gridIndex: 229,
|
|
104
125
|
position: Vector(220, 700),
|
|
105
126
|
},
|
|
106
127
|
{
|
|
107
128
|
type: CornerType.BOTTOM_RIGHT,
|
|
129
|
+
gridIndex: 235,
|
|
108
130
|
position: Vector(420, 700),
|
|
109
131
|
},
|
|
110
132
|
],
|
|
@@ -113,18 +135,22 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
113
135
|
[RoomShape.SHAPE_2x1]: [
|
|
114
136
|
{
|
|
115
137
|
type: CornerType.TOP_LEFT,
|
|
138
|
+
gridIndex: 0,
|
|
116
139
|
position: Vector(60, 140),
|
|
117
140
|
},
|
|
118
141
|
{
|
|
119
142
|
type: CornerType.TOP_RIGHT,
|
|
143
|
+
gridIndex: 27,
|
|
120
144
|
position: Vector(1100, 140),
|
|
121
145
|
},
|
|
122
146
|
{
|
|
123
147
|
type: CornerType.BOTTOM_LEFT,
|
|
148
|
+
gridIndex: 224,
|
|
124
149
|
position: Vector(60, 420),
|
|
125
150
|
},
|
|
126
151
|
{
|
|
127
152
|
type: CornerType.BOTTOM_RIGHT,
|
|
153
|
+
gridIndex: 251,
|
|
128
154
|
position: Vector(1100, 420),
|
|
129
155
|
},
|
|
130
156
|
],
|
|
@@ -133,18 +159,22 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
133
159
|
[RoomShape.IIH]: [
|
|
134
160
|
{
|
|
135
161
|
type: CornerType.TOP_LEFT,
|
|
162
|
+
gridIndex: 56,
|
|
136
163
|
position: Vector(60, 220),
|
|
137
164
|
},
|
|
138
165
|
{
|
|
139
166
|
type: CornerType.TOP_RIGHT,
|
|
167
|
+
gridIndex: 83,
|
|
140
168
|
position: Vector(1100, 220),
|
|
141
169
|
},
|
|
142
170
|
{
|
|
143
171
|
type: CornerType.BOTTOM_LEFT,
|
|
172
|
+
gridIndex: 168,
|
|
144
173
|
position: Vector(60, 340),
|
|
145
174
|
},
|
|
146
175
|
{
|
|
147
176
|
type: CornerType.BOTTOM_RIGHT,
|
|
177
|
+
gridIndex: 195,
|
|
148
178
|
position: Vector(1100, 340),
|
|
149
179
|
},
|
|
150
180
|
],
|
|
@@ -153,18 +183,22 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
153
183
|
[RoomShape.SHAPE_2x2]: [
|
|
154
184
|
{
|
|
155
185
|
type: CornerType.TOP_LEFT,
|
|
186
|
+
gridIndex: 0,
|
|
156
187
|
position: Vector(60, 140),
|
|
157
188
|
},
|
|
158
189
|
{
|
|
159
190
|
type: CornerType.TOP_RIGHT,
|
|
191
|
+
gridIndex: 27,
|
|
160
192
|
position: Vector(1100, 140),
|
|
161
193
|
},
|
|
162
194
|
{
|
|
163
195
|
type: CornerType.BOTTOM_LEFT,
|
|
196
|
+
gridIndex: 420,
|
|
164
197
|
position: Vector(60, 700),
|
|
165
198
|
},
|
|
166
199
|
{
|
|
167
200
|
type: CornerType.BOTTOM_RIGHT,
|
|
201
|
+
gridIndex: 447,
|
|
168
202
|
position: Vector(1100, 700),
|
|
169
203
|
},
|
|
170
204
|
],
|
|
@@ -173,26 +207,32 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
173
207
|
[RoomShape.LTL]: [
|
|
174
208
|
{
|
|
175
209
|
type: CornerType.TOP_LEFT,
|
|
176
|
-
|
|
210
|
+
gridIndex: 13,
|
|
211
|
+
position: Vector(580, 140), // Center
|
|
177
212
|
},
|
|
178
213
|
{
|
|
179
214
|
type: CornerType.TOP_RIGHT,
|
|
215
|
+
gridIndex: 27,
|
|
180
216
|
position: Vector(1100, 140),
|
|
181
217
|
},
|
|
182
218
|
{
|
|
183
219
|
type: CornerType.TOP_LEFT,
|
|
184
|
-
|
|
220
|
+
gridIndex: 196,
|
|
221
|
+
position: Vector(60, 420), // Left
|
|
185
222
|
},
|
|
186
223
|
{
|
|
187
224
|
type: CornerType.BOTTOM_RIGHT,
|
|
188
|
-
|
|
225
|
+
gridIndex: 209,
|
|
226
|
+
position: Vector(580, 420), // Center
|
|
189
227
|
},
|
|
190
228
|
{
|
|
191
229
|
type: CornerType.BOTTOM_LEFT,
|
|
230
|
+
gridIndex: 420,
|
|
192
231
|
position: Vector(60, 700),
|
|
193
232
|
},
|
|
194
233
|
{
|
|
195
234
|
type: CornerType.BOTTOM_RIGHT,
|
|
235
|
+
gridIndex: 447,
|
|
196
236
|
position: Vector(1100, 700),
|
|
197
237
|
},
|
|
198
238
|
],
|
|
@@ -201,26 +241,32 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
201
241
|
[RoomShape.LTR]: [
|
|
202
242
|
{
|
|
203
243
|
type: CornerType.TOP_LEFT,
|
|
244
|
+
gridIndex: 0,
|
|
204
245
|
position: Vector(60, 140),
|
|
205
246
|
},
|
|
206
247
|
{
|
|
207
248
|
type: CornerType.TOP_RIGHT,
|
|
208
|
-
|
|
249
|
+
gridIndex: 14,
|
|
250
|
+
position: Vector(580, 140), // Center
|
|
209
251
|
},
|
|
210
252
|
{
|
|
211
253
|
type: CornerType.BOTTOM_LEFT,
|
|
212
|
-
|
|
254
|
+
gridIndex: 210,
|
|
255
|
+
position: Vector(580, 420), // Center
|
|
213
256
|
},
|
|
214
257
|
{
|
|
215
258
|
type: CornerType.TOP_RIGHT,
|
|
216
|
-
|
|
259
|
+
gridIndex: 223,
|
|
260
|
+
position: Vector(1100, 420), // Right
|
|
217
261
|
},
|
|
218
262
|
{
|
|
219
263
|
type: CornerType.BOTTOM_LEFT,
|
|
264
|
+
gridIndex: 420,
|
|
220
265
|
position: Vector(60, 700),
|
|
221
266
|
},
|
|
222
267
|
{
|
|
223
268
|
type: CornerType.BOTTOM_RIGHT,
|
|
269
|
+
gridIndex: 447,
|
|
224
270
|
position: Vector(1100, 700),
|
|
225
271
|
},
|
|
226
272
|
],
|
|
@@ -229,26 +275,32 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
229
275
|
[RoomShape.LBL]: [
|
|
230
276
|
{
|
|
231
277
|
type: CornerType.TOP_LEFT,
|
|
278
|
+
gridIndex: 0,
|
|
232
279
|
position: Vector(60, 140),
|
|
233
280
|
},
|
|
234
281
|
{
|
|
235
282
|
type: CornerType.TOP_RIGHT,
|
|
283
|
+
gridIndex: 27,
|
|
236
284
|
position: Vector(1100, 140),
|
|
237
285
|
},
|
|
238
286
|
{
|
|
239
287
|
type: CornerType.BOTTOM_LEFT,
|
|
240
|
-
|
|
288
|
+
gridIndex: 224,
|
|
289
|
+
position: Vector(580, 140), // Left
|
|
241
290
|
},
|
|
242
291
|
{
|
|
243
292
|
type: CornerType.TOP_RIGHT,
|
|
244
|
-
|
|
293
|
+
gridIndex: 237,
|
|
294
|
+
position: Vector(580, 420), // Center
|
|
245
295
|
},
|
|
246
296
|
{
|
|
247
297
|
type: CornerType.BOTTOM_LEFT,
|
|
248
|
-
|
|
298
|
+
gridIndex: 433,
|
|
299
|
+
position: Vector(580, 700), // Center
|
|
249
300
|
},
|
|
250
301
|
{
|
|
251
302
|
type: CornerType.BOTTOM_RIGHT,
|
|
303
|
+
gridIndex: 447,
|
|
252
304
|
position: Vector(1100, 700),
|
|
253
305
|
},
|
|
254
306
|
],
|
|
@@ -257,27 +309,33 @@ export const ROOM_SHAPE_CORNERS: {
|
|
|
257
309
|
[RoomShape.LBR]: [
|
|
258
310
|
{
|
|
259
311
|
type: CornerType.TOP_LEFT,
|
|
312
|
+
gridIndex: 0,
|
|
260
313
|
position: Vector(60, 140),
|
|
261
314
|
},
|
|
262
315
|
{
|
|
263
316
|
type: CornerType.TOP_RIGHT,
|
|
317
|
+
gridIndex: 27,
|
|
264
318
|
position: Vector(1100, 140),
|
|
265
319
|
},
|
|
266
320
|
{
|
|
267
321
|
type: CornerType.TOP_LEFT,
|
|
268
|
-
|
|
322
|
+
gridIndex: 238,
|
|
323
|
+
position: Vector(580, 420), // Center
|
|
269
324
|
},
|
|
270
325
|
{
|
|
271
326
|
type: CornerType.BOTTOM_RIGHT,
|
|
272
|
-
|
|
327
|
+
gridIndex: 251,
|
|
328
|
+
position: Vector(1100, 420), // Right
|
|
273
329
|
},
|
|
274
330
|
{
|
|
275
331
|
type: CornerType.BOTTOM_LEFT,
|
|
332
|
+
gridIndex: 420,
|
|
276
333
|
position: Vector(60, 700),
|
|
277
334
|
},
|
|
278
335
|
{
|
|
279
336
|
type: CornerType.BOTTOM_RIGHT,
|
|
280
|
-
|
|
337
|
+
gridIndex: 434,
|
|
338
|
+
position: Vector(580, 700), // Right
|
|
281
339
|
},
|
|
282
340
|
],
|
|
283
341
|
} as const;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Keyboard } from "isaac-typescript-definitions";
|
|
2
|
-
/**
|
|
3
|
-
* Helper function to run arbitrary code when you press and release a specific keyboard key.
|
|
4
|
-
*
|
|
5
|
-
* This can be used to easily set up custom hotkeys to facilitate custom game features or to assist
|
|
6
|
-
* in debugging.
|
|
7
|
-
*
|
|
8
|
-
* @param keyboardOrFunc Either the key that you want to trigger the hotkey or a function that
|
|
9
|
-
* returns the key that will trigger the hotkey. Normally, you would just
|
|
10
|
-
* specify the key directly, but you can use a function for situations where
|
|
11
|
-
* the key can change (like if end-users can specify a custom hotkey using Mod
|
|
12
|
-
* Config Menu).
|
|
13
|
-
* @param triggerFunc A function containing the arbitrary code that you want to execute when the
|
|
14
|
-
* hotkey is triggered.
|
|
15
|
-
*/
|
|
16
|
-
export declare function registerHotkey(keyboardOrFunc: Keyboard | (() => Keyboard | undefined), triggerFunc: () => void): void;
|
|
17
|
-
/**
|
|
18
|
-
* Helper function to remove a hotkey created with the `registerHotkey` function.
|
|
19
|
-
*
|
|
20
|
-
* @param keyboardOrFunc Equal to the value that you passed when initially registering the hotkey.
|
|
21
|
-
*/
|
|
22
|
-
export declare function unregisterHotkey(keyboardOrFunc: Keyboard | (() => Keyboard | undefined)): void;
|
|
23
|
-
//# sourceMappingURL=registerHotkey.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registerHotkey.d.ts","sourceRoot":"","sources":["../../../src/features/registerHotkey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,8BAA8B,CAAC;AAyDrE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC5B,cAAc,EAAE,QAAQ,GAAG,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC,EACvD,WAAW,EAAE,MAAM,IAAI,GACtB,IAAI,CAoBN;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,QAAQ,GAAG,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC,GACtD,IAAI,CAoBN"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
local ____lualib = require("lualib_bundle")
|
|
2
|
-
local Map = ____lualib.Map
|
|
3
|
-
local __TS__New = ____lualib.__TS__New
|
|
4
|
-
local __TS__Iterator = ____lualib.__TS__Iterator
|
|
5
|
-
local ____exports = {}
|
|
6
|
-
local postRender, checkIfTriggered, staticHotkeyFunctionMap, dynamicHotkeyFunctionMap, keyPressedMap
|
|
7
|
-
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
8
|
-
local Keyboard = ____isaac_2Dtypescript_2Ddefinitions.Keyboard
|
|
9
|
-
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
|
|
10
|
-
local ____DefaultMap = require("src.classes.DefaultMap")
|
|
11
|
-
local DefaultMap = ____DefaultMap.DefaultMap
|
|
12
|
-
local ____featuresInitialized = require("src.featuresInitialized")
|
|
13
|
-
local errorIfFeaturesNotInitialized = ____featuresInitialized.errorIfFeaturesNotInitialized
|
|
14
|
-
local ____input = require("src.functions.input")
|
|
15
|
-
local isKeyboardPressed = ____input.isKeyboardPressed
|
|
16
|
-
local ____types = require("src.functions.types")
|
|
17
|
-
local isFunction = ____types.isFunction
|
|
18
|
-
function postRender(self)
|
|
19
|
-
for ____, ____value in __TS__Iterator(staticHotkeyFunctionMap:entries()) do
|
|
20
|
-
local keyboard = ____value[1]
|
|
21
|
-
local triggerFunc = ____value[2]
|
|
22
|
-
checkIfTriggered(nil, keyboard, triggerFunc)
|
|
23
|
-
end
|
|
24
|
-
for ____, ____value in __TS__Iterator(dynamicHotkeyFunctionMap:entries()) do
|
|
25
|
-
local keyboardFunc = ____value[1]
|
|
26
|
-
local triggerFunc = ____value[2]
|
|
27
|
-
local keyboard = keyboardFunc(nil)
|
|
28
|
-
if keyboard ~= nil then
|
|
29
|
-
checkIfTriggered(nil, keyboard, triggerFunc)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
function checkIfTriggered(self, keyboard, triggerFunc)
|
|
34
|
-
local isPressed = isKeyboardPressed(nil, keyboard)
|
|
35
|
-
local wasPreviouslyPressed = keyPressedMap:getAndSetDefault(keyboard)
|
|
36
|
-
keyPressedMap:set(keyboard, isPressed)
|
|
37
|
-
if isPressed and not wasPreviouslyPressed then
|
|
38
|
-
triggerFunc(nil)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
local FEATURE_NAME = "registerHotkeys"
|
|
42
|
-
staticHotkeyFunctionMap = __TS__New(Map)
|
|
43
|
-
dynamicHotkeyFunctionMap = __TS__New(Map)
|
|
44
|
-
keyPressedMap = __TS__New(DefaultMap, false)
|
|
45
|
-
---
|
|
46
|
-
-- @internal
|
|
47
|
-
function ____exports.registerHotkeyInit(self, mod)
|
|
48
|
-
mod:AddCallback(ModCallback.POST_RENDER, postRender)
|
|
49
|
-
end
|
|
50
|
-
--- Helper function to run arbitrary code when you press and release a specific keyboard key.
|
|
51
|
-
--
|
|
52
|
-
-- This can be used to easily set up custom hotkeys to facilitate custom game features or to assist
|
|
53
|
-
-- in debugging.
|
|
54
|
-
--
|
|
55
|
-
-- @param keyboardOrFunc Either the key that you want to trigger the hotkey or a function that
|
|
56
|
-
-- returns the key that will trigger the hotkey. Normally, you would just
|
|
57
|
-
-- specify the key directly, but you can use a function for situations where
|
|
58
|
-
-- the key can change (like if end-users can specify a custom hotkey using Mod
|
|
59
|
-
-- Config Menu).
|
|
60
|
-
-- @param triggerFunc A function containing the arbitrary code that you want to execute when the
|
|
61
|
-
-- hotkey is triggered.
|
|
62
|
-
function ____exports.registerHotkey(self, keyboardOrFunc, triggerFunc)
|
|
63
|
-
errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
|
|
64
|
-
if isFunction(nil, keyboardOrFunc) then
|
|
65
|
-
if dynamicHotkeyFunctionMap:has(keyboardOrFunc) then
|
|
66
|
-
error("Failed to register a hotkey due to a custom hotkey already being defined for the submitted function.")
|
|
67
|
-
end
|
|
68
|
-
dynamicHotkeyFunctionMap:set(keyboardOrFunc, triggerFunc)
|
|
69
|
-
else
|
|
70
|
-
if staticHotkeyFunctionMap:has(keyboardOrFunc) then
|
|
71
|
-
error(((("Failed to register a hotkey due to a hotkey already being defined for key: Keyboard." .. tostring(Keyboard[keyboardOrFunc])) .. " (") .. tostring(keyboardOrFunc)) .. ")")
|
|
72
|
-
end
|
|
73
|
-
staticHotkeyFunctionMap:set(keyboardOrFunc, triggerFunc)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
--- Helper function to remove a hotkey created with the `registerHotkey` function.
|
|
77
|
-
--
|
|
78
|
-
-- @param keyboardOrFunc Equal to the value that you passed when initially registering the hotkey.
|
|
79
|
-
function ____exports.unregisterHotkey(self, keyboardOrFunc)
|
|
80
|
-
errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
|
|
81
|
-
if isFunction(nil, keyboardOrFunc) then
|
|
82
|
-
if not dynamicHotkeyFunctionMap:has(keyboardOrFunc) then
|
|
83
|
-
error("Failed to unregister a hotkey since there is no existing hotkey defined for the submitted function.")
|
|
84
|
-
end
|
|
85
|
-
dynamicHotkeyFunctionMap:delete(keyboardOrFunc)
|
|
86
|
-
else
|
|
87
|
-
if not staticHotkeyFunctionMap:has(keyboardOrFunc) then
|
|
88
|
-
error(((("Failed to unregister a hotkey since there is no existing hotkey defined for key: Keyboard." .. tostring(Keyboard[keyboardOrFunc])) .. " (") .. tostring(keyboardOrFunc)) .. ")")
|
|
89
|
-
end
|
|
90
|
-
staticHotkeyFunctionMap:delete(keyboardOrFunc)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
return ____exports
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { Keyboard, ModCallback } from "isaac-typescript-definitions";
|
|
2
|
-
import { DefaultMap } from "../classes/DefaultMap";
|
|
3
|
-
import { errorIfFeaturesNotInitialized } from "../featuresInitialized";
|
|
4
|
-
import { isKeyboardPressed } from "../functions/input";
|
|
5
|
-
import { isFunction } from "../functions/types";
|
|
6
|
-
|
|
7
|
-
const FEATURE_NAME = "registerHotkeys";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The keys are the keyboard keys that trigger the hotkey. The values are the functions that contain
|
|
11
|
-
* the arbitrary code to run.
|
|
12
|
-
*/
|
|
13
|
-
const staticHotkeyFunctionMap = new Map<Keyboard, () => void>();
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The keys are the functions that determine what the hotkey key is. The values are the functions
|
|
17
|
-
* that contain the arbitrary code to run.
|
|
18
|
-
*/
|
|
19
|
-
const dynamicHotkeyFunctionMap = new Map<
|
|
20
|
-
() => Keyboard | undefined,
|
|
21
|
-
() => void
|
|
22
|
-
>();
|
|
23
|
-
|
|
24
|
-
const keyPressedMap = new DefaultMap<Keyboard, boolean>(false);
|
|
25
|
-
|
|
26
|
-
/** @internal */
|
|
27
|
-
export function registerHotkeyInit(mod: Mod): void {
|
|
28
|
-
mod.AddCallback(ModCallback.POST_RENDER, postRender); // 2
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ModCallback.POST_RENDER (2)
|
|
32
|
-
function postRender() {
|
|
33
|
-
for (const [keyboard, triggerFunc] of staticHotkeyFunctionMap.entries()) {
|
|
34
|
-
checkIfTriggered(keyboard, triggerFunc);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
for (const [
|
|
38
|
-
keyboardFunc,
|
|
39
|
-
triggerFunc,
|
|
40
|
-
] of dynamicHotkeyFunctionMap.entries()) {
|
|
41
|
-
const keyboard = keyboardFunc();
|
|
42
|
-
if (keyboard !== undefined) {
|
|
43
|
-
checkIfTriggered(keyboard, triggerFunc);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function checkIfTriggered(keyboard: Keyboard, triggerFunc: () => void) {
|
|
49
|
-
const isPressed = isKeyboardPressed(keyboard);
|
|
50
|
-
const wasPreviouslyPressed = keyPressedMap.getAndSetDefault(keyboard);
|
|
51
|
-
keyPressedMap.set(keyboard, isPressed);
|
|
52
|
-
|
|
53
|
-
if (isPressed && !wasPreviouslyPressed) {
|
|
54
|
-
triggerFunc();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Helper function to run arbitrary code when you press and release a specific keyboard key.
|
|
60
|
-
*
|
|
61
|
-
* This can be used to easily set up custom hotkeys to facilitate custom game features or to assist
|
|
62
|
-
* in debugging.
|
|
63
|
-
*
|
|
64
|
-
* @param keyboardOrFunc Either the key that you want to trigger the hotkey or a function that
|
|
65
|
-
* returns the key that will trigger the hotkey. Normally, you would just
|
|
66
|
-
* specify the key directly, but you can use a function for situations where
|
|
67
|
-
* the key can change (like if end-users can specify a custom hotkey using Mod
|
|
68
|
-
* Config Menu).
|
|
69
|
-
* @param triggerFunc A function containing the arbitrary code that you want to execute when the
|
|
70
|
-
* hotkey is triggered.
|
|
71
|
-
*/
|
|
72
|
-
export function registerHotkey(
|
|
73
|
-
keyboardOrFunc: Keyboard | (() => Keyboard | undefined),
|
|
74
|
-
triggerFunc: () => void,
|
|
75
|
-
): void {
|
|
76
|
-
errorIfFeaturesNotInitialized(FEATURE_NAME);
|
|
77
|
-
|
|
78
|
-
if (isFunction(keyboardOrFunc)) {
|
|
79
|
-
if (dynamicHotkeyFunctionMap.has(keyboardOrFunc)) {
|
|
80
|
-
error(
|
|
81
|
-
"Failed to register a hotkey due to a custom hotkey already being defined for the submitted function.",
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
dynamicHotkeyFunctionMap.set(keyboardOrFunc, triggerFunc);
|
|
86
|
-
} else {
|
|
87
|
-
if (staticHotkeyFunctionMap.has(keyboardOrFunc)) {
|
|
88
|
-
error(
|
|
89
|
-
`Failed to register a hotkey due to a hotkey already being defined for key: Keyboard.${Keyboard[keyboardOrFunc]} (${keyboardOrFunc})`,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
staticHotkeyFunctionMap.set(keyboardOrFunc, triggerFunc);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Helper function to remove a hotkey created with the `registerHotkey` function.
|
|
99
|
-
*
|
|
100
|
-
* @param keyboardOrFunc Equal to the value that you passed when initially registering the hotkey.
|
|
101
|
-
*/
|
|
102
|
-
export function unregisterHotkey(
|
|
103
|
-
keyboardOrFunc: Keyboard | (() => Keyboard | undefined),
|
|
104
|
-
): void {
|
|
105
|
-
errorIfFeaturesNotInitialized(FEATURE_NAME);
|
|
106
|
-
|
|
107
|
-
if (isFunction(keyboardOrFunc)) {
|
|
108
|
-
if (!dynamicHotkeyFunctionMap.has(keyboardOrFunc)) {
|
|
109
|
-
error(
|
|
110
|
-
"Failed to unregister a hotkey since there is no existing hotkey defined for the submitted function.",
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
dynamicHotkeyFunctionMap.delete(keyboardOrFunc);
|
|
115
|
-
} else {
|
|
116
|
-
if (!staticHotkeyFunctionMap.has(keyboardOrFunc)) {
|
|
117
|
-
error(
|
|
118
|
-
`Failed to unregister a hotkey since there is no existing hotkey defined for key: Keyboard.${Keyboard[keyboardOrFunc]} (${keyboardOrFunc})`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
staticHotkeyFunctionMap.delete(keyboardOrFunc);
|
|
123
|
-
}
|
|
124
|
-
}
|