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
@@ -15,6 +15,7 @@ local ____familiars = require("functions.familiars")
15
15
  local removeAllFamiliars = ____familiars.removeAllFamiliars
16
16
  local ____log = require("functions.log")
17
17
  local log = ____log.log
18
+ local logError = ____log.logError
18
19
  local ____playerIndex = require("functions.playerIndex")
19
20
  local getPlayerFromIndex = ____playerIndex.getPlayerFromIndex
20
21
  local getPlayerIndex = ____playerIndex.getPlayerIndex
@@ -97,25 +98,19 @@ function playerIsAboutToDie(self, player)
97
98
  player:AddCollectible(CollectibleType.COLLECTIBLE_1UP, 0, false)
98
99
  removeAllFamiliars(nil, FamiliarVariant.ONE_UP)
99
100
  removeCollectibleFromItemTracker(nil, CollectibleType.COLLECTIBLE_1UP)
100
- local character = player:GetPlayerType()
101
- if character ~= PlayerType.PLAYER_SAMSON_B then
102
- return
103
- end
104
101
  local playerIndex = getPlayerIndex(nil, player)
105
102
  runNextGameFrame(
106
103
  nil,
107
104
  function()
108
- local taintedSamson = getPlayerFromIndex(nil, playerIndex)
109
- if taintedSamson == nil then
105
+ local futurePlayer = getPlayerFromIndex(nil, playerIndex)
106
+ if futurePlayer == nil then
110
107
  return
111
108
  end
112
- local effects = player:GetEffects()
113
- local isBerserk = effects:HasCollectibleEffect(CollectibleType.COLLECTIBLE_BERSERK)
114
- if not isBerserk then
109
+ if futurePlayer:IsDead() then
115
110
  return
116
111
  end
117
- effects:RemoveCollectibleEffect(CollectibleType.COLLECTIBLE_BERSERK, -1)
118
- removeAllFamiliars(nil, FamiliarVariant.ONE_UP)
112
+ logError("The player is still alive after initializing a custom revive. Explicitly killing the player.")
113
+ futurePlayer:Kill()
119
114
  end
120
115
  )
121
116
  end
@@ -7,7 +7,7 @@ local ____gridEntity = require("functions.gridEntity")
7
7
  local getTopLeftWallGridIndex = ____gridEntity.getTopLeftWallGridIndex
8
8
  local spawnGridEntity = ____gridEntity.spawnGridEntity
9
9
  local ____log = require("functions.log")
10
- local log = ____log.log
10
+ local logError = ____log.logError
11
11
  local ____postNewRoomEarly = require("callbacks.subscriptions.postNewRoomEarly")
12
12
  local postNewRoomEarlyFire = ____postNewRoomEarly.postNewRoomEarlyFire
13
13
  local postNewRoomEarlyHasSubscriptions = ____postNewRoomEarly.postNewRoomEarlyHasSubscriptions
@@ -35,18 +35,16 @@ function checkRoomChanged(self)
35
35
  if topLeftWall == nil then
36
36
  topLeftWall = spawnGridEntity(nil, GridEntityType.GRID_WALL, topLeftWallGridIndex)
37
37
  if topLeftWall == nil then
38
- log("Error: Failed to spawn a new wall (1) for the PostNewRoomEarly callback.")
38
+ logError("Failed to spawn a new wall (1) for the PostNewRoomEarly callback.")
39
39
  return
40
40
  end
41
- log("Spawned a new wall (1) for the PostNewRoomEarly callback.")
42
41
  end
43
42
  if topLeftWall2 == nil then
44
43
  topLeftWall2 = spawnGridEntity(nil, GridEntityType.GRID_WALL, rightOfTopWallGridIndex)
45
44
  if topLeftWall2 == nil then
46
- log("Error: Failed to spawn a new wall (2) for the PostNewRoomEarly callback.")
45
+ logError("Failed to spawn a new wall (2) for the PostNewRoomEarly callback.")
47
46
  return
48
47
  end
49
- log("Spawned a new wall (2) for the PostNewRoomEarly callback.")
50
48
  end
51
49
  local topLeftWallPtrHash = GetPtrHash(topLeftWall)
52
50
  local topLeftWallPtrHash2 = GetPtrHash(topLeftWall2)
