isaacscript-common 1.2.200 → 1.2.203

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.
Files changed (56) hide show
  1. package/dist/callbacks/customRevive.lua +6 -11
  2. package/dist/callbacks/postNewRoomEarly.lua +3 -5
  3. package/dist/classes/ModUpgraded.d.ts +1 -3
  4. package/dist/classes/ModUpgraded.lua +2 -36
  5. package/dist/constants.d.ts +4 -0
  6. package/dist/constants.lua +2 -0
  7. package/dist/enums/private/SerializationBrand.d.ts +2 -0
  8. package/dist/enums/private/SerializationBrand.lua +2 -0
  9. package/dist/features/deployJSONRoom.d.ts +6 -12
  10. package/dist/features/deployJSONRoom.lua +17 -18
  11. package/dist/features/saveDataManager/load.lua +2 -1
  12. package/dist/features/saveDataManager/main.lua +3 -3
  13. package/dist/features/saveDataManager/merge.d.ts +12 -3
  14. package/dist/features/saveDataManager/merge.lua +16 -11
  15. package/dist/functions/array.d.ts +7 -7
  16. package/dist/functions/array.lua +22 -22
  17. package/dist/functions/cards.d.ts +6 -6
  18. package/dist/functions/cards.lua +14 -12
  19. package/dist/functions/color.d.ts +19 -1
  20. package/dist/functions/color.lua +89 -10
  21. package/dist/functions/deepCopy.d.ts +8 -12
  22. package/dist/functions/deepCopy.lua +13 -29
  23. package/dist/functions/doors.d.ts +4 -0
  24. package/dist/functions/doors.lua +12 -2
  25. package/dist/functions/entity.lua +4 -4
  26. package/dist/functions/jsonHelpers.lua +2 -2
  27. package/dist/functions/jsonRoom.d.ts +1 -1
  28. package/dist/functions/jsonRoom.lua +6 -4
  29. package/dist/functions/log.d.ts +12 -1
  30. package/dist/functions/log.lua +12 -4
  31. package/dist/functions/map.d.ts +0 -12
  32. package/dist/functions/map.lua +0 -23
  33. package/dist/functions/random.d.ts +27 -27
  34. package/dist/functions/random.lua +35 -29
  35. package/dist/functions/revive.lua +7 -0
  36. package/dist/functions/rng.d.ts +44 -0
  37. package/dist/functions/rng.lua +106 -0
  38. package/dist/functions/roomData.d.ts +5 -0
  39. package/dist/functions/roomData.lua +31 -4
  40. package/dist/functions/set.d.ts +2 -2
  41. package/dist/functions/set.lua +6 -4
  42. package/dist/functions/spawnCollectible.d.ts +3 -3
  43. package/dist/functions/spawnCollectible.lua +11 -10
  44. package/dist/functions/table.d.ts +30 -0
  45. package/dist/functions/table.lua +73 -1
  46. package/dist/functions/utils.d.ts +5 -0
  47. package/dist/functions/utils.lua +12 -0
  48. package/dist/functions/vector.d.ts +23 -3
  49. package/dist/functions/vector.lua +72 -21
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.lua +8 -0
  52. package/dist/objects/roomShapeToDoorSlots.d.ts +4 -0
  53. package/dist/objects/roomShapeToDoorSlots.lua +44 -0
  54. package/dist/upgradeMod.d.ts +1 -3
  55. package/dist/upgradeMod.lua +2 -5
  56. package/package.json +2 -2
@@ -20,6 +20,8 @@ local CARD_TYPES = ____cardTypes.CARD_TYPES
20
20
  local DEFAULT_CARD_TYPE = ____cardTypes.DEFAULT_CARD_TYPE
21
21
  local ____math = require("functions.math")
22
22
  local range = ____math.range
23
+ local ____rng = require("functions.rng")
24
+ local newRNG = ____rng.newRNG
23
25
  local ____set = require("functions.set")
24
26
  local addSetsToSet = ____set.addSetsToSet
25
27
  local getRandomSetElement = ____set.getRandomSetElement
@@ -98,35 +100,35 @@ function ____exports.getCardName(self, card)
98
100
  end
99
101
  return DEFAULT_CARD_NAME
100
102
  end
