isaacscript-common 12.3.5 → 12.3.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "12.3.5",
3
+ "version": "12.3.7",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -163,7 +163,12 @@ function makeGlowingHourGlassBackup() {
163
163
  );
164
164
  }
165
165
 
166
- const copiedChildTable = deepCopy(childTable);
166
+ // We serialize the table so that we can use the `merge` function later on with no other
167
+ // modifications.
168
+ const copiedChildTable = deepCopy(
169
+ childTable,
170
+ SerializationType.SERIALIZE,
171
+ ) as Record<string, unknown>;
167
172
  saveDataGlowingHourGlass[saveDataKey] = copiedChildTable;
168
173
  }
169
174
  },
@@ -13,5 +13,8 @@ export const saveDataConditionalFuncMap = new LuaMap<string, () => boolean>();
13
13
  /**
14
14
  * We backup some save data keys on every new room for the purposes of restoring it when Glowing
15
15
  * Hour Glass is used.
16
+ *
17
+ * Note that the save data is backed up in serialized form so that we can use the `merge` function
18
+ * to restore it.
16
19
  */
17
20
  export const saveDataGlowingHourGlassMap = new LuaMap<string, SaveData>();
@@ -59,23 +59,28 @@ export function merge(
59
59
 
60
60
  // First, handle the special case of an array with a shallow copy.
61
61
  if (isArray(oldObject) && isArray(newTable)) {
62
- mergeArray(oldObject, newTable);
62
+ mergeSerializedArray(oldObject, newTable, traversalDescription);
63
63
  return;
64
64
  }
65
65
 
66
66
  // Depending on whether we are working on a Lua table or a TypeScriptToLua object, we need to
67
67
  // iterate in a specific way.
68
68
  if (isTSTLMap(oldObject) || isTSTLSet(oldObject) || isDefaultMap(oldObject)) {
69
- mergeTSTLObject(oldObject, newTable, traversalDescription);
69
+ mergeSerializedTSTLObject(oldObject, newTable, traversalDescription);
70
70
  } else {
71
- mergeTable(oldObject, newTable, traversalDescription);
71
+ mergeSerializedTable(oldObject, newTable, traversalDescription);
72
72
  }
73
73
  }
74
74
 
75
- function mergeArray(
75
+ function mergeSerializedArray(
76
76
  oldArray: LuaMap<AnyNotNil, unknown>,
77
77
  newArray: LuaMap<AnyNotNil, unknown>,
78
+ traversalDescription: string,
78
79
  ) {
80
+ if (SAVE_DATA_MANAGER_DEBUG) {
81
+ log(`merge encountered an array: ${traversalDescription}`);
82
+ }
83
+
79
84
  // Assume that we should blow away all array values with whatever is present in the incoming
80
85
  // array.
81
86
  clearTable(oldArray);
@@ -88,11 +93,15 @@ function mergeArray(
88
93
  );
89
94
  }
90
95
 
91
- function mergeTSTLObject(
96
+ function mergeSerializedTSTLObject(
92
97
  oldObject: Map<AnyNotNil, unknown> | Set<AnyNotNil>,
93
98
  newTable: LuaMap<AnyNotNil, unknown>,
94
99
  traversalDescription: string,
95
100
  ) {
101
+ if (SAVE_DATA_MANAGER_DEBUG) {
102
+ log(`merge encountered a TSTL object: ${traversalDescription}`);
103
+ }
104
+
96
105
  // We blow away the old object and recursively copy over all of the incoming values.
97
106
  oldObject.clear();
98
107
 
@@ -139,11 +148,15 @@ function mergeTSTLObject(
139
148
  );
140
149
  }
141
150
 
142
- function mergeTable(
151
+ function mergeSerializedTable(
143
152
  oldTable: LuaMap<AnyNotNil, unknown>,
144
153
  newTable: LuaMap<AnyNotNil, unknown>,
145
154
  traversalDescription: string,
146
155
  ) {
156
+ if (SAVE_DATA_MANAGER_DEBUG) {
157
+ log(`merge encountered a Lua table: ${traversalDescription}`);
158
+ }
159
+
147
160
  iterateTableInOrder(
148
161
  newTable,
149
162
  (key, value) => {
@@ -9,6 +9,7 @@ import {
9
9
  ItemType,
10
10
  PickupPrice,
11
11
  PickupVariant,
12
+ RenderMode,
12
13
  RoomType,
13
14
  } from "isaac-typescript-definitions";
14
15
  import { game, itemConfig } from "../core/cachedClasses";
@@ -408,7 +409,12 @@ export function isActiveCollectible(collectibleType: CollectibleType): boolean {
408
409
  return itemType === ItemType.ACTIVE;
409
410
  }
410
411
 
411
- /** Returns true if the collectible has a red question mark sprite. */
412
+ /**
413
+ * Returns true if the collectible has a red question mark sprite.
414
+ *
415
+ * Note that this function will not work properly in a render callback with the `RenderMode` set to
416
+ * `RenderMode.WATER_REFLECT`. If this is detected, this function will throw a run-time error.
417
+ */
412
418
  export function isBlindCollectible(collectible: EntityPickup): boolean {
413
419
  if (!isCollectible(collectible)) {
414
420
  const entityID = getEntityID(collectible);
@@ -417,6 +423,14 @@ export function isBlindCollectible(collectible: EntityPickup): boolean {
417
423
  );
418
424
  }
419
425
 
426
+ const room = game.GetRoom();
427
+ const renderMode = room.GetRenderMode();
428
+ if (renderMode === RenderMode.WATER_REFLECT) {
429
+ error(
430
+ 'The "isBlindCollectible" function will not work properly in a render callback with the render mode equal to "RenderMode.WATER_REFLECT". Make sure that you properly account for this case if you are calling this function in a render callback.',
431
+ );
432
+ }
433
+
420
434
  const sprite = collectible.GetSprite();
421
435
  const animation = sprite.GetAnimation();
422
436
  const frame = sprite.GetFrame();
@@ -365,9 +365,7 @@ export function logTable(luaTable: unknown, parentTables = 0): void {
365
365
  // Put it in an IIFE so that it will show as "func" instead of "logTable" and align with the
366
366
  // other text. We have to use a non-arrow function to prevent Lua language server errors with
367
367
  // the self argument.
368
- /** @noSelf */
369
- // eslint-disable-next-line func-names
370
- (function () {
368
+ (function func() {
371
369
  log(
372
370
  `${indentation}n/a (encountered a variable of type "${typeof luaTable}" instead of a table)`,
373
371
  );
@@ -397,9 +395,7 @@ export function logTable(luaTable: unknown, parentTables = 0): void {
397
395
  // Put it in an IIFE so that it will show as "func" instead of "logTable" and align with the other
398
396
  // text. We have to use a non-arrow function to prevent Lua language server errors with the self
399
397
  // argument.
400
- /** @noSelf */
401
- // eslint-disable-next-line func-names
402
- (function () {
398
+ (function func() {
403
399
  log(`${indentation}The size of the table was: ${numElements}`);
404
400
  })();
405
401
  }