@@ -6,9 +6,7 @@ export declare class ModUpgraded implements Mod {
6
6
  Name: string;
7
7
  /** We store a copy of the original mod object so that we can re-implement its functions. */
8
8
  Mod: Mod;
9
- /** End-users can optionally enable verbose-mode, which helps troubleshoot crashes. */
10
- Verbose: boolean;
11
- constructor(mod: Mod, verbose: boolean);
9
+ constructor(mod: Mod);
12
10
  AddCallback<T extends ModCallbacks>(modCallbacks: T, ...args: AddCallbackParameters[T]): void;
13
11
  HasData(): boolean;
14
12
  LoadData(): string;
@@ -1,51 +1,17 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
- local __TS__Spread = ____lualib.__TS__Spread
4
- local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
5
3
  local ____exports = {}
6
- local getCallbackName
7
- local ____log = require("functions.log")
8
- local getDebugPrependString = ____log.getDebugPrependString
9
4
  local ____callbackRegisterFunctions = require("objects.callbackRegisterFunctions")
10
5
  local CALLBACK_REGISTER_FUNCTIONS = ____callbackRegisterFunctions.CALLBACK_REGISTER_FUNCTIONS
11
- function getCallbackName(self, callbackID)
12
- for ____, ____value in ipairs(__TS__ObjectEntries(ModCallbacks)) do
13
- local key = ____value[1]
14
- local value = ____value[2]
15
- if value == callbackID then
16
- return key
17
- end
18
- end
19
- return "MC_UNKNOWN"
20
- end
21
6
  ____exports.ModUpgraded = __TS__Class()
22
7
  local ModUpgraded = ____exports.ModUpgraded
23
8
  ModUpgraded.name = "ModUpgraded"
24
- function ModUpgraded.prototype.____constructor(self, mod, verbose)
9
+ function ModUpgraded.prototype.____constructor(self, mod)
25
10
  self.Name = mod.Name
26
11
  self.Mod = mod
27
- self.Verbose = verbose
28
12
  end
29
13
  function ModUpgraded.prototype.AddCallback(self, modCallbacks, ...)
30
- local args = {...}
31
- if self.Verbose then
32
- local callback = args[1]
33
- local optionalArg = args[2]
34
- local callbackName = getCallbackName(nil, modCallbacks)
35
- local debugMsg = getDebugPrependString(nil, callbackName)
36
- local function callbackWithLogger(____, ...)
37
- Isaac.DebugString(debugMsg .. " - START")
38
- local value = callback(nil, ...)
39
- Isaac.DebugString((debugMsg .. " - END - ") .. tostring(value))
40
- return value
41
- end
42
- self.Mod:AddCallback(modCallbacks, callbackWithLogger, optionalArg)
43
- else
44
- self.Mod:AddCallback(
45
- modCallbacks,
46
- __TS__Spread(args)
47
- )
48
- end
14
+ self.Mod:AddCallback(modCallbacks, ...)
49
15
  end
50
16
  function ModUpgraded.prototype.HasData(self)
51
17
  return self.Mod:HasData()
@@ -69,6 +69,8 @@ export declare const MAX_ROOM_INDEX = 168;
69
69
  * effect.
70
70
  */
71
71
  export declare const MAX_SPEED_STAT = 2;
72
+ /** Corresponds to the maximum value for `EntityPlayer.SamsonBerserkCharge`. */
73
+ export declare const MAX_TAINTED_SAMSON_BERSERK_CHARGE = 100000;
72
74
  export declare const MAX_VANILLA_CHARACTER: number;
73
75
  export declare const MAX_VANILLA_COLLECTIBLE_TYPE: number;
74
76
  export declare const NUM_DIMENSIONS = 3;
@@ -89,6 +91,8 @@ export declare const PILL_COLOR_MASK = 2047;
89
91
  * 1 << 11
90
92
  */
91
93
  export declare const PILL_GIANT_FLAG = 2048;
94
+ /** After taking damage, `EntityPlayer.SamsonBerserkCharge` is incremented by this amount. */
95
+ export declare const TAINTED_SAMSON_BERSERK_CHARGE_FROM_TAKING_DAMAGE = 10000;
92
96
  /**
93
97
  * Add this to a `TrinketType` to get the corresponding golden trinket type.
94
98
  *
@@ -22,6 +22,7 @@ ____exports.MAX_PLAYER_SPEED_IN_UNITS = 9.8
22
22
  ____exports.MAX_PLAYER_TRINKET_SLOTS = 2
23
23
  ____exports.MAX_ROOM_INDEX = 168
24
24
  ____exports.MAX_SPEED_STAT = 2
25
+ ____exports.MAX_TAINTED_SAMSON_BERSERK_CHARGE = 100000
25
26
  ____exports.MAX_VANILLA_CHARACTER = PlayerType.NUM_PLAYER_TYPES - 1
26
27
  ____exports.MAX_VANILLA_COLLECTIBLE_TYPE = CollectibleType.NUM_COLLECTIBLES - 1
27
28
  ____exports.NUM_DIMENSIONS = 3
@@ -30,6 +31,7 @@ ____exports.MINUTE_IN_MILLISECONDS = 60 * ____exports.SECOND_IN_MILLISECONDS
30
31
  ____exports.ONE_BY_ONE_ROOM_GRID_SIZE = 135
31
32
  ____exports.PILL_COLOR_MASK = 2047
32
33
  ____exports.PILL_GIANT_FLAG = 2048
34
+ ____exports.TAINTED_SAMSON_BERSERK_CHARGE_FROM_TAKING_DAMAGE = 10000
33
35
  ____exports.TRINKET_GOLDEN_FLAG = 32768
34
36
  ____exports.TRINKET_ID_MASK = 32767
35
37
  ____exports.UI_HEART_WIDTH = 12
@@ -10,6 +10,8 @@ export declare enum SerializationBrand {
10
10
  SET = "__TSTL_SET",
11
11
  CLASS = "__TSTL_CLASS",
12
12
  OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS",
13
+ COLOR = "__COLOR",
14
+ RNG = "__RNG",
13
15
  VECTOR = "__VECTOR"
14
16
  }
15
17
  export declare function isSerializationBrand(key: AnyNotNil): boolean;
@@ -11,6 +11,8 @@ ____exports.SerializationBrand.MAP = "__TSTL_MAP"
11
11
  ____exports.SerializationBrand.SET = "__TSTL_SET"
12
12
  ____exports.SerializationBrand.CLASS = "__TSTL_CLASS"
13
13
  ____exports.SerializationBrand.OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS"
14
+ ____exports.SerializationBrand.COLOR = "__COLOR"
15
+ ____exports.SerializationBrand.RNG = "__RNG"
14
16
  ____exports.SerializationBrand.VECTOR = "__VECTOR"
15
17
  local SERIALIZATION_BRANDS = getEnumValues(nil, ____exports.SerializationBrand)
16
18
  local SERIALIZATION_BRAND_SET = __TS__New(Set, SERIALIZATION_BRANDS)
@@ -14,15 +14,12 @@ import { JSONRoom } from "../types/JSONRoom";
14
14
  * const firstJSONRoom = customRooms.rooms.room[0];
15
15
  * deployJSONRoom(firstJSONRoom);
16
16
  * ```
17
- * @param seed Optional. Specifies the seed that will be used for spawning every entity in the room.
18
- * Default is `Random()`.
17
+ * @param rng Optional. Specifies the RNG object that will be used for spawning every entity in the
18
+ * room. Default is `newRNG()`.
19
19
  * @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
20
20
  * what the function is doing. Default is false.
21
- * @returns Before using the seed for spawning each entity, it is iterated with `nextSeed`. The
22
- * function returns the final iterated seed after spawning everything, which can be used in
23
- * subsequent room deployments.
24
21
  */
25
- export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: Seed, verbose?: boolean): Seed;
22
+ export declare function deployJSONRoom(jsonRoom: JSONRoom, rng?: RNG, verbose?: boolean): void;
26
23
  /**
27
24
  * Helper function to deconstruct a vanilla room and set up a custom room in its place.
28
25
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
@@ -42,15 +39,12 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: Seed, verbose?
42
39
  * const jsonRooms = customRooms.rooms.room;
43
40
  * deployRandomJSONRoom(jsonRooms);
44
41
  * ```
45
- * @param seed Optional. Specifies the seed that will be used for determining the random room. After
46
- * that, it is also used for spawning every entity in the room. Default is `Random()`.
42
+ * @param rng Optional. Specifies the RNG object that will be used for determining the random room.
43
+ * After that, it is also used for spawning every entity in the room. Default is `newRNG()`.
47
44
  * @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
48
45
  * what the function is doing. Default is false.
49
- * @returns Before using the seed for spawning each entity, it is iterated with `nextSeed`. The
50
- * function returns the final iterated seed after spawning everything, which can be used in
51
- * subsequent room deployments.
52
46
  */