101
- function ____exports.getRandomCard(self, seed, exceptions)
102
- if seed == nil then
103
- seed = Random()
103
+ function ____exports.getRandomCard(self, rng, exceptions)
104
+ if rng == nil then
105
+ rng = newRNG(nil)
104
106
  end
105
107
  if exceptions == nil then
106
108
  exceptions = {}
107
109
  end
108
- return getRandomSetElement(nil, CARD_SET, seed, exceptions)
110
+ return getRandomSetElement(nil, CARD_SET, rng, exceptions)
109
111
  end
110
- function ____exports.getRandomCardOfType(self, cardType, seed, exceptions)
111
- if seed == nil then
112
- seed = Random()
112
+ function ____exports.getRandomCardOfType(self, cardType, rng, exceptions)
113
+ if rng == nil then
114
+ rng = newRNG(nil)
113
115
  end
114
116
  if exceptions == nil then
115
117
  exceptions = {}
116
118
  end
117
119
  local cardSet = ____exports.getCardsOfType(nil, cardType)
118
- return getRandomSetElement(nil, cardSet, seed, exceptions)
120
+ return getRandomSetElement(nil, cardSet, rng, exceptions)
119
121
  end
120
- function ____exports.getRandomRune(self, seed, exceptions)
121
- if seed == nil then
122
- seed = Random()
122
+ function ____exports.getRandomRune(self, rng, exceptions)
123
+ if rng == nil then
124
+ rng = newRNG(nil)
123
125
  end
124
126
  if exceptions == nil then
125
127
  exceptions = {}
126
128
  end
127
129
  local runesSet = ____exports.getCardsOfType(nil, CardType.RUNE)
128
130
  runesSet:delete(Card.RUNE_SHARD)
129
- return getRandomSetElement(nil, runesSet, seed, exceptions)
131
+ return getRandomSetElement(nil, runesSet, rng, exceptions)
130
132
  end
131
133
  function ____exports.isCard(self, card)
132
134
  return CARD_SET:has(card)
@@ -1,5 +1,23 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
- export declare function copyColor(color: Color): Color;
2
+ /// <reference types="typescript-to-lua/language-extensions" />
3
+ import { SerializationType } from "../enums/SerializationType";
4
+ declare type SerializedColor = LuaTable<string, string | number>;
5
+ interface CopyColorReturn {
6
+ [SerializationType.NONE]: Color;
7
+ [SerializationType.SERIALIZE]: SerializedColor;
8
+ [SerializationType.DESERIALIZE]: Color;
9
+ }
10
+ /**
11
+ * Helper function to copy a `Color` object.
12
+ *
13
+ * @param color The Color object to copy. In the case of deserialization, this will actually be a
14
+ * Lua table instead of an instantiated Color class.
15
+ * @param serializationType Default is `SerializationType.NONE`.
16
+ */
17
+ export declare function copyColor<C extends Color | SerializedColor, S extends SerializationType>(color: C, serializationType: S): CopyColorReturn[S];
3
18
  export declare function copyKColor(kColor: KColor): KColor;
4
19
  export declare function getDefaultColor(): Color;
5
20
  export declare function getDefaultKColor(): KColor;
