isaacscript-common 2.0.29 → 2.0.32

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.
@@ -0,0 +1,7 @@
1
+ export declare enum SaveDataKey {
2
+ PERSISTENT = "persistent",
3
+ RUN = "run",
4
+ LEVEL = "level",
5
+ ROOM = "room"
6
+ }
7
+ export declare const RESETTABLE_SAVE_DATA_KEYS: ReadonlySet<SaveDataKey>;
@@ -0,0 +1,11 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Set = ____lualib.Set
3
+ local __TS__New = ____lualib.__TS__New
4
+ local ____exports = {}
5
+ ____exports.SaveDataKey = {}
6
+ ____exports.SaveDataKey.PERSISTENT = "persistent"
7
+ ____exports.SaveDataKey.RUN = "run"
8
+ ____exports.SaveDataKey.LEVEL = "level"
9
+ ____exports.SaveDataKey.ROOM = "room"
10
+ ____exports.RESETTABLE_SAVE_DATA_KEYS = __TS__New(Set, {____exports.SaveDataKey.RUN, ____exports.SaveDataKey.LEVEL, ____exports.SaveDataKey.ROOM})
11
+ return ____exports
@@ -105,3 +105,24 @@ export declare function saveDataManagerSave(): void;
105
105
  * e.g. `l print(g.feature1.foo)`
106
106
  */
107
107
  export declare function saveDataManagerSetGlobal(): void;
108
+ /**
109
+ * The save data manager will automatically reset variables at the appropriate times (i.e. when a
110
+ * player enters a new room). Use this function to explicitly force the save data manager to reset a
111
+ * specific variable group.
112
+ *
113
+ * For example:
114
+ *
115
+ * ```
116
+ * const v = {
117
+ * room: {
118
+ * foo: 123,
119
+ * },
120
+ * };
121
+ *
122
+ * saveDataManager("file1", v);
123
+ *
124
+ * // Then, later on, to explicit reset all of the "room" variables:
125
+ * saveDataManagerReset("file1", "room");
126
+ * ```
127
+ */
128
+ export declare function saveDataManagerReset(key: string, childObjectKey: string): void;
@@ -13,6 +13,7 @@ local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_N
13
13
  local ____main = require("features.saveDataManager.main")
14
14
  local forceSaveDataManagerLoad = ____main.forceSaveDataManagerLoad
15
15
  local forceSaveDataManagerSave = ____main.forceSaveDataManagerSave
16
+ local restoreDefaultSaveData = ____main.restoreDefaultSaveData
16
17
  local ____maps = require("features.saveDataManager.maps")
17
18
  local saveDataConditionalFuncMap = ____maps.saveDataConditionalFuncMap
18
19
  local saveDataDefaultsMap = ____maps.saveDataDefaultsMap
@@ -50,4 +51,16 @@ function ____exports.saveDataManagerSetGlobal(self)
50
51
  g = saveDataMap
51
52
  gd = saveDataDefaultsMap
52
53
  end
54
+ function ____exports.saveDataManagerReset(self, key, childObjectKey)
55
+ errorIfFeaturesNotInitialized(nil, SAVE_DATA_MANAGER_FEATURE_NAME)
56
+ local keyType = type(key)
57
+ if keyType ~= "string" then
58
+ error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " requires that keys are strings. You tried to use a key of type: ") .. keyType)
59
+ end
60
+ local saveData = saveDataMap[key]
61
+ if saveData == nil then
62
+ error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " is not managing save data for a key of: ") .. key)
63
+ end
64
+ restoreDefaultSaveData(nil, key, saveData, childObjectKey)
65
+ end
53
66
  return ____exports
@@ -1 +1,3 @@
1
- export {};
1
+ import { SaveDataKey } from "../../enums/private/SaveDataKey";
2
+ import { SaveData } from "../../types/private/SaveData";
3
+ export declare function restoreDefaultSaveData(subscriberName: string, saveData: SaveData, saveDataKey: SaveDataKey): void;
@@ -8,8 +8,9 @@ local ____cachedClasses = require("cachedClasses")
8
8
  local game = ____cachedClasses.game
9
9
  local ____ModCallbackCustom = require("enums.ModCallbackCustom")
10
10
  local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
11
- local ____SaveDataKeys = require("enums.private.SaveDataKeys")
12
- local SaveDataKeys = ____SaveDataKeys.SaveDataKeys
11
+ local ____SaveDataKey = require("enums.private.SaveDataKey")
12
+ local RESETTABLE_SAVE_DATA_KEYS = ____SaveDataKey.RESETTABLE_SAVE_DATA_KEYS
13
+ local SaveDataKey = ____SaveDataKey.SaveDataKey
13
14
  local ____SerializationType = require("enums.SerializationType")