53
- export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?: Seed, verbose?: boolean): Seed;
47
+ export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], rng?: RNG, verbose?: boolean): void;
54
48
  /**
55
49
  * Helper function to remove all naturally spawning entities and grid entities from a room. Notably,
56
50
  * this will not remove players (1), tears (2), familiars (3), lasers (7), knives (8),
@@ -32,8 +32,8 @@ local ____npc = require("functions.npc")
32
32
  local getNPCs = ____npc.getNPCs
33
33
  local ____pickups = require("functions.pickups")
34
34
  local removeAllPickups = ____pickups.removeAllPickups
35
- local ____random = require("functions.random")
36
- local nextSeed = ____random.nextSeed
35
+ local ____rng = require("functions.rng")
36
+ local newRNG = ____rng.newRNG
37
37
  local ____roomData = require("functions.roomData")
38
38
  local getRoomListIndex = ____roomData.getRoomListIndex
39
39
  local ____rooms = require("functions.rooms")
@@ -136,7 +136,7 @@ function fillRoomWithDecorations(self)
136
136
  ::__continue30::
137
137
  end
138
138
  end
139
- function spawnAllEntities(self, jsonRoom, seed, verbose)
139
+ function spawnAllEntities(self, jsonRoom, rng, verbose)
140
140
  if verbose == nil then
141
141
  verbose = false
142
142
  end
@@ -183,7 +183,6 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
183
183
  y
184
184
  )
185
185
  else
186
- seed = nextSeed(nil, seed)
187
186
  if verbose then
188
187
  log(((((((((("Spawning normal entity " .. tostring(entityType)) .. ".") .. tostring(variant)) .. ".") .. tostring(subType)) .. " at: (") .. tostring(x)) .. ", ") .. tostring(y)) .. ")")
189
188
  end
@@ -194,7 +193,7 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
194
193
  subType,
195
194
  x,
196
195
  y,
197
- seed
196
+ rng
198
197
  )
199
198
  local npc = entity:ToNPC()
200
199
  if npc ~= nil and npc.CanShutDoors then
@@ -210,7 +209,6 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
210
209
  elseif verbose then
211
210
  log("Leaving the room cleared since there were no battle NPCs spawned.")
212
211
  end
213
- return seed
214
212
  end
215
213
  function spawnGridEntityForJSONRoom(self, xmlEntityType, xmlEntityVariant, x, y)
216
214
  local room = game:GetRoom()
@@ -232,7 +230,7 @@ function spawnGridEntityForJSONRoom(self, xmlEntityType, xmlEntityVariant, x, y)
232
230
  end
233
231
  return gridEntity
234
232
  end
235
- function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y, seed)
233
+ function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y, rng)
236
234
  local room = game:GetRoom()
237
235
  local roomType = room:GetType()
238
236
  local position = gridToPos(nil, x, y)
@@ -243,10 +241,12 @@ function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y,
243
241
  nil,
244
242
  subType,
245
243
  position,
246
- seed,
244
+ rng,
247
245
  options
248
246
  )
249
247
  else
248
+ rng:Next()
249
+ local seed = rng:GetSeed()
250
250
  entity = game:Spawn(
251
251
  entityType,
252
252
  variant,
@@ -403,9 +403,9 @@ function ____exports.deployJSONRoomInit(self, mod)
403
403
  saveDataManager(nil, "deployJSONRoom", v)
404
404
  mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, postNewRoom)
405
405
  end
406
- function ____exports.deployJSONRoom(self, jsonRoom, seed, verbose)
407
- if seed == nil then
408
- seed = Random()
406
+ function ____exports.deployJSONRoom(self, jsonRoom, rng, verbose)
407
+ if rng == nil then
408
+ rng = newRNG(nil)
409
409
  end
410
410
  if verbose == nil then
411
411
  verbose = false
@@ -421,26 +421,25 @@ function ____exports.deployJSONRoom(self, jsonRoom, seed, verbose)
421
421
  if verbose then
422
422
  log("Starting to spawn all of the new entities and grid entities.")
423
423
  end
424
- local newSeed = spawnAllEntities(nil, jsonRoom, seed, verbose)
424
+ spawnAllEntities(nil, jsonRoom, rng, verbose)
425
425
  if verbose then
426
426
  log("Finished spawning all of the new entities and grid entities.")
427
427
  end
428
428
  fixPitGraphics(nil)
429
429
  fillRoomWithDecorations(nil)
430
- return newSeed
431
430
  end
432
- function ____exports.deployRandomJSONRoom(self, jsonRooms, seed, verbose)
433
- if seed == nil then
434
- seed = Random()
431
+ function ____exports.deployRandomJSONRoom(self, jsonRooms, rng, verbose)
432
+ if rng == nil then
433
+ rng = newRNG(nil)
435
434
  end
436
435
  if verbose == nil then
437
436
  verbose = false
438
437
  end
439
438
  errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
440
- local randomJSONRoom = getRandomJSONRoom(nil, jsonRooms, seed, verbose)
439
+ local randomJSONRoom = getRandomJSONRoom(nil, jsonRooms, rng, verbose)
441
440
  if verbose then
442
441
  log((((((("Randomly chose JSON room " .. randomJSONRoom["$"].type) .. ".") .. randomJSONRoom["$"].variant) .. ".") .. randomJSONRoom["$"].subtype) .. " with name: ") .. randomJSONRoom["$"].name)
443
442
  end
444
- return ____exports.deployJSONRoom(nil, randomJSONRoom, seed, verbose)
443
+ return ____exports.deployJSONRoom(nil, randomJSONRoom, rng, verbose)
445
444
  end
446
445
  return ____exports
@@ -6,6 +6,7 @@ local ____jsonHelpers = require("functions.jsonHelpers")
6
6
  local jsonDecode = ____jsonHelpers.jsonDecode
7
7
  local ____log = require("functions.log")
8
8
  local log = ____log.log
9
+ local logError = ____log.logError
9
10
  local ____constants = require("features.saveDataManager.constants")
10
11
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
11
12
  local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
@@ -15,7 +16,7 @@ function readSaveDatFile(self, mod)
15
16
  local renderFrameCount = Isaac.GetFrameCount()
16
17
  local ok, jsonStringOrErrMsg = pcall(tryLoadModData, mod)
17
18
  if not ok then
18
- log((("Error: Failed to read from the \"save#.dat\" file on render frame " .. tostring(renderFrameCount)) .. ": ") .. jsonStringOrErrMsg)
19
+ logError((("Failed to read from the \"save#.dat\" file on render frame " .. tostring(renderFrameCount)) .. ": ") .. jsonStringOrErrMsg)
19
20
  return DEFAULT_MOD_DATA
20
21
  end
21
22
  if jsonStringOrErrMsg == nil then
@@ -13,7 +13,7 @@ local SerializationType = ____SerializationType.SerializationType
13
13
  local ____deepCopy = require("functions.deepCopy")
14
14
  local deepCopy = ____deepCopy.deepCopy
15
15
  local ____log = require("functions.log")
16
- local log = ____log.log
16
+ local logError = ____log.logError
17
17
  local ____table = require("functions.table")
18
18
  local clearTable = ____table.clearTable
19
19
  local ____constants = require("features.saveDataManager.constants")
@@ -72,12 +72,12 @@ function restoreDefaults(self, childTableName)
72
72
  end
73
73
  local saveDataDefaults = saveDataDefaultsMap[subscriberName]
74
74
  if saveDataDefaults == nil then
75
- log("Error: Failed to find the default copy of the save data for subscriber: " .. subscriberName)
75
+ logError("Failed to find the default copy of the save data for subscriber: " .. subscriberName)
76
76
  goto __continue14
77
77
  end
78
78
  local childTableDefaults = saveDataDefaults[childTableName]
79
79
  if childTableDefaults == nil then
80
- log((("Error: Failed to find the default copy of the child table \"" .. childTableName) .. "\" for subscriber: ") .. subscriberName)
80
+ logError((("Failed to find the default copy of the child table \"" .. childTableName) .. "\" for subscriber: ") .. subscriberName)
81
81
  goto __continue14
82
82
  end
83
83
  local childTableDefaultsTable = childTableDefaults
@@ -1,8 +1,17 @@
1
1
  /// <reference types="typescript-to-lua/language-extensions" />
2
2
  /**
3
- * merge takes the values from a new table and recursively merges them into an old object
4
- * (while performing appropriate deserialization).
5
- * This function handles Lua tables and TypeScriptToLua Maps/Sets/Classes.
3
+ * merge takes the values from a new table and recursively merges them into an old object (while
4
+ * performing appropriate deserialization).
5
+ *
6
+ * It supports the following object types:
7
+ *
8
+ * - `LuaTable` / basic TSTL objects
9
+ * - TSTL `Map`
10
+ * - TSTL `Set`
11
+ * - TSTL classes
12
+ * - `DefaultMap`
13
+ * - Isaac `RNG` objects
14
+ * - Isaac `Vector` objects
6
15
  *
7
16
  * Since it is common for a variable to have a type of `something | null`, we must iterate over the
8
17
  * new object and copy over all of the values. (A value of null transpiles to nil, which means the
@@ -3,7 +3,7 @@ local Map = ____lualib.Map
3
3
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
4
4
  local Set = ____lualib.Set
5
5
  local ____exports = {}
6
- local mergeArray, mergeTSTLObject, mergeTable, mergeVector
6
+ local mergeArray, mergeTSTLObject, mergeTable, tryDeserializeIsaacClass
7
7
  local ____SerializationBrand = require("enums.private.SerializationBrand")
8
8
  local isSerializationBrand = ____SerializationBrand.isSerializationBrand
9
9
  local SerializationBrand = ____SerializationBrand.SerializationBrand
@@ -13,15 +13,18 @@ local ____array = require("functions.array")
13
13
  local isArray = ____array.isArray
14
14
  local ____deepCopy = require("functions.deepCopy")
15
15
  local deepCopy = ____deepCopy.deepCopy
16
- local isSerializedVector = ____deepCopy.isSerializedVector
17
16
  local ____log = require("functions.log")
18
17
  local log = ____log.log
18
+ local ____rng = require("functions.rng")
19
+ local copyRNG = ____rng.copyRNG
20
+ local isSerializedRNG = ____rng.isSerializedRNG
19
21
  local ____table = require("functions.table")
20
22
  local clearTable = ____table.clearTable
21
23
  local ____utils = require("functions.utils")
22
24
  local getTraversalDescription = ____utils.getTraversalDescription
23
25
  local ____vector = require("functions.vector")
24
- local deserializeVector = ____vector.deserializeVector
26
+ local copyVector = ____vector.copyVector
27
+ local isSerializedVector = ____vector.isSerializedVector
25
28
  local ____constants = require("features.saveDataManager.constants")
26
29
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
27
30
  function ____exports.merge(self, oldObject, newTable, traversalDescription)
@@ -100,7 +103,9 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
100
103
  if isSerializationBrand(nil, key) then
101
104
  goto __continue23
102
105
  end
103
- if mergeVector(nil, oldTable, key, value) then
106
+ local deserializedIsaacClass = tryDeserializeIsaacClass(nil, value)
107
+ if deserializedIsaacClass ~= nil then
108
+ oldTable[key] = deserializedIsaacClass
104
109
  goto __continue23
105
110
  end
106
111
  local valueType = type(value)
@@ -123,13 +128,13 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
123
128
  ::__continue23::
124
129
  end
125
130
  end
126
- function mergeVector(self, oldTable, key, value)
127
- if not isSerializedVector(nil, value) then
128
- return false
131
+ function tryDeserializeIsaacClass(self, value)
132
+ if isSerializedVector(nil, value) then
133
+ return copyVector(nil, value, SerializationType.DESERIALIZE)
129
134
  end
130
- local serializedVector = value
131
- local vector = deserializeVector(nil, serializedVector)
132
- oldTable[key] = vector
133
- return true
135
+ if isSerializedRNG(nil, value) then
136
+ return copyRNG(nil, value, SerializationType.DESERIALIZE)
137
+ end
138
+ return nil
134
139
  end
135
140
  return ____exports
@@ -43,20 +43,20 @@ export declare function getLastElement<T>(array: T[]): T;
43
43
  * Helper function to get a random element from the provided array.
44
44
  *
45
45
  * @param array The array to get an element from.
46
- * @param seed Optional. The seed used to select the random element. Default is `Random()`.
46
+ * @param rng Optional. The RNG object used to select the random element. Default is `newRNG()`.
47
47
  * @param exceptions Optional. An array of elements to skip over if selected.
48
48
  */
