isaacscript-common 11.2.4 → 12.0.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.
Files changed (67) hide show
  1. package/dist/index.d.ts +8 -3
  2. package/dist/isaacscript-common.lua +138 -62
  3. package/dist/package.lua +1 -1
  4. package/dist/src/features/customStage/backdrop.lua +2 -2
  5. package/dist/src/features/customStage/{customStageConstants.d.ts → constants.d.ts} +1 -1
  6. package/dist/src/features/customStage/constants.d.ts.map +1 -0
  7. package/dist/src/features/customStage/{customStageConstants.lua → constants.lua} +0 -0
  8. package/dist/src/features/customStage/init.lua +2 -2
  9. package/dist/src/features/customStage/shadows.lua +2 -2
  10. package/dist/src/features/customStage/streakText.d.ts.map +1 -1
  11. package/dist/src/features/customStage/streakText.lua +3 -3
  12. package/dist/src/features/customStage/v.d.ts +1 -1
  13. package/dist/src/features/customStage/v.d.ts.map +1 -1
  14. package/dist/src/features/customStage/v.lua +2 -2
  15. package/dist/src/features/customStage/versusScreen.lua +3 -3
  16. package/dist/src/features/customTrapdoor/{customTrapdoorConstants.d.ts → constants.d.ts} +1 -1
  17. package/dist/src/features/customTrapdoor/constants.d.ts.map +1 -0
  18. package/dist/src/features/customTrapdoor/{customTrapdoorConstants.lua → constants.lua} +0 -0
  19. package/dist/src/features/customTrapdoor/exports.lua +2 -2
  20. package/dist/src/features/customTrapdoor/init.lua +4 -4
  21. package/dist/src/features/customTrapdoor/openClose.lua +4 -4
  22. package/dist/src/features/customTrapdoor/spawn.lua +2 -2
  23. package/dist/src/features/customTrapdoor/touched.lua +6 -6
  24. package/dist/src/features/saveDataManager/constants.d.ts +10 -0
  25. package/dist/src/features/saveDataManager/constants.d.ts.map +1 -0
  26. package/dist/src/features/saveDataManager/constants.lua +10 -0
  27. package/dist/src/features/saveDataManager/exports.d.ts +8 -3
  28. package/dist/src/features/saveDataManager/exports.d.ts.map +1 -1
  29. package/dist/src/features/saveDataManager/exports.lua +10 -5
  30. package/dist/src/features/saveDataManager/load.d.ts.map +1 -1
  31. package/dist/src/features/saveDataManager/load.lua +9 -9
  32. package/dist/src/features/saveDataManager/main.d.ts.map +1 -1
  33. package/dist/src/features/saveDataManager/main.lua +67 -4
  34. package/dist/src/features/saveDataManager/maps.d.ts +5 -0
  35. package/dist/src/features/saveDataManager/maps.d.ts.map +1 -1
  36. package/dist/src/features/saveDataManager/maps.lua +3 -0
  37. package/dist/src/features/saveDataManager/merge.lua +2 -2
  38. package/dist/src/features/saveDataManager/save.lua +3 -3
  39. package/dist/src/functions/deepCopy.lua +2 -2
  40. package/package.json +1 -1
  41. package/src/features/customStage/backdrop.ts +1 -1
  42. package/src/features/customStage/{customStageConstants.ts → constants.ts} +0 -0
  43. package/src/features/customStage/init.ts +1 -1
  44. package/src/features/customStage/shadows.ts +1 -1
  45. package/src/features/customStage/streakText.ts +1 -4
  46. package/src/features/customStage/v.ts +1 -1
  47. package/src/features/customStage/versusScreen.ts +1 -1
  48. package/src/features/customTrapdoor/{customTrapdoorConstants.ts → constants.ts} +0 -0
  49. package/src/features/customTrapdoor/exports.ts +1 -1
  50. package/src/features/customTrapdoor/init.ts +1 -1
  51. package/src/features/customTrapdoor/openClose.ts +1 -1
  52. package/src/features/customTrapdoor/spawn.ts +1 -1
  53. package/src/features/customTrapdoor/touched.ts +1 -1
  54. package/src/features/saveDataManager/constants.ts +15 -0
  55. package/src/features/saveDataManager/exports.ts +9 -4
  56. package/src/features/saveDataManager/load.ts +13 -9
  57. package/src/features/saveDataManager/main.ts +78 -4
  58. package/src/features/saveDataManager/maps.ts +6 -0
  59. package/src/features/saveDataManager/merge.ts +1 -1
  60. package/src/features/saveDataManager/save.ts +1 -1
  61. package/src/functions/deepCopy.ts +1 -1
  62. package/dist/src/features/customStage/customStageConstants.d.ts.map +0 -1
  63. package/dist/src/features/customTrapdoor/customTrapdoorConstants.d.ts.map +0 -1
  64. package/dist/src/features/saveDataManager/saveDataManagerConstants.d.ts +0 -4
  65. package/dist/src/features/saveDataManager/saveDataManagerConstants.d.ts.map +0 -1
  66. package/dist/src/features/saveDataManager/saveDataManagerConstants.lua +0 -5
  67. package/src/features/saveDataManager/saveDataManagerConstants.ts +0 -4