14
15
  local SerializationType = ____SerializationType.SerializationType
15
16
  local ____deepCopy = require("functions.deepCopy")
@@ -52,41 +53,41 @@ function preGameExit(self)
52
53
  loadedDataOnThisRun = false
53
54
  end
54
55
  function postNewLevel(self)
55
- restoreDefaults(nil, SaveDataKeys.LEVEL)
56
+ restoreDefaults(nil, SaveDataKey.LEVEL)
56
57
  end
57
58
  function postNewRoomEarly(self)
58
- restoreDefaults(nil, SaveDataKeys.ROOM)
59
+ restoreDefaults(nil, SaveDataKey.ROOM)
59
60
  end
60
61
  function restoreDefaultsAll(self)
61
- restoreDefaults(nil, SaveDataKeys.RUN)
62
- restoreDefaults(nil, SaveDataKeys.LEVEL)
63
- restoreDefaults(nil, SaveDataKeys.ROOM)
62
+ restoreDefaults(nil, SaveDataKey.RUN)
63
+ restoreDefaults(nil, SaveDataKey.LEVEL)
64
+ restoreDefaults(nil, SaveDataKey.ROOM)
64
65
  end
65
- function restoreDefaults(self, childTableName)
66
- if childTableName ~= SaveDataKeys.RUN and childTableName ~= SaveDataKeys.LEVEL and childTableName ~= SaveDataKeys.ROOM then
67
- error("Unknown child table name of: " .. childTableName)
68
- end
66
+ function restoreDefaults(self, saveDataKey)
69
67
  for subscriberName, saveData in pairs(saveDataMap) do
70
- do
71
- local childTable = saveData[childTableName]
72
- if childTable == nil then
73
- goto __continue14
74
- end
75
- local saveDataDefaults = saveDataDefaultsMap[subscriberName]
76
- if saveDataDefaults == nil then
77
- logError("Failed to find the default copy of the save data for subscriber: " .. subscriberName)
78
- goto __continue14
79
- end
80
- local childTableDefaults = saveDataDefaults[childTableName]
81
- if childTableDefaults == nil then
82
- logError(((("Failed to find the default copy of the child table \"" .. childTableName) .. "\" for subscriber \"") .. subscriberName) .. "\". This error usually means that your save data is out of date. You can try purging all of your save data by deleting the following directory: C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Binding of Isaac Rebirth\\data")
83
- goto __continue14
84
- end
85
- local childTableDefaultsCopy = deepCopy(nil, childTableDefaults, SerializationType.NONE, (subscriberName .. " --> ") .. childTableName)
86
- clearAndCopyAllElements(nil, childTable, childTableDefaultsCopy)
87
- end
88
- ::__continue14::
68
+ ____exports.restoreDefaultSaveData(nil, subscriberName, saveData, saveDataKey)
69
+ end
70
+ end
71
+ function ____exports.restoreDefaultSaveData(self, subscriberName, saveData, saveDataKey)
72
+ if not RESETTABLE_SAVE_DATA_KEYS:has(saveDataKey) then
73
+ error("Unknown save data key name of: " .. saveDataKey)
74
+ end
75
+ local childTable = saveData[saveDataKey]
76
+ if childTable == nil then
77
+ return
78
+ end
79
+ local saveDataDefaults = saveDataDefaultsMap[subscriberName]
80
+ if saveDataDefaults == nil then
81
+ logError("Failed to find the default copy of the save data for subscriber: " .. subscriberName)
82
+ return
83
+ end
84
+ local childTableDefaults = saveDataDefaults[saveDataKey]
85
+ if childTableDefaults == nil then
86
+ logError(((("Failed to find the default copy of the child table \"" .. saveDataKey) .. "\" for subscriber \"") .. subscriberName) .. "\". This error usually means that your save data is out of date. You can try purging all of your save data by deleting the following directory: C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Binding of Isaac Rebirth\\data")
87
+ return
89
88
  end
89
+ local childTableDefaultsCopy = deepCopy(nil, childTableDefaults, SerializationType.NONE, (subscriberName .. " --> ") .. saveDataKey)
90
+ clearAndCopyAllElements(nil, childTable, childTableDefaultsCopy)
90
91
  end
91
92
  function clearAndCopyAllElements(self, oldTable, newTable)
92
93
  clearTable(nil, oldTable)
@@ -15,8 +15,11 @@ local VANILLA_COLLECTIBLES_SET = __TS__New(Set)
15
15
  local MODDED_COLLECTIBLES_SET = __TS__New(Set)
16
16
  local function initCollectibleSets(self)
17
17
  for ____, collectibleType in ipairs(getCollectibleTypeRange(nil)) do