49
- export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed?: Seed, exceptions?: T[] | readonly T[]): T;
49
+ export declare function getRandomArrayElement<T>(array: T[] | readonly T[], rng?: RNG, exceptions?: T[] | readonly T[]): T;
50
50
  /**
51
51
  * Helper function to get a random element from the provided array. Once the random element is
52
52
  * decided, it is then removed from the array (in-place).
53
53
  *
54
54
  * @param array The array to get an element from.
55
- * @param seed Optional. The seed used to select the random element. Default is `Random()`.
55
+ * @param rng Optional. The RNG object used to select the random element. Default is `newRNG()`.
56
56
  * @param exceptions Optional. An array of elements to skip over if selected.
57
57
  */
58
- export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?: Seed, exceptions?: T[] | readonly T[]): T;
59
- export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seed?: Seed): int;
58
+ export declare function getRandomArrayElementAndRemove<T>(array: T[], rng?: RNG, exceptions?: T[] | readonly T[]): T;
59
+ export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], rng?: RNG): int;
60
60
  /**
61
61
  * Initializes an array with all elements containing the specified default value.
62
62
  *
@@ -80,11 +80,11 @@ export declare function isArrayInArray<T>(arrayToMatch: T[] | readonly T[], pare
80
80
  *
81
81
  * From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
82
82
  */
