isaacscript-common 1.2.212 → 1.2.215

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.
@@ -37,6 +37,7 @@ export declare const FIRST_GLITCHED_COLLECTIBLE_TYPE: number;
37
37
  export declare const GAME_FRAMES_PER_SECOND = 30;
38
38
  export declare const GRID_INDEX_CENTER_OF_1X1_ROOM = 67;
39
39
  export declare const ISAAC_FRAMES_PER_SECOND = 60;
40
+ export declare const LEVEL_GRID_ROW_LENGTH = 13;
40
41
  /** In a 2x2 room, there can be 8 doors. */
41
42
  export declare const MAX_NUM_DOORS = 8;
42
43
  /**
@@ -13,6 +13,7 @@ ____exports.FIRST_GLITCHED_COLLECTIBLE_TYPE = (1 << 32) - 1
13
13
  ____exports.GAME_FRAMES_PER_SECOND = 30
14
14
  ____exports.GRID_INDEX_CENTER_OF_1X1_ROOM = 67
15
15
  ____exports.ISAAC_FRAMES_PER_SECOND = 60
16
+ ____exports.LEVEL_GRID_ROW_LENGTH = 13
16
17
  ____exports.MAX_NUM_DOORS = 8
17
18
  ____exports.MAX_NUM_FAMILIARS = 64
18
19
  ____exports.MAX_NUM_INPUTS = 4
@@ -10,6 +10,7 @@
10
10
  * - TSTL `Set`
11
11
  * - TSTL classes
12
12
  * - `DefaultMap`
13
+ * - Isaac `Color` objects
13
14
  * - Isaac `RNG` objects
14
15
  * - Isaac `Vector` objects
15
16
  *
@@ -11,6 +11,7 @@ import { SerializationType } from "../enums/SerializationType";
11
11
  * - TSTL `Set`
12
12
  * - TSTL classes
13
13
  * - `DefaultMap`
14
+ * - Isaac `Color` objects
14
15
  * - Isaac `RNG` objects
15
16
  * - Isaac `Vector` objects
16
17
  *
@@ -5,7 +5,7 @@ local Map = ____lualib.Map
5
5
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
6
6
  local __TS__Iterator = ____lualib.__TS__Iterator
7
7
  local ____exports = {}
8
- local isTSTLClass, copyClass, getNewClassFromMetatable, deepCopyValue, checkMetatable, validateValue, TSTL_CLASS_KEYS
8
+ local isTSTLClass, copyClass, getNewClassFromMetatable, deepCopyValue, checkMetatable, validateValue, isCopyableIsaacAPIClass, TSTL_CLASS_KEYS
9
9
  local ____DefaultMap = require("classes.DefaultMap")
10
10
  local DefaultMap = ____DefaultMap.DefaultMap
11
11
  local ____SerializationBrand = require("enums.private.SerializationBrand")
@@ -15,6 +15,8 @@ local ____SerializationType = require("enums.SerializationType")
15
15
  local SerializationType = ____SerializationType.SerializationType
16
16
  local ____constants = require("features.saveDataManager.constants")
17
17
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
18
+ local ____color = require("functions.color")
19
+ local isColor = ____color.isColor
18
20
  local ____log = require("functions.log")
19
21
  local log = ____log.log
20
22
  local ____rng = require("functions.rng")
@@ -236,12 +238,15 @@ function checkMetatable(self, ____table, traversalDescription)
236
238
  error(("The deepCopy function detected that \"" .. tableDescription) .. "\" has a metatable. Copying tables with metatables is not supported, unless they are explicitly handled by the save data manager. (e.g. Vectors, TypeScriptToLua Maps, etc.)")
237
239
  end
238
240
  function validateValue(self, value, valueType, traversalDescription)
239
- if isVector(nil, value) then
241
+ if isCopyableIsaacAPIClass(nil, value) then
240
242
  return
241
243
  end
242
244
  if valueType == "function" or valueType == "nil" or valueType == "thread" or valueType == "userdata" then
243
- error(((("The deepCopy function detected that \"" .. traversalDescription) .. "\" is of type \"") .. valueType) .. "\", which is not supported.")
245
+ error(((("The deepCopy function detected that \"" .. traversalDescription) .. "\" has a value of type \"") .. valueType) .. "\", which is not supported.")
244
246
  end
245
247
  end
248
+ function isCopyableIsaacAPIClass(self, value)
249
+ return isColor(nil, value) or isRNG(nil, value) or isVector(nil, value)
250
+ end
246
251
  TSTL_CLASS_KEYS = __TS__New(Set, {"____constructor", "__index", "constructor"})
247
252
  return ____exports
@@ -16,9 +16,9 @@ export declare function logColor(this: void, color: Color): void;
16
16
  export declare function logDamageFlags(this: void, flags: int): void;
17
17
  /** Helper function for printing out every entity (or filtered entity) in the current room. */