@@ -13,8 +13,8 @@ local ____vector = require("src.functions.vector")
13
13
  local isVector = ____vector.isVector
14
14
  local ____customGridEntity = require("src.features.customGridEntity")
15
15
  local spawnCustomGridEntity = ____customGridEntity.spawnCustomGridEntity
16
- local ____customTrapdoorConstants = require("src.features.customTrapdoor.customTrapdoorConstants")
17
- local GridEntityTypeCustom = ____customTrapdoorConstants.GridEntityTypeCustom
16
+ local ____constants = require("src.features.customTrapdoor.constants")
17
+ local GridEntityTypeCustom = ____constants.GridEntityTypeCustom
18
18
  local ____openClose = require("src.features.customTrapdoor.openClose")
19
19
  local shouldTrapdoorSpawnOpen = ____openClose.shouldTrapdoorSpawnOpen
20
20
  local ____v = require("src.features.customTrapdoor.v")
@@ -29,12 +29,12 @@ local isPlayerUsingPony = ____ponyDetection.isPlayerUsingPony
29
29
  local ____runInNFrames = require("src.features.runInNFrames")
30
30
  local runInNGameFrames = ____runInNFrames.runInNGameFrames
31
31
  local runNextRenderFrame = ____runInNFrames.runNextRenderFrame
32
- local ____customTrapdoorConstants = require("src.features.customTrapdoor.customTrapdoorConstants")
33
- local ANIMATIONS_THAT_PREVENT_STAGE_TRAVEL = ____customTrapdoorConstants.ANIMATIONS_THAT_PREVENT_STAGE_TRAVEL
34
- local CUSTOM_TRAPDOOR_FEATURE_NAME = ____customTrapdoorConstants.CUSTOM_TRAPDOOR_FEATURE_NAME
35
- local OTHER_PLAYER_TRAPDOOR_JUMP_DELAY_GAME_FRAMES = ____customTrapdoorConstants.OTHER_PLAYER_TRAPDOOR_JUMP_DELAY_GAME_FRAMES
36
- local OTHER_PLAYER_TRAPDOOR_JUMP_DURATION_GAME_FRAMES = ____customTrapdoorConstants.OTHER_PLAYER_TRAPDOOR_JUMP_DURATION_GAME_FRAMES
37
- local TRAPDOOR_TOUCH_DISTANCE = ____customTrapdoorConstants.TRAPDOOR_TOUCH_DISTANCE
32
+ local ____constants = require("src.features.customTrapdoor.constants")
33
+ local ANIMATIONS_THAT_PREVENT_STAGE_TRAVEL = ____constants.ANIMATIONS_THAT_PREVENT_STAGE_TRAVEL
34
+ local CUSTOM_TRAPDOOR_FEATURE_NAME = ____constants.CUSTOM_TRAPDOOR_FEATURE_NAME
35
+ local OTHER_PLAYER_TRAPDOOR_JUMP_DELAY_GAME_FRAMES = ____constants.OTHER_PLAYER_TRAPDOOR_JUMP_DELAY_GAME_FRAMES
36
+ local OTHER_PLAYER_TRAPDOOR_JUMP_DURATION_GAME_FRAMES = ____constants.OTHER_PLAYER_TRAPDOOR_JUMP_DURATION_GAME_FRAMES
37
+ local TRAPDOOR_TOUCH_DISTANCE = ____constants.TRAPDOOR_TOUCH_DISTANCE
38
38
  local ____v = require("src.features.customTrapdoor.v")
39
39
  local v = ____v.default
40
40
  function canPlayerInteractWithTrapdoor(self, player)
@@ -0,0 +1,10 @@
1
+ import { SaveDataKey } from "../../enums/SaveDataKey";
2
+ /** Set this to true to enable more verbosity in the save data manger. */
3
+ export declare const SAVE_DATA_MANAGER_DEBUG: boolean;
4
+ export declare const SAVE_DATA_MANAGER_FEATURE_NAME = "save data manager";
5
+ /**
6
+ * When the Glowing Hour Glass is used, certain save data keys will automatically be restored to a
7
+ * backup.
8
+ */
9
+ export declare const SAVE_DATA_MANAGER_GLOWING_HOUR_GLASS_BACKUP_KEYS: SaveDataKey[];
10
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,yEAAyE;AACzE,eAAO,MAAM,uBAAuB,SAAmB,CAAC;AAExD,eAAO,MAAM,8BAA8B,sBAAsB,CAAC;AAElE;;;GAGG;AACH,eAAO,MAAM,gDAAgD,eAG5D,CAAC"}
@@ -0,0 +1,10 @@
1
+ local ____exports = {}
2
+ local ____SaveDataKey = require("src.enums.SaveDataKey")
3
+ local SaveDataKey = ____SaveDataKey.SaveDataKey
4
+ --- Set this to true to enable more verbosity in the save data manger.
5
+ ____exports.SAVE_DATA_MANAGER_DEBUG = false
6
+ ____exports.SAVE_DATA_MANAGER_FEATURE_NAME = "save data manager"
7
+ --- When the Glowing Hour Glass is used, certain save data keys will automatically be restored to a
8
+ -- backup.
9
+ ____exports.SAVE_DATA_MANAGER_GLOWING_HOUR_GLASS_BACKUP_KEYS = {SaveDataKey.RUN, SaveDataKey.LEVEL}
10
+ return ____exports
@@ -72,9 +72,14 @@ import { SaveData } from "../../interfaces/SaveData";
72
72
  * data manager cannot do this on its own because it cannot know when your mod features are finished