83
- export declare function shuffleArray<T>(originalArray: T[] | readonly T[], seed?: Seed): T[];
83
+ export declare function shuffleArray<T>(originalArray: T[] | readonly T[], rng?: RNG): T[];
84
84
  /**
85
85
  * Shuffles the provided array in-place using the Fisher-Yates algorithm.
86
86
  *
87
87
  * From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
88
88
  */
89
- export declare function shuffleArrayInPlace<T>(array: T[], seed?: Seed): void;
89
+ export declare function shuffleArrayInPlace<T>(array: T[], rng?: RNG): void;
90
90
  export declare function sumArray(array: number[] | readonly number[]): number;
@@ -11,28 +11,28 @@ local __TS__ArrayReduce = ____lualib.__TS__ArrayReduce
11
11
  local ____exports = {}
12
12
  local ____random = require("functions.random")
13
13
  local getRandomInt = ____random.getRandomInt
14
- local nextSeed = ____random.nextSeed
14
+ local ____rng = require("functions.rng")
15
+ local newRNG = ____rng.newRNG
15
16
  local ____utils = require("functions.utils")
16
17
  local ____repeat = ____utils["repeat"]
17
- function ____exports.getRandomArrayIndex(self, array, seed)
18
- if seed == nil then
19
- seed = Random()
18
+ function ____exports.getRandomArrayIndex(self, array, rng)
19
+ if rng == nil then
20
+ rng = newRNG(nil)
20
21
  end