18
18
  export declare function logEntities(this: void, includeBackgroundEffects: boolean, entityTypeFilter?: EntityType | int): void;
19
- export declare function logEntity(this: void, entity: Entity): void;
20
19
  /** Helper function for printing out every entity flag that is turned on. Useful when debugging. */
21
20
  export declare function logEntityFlags(this: void, flags: int): void;
21
+ export declare function logEntityID(this: void, entity: Entity): void;
22
22
  /**
23
23
  * Helper function to log an error message and also print it to the console for better visibility.
24
24
  * This is useful in combination with an early return when invoking the `error` function would be
@@ -59,6 +59,11 @@ export declare function logTearFlags(this: void, flags: int): void;
59
59
  export declare function logTemporaryEffects(this: void, player: EntityPlayer): void;
60
60
  /** Helper function for printing out every use flag that is turned on. Useful when debugging. */
61
61
  export declare function logUseFlags(this: void, flags: int): void;
62
+ /**
63
+ * Helper function to enumerate all of the properties of a "userdata" object (i.e. an object from
64
+ * the Isaac API).
65
+ */
66
+ export declare function logUserdata(this: void, userdata: unknown): void;
62
67
  export declare function logVector(this: void, vector: Vector): void;
63
68
  /**
64
69
  * Converts every `isaacscript-common` function that begins with "log" to a global function.
@@ -190,12 +190,12 @@ function ____exports.logEntities(includeBackgroundEffects, entityTypeFilter)
190
190
  ____exports.log(("(" .. tostring(numMatchedEntities)) .. " total entities)")
191
191
  end
192
192
  end
193
- function ____exports.logEntity(entity)
194
- ____exports.log((((("Entity: " .. tostring(entity.Type)) .. ".") .. tostring(entity.Variant)) .. ".") .. tostring(entity.SubType))
195
- end
196
193
  function ____exports.logEntityFlags(flags)
197
194
  ____exports.logFlags(flags, EntityFlag, "entity")
198
195
  end
196
+ function ____exports.logEntityID(entity)
197
+ ____exports.log((((("Entity: " .. tostring(entity.Type)) .. ".") .. tostring(entity.Variant)) .. ".") .. tostring(entity.SubType))
198
+ end
199
199
  function ____exports.logError(msg)
200
200
  local errorMsg = "Error: " .. msg
201
201
  ____exports.log(errorMsg)
@@ -379,7 +379,11 @@ function ____exports.logTable(____table, parentTables)
379
379
  ____exports.log((((indentation .. "Key: ") .. tostring(key)) .. ", Value: ") .. tostring(value))
380
380
  local valueType = type(value)
381
381
  if valueType == "table" then
382
- ____exports.logTable(value, parentTables + 1)
382
+ if key == "__class" then
383
+ ____exports.log(indentation .. "(skipping enumerating this key to avoid infinite recursion)")
384
+ else
385
+ ____exports.logTable(value, parentTables + 1)
386
+ end
383
387
  end
384
388
  numKeys = numKeys + 1
385
389
  end
@@ -415,6 +419,20 @@ end
415
419
  function ____exports.logUseFlags(flags)
416
420
  ____exports.logFlags(flags, UseFlag, "use")
417
421
  end
422
+ function ____exports.logUserdata(userdata)
423
+ local userdataType = type(userdata)
424
+ if userdataType ~= "userdata" then
425
+ ____exports.log("Userdata: [not userdata]")
426
+ return
427
+ end
428
+ local metatable = getmetatable(userdata)
429
+ if metatable == nil then
430
+ ____exports.log("Userdata: [no metatable]")
431
+ return
432
+ end
433
+ ____exports.log("Userdata: " .. metatable.__type)
434
+ ____exports.logTable(metatable)
435
+ end
418
436
  function ____exports.logVector(vector)
419
437
  ____exports.log(((("Vector: (" .. tostring(vector.X)) .. ", ") .. tostring(vector.Y)) .. ")")
420
438
  end
@@ -425,7 +443,7 @@ function ____exports.setLogFunctionsGlobal(self)
425
443
  globals.logColor = ____exports.logColor
426
444
  globals.logDamageFlags = ____exports.logDamageFlags
427
445
  globals.logEntities = ____exports.logEntities
428
- globals.logEntity = ____exports.logEntity
446
+ globals.logEntityID = ____exports.logEntityID
429
447
  globals.logEntityFlags = ____exports.logEntityFlags
430
448
  globals.logError = ____exports.logError
431
449
  globals.logFlags = ____exports.logFlags
@@ -443,6 +461,7 @@ function ____exports.setLogFunctionsGlobal(self)
443
461
  globals.logTearFlags = ____exports.logTearFlags
444
462
  globals.logTemporaryEffects = ____exports.logTemporaryEffects
445
463
  globals.logUseFlags = ____exports.logUseFlags
464
+ globals.logUserdata = ____exports.logUserdata
446
465
  globals.logVector = ____exports.logVector
447
466
  end
448
467
  return ____exports
@@ -49,6 +49,8 @@ export declare function isDyingEggyWithNoSpidersLeft(npc: EntityNPC): boolean;
49
49
  * enemies.
50
50
  */