73
73
  * initializing.)
74
74
  *
75
- * Finally, some features may have variables that need to be automatically reset per run/level, but
76
- * not saved to disk on game exit. (For example, if they contain functions or other non-serializable
77
- * data.) For these cases, set the second argument to `() => false`.
75
+ * Some features may have variables that need to be automatically reset per run/level, but not saved
76
+ * to disk on game exit. (For example, if they contain functions or other non-serializable data.)
77
+ * For these cases, set the second argument to `() => false`.
78
+ *
79
+ * Note that when the player uses Glowing Hour Glass, the save data manager will automatically
80
+ * restore any variables on a "run" or "level" object with a backup that was created when the room
81
+ * was entered. Thus, you should not have to explicitly program support for Glowing Hour Glass into
82
+ * your mod features that use the save data manager.
78
83
  *
79
84
  * @param key The name of the file or feature that is submitting data to be managed by the save data
80
85
  * manager. The save data manager will throw an error if the key is already registered.
@@ -1 +1 @@
1
- {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAKtD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAarD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EACpD,GAAG,EAAE,MAAM,EAAE,qEAAqE;AAClF,CAAC,EAAE,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,EACnC,eAAe,CAAC,EAAE,MAAM,OAAO,GAC9B,IAAI,CAAC;AACR,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EAAE,kEAAkE;AAC/E,CAAC,EAAE,QAAQ,EACX,eAAe,EAAE,KAAK,GACrB,IAAI,CAAC;AA+CR;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAQD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAK/C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,WAAW,GAC1B,IAAI,CAiBN"}
1
+ {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAKtD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAarD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EACpD,GAAG,EAAE,MAAM,EAAE,qEAAqE;AAClF,CAAC,EAAE,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,EACnC,eAAe,CAAC,EAAE,MAAM,OAAO,GAC9B,IAAI,CAAC;AACR,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EAAE,kEAAkE;AAC/E,CAAC,EAAE,QAAQ,EACX,eAAe,EAAE,KAAK,GACrB,IAAI,CAAC;AA+CR;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAQD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAK/C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,WAAW,GAC1B,IAAI,CAiBN"}
@@ -10,6 +10,8 @@ local ____deepCopy = require("src.functions.deepCopy")
10
10
  local deepCopy = ____deepCopy.deepCopy
11
11
  local ____types = require("src.functions.types")
12
12
  local isString = ____types.isString
13
+ local ____constants = require("src.features.saveDataManager.constants")
14
+ local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
13
15
  local ____main = require("src.features.saveDataManager.main")
14
16
  local forceSaveDataManagerLoad = ____main.forceSaveDataManagerLoad
15
17
  local forceSaveDataManagerSave = ____main.forceSaveDataManagerSave
@@ -18,8 +20,6 @@ local ____maps = require("src.features.saveDataManager.maps")
18
20
  local saveDataConditionalFuncMap = ____maps.saveDataConditionalFuncMap
19
21
  local saveDataDefaultsMap = ____maps.saveDataDefaultsMap
20
22
  local saveDataMap = ____maps.saveDataMap
21
- local ____saveDataManagerConstants = require("src.features.saveDataManager.saveDataManagerConstants")
22
- local SAVE_DATA_MANAGER_FEATURE_NAME = ____saveDataManagerConstants.SAVE_DATA_MANAGER_FEATURE_NAME
23
23
  --- This is the entry point to the save data manager, a system which provides two major features:
24
24
  --
25
25
  -- 1. automatic resetting of variables on a new run, on a new level, or on a new room (as desired)
@@ -91,9 +91,14 @@ local SAVE_DATA_MANAGER_FEATURE_NAME = ____saveDataManagerConstants.SAVE_DATA_MA
91
91
  -- data manager cannot do this on its own because it cannot know when your mod features are finished
92
92
  -- initializing.)
93
93
  --
94
- -- Finally, some features may have variables that need to be automatically reset per run/level, but
95
- -- not saved to disk on game exit. (For example, if they contain functions or other non-serializable
96
- -- data.) For these cases, set the second argument to `() => false`.
94
+ -- Some features may have variables that need to be automatically reset per run/level, but not saved
95
+ -- to disk on game exit. (For example, if they contain functions or other non-serializable data.)
96
+ -- For these cases, set the second argument to `() => false`.
97
+ --
98
+ -- Note that when the player uses Glowing Hour Glass, the save data manager will automatically
99
+ -- restore any variables on a "run" or "level" object with a backup that was created when the room
100
+ -- was entered. Thus, you should not have to explicitly program support for Glowing Hour Glass into
101
+ -- your mod features that use the save data manager.
97
102
  --
98
103
  -- @param key The name of the file or feature that is submitting data to be managed by the save data
99
104
  -- manager. The save data manager will throw an error if the key is already registered.
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/load.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AASrD,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GACpC,IAAI,CAmDN"}
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/load.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AASrD,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GACpC,IAAI,CAuDN"}
@@ -12,11 +12,11 @@ local iterateTableInOrder = ____table.iterateTableInOrder
12
12
  local ____types = require("src.functions.types")
13
13
  local isString = ____types.isString
14
14
  local isTable = ____types.isTable
15
+ local ____constants = require("src.features.saveDataManager.constants")
16
+ local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
17
+ local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
15
18
  local ____merge = require("src.features.saveDataManager.merge")
16
19
  local merge = ____merge.merge
17
- local ____saveDataManagerConstants = require("src.features.saveDataManager.saveDataManagerConstants")
18
- local SAVE_DATA_MANAGER_DEBUG = ____saveDataManagerConstants.SAVE_DATA_MANAGER_DEBUG
19
- local SAVE_DATA_MANAGER_FEATURE_NAME = ____saveDataManagerConstants.SAVE_DATA_MANAGER_FEATURE_NAME
20
20
  function readSaveDatFile(self, mod)
21
21
  local renderFrameCount = Isaac.GetFrameCount()
22
22
  local ok, jsonStringOrErrMsg = pcall(tryLoadModData, mod)
@@ -52,21 +52,21 @@ function ____exports.loadFromDisk(self, mod, oldSaveData)
52
52
  iterateTableInOrder(
53
53
  nil,
54
54
  newSaveData,
55
- function(____, key, value)
56
- if not isString(nil, key) then
55
+ function(____, subscriberName, saveData)
56
+ if not isString(nil, subscriberName) then
57
57
  return
58
58
  end
59
- if not isTable(nil, value) then
59
+ if not isTable(nil, saveData) then
60
60
  return
61
61
  end
62
- local oldSaveDataForSubscriber = oldSaveData[key]
62
+ local oldSaveDataForSubscriber = oldSaveData[subscriberName]
63
63
  if oldSaveDataForSubscriber == nil then
64
64
  return
65
65
  end
66
66
  if SAVE_DATA_MANAGER_DEBUG then
67
- log(nil, "Merging in stored data for feature: " .. key)
67
+ log(nil, "Merging in stored data for feature: " .. subscriberName)
68
68
  end
69
- merge(nil, oldSaveDataForSubscriber, value, key)
69
+ merge(nil, oldSaveDataForSubscriber, saveData, subscriberName)
70
70
  end,
71
71
  SAVE_DATA_MANAGER_DEBUG
72
72
  )
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAMtD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAsBrD,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAelE;AA2FD,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,GACvB,IAAI,CA4CN;AAiBD,wBAAgB,wBAAwB,IAAI,IAAI,CAM/C;AAED,wBAAgB,wBAAwB,IAAI,IAAI,CAM/C"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAMtD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AA0BrD,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAelE;AAiKD,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,GACvB,IAAI,CA4CN;AAiBD,wBAAgB,wBAAwB,IAAI,IAAI,CAM/C;AAED,wBAAgB,wBAAwB,IAAI,IAAI,CAM/C"}
@@ -2,7 +2,7 @@ local ____lualib = require("lualib_bundle")
2
2
  local Set = ____lualib.Set
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local ____exports = {}
5
- local postUseItemGlowingHourGlass, postPlayerInit, preGameExit, postNewLevel, postNewRoomEarly, restoreDefaultsAll, restoreDefaults, clearAndCopyAllElements, RESETTABLE_SAVE_DATA_KEYS, mod, loadedDataOnThisRun
5
+ local postUseItemGlowingHourGlass, postPlayerInit, preGameExit, postNewLevel, postNewRoomEarly, makeGlowingHourGlassBackup, restoreGlowingHourGlassBackup, restoreDefaultsAll, restoreDefaults, clearAndCopyAllElements, RESETTABLE_SAVE_DATA_KEYS, mod, loadedDataOnThisRun, restoreGlowingHourGlassDataOnNextRoom
6
6
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
7
7
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
8
8
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
@@ -23,18 +23,23 @@ local onFirstFloor = ____stage.onFirstFloor
23
23
  local ____table = require("src.functions.table")