21
22
  if #array == 0 then
22
23
  error("Failed to get a random array index since the provided array is empty.")
23
24
  end
24
- return getRandomInt(nil, 0, #array - 1, seed)
25
+ return getRandomInt(nil, 0, #array - 1, rng)
25
26
  end
26
- function ____exports.shuffleArrayInPlace(self, array, seed)
27
- if seed == nil then
28
- seed = Random()
27
+ function ____exports.shuffleArrayInPlace(self, array, rng)
28
+ if rng == nil then
29
+ rng = newRNG(nil)
29
30
  end
30
31
  local currentIndex = #array
31
32
  local randomIndex
32
33
  while currentIndex > 0 do
33
34
  currentIndex = currentIndex - 1
34
- seed = nextSeed(nil, seed)
35
- randomIndex = ____exports.getRandomArrayIndex(nil, array, seed)
35
+ randomIndex = ____exports.getRandomArrayIndex(nil, array, rng)
36
36
  local ____temp_0 = {array[randomIndex + 1], array[currentIndex + 1]}
37
37
  array[currentIndex + 1] = ____temp_0[1]
38
38
  array[randomIndex + 1] = ____temp_0[2]
@@ -115,9 +115,9 @@ end
115
115
  function ____exports.getLastElement(self, array)
116
116
  return array[#array]
117
117
  end
118
- function ____exports.getRandomArrayElement(self, array, seed, exceptions)
119
- if seed == nil then
120
- seed = Random()
118
+ function ____exports.getRandomArrayElement(self, array, rng, exceptions)
119
+ if rng == nil then
120
+ rng = newRNG(nil)
121
121
  end
122
122
  if exceptions == nil then
123
123
  exceptions = {}
@@ -130,17 +130,17 @@ function ____exports.getRandomArrayElement(self, array, seed, exceptions)
130
130
  array,
131
131
  table.unpack(exceptions)
132
132
  )
133
- local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions, seed)
133
+ local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions, rng)
134
134
  return arrayWithoutExceptions[randomIndex + 1]