51
51
  export declare function isRaglingDeathPatch(npc: EntityNPC): boolean;
52
+ /** Helper function to check if the provided NPC is a Sin miniboss, such as Sloth or Lust. */
53
+ export declare function isSin(npc: EntityNPC): boolean;
52
54
  /**
53
55
  * Helper function to remove all NPCs in the room.
54
56
  *
@@ -7,6 +7,8 @@ local ____exports = {}
7
7
  local NON_ALIVE_NPCS_TYPE_VARIANT, NON_ALIVE_NPCS_TYPE_VARIANT_SUBTYPE
8
8
  local ____constants = require("constants")
9
9
  local EGGY_STATE_FRAME_OF_FINAL_SPIDER = ____constants.EGGY_STATE_FRAME_OF_FINAL_SPIDER
10
+ local ____sinEntityTypesSet = require("sets.sinEntityTypesSet")
11
+ local SIN_ENTITY_TYPES_SET = ____sinEntityTypesSet.SIN_ENTITY_TYPES_SET
10
12
  local ____entity = require("functions.entity")
11
13
  local getEntities = ____entity.getEntities
12
14
  local getFilteredNewEntities = ____entity.getFilteredNewEntities
@@ -139,6 +141,9 @@ function ____exports.getBosses(self, matchingEntityType, matchingVariant, matchi
139
141
  function(____, npc) return npc:IsBoss() end
140
142
  )
141
143
  end
144
+ function ____exports.isSin(self, npc)
145
+ return SIN_ENTITY_TYPES_SET:has(npc.Type)
146
+ end
142
147
  function ____exports.removeAllNPCs(self, cap)
143
148
  local npcs = ____exports.getNPCs(nil)
144
149
  return removeEntities(nil, npcs, cap)
@@ -15,6 +15,13 @@ export declare function getAllRoomGridIndexes(): int[];
15
15
  * tricky to properly detect.
16
16
  */
17
17
  export declare function getCurrentDimension(): Dimension;