21
+ /** Helper function to check if something is an instantiated Color object. */
22
+ export declare function isColor(object: unknown): object is Color;
23
+ export {};
@@ -1,15 +1,94 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
- function ____exports.copyColor(self, color)
4
- return Color(
5
- color.R,
6
- color.G,
7
- color.B,
8
- color.A,
9
- color.RO,
10
- color.GO,
11
- color.BO
12
- )
3
+ local OBJECT_NAME
4
+ local ____SerializationBrand = require("enums.private.SerializationBrand")
5
+ local SerializationBrand = ____SerializationBrand.SerializationBrand
6
+ local ____SerializationType = require("enums.SerializationType")
7
+ local SerializationType = ____SerializationType.SerializationType
8
+ local ____table = require("functions.table")
9
+ local copyValuesToTable = ____table.copyValuesToTable
10
+ local getNumbersFromTable = ____table.getNumbersFromTable
11
+ local ____utils = require("functions.utils")
12
+ local ensureAllCases = ____utils.ensureAllCases
13
+ local isUserdataObject = ____utils.isUserdataObject
14
+ function ____exports.isColor(self, object)
15
+ return isUserdataObject(nil, object, OBJECT_NAME)
16
+ end
17
+ local KEYS = {
18
+ "R",
19
+ "G",
20
+ "B",
21
+ "A",
22
+ "RO",
23
+ "GO",
24
+ "BO"
25
+ }
26
+ OBJECT_NAME = "Color"
27
+ function ____exports.copyColor(self, color, serializationType)
28
+ if serializationType == nil then
29
+ serializationType = SerializationType.NONE
30
+ end
31
+ repeat
32
+ local ____switch3 = serializationType
33
+ local ____cond3 = ____switch3 == SerializationType.NONE
34
+ if ____cond3 then
35
+ do
36
+ if not ____exports.isColor(nil, color) then
37
+ error(((("Failed to copy a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
38
+ end
39
+ return Color(
40
+ color.R,
41
+ color.G,
42
+ color.B,
43
+ color.A,
44
+ color.RO,
45
+ color.GO,
46
+ color.BO
47
+ )
48
+ end
49
+ end
50
+ ____cond3 = ____cond3 or ____switch3 == SerializationType.SERIALIZE
51
+ if ____cond3 then
52
+ do
53
+ if not ____exports.isColor(nil, color) then
54
+ error(((("Failed to serialize a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
55
+ end
56
+ local colorTable = {}
57
+ copyValuesToTable(nil, color, KEYS, colorTable)
58
+ colorTable[SerializationBrand.COLOR] = ""
59
+ return colorTable
60
+ end
61
+ end
62
+ ____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
63
+ if ____cond3 then
64
+ do
65
+ local colorType = type(color)
66
+ if ____exports.isColor(nil, color) or colorType ~= "table" then
67
+ error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
68
+ end
69
+ local r, g, b, a, ro, go, bo = table.unpack(getNumbersFromTable(
70
+ nil,
71
+ color,
72
+ OBJECT_NAME,
73
+ table.unpack(KEYS)
74
+ ))
75
+ return Color(
76
+ r,
77
+ g,
78
+ b,
79
+ a,
80
+ ro,
81
+ go,
82
+ bo
83
+ )
84
+ end
85
+ end
86
+ do
87
+ do
88
+ return ensureAllCases(nil, serializationType)
89
+ end
90
+ end
91
+ until true
13
92
  end
14
93
  function ____exports.copyKColor(self, kColor)
15
94
  return KColor(kColor.Red, kColor.Green, kColor.Blue, kColor.Alpha)
@@ -6,22 +6,18 @@ import { SerializationType } from "../enums/SerializationType";
6
6
  *
7
7
  * It supports the following object types:
8
8
  *
9
- * - LuaTables / basic TSTL objects
10
- * - TSTL Maps
11
- * - TSTL Sets
12
- * - TSTL Classes
13
- * - DefaultMaps
14
- * - Isaac Vectors
9
+ * - `LuaTable` / basic TSTL objects
10
+ * - TSTL `Map`
11
+ * - TSTL `Set`
12
+ * - TSTL classes
13
+ * - `DefaultMap`
14
+ * - Isaac `RNG` objects
15
+ * - Isaac `Vector` objects
15
16
  *
16
17
  * @param oldObject The object to copy.
17
18
  * @param serializationType Has 3 possible values. Can leave TypeScriptToLua objects as-is, or can
18
- * serialize objects to Lua tables, or can deserialize Lua tables to objects. Defaults to
19
+ * serialize objects to Lua tables, or can deserialize Lua tables to objects. Default is
19
20
  * `SerializationType.NONE`.
20
21
  * @param traversalDescription Used to track the current key that we are operating on.
21
22
  */
22
23
  export declare function deepCopy(oldObject: LuaTable | Map<AnyNotNil, unknown> | Set<AnyNotNil>, serializationType?: SerializationType, traversalDescription?: string): LuaTable | Map<AnyNotNil, unknown> | Set<AnyNotNil>;
23
- /**
24
- * Used to determine is the given table is a serialized Vector created by the save data manager
25
- * and/or the `deepCopy` function.
26
- */
27
- export declare function isSerializedVector(object: unknown): boolean;
@@ -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, copyVector, checkMetatable, validateValue, TSTL_CLASS_KEYS
8
+ local isTSTLClass, copyClass, getNewClassFromMetatable, deepCopyValue, checkMetatable, validateValue, TSTL_CLASS_KEYS
9
9
  local ____DefaultMap = require("classes.DefaultMap")
10
10
  local DefaultMap = ____DefaultMap.DefaultMap
11
11
  local ____SerializationBrand = require("enums.private.SerializationBrand")
@@ -17,10 +17,15 @@ local ____constants = require("features.saveDataManager.constants")
17
17
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
18
18
  local ____log = require("functions.log")
19
19
  local log = ____log.log
20
+ local ____rng = require("functions.rng")
21
+ local copyRNG = ____rng.copyRNG
22
+ local isRNG = ____rng.isRNG
23
+ local isSerializedRNG = ____rng.isSerializedRNG
20
24
  local ____utils = require("functions.utils")
21
25
  local getTraversalDescription = ____utils.getTraversalDescription
22
26
  local ____vector = require("functions.vector")
23
- local deserializeVector = ____vector.deserializeVector
27
+ local copyVector = ____vector.copyVector
28
+ local isSerializedVector = ____vector.isSerializedVector
24
29
  local isVector = ____vector.isVector
25
30
  function ____exports.deepCopy(self, oldObject, serializationType, traversalDescription)
26
31
  if serializationType == nil then
@@ -202,12 +207,10 @@ function deepCopyValue(self, oldObject, newObject, key, value, traversalDescript
202
207
  end
203
208
  end
204
209
  local newValue
205
- if isVector(nil, value) then
206
- local vector = value
207
- newValue = copyVector(nil, vector, serializationType)
208
- elseif ____exports.isSerializedVector(nil, value) and serializationType == SerializationType.DESERIALIZE then
209
- local serializedVector = value
210
- newValue = deserializeVector(nil, serializedVector)
210
+ if isRNG(nil, value) or isSerializedRNG(nil, value) and serializationType == SerializationType.DESERIALIZE then
211
+ newValue = copyRNG(nil, value, serializationType)
212
+ elseif isVector(nil, value) or isSerializedVector(nil, value) and serializationType == SerializationType.DESERIALIZE then
213
+ newValue = copyVector(nil, value, serializationType)
211
214
  elseif valueType == "table" then
212
215
  local ____table = value
213
216
  traversalDescription = getTraversalDescription(nil, key, traversalDescription)
@@ -224,40 +227,21 @@ function deepCopyValue(self, oldObject, newObject, key, value, traversalDescript
224
227
  newObject[keyToUse] = newValue
225
228
  end
226
229
  end
227
- function copyVector(self, vector, serializationType)
228
- if serializationType == SerializationType.SERIALIZE then
229
- local vectorTable = {}
230
- vectorTable.X = vector.X
231
- vectorTable.Y = vector.Y
232
- vectorTable[SerializationBrand.VECTOR] = ""
233
- return vectorTable
234
- end
235
- local newVector = Vector(vector.X, vector.Y)
236
- return newVector
237
- end
238
230
  function checkMetatable(self, ____table, traversalDescription)
239
231
  local metatable = getmetatable(____table)
240
232
  if metatable == nil then
241
233
  return
242
234
  end
243
235
  local tableDescription = traversalDescription == "" and "the table to copy" or ("\"" .. traversalDescription) .. "\""
244
- error(("The deepCopy function detected that " .. tableDescription) .. " has a metatable. Copying tables with metatables is not supported (unless they are TypeScriptToLua Maps, Sets, or Classes).")
236
+ 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.)")
245
237
  end
246
238
  function validateValue(self, value, valueType, traversalDescription)
247
239
  if isVector(nil, value) then
248
240
  return
249
241
  end
250
242
  if valueType == "function" or valueType == "nil" or valueType == "thread" or valueType == "userdata" then
251
- error(((("The deepCopy function detected that \"" .. traversalDescription) .. "\" is type ") .. valueType) .. ", which is not supported.")
252
- end
253
- end
254
- function ____exports.isSerializedVector(self, object)
255
- local objectType = type(object)
256
- if objectType ~= "table" then
257
- return false
243
+ error(((("The deepCopy function detected that \"" .. traversalDescription) .. "\" is of type \"") .. valueType) .. "\", which is not supported.")
258
244
  end
259
- local ____table = object
260
- return ____table[SerializationBrand.VECTOR] ~= nil and ____table.X ~= nil and ____table.Y ~= nil
261
245
  end
262
246
  TSTL_CLASS_KEYS = __TS__New(Set, {"____constructor", "__index", "constructor"})
263
247
  return ____exports
@@ -13,6 +13,8 @@ export declare function getDevilRoomDoor(): GridEntityDoor | undefined;
13
13
  * lowest slot number.
14
14
  */
15
15
  export declare function getDevilRoomOrAngelRoomDoor(): GridEntityDoor | undefined;
16
+ /** Helper function to get the possible door slots that can exist for a given room shape. */
17
+ export declare function getDoorSlotsForRoomShape(roomShape: RoomShape): ReadonlySet<DoorSlot>;
16
18
  /**
17
19
  * Helper function to get all of the doors in the room. By default, it will return every door. You
18
20
  * can optionally specify one or more room types to return only the doors that match the specified
@@ -29,6 +31,8 @@ export declare function getDoorsToRoomIndex(...roomGridIndex: int[]): GridEntity
29
31
  export declare function getRepentanceDoor(): GridEntityDoor | undefined;
30
32
  export declare function isAngelRoomDoor(door: GridEntityDoor): boolean;
31
33
  export declare function isDevilRoomDoor(door: GridEntityDoor): boolean;
34
+ /** Helper function to see if a door slot could exist for a given room shape. */
35
+ export declare function isDoorSlotInRoomShape(doorSlot: DoorSlot, roomShape: RoomShape): boolean;
32
36
  /**
33
37
  * This refers to the Repentance door that spawns in a boss room after defeating the boss.
34
38
  * You have to spend one key to open it.
@@ -11,6 +11,8 @@ local ____constants = require("constants")
11
11
  local MAX_NUM_DOORS = ____constants.MAX_NUM_DOORS
12
12
  local ____doorSlotToDirection = require("objects.doorSlotToDirection")
13
13
  local DOOR_SLOT_TO_DIRECTION = ____doorSlotToDirection.DOOR_SLOT_TO_DIRECTION
14
+ local ____roomShapeToDoorSlots = require("objects.roomShapeToDoorSlots")
15
+ local ROOM_SHAPE_TO_DOOR_SLOTS = ____roomShapeToDoorSlots.ROOM_SHAPE_TO_DOOR_SLOTS
14
16
  function ____exports.getDoors(self, ...)
15
17
  local roomTypes = {...}
16
18
  local room = game:GetRoom()
@@ -22,13 +24,13 @@ function ____exports.getDoors(self, ...)
22
24
  do
23
25
  local door = room:GetDoor(i)
24
26
  if door == nil then
25
- goto __continue11
27
+ goto __continue12
26
28
  end
27
29
  if #roomTypes == 0 or roomTypesSet:has(door.TargetRoomType) then
28
30
  __TS__ArrayPush(doors, door)
29
31
  end
30
32
  end
31
- ::__continue11::
33
+ ::__continue12::
32
34
  i = i + 1
33
35
  end
34
36
  end
@@ -95,6 +97,10 @@ function ____exports.getDevilRoomOrAngelRoomDoor(self)
95
97
  end
96
98
  return ____temp_2
97
99
  end
100
+ function ____exports.getDoorSlotsForRoomShape(self, roomShape)
101
+ local doorSlots = ROOM_SHAPE_TO_DOOR_SLOTS[roomShape]
102
+ return doorSlots == nil and __TS__New(Set) or doorSlots
103
+ end
98
104
  function ____exports.getDoorsToRoomIndex(self, ...)
99
105
  local roomGridIndex = {...}
100
106
  local roomGridIndexesSet = __TS__New(Set, roomGridIndex)
@@ -117,6 +123,10 @@ end
117
123
  function ____exports.isDevilRoomDoor(self, door)
118
124
  return door.TargetRoomType == RoomType.ROOM_DEVIL
119
125
  end
126
+ function ____exports.isDoorSlotInRoomShape(self, doorSlot, roomShape)
127
+ local doorSlots = ____exports.getDoorSlotsForRoomShape(nil, roomShape)
128
+ return doorSlots:has(doorSlot)
129
+ end
120
130
  function ____exports.isDoorToDownpour(self, door)
121
131
  if not ____exports.isRepentanceDoor(nil, door) then
122
132
  return false
@@ -10,7 +10,8 @@ local ____storyBossesSet = require("sets.storyBossesSet")
10
10
  local STORY_BOSSES_SET = ____storyBossesSet.STORY_BOSSES_SET
11
11
  local ____random = require("functions.random")
12
12
  local getRandom = ____random.getRandom
13
- local nextSeed = ____random.nextSeed
13
+ local ____rng = require("functions.rng")
14
+ local newRNG = ____rng.newRNG
14
15
  local ____utils = require("functions.utils")
15
16
  local ____repeat = ____utils["repeat"]
16
17
  function ____exports.removeEntities(self, entities, cap)
@@ -136,13 +137,12 @@ function ____exports.rerollEnemy(self, entity)
136
137
  end
137
138
  function ____exports.setEntityRandomColor(self, entity)
138
139
  local colorValues = {}
139
- local seed = entity.InitSeed
140
+ local rng = newRNG(nil, entity.InitSeed)
140
141
  ____repeat(
141
142
  nil,
142
143
  3,
143
144
  function()
144
- seed = nextSeed(nil, seed)
145
- local randomColorValue = getRandom(nil, seed)
145
+ local randomColorValue = getRandom(nil, rng)
146
146
  __TS__ArrayPush(colorValues, randomColorValue)
147
147
  end
148
148
  )
@@ -2,7 +2,7 @@
2
2
  local ____exports = {}
3
3
  local json = require("@NoResolution:json")
4
4
  local ____log = require("functions.log")
5
- local log = ____log.log
5
+ local logError = ____log.logError
6
6
  local function tryDecode(jsonString)
7
7
  return json.decode(jsonString)
8
8
  end
@@ -12,7 +12,7 @@ end
12
12
  function ____exports.jsonDecode(self, jsonString)
13
13
  local ok, luaTableOrErrMsg = pcall(tryDecode, jsonString)
14
14
  if not ok then
15
- log("Error: Failed to convert the JSON string to a Lua table: " .. jsonString)
15
+ logError("Failed to convert the JSON string to a Lua table: " .. jsonString)
16
16
  return {}
17
17
  end
18
18
  return luaTableOrErrMsg
@@ -9,4 +9,4 @@ export declare function getJSONRoomsOfSubType(jsonRooms: JSONRoom[], subType: in
9
9
  * properly account for each room weight using the algorithm from:
10
10
  * https://stackoverflow.com/questions/1761626/weighted-random-numbers
11
11
  */
12
- export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], seed?: Seed, verbose?: boolean): JSONRoom;
12
+ export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], rng?: RNG, verbose?: boolean): JSONRoom;
@@ -9,6 +9,8 @@ local ____log = require("functions.log")
9
9
  local log = ____log.log
10
10
  local ____random = require("functions.random")
11
11
  local getRandomFloat = ____random.getRandomFloat
12
+ local ____rng = require("functions.rng")
13
+ local newRNG = ____rng.newRNG
12
14
  function getTotalWeightOfJSONRooms(self, jsonRooms)
13
15
  local weights = __TS__ArrayMap(
14
16
  jsonRooms,
@@ -64,9 +66,9 @@ function ____exports.getJSONRoomsOfSubType(self, jsonRooms, subType)
64
66
  end
65
67
  )
66
68
  end
67
- function ____exports.getRandomJSONRoom(self, jsonRooms, seed, verbose)
68
- if seed == nil then
69
- seed = Random()
69
+ function ____exports.getRandomJSONRoom(self, jsonRooms, rng, verbose)
70
+ if rng == nil then
71
+ rng = newRNG(nil)
70
72
  end
71
73
  if verbose == nil then
72
74
  verbose = false
@@ -75,7 +77,7 @@ function ____exports.getRandomJSONRoom(self, jsonRooms, seed, verbose)
75
77
  if verbose then
76
78
  log("Total weight of the JSON rooms provided: " .. tostring(totalWeight))
77
79
  end
78
- local chosenWeight = getRandomFloat(nil, 0, totalWeight, seed)
80
+ local chosenWeight = getRandomFloat(nil, 0, totalWeight, rng)
79
81
  if verbose then
80
82
  log("Randomly chose weight for JSON room: " .. tostring(chosenWeight))
81
83
  end
@@ -14,16 +14,27 @@ export declare function logArray<T>(this: void, array: T[]): void;
14
14
  export declare function logColor(this: void, color: Color): void;
15
15
  /** Helper function for printing out every damage flag that is turned on. Useful when debugging. */
16
16
  export declare function logDamageFlags(this: void, flags: int): void;
17
+ /** Helper function for printing out every entity (or filtered entity) in the current room. */
17
18
  export declare function logEntities(this: void, includeBackgroundEffects: boolean, entityTypeFilter?: EntityType | int): void;
18
19
  export declare function logEntity(this: void, entity: Entity): void;
19
20
  /** Helper function for printing out every entity flag that is turned on. Useful when debugging. */
20
21
  export declare function logEntityFlags(this: void, flags: int): void;
22
+ /**
23
+ * Helper function to log an error message and also print it to the console for better visibility.
24
+ * This is useful in combination with an early return when invoking the `error` function would be
25
+ * dangerous (since it prevents all of the subsequent code in the callback from running).
26
+ */
27
+ export declare function logError(this: void, msg: string): void;
21
28
  /** Helper function for printing out every flag that is turned on. Useful when debugging. */
22
29
  export declare function logFlags(this: void, flags: int, flagEnum?: LuaTable, description?: string): void;
23
30
  /**
24
31
  * Helper function for printing out every game state flag that is turned on. Useful when debugging.
25
32
  */
26
33
  export declare function logGameStateFlags(this: void): void;
34
+ /**
35
+ * Helper function for printing out every grid entity (or filtered grid entity) in the current
36
+ * room.
37
+ */
27
38
  export declare function logGridEntities(this: void, includeWalls: boolean, gridEntityTypeFilter?: GridEntityType | int): void;
28
39
  export declare function logKColor(this: void, kColor: KColor): void;
29
40
  export declare function logMap(this: void, map: Map<AnyNotNil, unknown>): void;
@@ -47,7 +58,7 @@ export declare function logTable(this: void, table: unknown, parentTables?: numb
47
58
  export declare function logTearFlags(this: void, flags: int): void;
48
59
  export declare function logTemporaryEffects(this: void, player: EntityPlayer): void;
49
60
  /** Helper function for printing out every use flag that is turned on. Useful when debugging. */
50
- export declare function logUseFlags(this: void, _flags: int): void;
61
+ export declare function logUseFlags(this: void, flags: int): void;
51
62
  export declare function logVector(this: void, vector: Vector): void;
52
63
  /**
53
64
  * Converts every `isaacscript-common` function that begins with "log" to a global function.
@@ -35,6 +35,8 @@ local ____set = require("functions.set")
35
35
  local getSortedSetValues = ____set.getSortedSetValues
36
36
  local ____trinkets = require("functions.trinkets")
37
37
  local getTrinketName = ____trinkets.getTrinketName
38
+ local ____utils = require("functions.utils")
39
+ local printConsole = ____utils.printConsole
38
40
  function ____exports.getDebugPrependString(self, msg, numParentFunctions)
39
41
  if numParentFunctions == nil then
40
42
  numParentFunctions = 3
@@ -76,14 +78,14 @@ function ____exports.logFlags(flags, flagEnum, description)
76
78
  for key, value in pairs(flagEnum) do
77
79
  do
78
80
  if type(value) ~= "number" then
79
- goto __continue34
81
+ goto __continue35
80
82
  end
81
83
  if hasFlag(nil, flags, value) then
82
84
  ____exports.log((((" Has flag: " .. tostring(key)) .. " (") .. tostring(value)) .. ")")
83
85
  hasNoFlags = false
84
86
  end
85
87
  end
86
- ::__continue34::
88
+ ::__continue35::
87
89
  end
88
90
  if hasNoFlags then
89
91
  ____exports.log(" n/a (no flags)")
@@ -194,6 +196,11 @@ end
194
196
  function ____exports.logEntityFlags(flags)
195
197
  ____exports.logFlags(flags, EntityFlag, "entity")
196
198
  end
199
+ function ____exports.logError(msg)
200
+ local errorMsg = "Error: " .. msg
201
+ ____exports.log(errorMsg)
202
+ printConsole(nil, errorMsg)
203
+ end
197
204
  function ____exports.logGameStateFlags()
198
205
  ____exports.log("Logging game state flags:")
199
206
  local hasNoFlags = true
@@ -405,8 +412,8 @@ function ____exports.logTemporaryEffects(player)
405
412
  end
406
413
  )
407
414
  end
408
- function ____exports.logUseFlags(_flags)
409
- ____exports.log("The \"logUseFlags\" helper function is temporarily disabled while the UseFlag enum remains unpatched in vanilla.")
415
+ function ____exports.logUseFlags(flags)
416
+ ____exports.logFlags(flags, UseFlag, "use")
410
417
  end
411
418
  function ____exports.logVector(vector)
412
419
  ____exports.log(((("Vector: (" .. tostring(vector.X)) .. ", ") .. tostring(vector.Y)) .. ")")
@@ -420,6 +427,7 @@ function ____exports.setLogFunctionsGlobal(self)
420
427
  globals.logEntities = ____exports.logEntities
421
428
  globals.logEntity = ____exports.logEntity
422
429
  globals.logEntityFlags = ____exports.logEntityFlags
430
+ globals.logError = ____exports.logError
423
431
  globals.logFlags = ____exports.logFlags
424
432
  globals.logGameStateFlags = ____exports.logGameStateFlags
425
433
  globals.logGridEntities = ____exports.logGridEntities
@@ -1,12 +1,5 @@
1
- /// <reference types="isaac-typescript-definitions" />
2
- import { DefaultMap } from "../classes/DefaultMap";
3
1
  /** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
4
2
  export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
5
- /**
6
- * Helper function to make using default maps with `Seed` values easier. Use this instead of
7
- * manually getting the current value, incrementing it, and then setting it.
8
- */
9
- export declare function defaultMapGetNextSeed<K, A extends unknown[]>(map: DefaultMap<K, Seed, A>, key: K, ...extraArgs: A): Seed;
10
3
  /**
11
4
  * Helper function to get the closest value from a map based on partial search text. For the
12
5
  * purposes of this function, both search text and map keys are converted to lowercase before
@@ -26,8 +19,3 @@ export declare function defaultMapGetNextSeed<K, A extends unknown[]>(map: Defau
26
19
  * ```
27
20
  */
28
21
  export declare function getMapPartialMatch<T>(searchText: string, map: ReadonlyMap<string, T>): [string, T] | undefined;
29
- /**
30
- * Helper function to make using maps with `Seed` values easier. Use this instead of manually
31
- * getting the current value, incrementing it, and then setting it.
32
- */
33
- export declare function mapGetNextSeed<K>(map: Map<K, Seed>, key: K): Seed | undefined;
@@ -8,8 +8,6 @@ local __TS__StringReplaceAll = ____lualib.__TS__StringReplaceAll
8
8
  local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
9
9
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
10
10
  local ____exports = {}
11
- local ____random = require("functions.random")
12
- local nextSeed = ____random.nextSeed
13
11
  function ____exports.copyMap(self, oldMap)
14
12
  local newMap = __TS__New(Map)
15
13
  for ____, ____value in __TS__Iterator(oldMap:entries()) do
@@ -19,15 +17,6 @@ function ____exports.copyMap(self, oldMap)
19
17
  end
20
18
  return newMap
21
19
  end
22
- function ____exports.defaultMapGetNextSeed(self, map, key, ...)
23
- local seed = map:getAndSetDefault(key, ...)
24
- if seed == 0 then
25
- error("The seed map had a value of 0 for the key of: " .. tostring(key))
26
- end
27
- local newSeed = nextSeed(nil, seed)
28
- map:set(key, newSeed)
29
- return newSeed
30
- end
31
20
  function ____exports.getMapPartialMatch(self, searchText, map)
32
21
  local keys = {__TS__Spread(map:keys())}
33
22
  __TS__ArraySort(keys)
@@ -51,16 +40,4 @@ function ____exports.getMapPartialMatch(self, searchText, map)
51
40
  end
52
41
  return {matchingKey, value}
53
42
  end
54
- function ____exports.mapGetNextSeed(self, map, key)
55
- local seed = map:get(key)
56
- if seed == nil then
57
- return nil
58
- end
59
- if seed == 0 then
60
- error("The seed map had a value of 0 for the key of: " .. tostring(key))
61
- end
62
- local newSeed = nextSeed(nil, seed)
63
- map:set(key, newSeed)
64
- return newSeed
65
- end
66
43
  return ____exports