135
135
  end
136
- function ____exports.getRandomArrayElementAndRemove(self, array, seed, exceptions)
137
- if seed == nil then
138
- seed = Random()
136
+ function ____exports.getRandomArrayElementAndRemove(self, array, rng, exceptions)
137
+ if rng == nil then
138
+ rng = newRNG(nil)
139
139
  end
140
140
  if exceptions == nil then
141
141
  exceptions = {}
142
142
  end
143
- local randomArrayElement = ____exports.getRandomArrayElement(nil, array, seed, exceptions)
143
+ local randomArrayElement = ____exports.getRandomArrayElement(nil, array, rng, exceptions)
144
144
  ____exports.arrayRemoveInPlace(nil, array, randomArrayElement)
145
145
  return randomArrayElement
146
146
  end
@@ -192,12 +192,12 @@ function ____exports.isArrayInArray(self, arrayToMatch, parentArray)
192
192
  function(____, element) return ____exports.arrayEquals(nil, element, arrayToMatch) end
193
193
  )
194
194
  end
195
- function ____exports.shuffleArray(self, originalArray, seed)
196
- if seed == nil then
197
- seed = Random()
195
+ function ____exports.shuffleArray(self, originalArray, rng)
196
+ if rng == nil then
197
+ rng = newRNG(nil)
198
198
  end