18
+ /**
19
+ * Helper function to get the grid index delta that a door out of the given room shape would lead
20
+ * to. For example, if you went through the bottom door in a room of `RoomShape.ROOMSHAPE_1x2`, you
21
+ * would end up in a room with a grid index that is +26 units from the `SafeGridIndex` of where you
22
+ * started.
23
+ */
24
+ export declare function getGridIndexDelta(roomShape: RoomShape, doorSlot: DoorSlot): int | undefined;
18
25
  /**
19
26
  * Helper function to get an array of all of the safe grid indexes for rooms that match the
20
27
  * specified room type.
@@ -1,11 +1,11 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
3
+ local Map = ____lualib.Map
3
4
  local Set = ____lualib.Set
4
5
  local __TS__New = ____lualib.__TS__New
5
6
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
7
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
7
8
  local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
8
- local Map = ____lualib.Map
9
9
  local ____exports = {}
10
10
  local ____cachedClasses = require("cachedClasses")
11
11
  local game = ____cachedClasses.game
@@ -13,6 +13,8 @@ local sfxManager = ____cachedClasses.sfxManager
13
13
  local ____constants = require("constants")
14
14
  local MAX_ROOM_INDEX = ____constants.MAX_ROOM_INDEX
15
15
  local NUM_DIMENSIONS = ____constants.NUM_DIMENSIONS
16
+ local ____roomShapeToGridIndexDelta = require("objects.roomShapeToGridIndexDelta")
17
+ local ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA = ____roomShapeToGridIndexDelta.ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA
16
18
  local ____doors = require("functions.doors")
17
19
  local closeAllDoors = ____doors.closeAllDoors
18
20
  local getDoors = ____doors.getDoors
@@ -106,6 +108,13 @@ function ____exports.getCurrentDimension(self)
106
108
  end
107
109
  return error("Failed to get the current dimension using the starting room index of: " .. tostring(startingRoomGridIndex))
108
110
  end
111
+ function ____exports.getGridIndexDelta(self, roomShape, doorSlot)
112
+ local doorSlotToGridIndexMap = ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA[roomShape]
113
+ if doorSlotToGridIndexMap == nil then
114
+ return nil
115
+ end
116
+ return doorSlotToGridIndexMap:get(doorSlot)
117
+ end
109
118
  function ____exports.getRoomGridIndexesForType(self, ...)
110
119
  local roomTypesSet = __TS__New(Set, {...})
111
120
  local rooms = ____exports.getRooms(nil)
@@ -246,12 +255,12 @@ function ____exports.setRoomCleared(self)
246
255
  for ____, door in ipairs(getDoors(nil)) do
247
256
  do
248
257
  if isHiddenSecretRoomDoor(nil, door) then
249
- goto __continue46
258
+ goto __continue48
250
259
  end
251
260
  openDoorFast(nil, door)
252
261
  door.ExtraVisible = false
253
262
  end
254
- ::__continue46::
263
+ ::__continue48::
255
264
  end
256
265
  sfxManager:Stop(SoundEffect.SOUND_DOOR_HEAVY_OPEN)
257
266
  game:ShakeScreen(0)
@@ -0,0 +1,8 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Deltas are considered to be from the safe grid index of the room (i.e. the top left corner, or
4
+ * top right corner in the case of `RoomShape.ROOMSHAPE_LTL`).
5
+ */
6
+ export declare const ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA: {
7
+ readonly [key in RoomShape]: Map<DoorSlot, int> | undefined;
8
+ };
@@ -0,0 +1,85 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Map = ____lualib.Map
3
+ local __TS__New = ____lualib.__TS__New
4
+ local ____exports = {}
5
+ local ____constants = require("constants")
6
+ local LEVEL_GRID_ROW_LENGTH = ____constants.LEVEL_GRID_ROW_LENGTH
7
+ local LEFT = -1
8
+ local UP = -LEVEL_GRID_ROW_LENGTH
9
+ local RIGHT = 1
10
+ local DOWN = LEVEL_GRID_ROW_LENGTH
11
+ ____exports.ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA = {
12
+ [RoomShape.ROOMSHAPE_1x1] = __TS__New(Map, {{DoorSlot.LEFT0, LEFT}, {DoorSlot.UP0, UP}, {DoorSlot.RIGHT0, RIGHT}, {DoorSlot.DOWN0, DOWN}}),
13
+ [RoomShape.ROOMSHAPE_IH] = __TS__New(Map, {{DoorSlot.LEFT0, LEFT}, {DoorSlot.RIGHT0, RIGHT}}),
14
+ [RoomShape.ROOMSHAPE_IV] = __TS__New(Map, {{DoorSlot.UP0, UP}, {DoorSlot.DOWN0, DOWN}}),
15
+ [RoomShape.ROOMSHAPE_1x2] = __TS__New(Map, {
16
+ {DoorSlot.LEFT0, LEFT},
17
+ {DoorSlot.UP0, UP},
18
+ {DoorSlot.RIGHT0, RIGHT},
19
+ {DoorSlot.DOWN0, DOWN + DOWN},
20
+ {DoorSlot.LEFT1, DOWN + LEFT},
21
+ {DoorSlot.RIGHT1, DOWN + RIGHT}
22
+ }),
23
+ [RoomShape.ROOMSHAPE_IIV] = __TS__New(Map, {{DoorSlot.UP0, UP}, {DoorSlot.DOWN0, DOWN + DOWN}}),
24
+ [RoomShape.ROOMSHAPE_2x1] = __TS__New(Map, {
25
+ {DoorSlot.LEFT0, LEFT},
26
+ {DoorSlot.UP0, UP},
27
+ {DoorSlot.RIGHT0, RIGHT + RIGHT},
28
+ {DoorSlot.DOWN0, DOWN},
29
+ {DoorSlot.UP1, RIGHT + UP},
30
+ {DoorSlot.DOWN1, RIGHT + DOWN}
31
+ }),
32
+ [RoomShape.ROOMSHAPE_IIH] = __TS__New(Map, {{DoorSlot.LEFT0, LEFT}, {DoorSlot.RIGHT0, RIGHT + RIGHT}}),
33
+ [RoomShape.ROOMSHAPE_2x2] = __TS__New(Map, {
34
+ {DoorSlot.LEFT0, LEFT},
35
+ {DoorSlot.UP0, UP},
36
+ {DoorSlot.RIGHT0, RIGHT + RIGHT},
37
+ {DoorSlot.DOWN0, DOWN + DOWN},
38
+ {DoorSlot.LEFT1, DOWN + LEFT},
39
+ {DoorSlot.UP1, RIGHT + UP},
40
+ {DoorSlot.RIGHT1, RIGHT + DOWN + RIGHT},
41
+ {DoorSlot.DOWN1, RIGHT + DOWN + DOWN}
42
+ }),
43
+ [RoomShape.ROOMSHAPE_LTL] = __TS__New(Map, {
44
+ {DoorSlot.LEFT0, LEFT},
45
+ {DoorSlot.UP0, DOWN + LEFT + UP},
46
+ {DoorSlot.RIGHT0, RIGHT},
47
+ {DoorSlot.DOWN0, DOWN + LEFT + DOWN},
48
+ {DoorSlot.LEFT1, DOWN + LEFT + LEFT},
49
+ {DoorSlot.UP1, UP},
50
+ {DoorSlot.RIGHT1, DOWN + RIGHT},
51
+ {DoorSlot.DOWN1, DOWN + DOWN}
52
+ }),
53
+ [RoomShape.ROOMSHAPE_LTR] = __TS__New(Map, {
54
+ {DoorSlot.LEFT0, LEFT},
55
+ {DoorSlot.UP0, UP},
56
+ {DoorSlot.RIGHT0, RIGHT},
57
+ {DoorSlot.DOWN0, DOWN + DOWN},
58
+ {DoorSlot.LEFT1, DOWN + LEFT},
59
+ {DoorSlot.UP1, DOWN + RIGHT + UP},
60
+ {DoorSlot.RIGHT1, DOWN + RIGHT + RIGHT},
61
+ {DoorSlot.DOWN1, DOWN + RIGHT + DOWN}
62
+ }),
63
+ [RoomShape.ROOMSHAPE_LBL] = __TS__New(Map, {
64
+ {DoorSlot.LEFT0, LEFT},
65
+ {DoorSlot.UP0, UP},
66
+ {DoorSlot.RIGHT0, RIGHT + RIGHT},
67
+ {DoorSlot.DOWN0, DOWN},
68
+ {DoorSlot.LEFT1, RIGHT + DOWN + LEFT},
69
+ {DoorSlot.UP1, RIGHT + UP},
70
+ {DoorSlot.RIGHT1, RIGHT + DOWN + RIGHT},
71
+ {DoorSlot.DOWN1, RIGHT + DOWN + DOWN}
72
+ }),
73
+ [RoomShape.ROOMSHAPE_LBR] = __TS__New(Map, {
74
+ {DoorSlot.LEFT0, LEFT},
75
+ {DoorSlot.UP0, UP},
76
+ {DoorSlot.RIGHT0, RIGHT + RIGHT},
77
+ {DoorSlot.DOWN0, DOWN + DOWN},
78
+ {DoorSlot.LEFT1, DOWN + LEFT},
79
+ {DoorSlot.UP1, RIGHT + UP},
80
+ {DoorSlot.RIGHT1, DOWN + RIGHT},
81
+ {DoorSlot.DOWN1, RIGHT + DOWN}
82
+ }),
83
+ [RoomShape.NUM_ROOMSHAPES] = nil
84
+ }
85
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ export declare const SIN_ENTITY_TYPES_SET: ReadonlySet<EntityType>;
@@ -0,0 +1,14 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Set = ____lualib.Set
3
+ local __TS__New = ____lualib.__TS__New
4
+ local ____exports = {}
5
+ ____exports.SIN_ENTITY_TYPES_SET = __TS__New(Set, {
6
+ EntityType.ENTITY_SLOTH,
7
+ EntityType.ENTITY_LUST,
8
+ EntityType.ENTITY_WRATH,
9
+ EntityType.ENTITY_GLUTTONY,
10
+ EntityType.ENTITY_GREED,
11
+ EntityType.ENTITY_ENVY,
12
+ EntityType.ENTITY_PRIDE
13
+ })
14
+ return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.212",
3
+ "version": "1.2.215",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -29,7 +29,7 @@
29
29
  "isaacscript-lint": "^1.0.95",
30
30
  "isaacscript-tsconfig": "^1.1.8",
31
31
  "typedoc": "^0.22.13",
32
- "typescript": "4.6.2",
32
+ "typescript": "4.6.3",
33
33
  "typescript-to-lua": "^1.4.2"
34
34
  }
35
35
  }