24
24
  local clearTable = ____table.clearTable
25
25
  local iterateTableInOrder = ____table.iterateTableInOrder
26
+ local ____constants = require("src.features.saveDataManager.constants")
27
+ local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
28
+ local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
29
+ local SAVE_DATA_MANAGER_GLOWING_HOUR_GLASS_BACKUP_KEYS = ____constants.SAVE_DATA_MANAGER_GLOWING_HOUR_GLASS_BACKUP_KEYS
26
30
  local ____load = require("src.features.saveDataManager.load")
27
31
  local loadFromDisk = ____load.loadFromDisk
28
32
  local ____maps = require("src.features.saveDataManager.maps")
29
33
  local saveDataConditionalFuncMap = ____maps.saveDataConditionalFuncMap
30
34
  local saveDataDefaultsMap = ____maps.saveDataDefaultsMap
35
+ local saveDataGlowingHourGlassMap = ____maps.saveDataGlowingHourGlassMap
31
36
  local saveDataMap = ____maps.saveDataMap
37
+ local ____merge = require("src.features.saveDataManager.merge")
38
+ local merge = ____merge.merge
32
39
  local ____save = require("src.features.saveDataManager.save")
33
40
  local saveToDisk = ____save.saveToDisk
34
- local ____saveDataManagerConstants = require("src.features.saveDataManager.saveDataManagerConstants")
35
- local SAVE_DATA_MANAGER_DEBUG = ____saveDataManagerConstants.SAVE_DATA_MANAGER_DEBUG
36
- local SAVE_DATA_MANAGER_FEATURE_NAME = ____saveDataManagerConstants.SAVE_DATA_MANAGER_FEATURE_NAME
37
41
  function postUseItemGlowingHourGlass(self)