18
- local itemConfigItem = itemConfig:GetCollectible(collectibleType)
19
- if itemConfigItem ~= nil then
18
+ do
19
+ local itemConfigItem = itemConfig:GetCollectible(collectibleType)
20
+ if itemConfigItem == nil then
21
+ goto __continue3
22
+ end
20
23
  ALL_COLLECTIBLES_SET:add(collectibleType)
21
24
  if collectibleType <= LAST_VANILLA_COLLECTIBLE_TYPE then
22
25
  VANILLA_COLLECTIBLES_SET:add(collectibleType)
@@ -24,6 +27,7 @@ local function initCollectibleSets(self)
24
27
  MODDED_COLLECTIBLES_SET:add(collectibleType)
25
28
  end
26
29
  end
30
+ ::__continue3::
27
31
  end
28
32
  end
29
33
  function ____exports.getCollectibleSet(self)
@@ -142,6 +142,12 @@ export declare function isBlindCollectible(collectible: EntityPickup): boolean;
142
142
  * in secret rooms and I AM ERROR rooms if the "Corrupted Data" achievement is unlocked.
143
143
  */
144
144
  export declare function isGlitchedCollectible(pickup: EntityPickup): boolean;
145
+ /**
146
+ * Returns true if the collectible has the "Hidden" attribute in the item config.
147
+ *
148
+ * Hidden collectibles will not show up in any pools and Eden will not start with them.
149
+ */
150
+ export declare function isHiddenCollectible(collectibleType: CollectibleType): boolean;
145
151
  /**
146
152
  * Returns true if the item type in the item config is equal to `ItemType.ITEM_PASSIVE` or
147
153
  * `ItemType.ITEM_FAMILIAR`.
@@ -216,6 +216,10 @@ end
216
216
  function ____exports.isGlitchedCollectible(self, pickup)
217
217
  return pickup.Variant == PickupVariant.COLLECTIBLE and pickup.SubType > GLITCHED_ITEM_THRESHOLD
218
218
  end
219
+ function ____exports.isHiddenCollectible(self, collectibleType)
220
+ local itemConfigItem = itemConfig:GetCollectible(collectibleType)
221
+ return itemConfigItem ~= nil and itemConfigItem.Hidden
222
+ end
219
223
  function ____exports.isPassiveCollectible(self, collectibleType)
220
224
  local itemType = ____exports.getCollectibleItemType(nil, collectibleType)
221
225
  return itemType == ItemType.PASSIVE or itemType == ItemType.FAMILIAR
@@ -0,0 +1,3 @@
1
+ import { CollectibleType } from "isaac-typescript-definitions";
2
+ export declare function getEdenPassives(): Set<CollectibleType>;
3
+ export declare function getRandomEdenPassive(seedOrRNG?: Seed | RNG, exceptions?: CollectibleType[] | readonly CollectibleType[]): CollectibleType;
@@ -0,0 +1,47 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Set = ____lualib.Set
3
+ local __TS__New = ____lualib.__TS__New
4
+ local __TS__Iterator = ____lualib.__TS__Iterator
5
+ local ____exports = {}
6
+ local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
7
+ local ItemConfigTag = ____isaac_2Dtypescript_2Ddefinitions.ItemConfigTag
8
+ local ____collectibles = require("functions.collectibles")
9
+ local isHiddenCollectible = ____collectibles.isHiddenCollectible
10
+ local isPassiveCollectible = ____collectibles.isPassiveCollectible
11
+ local ____collectibleSet = require("functions.collectibleSet")
12
+ local getCollectibleSet = ____collectibleSet.getCollectibleSet
13
+ local ____collectibleTag = require("functions.collectibleTag")
14
+ local collectibleHasTag = ____collectibleTag.collectibleHasTag
15
+ local ____rng = require("functions.rng")
16
+ local getRandomSeed = ____rng.getRandomSeed
17
+ local ____set = require("functions.set")
18
+ local copySet = ____set.copySet
19
+ local getRandomSetElement = ____set.getRandomSetElement
20
+ local EDEN_PASSIVE_COLLECTIBLES_SET = __TS__New(Set)
21
+ local function initCollectibleSet(self)
22
+ local collectibleSet = getCollectibleSet(nil)
23
+ for ____, collectibleType in __TS__Iterator(collectibleSet:values()) do
24
+ if isPassiveCollectible(nil, collectibleType) and not isHiddenCollectible(nil, collectibleType) and not collectibleHasTag(nil, collectibleType, ItemConfigTag.NO_EDEN) then
25
+ EDEN_PASSIVE_COLLECTIBLES_SET:add(collectibleType)
26
+ end
27
+ end
28
+ end
29
+ function ____exports.getEdenPassives(self)
30
+ if EDEN_PASSIVE_COLLECTIBLES_SET.size == 0 then
31
+ initCollectibleSet(nil)
32
+ end
33
+ return copySet(nil, EDEN_PASSIVE_COLLECTIBLES_SET)
34
+ end
35
+ function ____exports.getRandomEdenPassive(self, seedOrRNG, exceptions)
36
+ if seedOrRNG == nil then
37
+ seedOrRNG = getRandomSeed(nil)
38
+ end
39
+ if exceptions == nil then
40
+ exceptions = {}
41
+ end
42
+ if EDEN_PASSIVE_COLLECTIBLES_SET.size == 0 then
43
+ initCollectibleSet(nil)
44
+ end
45
+ return getRandomSetElement(nil, EDEN_PASSIVE_COLLECTIBLES_SET, seedOrRNG, exceptions)
46
+ end
47
+ return ____exports
@@ -25,11 +25,8 @@ local DEFAULT_PILL_EFFECT_TYPE = ____pillEffectTypes.DEFAULT_PILL_EFFECT_TYPE
25
25
  local PILL_EFFECT_TYPES = ____pillEffectTypes.PILL_EFFECT_TYPES
26
26
  local ____enums = require("functions.enums")
27
27
  local getEnumValues = ____enums.getEnumValues
28
- local ____flag = require("functions.flag")
29
- local hasFlag = ____flag.hasFlag
30
28
  local ____utils = require("functions.utils")
31
29
  local irange = ____utils.irange
32
- local HORSE_PILL_FLAG = 2047
33
30
  local HORSE_PILL_ADJUSTMENT = 2048
34
31
  function ____exports.getAllPillColors(self)
35
32
  local pillColors = getEnumValues(nil, PillColor)
@@ -81,6 +78,6 @@ function ____exports.getVanillaPillEffects(self)
81
78
  return irange(nil, FIRST_PILL_EFFECT, LAST_VANILLA_PILL_EFFECT)
82
79
  end
83
80
  function ____exports.isHorsePill(self, pillColor)
84
- return hasFlag(nil, pillColor, HORSE_PILL_FLAG)
81
+ return pillColor > HORSE_PILL_ADJUSTMENT
85
82
  end
86
83
  return ____exports
@@ -28,7 +28,6 @@ local ____sprite = require("functions.sprite")
28
28
  local clearSprite = ____sprite.clearSprite
29
29
  local ____utils = require("functions.utils")
30
30
  local irange = ____utils.irange
31
- local GOLDEN_TRINKET_FLAG = 32767
32
31
  local GOLDEN_TRINKET_ADJUSTMENT = 32768
33
32
  local TRINKET_SPRITE_LAYER = 0
34
33
  function ____exports.getGoldenTrinketType(self, trinketType)
@@ -91,7 +90,7 @@ function ____exports.hasOpenTrinketSlot(self, player)
91
90
  return openTrinketSlot ~= nil
92
91
  end
93
92
  function ____exports.isGoldenTrinket(self, trinketType)
94
- return hasFlag(nil, trinketType, GOLDEN_TRINKET_FLAG)
93
+ return trinketType > GOLDEN_TRINKET_ADJUSTMENT
95
94
  end
96
95
  function ____exports.setTrinketSprite(self, trinket, pngPath)
97
96
  if not isTrinket(nil, trinket) then
package/dist/index.d.ts CHANGED
@@ -48,6 +48,7 @@ export { deepCopyTests } from "./functions/deepCopyTests";
48
48
  export * from "./functions/direction";
49
49
  export * from "./functions/doors";
50
50
  export * from "./functions/easing";
51
+ export * from "./functions/eden";
51
52
  export * from "./functions/entity";
52
53
  export * from "./functions/entitySpecific";
53
54
  export * from "./functions/entityTypes";
package/dist/index.lua CHANGED
@@ -397,6 +397,14 @@ do
397
397
  end
398
398
  end
399
399
  end
400
+ do
401
+ local ____export = require("functions.eden")
402
+ for ____exportKey, ____exportValue in pairs(____export) do
403
+ if ____exportKey ~= "default" then
404
+ ____exports[____exportKey] = ____exportValue
405
+ end
406
+ end
407
+ end
400
408
  do
401
409
  local ____export = require("functions.entity")
402
410
  for ____exportKey, ____exportValue in pairs(____export) do
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "2.0.29",
3
+ "version": "2.0.32",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,7 +25,7 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "dependencies": {
28
- "isaac-typescript-definitions": "^2.0.46"
28
+ "isaac-typescript-definitions": "^2.0.48"
29
29
  },
30
30
  "devDependencies": {
31
31
  "isaacscript-lint": "^1.0.159",