199
199
  local array = ____exports.copyArray(nil, originalArray)
200
- ____exports.shuffleArrayInPlace(nil, array, seed)
200
+ ____exports.shuffleArrayInPlace(nil, array, rng)
201
201
  return array
202
202
  end
203
203
  function ____exports.sumArray(self, array)
@@ -43,24 +43,24 @@ export declare function getMaxCards(): int;
43
43
  * - any objects like Dice Shard
44
44
  * - any modded cards.
45
45
  *
46
- * @param seed Optional. The seed with which to select the random card. Default is `Random()`.
46
+ * @param rng Optional. The RNG object with which to select the random card. Default is `newRNG()`.
47
47
  * @param exceptions Optional. An array of cards to not select.
48
48
  */
49
- export declare function getRandomCard(seed?: Seed, exceptions?: Card[]): Card;
49
+ export declare function getRandomCard(rng?: RNG, exceptions?: Card[]): Card;
50
50
  /**
51
51
  * @param cardType The card type that represents the pool of cards to select from.
52
- * @param seed Optional. The seed with which to select the random card. Default is `Random()`.
52
+ * @param rng Optional. The RNG object with which to select the random card. Default is `newRNG()`.
53
53
  * @param exceptions Optional. An array of cards to not select.
54
54
  */
55
- export declare function getRandomCardOfType(cardType: CardType, seed?: Seed, exceptions?: Card[]): Card;
55
+ export declare function getRandomCardOfType(cardType: CardType, rng?: RNG, exceptions?: Card[]): Card;
56
56
  /**
57
57
  * Has an equal chance of returning any rune (e.g. Rune of Hagalaz, Blank Rune, Black Rune, Soul of
58
58
  * Isaac, etc.). This will never return a Rune Shard.
59
59
  *
60
- * @param seed Optional. The seed with which to select the random rune. Default is `Random()`.
60
+ * @param rng Optional. The RNG object with which to select the random rune. Default is `newRNG()`.
61
61
  * @param exceptions Optional. An array of runes to not select.
62
62
  */
63
- export declare function getRandomRune(seed?: Seed, exceptions?: Card[]): Card;
63
+ export declare function getRandomRune(rng?: RNG, exceptions?: Card[]): Card;
64
64
  /**
65
65
  * Returns true for cards that have the following card type:
66
66
  * - CardType.TAROT