42
+ restoreGlowingHourGlassDataOnNextRoom = true
38
43
  return nil
39
44
  end
40
45
  function postPlayerInit(self)
@@ -71,6 +76,63 @@ function postNewLevel(self)
71
76
  end
72
77
  function postNewRoomEarly(self)
73
78
  restoreDefaults(nil, SaveDataKey.ROOM)
79
+ if restoreGlowingHourGlassDataOnNextRoom then
80
+ restoreGlowingHourGlassDataOnNextRoom = false
81
+ restoreGlowingHourGlassBackup(nil)
82
+ else
83
+ makeGlowingHourGlassBackup(nil)
84
+ end
85
+ end
86
+ function makeGlowingHourGlassBackup(self)
87
+ iterateTableInOrder(
88
+ nil,
89
+ saveDataMap,
90
+ function(____, subscriberName, saveData)
91
+ for ____, saveDataKey in ipairs(SAVE_DATA_MANAGER_GLOWING_HOUR_GLASS_BACKUP_KEYS) do
92
+ do
93
+ local childTable = saveData[saveDataKey]
94
+ if childTable == nil then
95
+ goto __continue18
96
+ end
97
+ local saveDataGlowingHourGlass = saveDataGlowingHourGlassMap[subscriberName]
98
+ if saveDataGlowingHourGlass == nil then
99
+ saveDataGlowingHourGlass = {}
100
+ end
101
+ local copiedChildTable = deepCopy(nil, childTable)
102
+ saveDataGlowingHourGlass[saveDataKey] = copiedChildTable
103
+ end
104
+ ::__continue18::
105
+ end
106
+ end,
107
+ SAVE_DATA_MANAGER_DEBUG
108
+ )
109
+ end
110
+ function restoreGlowingHourGlassBackup(self)
111
+ iterateTableInOrder(
112
+ nil,
113
+ saveDataMap,
114
+ function(____, subscriberName, saveData)
115
+ for ____, saveDataKey in ipairs(SAVE_DATA_MANAGER_GLOWING_HOUR_GLASS_BACKUP_KEYS) do
116
+ do
117
+ local childTable = saveData[saveDataKey]
118
+ if childTable == nil then
119
+ goto __continue24
120
+ end
121
+ local saveDataGlowingHourGlass = saveDataGlowingHourGlassMap[subscriberName]
122
+ if saveDataGlowingHourGlass == nil then
123
+ goto __continue24
124
+ end
125
+ local childTableBackup = saveDataGlowingHourGlass[saveDataKey]
126
+ if childTableBackup == nil then
127
+ goto __continue24
128
+ end
129
+ merge(nil, childTable, childTableBackup, subscriberName .. "__glowingHourGlass")
130
+ end
131
+ ::__continue24::
132
+ end
133
+ end,
134
+ SAVE_DATA_MANAGER_DEBUG
135
+ )
74
136
  end
75
137
  function restoreDefaultsAll(self)
76
138
  restoreDefaults(nil, SaveDataKey.RUN)
@@ -117,6 +179,7 @@ end
117
179
  RESETTABLE_SAVE_DATA_KEYS = __TS__New(Set, {SaveDataKey.RUN, SaveDataKey.LEVEL, SaveDataKey.ROOM})
118
180
  mod = nil
119
181
  loadedDataOnThisRun = false
182
+ restoreGlowingHourGlassDataOnNextRoom = false
120
183
  function ____exports.saveDataManagerInit(self, incomingMod)
121
184
  mod = incomingMod
122
185
  mod:AddCallback(ModCallback.POST_USE_ITEM, postUseItemGlowingHourGlass, CollectibleType.GLOWING_HOUR_GLASS)
@@ -8,4 +8,9 @@ import { SaveData } from "../../interfaces/SaveData";
8
8
  export declare const saveDataMap: LuaMap<string, SaveData<unknown, unknown, unknown>>;
9
9
  export declare const saveDataDefaultsMap: LuaMap<string, SaveData<unknown, unknown, unknown>>;
10
10
  export declare const saveDataConditionalFuncMap: LuaMap<string, () => boolean>;
11
+ /**
12
+ * We backup some save data keys on every new room for the purposes of restoring it when Glowing
13
+ * Hour Glass is used.
14
+ */
15
+ export declare const saveDataGlowingHourGlassMap: LuaMap<string, SaveData<unknown, unknown, unknown>>;
11
16
  //# sourceMappingURL=maps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"maps.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/maps.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,WAAW,qDAAiC,CAAC;AAE1D,eAAO,MAAM,mBAAmB,qDAAiC,CAAC;AAClE,eAAO,MAAM,0BAA0B,uBAA4B,OAAO,CAAG,CAAC"}
1
+ {"version":3,"file":"maps.d.ts","sourceRoot":"","sources":["../../../../src/features/saveDataManager/maps.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,WAAW,qDAAiC,CAAC;AAE1D,eAAO,MAAM,mBAAmB,qDAAiC,CAAC;AAClE,eAAO,MAAM,0BAA0B,uBAA4B,OAAO,CAAG,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,2BAA2B,qDAAiC,CAAC"}
@@ -5,4 +5,7 @@ local ____exports = {}
5
5
  ____exports.saveDataMap = {}
6
6
  ____exports.saveDataDefaultsMap = {}
7
7
  ____exports.saveDataConditionalFuncMap = {}
8
+ --- We backup some save data keys on every new room for the purposes of restoring it when Glowing
9
+ -- Hour Glass is used.
10
+ ____exports.saveDataGlowingHourGlassMap = {}
8
11
  return ____exports
@@ -27,8 +27,8 @@ local ____types = require("src.functions.types")
27
27
  local isTable = ____types.isTable
28
28
  local ____utils = require("src.functions.utils")
29
29
  local getTraversalDescription = ____utils.getTraversalDescription
30
- local ____saveDataManagerConstants = require("src.features.saveDataManager.saveDataManagerConstants")
31
- local SAVE_DATA_MANAGER_DEBUG = ____saveDataManagerConstants.SAVE_DATA_MANAGER_DEBUG
30
+ local ____constants = require("src.features.saveDataManager.constants")
31
+ local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
32
32
  local ____serializationBrands = require("src.features.saveDataManager.serializationBrands")
33
33
  local isSerializationBrand = ____serializationBrands.isSerializationBrand
34
34
  --- `merge` takes the values from a new table and recursively merges them into an old object (while
@@ -12,9 +12,9 @@ local ____log = require("src.functions.log")
12
12
  local log = ____log.log
13
13
  local ____table = require("src.functions.table")
14
14
  local iterateTableInOrder = ____table.iterateTableInOrder
15
- local ____saveDataManagerConstants = require("src.features.saveDataManager.saveDataManagerConstants")
16
- local SAVE_DATA_MANAGER_DEBUG = ____saveDataManagerConstants.SAVE_DATA_MANAGER_DEBUG
17
- local SAVE_DATA_MANAGER_FEATURE_NAME = ____saveDataManagerConstants.SAVE_DATA_MANAGER_FEATURE_NAME
15
+ local ____constants = require("src.features.saveDataManager.constants")
16
+ local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
17
+ local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
18
18
  function getAllSaveDataToWriteToDisk(self, saveDataMap, saveDataConditionalFuncMap)
19
19
  local allSaveData = {}
20
20
  iterateTableInOrder(
@@ -13,8 +13,8 @@ local ____SerializationBrand = require("src.enums.private.SerializationBrand")
13
13
  local SerializationBrand = ____SerializationBrand.SerializationBrand
14
14
  local ____SerializationType = require("src.enums.SerializationType")
15
15
  local SerializationType = ____SerializationType.SerializationType
16
- local ____saveDataManagerConstants = require("src.features.saveDataManager.saveDataManagerConstants")
17
- local SAVE_DATA_MANAGER_DEBUG = ____saveDataManagerConstants.SAVE_DATA_MANAGER_DEBUG
16
+ local ____constants = require("src.features.saveDataManager.constants")
17
+ local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
18
18
  local ____serializationBrands = require("src.features.saveDataManager.serializationBrands")
19
19
  local isSerializationBrand = ____serializationBrands.isSerializationBrand
20
20
  local ____array = require("src.functions.array")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "11.2.4",
3
+ "version": "12.0.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -17,7 +17,7 @@ import { isLRoom, isNarrowRoom } from "../../functions/roomShape";
17
17
  import { removeCharactersBefore, trimPrefix } from "../../functions/string";
18
18
  import { erange, irange } from "../../functions/utils";
19
19
  import { CustomStage } from "../../interfaces/private/CustomStage";
20
- import { ISAACSCRIPT_CUSTOM_STAGE_GFX_PATH } from "./customStageConstants";
20
+ import { ISAACSCRIPT_CUSTOM_STAGE_GFX_PATH } from "./constants";
21
21
 
22
22
  enum BackdropKind {
23
23
  /** The "N" stands for narrow rooms. */
@@ -17,7 +17,7 @@ import {
17
17
  import { CustomStage, RoomTypeMap } from "../../interfaces/private/CustomStage";
18
18
  import { saveDataManager } from "../saveDataManager/exports";
19
19
  import { setCustomStageBackdrop } from "./backdrop";
20
- import { CUSTOM_STAGE_FEATURE_NAME } from "./customStageConstants";
20
+ import { CUSTOM_STAGE_FEATURE_NAME } from "./constants";
21
21
  import {
22
22
  convertVanillaTrapdoors,
23
23
  removeUrnRewards,
@@ -4,7 +4,7 @@ import { getRandomArrayElement } from "../../functions/array";
4
4
  import { spawnEffectWithSeed } from "../../functions/entitiesSpecific";
5
5
  import { removeCharactersBefore } from "../../functions/string";
6
6
  import { CustomStage } from "../../interfaces/private/CustomStage";
7
- import { ISAACSCRIPT_CUSTOM_STAGE_GFX_PATH } from "./customStageConstants";
7
+ import { ISAACSCRIPT_CUSTOM_STAGE_GFX_PATH } from "./constants";
8
8
  import v from "./v";
9
9
 
10
10
  type ShadowAnimation = "1x1" | "1x2" | "2x1" | "2x2";
@@ -7,10 +7,7 @@ import {
7
7
  getScreenTopCenterPos,
8
8
  } from "../../functions/ui";
9
9
  import { CustomStage } from "../../interfaces/private/CustomStage";
10
- import {
11
- UIStreakAnimation,
12
- UI_STREAK_ANIMATION_END_FRAMES,
13
- } from "./customStageConstants";
10
+ import { UIStreakAnimation, UI_STREAK_ANIMATION_END_FRAMES } from "./constants";
14
11
  import v from "./v";
15
12
 
16
13
  /** This must match the name of the shader in "shaders.xml". */
@@ -1,6 +1,6 @@
1
1
  import { ControllerIndex } from "isaac-typescript-definitions";
2
2
  import { CustomStage } from "../../interfaces/private/CustomStage";
3
- import { UIStreakAnimation } from "./customStageConstants";
3
+ import { UIStreakAnimation } from "./constants";
4
4
 
5
5
  const v = {
6
6
  run: {
@@ -24,7 +24,7 @@ import { runNextGameFrame } from "../runInNFrames";
24
24
  import {
25
25
  CUSTOM_STAGE_FEATURE_NAME,
26
26
  ISAACSCRIPT_CUSTOM_STAGE_GFX_PATH,
27
- } from "./customStageConstants";
27
+ } from "./constants";
28
28
  import {
29
29
  CUSTOM_FLOOR_STAGE,
30
30
  CUSTOM_FLOOR_STAGE_TYPE,
@@ -2,7 +2,7 @@ import { LevelStage, StageType } from "isaac-typescript-definitions";
2
2
  import { errorIfFeaturesNotInitialized } from "../../featuresInitialized";
3
3
  import { getNextStage, getNextStageType } from "../../functions/nextStage";
4
4
  import { CustomTrapdoorDestination } from "../../interfaces/private/CustomTrapdoorDestination";
5
- import { CUSTOM_TRAPDOOR_FEATURE_NAME } from "./customTrapdoorConstants";
5
+ import { CUSTOM_TRAPDOOR_FEATURE_NAME } from "./constants";
6
6
  import { spawnCustomTrapdoorToDestination } from "./spawn";
7
7
 
8
8
  /**
@@ -25,7 +25,7 @@ import {
25
25
  CUSTOM_TRAPDOOR_FEATURE_NAME,
26
26
  GridEntityTypeCustom,
27
27
  PIXELATION_TO_BLACK_FRAMES,
28
- } from "./customTrapdoorConstants";
28
+ } from "./constants";
29
29
  import { checkCustomTrapdoorOpenClose } from "./openClose";
30
30
  import { checkCustomTrapdoorPlayerTouched } from "./touched";
31
31
  import v from "./v";
@@ -8,7 +8,7 @@ import {
8
8
  TRAPDOOR_BOSS_REACTION_FRAMES,
9
9
  TRAPDOOR_OPEN_DISTANCE,
10
10
  TRAPDOOR_OPEN_DISTANCE_AFTER_BOSS,
11
- } from "./customTrapdoorConstants";
11
+ } from "./constants";
12
12
 
13
13
  export function checkCustomTrapdoorOpenClose(
14
14
  gridEntity: GridEntity,
@@ -6,7 +6,7 @@ import { isVector } from "../../functions/vector";
6
6
  import { CustomTrapdoorDescription } from "../../interfaces/private/CustomTrapdoorDescription";
7
7
  import { CustomTrapdoorDestination } from "../../interfaces/private/CustomTrapdoorDestination";
8
8
  import { spawnCustomGridEntity } from "../customGridEntity";
9
- import { GridEntityTypeCustom } from "./customTrapdoorConstants";
9
+ import { GridEntityTypeCustom } from "./constants";
10
10
  import { shouldTrapdoorSpawnOpen } from "./openClose";
11
11
  import v from "./v";
12
12
 
@@ -24,7 +24,7 @@ import {
24
24
  OTHER_PLAYER_TRAPDOOR_JUMP_DELAY_GAME_FRAMES,
25
25
  OTHER_PLAYER_TRAPDOOR_JUMP_DURATION_GAME_FRAMES,
26
26
  TRAPDOOR_TOUCH_DISTANCE,
27
- } from "./customTrapdoorConstants";
27
+ } from "./constants";
28
28
  import v from "./v";
29
29
 
30
30
  export function checkCustomTrapdoorPlayerTouched(
@@ -0,0 +1,15 @@
1
+ import { SaveDataKey } from "../../enums/SaveDataKey";
2
+
3
+ /** Set this to true to enable more verbosity in the save data manger. */
4
+ export const SAVE_DATA_MANAGER_DEBUG = false as boolean;
5
+
6
+ export const SAVE_DATA_MANAGER_FEATURE_NAME = "save data manager";
7
+
8
+ /**
9
+ * When the Glowing Hour Glass is used, certain save data keys will automatically be restored to a
10
+ * backup.
11
+ */
12
+ export const SAVE_DATA_MANAGER_GLOWING_HOUR_GLASS_BACKUP_KEYS = [
13
+ SaveDataKey.RUN,
14
+ SaveDataKey.LEVEL,
15
+ ];
@@ -4,6 +4,7 @@ import { errorIfFeaturesNotInitialized } from "../../featuresInitialized";
4
4
  import { deepCopy } from "../../functions/deepCopy";
5
5
  import { isString } from "../../functions/types";
6
6
  import { SaveData } from "../../interfaces/SaveData";
7
+ import { SAVE_DATA_MANAGER_FEATURE_NAME } from "./constants";
7
8
  import {
8
9
  forceSaveDataManagerLoad,
9
10
  forceSaveDataManagerSave,
@@ -14,7 +15,6 @@ import {
14
15
  saveDataDefaultsMap,
15
16
  saveDataMap,
16
17
  } from "./maps";
17
- import { SAVE_DATA_MANAGER_FEATURE_NAME } from "./saveDataManagerConstants";
18
18
 
19
19
  /**
20
20
  * This is the entry point to the save data manager, a system which provides two major features:
@@ -88,9 +88,14 @@ import { SAVE_DATA_MANAGER_FEATURE_NAME } from "./saveDataManagerConstants";
88
88
  * data manager cannot do this on its own because it cannot know when your mod features are finished
89
89
  * initializing.)
90
90
  *
91
- * Finally, some features may have variables that need to be automatically reset per run/level, but
92
- * not saved to disk on game exit. (For example, if they contain functions or other non-serializable
93
- * data.) For these cases, set the second argument to `() => false`.
91
+ * Some features may have variables that need to be automatically reset per run/level, but not saved
92
+ * to disk on game exit. (For example, if they contain functions or other non-serializable data.)
93
+ * For these cases, set the second argument to `() => false`.
94
+ *
95
+ * Note that when the player uses Glowing Hour Glass, the save data manager will automatically
96
+ * restore any variables on a "run" or "level" object with a backup that was created when the room
97
+ * was entered. Thus, you should not have to explicitly program support for Glowing Hour Glass into
98
+ * your mod features that use the save data manager.
94
99
  *
95
100
  * @param key The name of the file or feature that is submitting data to be managed by the save data
96
101
  * manager. The save data manager will throw an error if the key is already registered.
@@ -3,11 +3,11 @@ import { log, logError } from "../../functions/log";
3
3
  import { iterateTableInOrder } from "../../functions/table";
4
4
  import { isString, isTable } from "../../functions/types";
5
5
  import { SaveData } from "../../interfaces/SaveData";
6
- import { merge } from "./merge";
7
6
  import {
8
7
  SAVE_DATA_MANAGER_DEBUG,
9
8
  SAVE_DATA_MANAGER_FEATURE_NAME,
10
- } from "./saveDataManagerConstants";
9
+ } from "./constants";
10
+ import { merge } from "./merge";
11
11
 
12
12
  const DEFAULT_MOD_DATA = "{}";
13
13
 
@@ -31,33 +31,37 @@ export function loadFromDisk(
31
31
  // Second, iterate over all the fields of the new table.)
32
32
  iterateTableInOrder(
33
33
  newSaveData,
34
- (key, value) => {
34
+ (subscriberName, saveData) => {
35
35
  // All elements of loaded save data should have keys that are strings equal to the name of the
36
36
  // subscriber/feature. Ignore elements with other types of keys.
37
- if (!isString(key)) {
37
+ if (!isString(subscriberName)) {
38
38
  return;
39
39
  }
40
40
 
41
41
  // All elements of loaded save data should be tables that contain fields corresponding to the
42
- // SaveData interface. Ignore elements that are not tables.
43
- if (!isTable(value)) {
42
+ // `SaveData` interface. Ignore elements that are not tables.
43
+ if (!isTable(saveData)) {
44
44
  return;
45
45
  }
46
46
 
47
47
  // Ignore elements that represent subscriptions that no longer exist in the current save data.
48
- const oldSaveDataForSubscriber = oldSaveData.get(key);
48
+ const oldSaveDataForSubscriber = oldSaveData.get(subscriberName);
49
49
  if (oldSaveDataForSubscriber === undefined) {
50
50
  return;
51
51
  }
52
52
 
53
53
  if (SAVE_DATA_MANAGER_DEBUG) {
54
- log(`Merging in stored data for feature: ${key}`);
54
+ log(`Merging in stored data for feature: ${subscriberName}`);
55
55
  }
56
56
 
57
57
  // We do not want to blow away the child tables of the existing map, because save data could
58
58
  // contain out-of-date fields. Instead, merge it one field at a time in a recursive way (and
59
59
  // convert Lua tables back to TypeScriptToLua Maps, if necessary).
60
- merge(oldSaveDataForSubscriber as LuaMap<AnyNotNil, unknown>, value, key);
60
+ merge(
61
+ oldSaveDataForSubscriber as LuaMap<AnyNotNil, unknown>,
62
+ saveData,
63
+ subscriberName,
64
+ );
61
65
  },
62
66
  SAVE_DATA_MANAGER_DEBUG,
63
67
  );