isaacscript-common 2.0.28 → 2.0.31
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/dist/callbacks/subscriptions/postPickupCollect.d.ts +4 -5
- package/dist/callbacks/subscriptions/postPickupInitLate.d.ts +3 -5
- package/dist/callbacks/subscriptions/postPickupStateChanged.d.ts +5 -5
- package/dist/classes/DefaultMap.d.ts +8 -8
- package/dist/enums/private/SaveDataKey.d.ts +7 -0
- package/dist/enums/private/SaveDataKey.lua +11 -0
- package/dist/features/saveDataManager/exports.d.ts +21 -0
- package/dist/features/saveDataManager/exports.lua +13 -0
- package/dist/features/saveDataManager/main.d.ts +3 -1
- package/dist/features/saveDataManager/main.lua +31 -30
- package/package.json +2 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare type PostPickupCollectRegisterParameters = [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
];
|
|
1
|
+
/// <reference types="isaac-typescript-definitions" />
|
|
2
|
+
export declare type PostPickupCollectRegisterParameters = PickupRegisterParameters<[
|
|
3
|
+
player: EntityPlayer
|
|
4
|
+
], void>;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export declare type PostPickupInitLateRegisterParameters = [
|
|
3
|
-
|
|
4
|
-
pickupVariant?: PickupVariant
|
|
5
|
-
];
|
|
1
|
+
/// <reference types="isaac-typescript-definitions" />
|
|
2
|
+
export declare type PostPickupInitLateRegisterParameters = PickupRegisterParameters<[
|
|
3
|
+
], void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export declare type PostPickupStateChangedRegisterParameters = [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
]
|
|
1
|
+
/// <reference types="isaac-typescript-definitions" />
|
|
2
|
+
export declare type PostPickupStateChangedRegisterParameters = PickupRegisterParameters<[
|
|
3
|
+
previousState: int,
|
|
4
|
+
currentState: int
|
|
5
|
+
], void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
declare type FactoryFunction<V,
|
|
2
|
-
declare type FirstArg<K, V,
|
|
3
|
-
declare type SecondArg<V,
|
|
1
|
+
declare type FactoryFunction<V, Args extends unknown[]> = (...extraArgs: Args) => V;
|
|
2
|
+
declare type FirstArg<K, V, Args extends unknown[]> = Iterable<[K, V]> | V | FactoryFunction<V, Args>;
|
|
3
|
+
declare type SecondArg<V, Args extends unknown[]> = V | FactoryFunction<V, Args>;
|
|
4
4
|
/**
|
|
5
5
|
* An extended Map with some new methods:
|
|
6
6
|
*
|
|
@@ -48,28 +48,28 @@ declare type SecondArg<V, A extends unknown[]> = V | FactoryFunction<V, A>;
|
|
|
48
48
|
* const defaultMapWithExtraArgs = new DefaultMap<string, string, [arg: boolean]>(factoryFunction);
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
|
-
export declare class DefaultMap<K, V,
|
|
51
|
+
export declare class DefaultMap<K, V, Args extends unknown[] = []> extends Map<K, V> {
|
|
52
52
|
private defaultValue;
|
|
53
53
|
private defaultValueFactory;
|
|
54
54
|
/**
|
|
55
55
|
* See the DefaultMap documentation:
|
|
56
56
|
* https://isaacscript.github.io/isaacscript-common/classes/types_DefaultMap.DefaultMap.html
|
|
57
57
|
*/
|
|
58
|
-
constructor(iterableOrDefaultValueOrDefaultValueFactory: FirstArg<K, V,
|
|
58
|
+
constructor(iterableOrDefaultValueOrDefaultValueFactory: FirstArg<K, V, Args>, defaultValueOrDefaultValueFactory?: SecondArg<V, Args>);
|
|
59
59
|
/**
|
|
60
60
|
* If the key exists, this will return the same thing as the `get` method. Otherwise, it will set
|
|
61
61
|
* a default value to the key, and then return the default value.
|
|
62
62
|
*/
|
|
63
|
-
getAndSetDefault(key: K, ...extraArgs:
|
|
63
|
+
getAndSetDefault(key: K, ...extraArgs: Args): V;
|
|
64
64
|
/**
|
|
65
65
|
* Returns the default value to be used for a new key. (If a factory function was provided during
|
|
66
66
|
* instantiation, this will execute the factory function.)
|
|
67
67
|
*/
|
|
68
|
-
getDefaultValue(...extraArgs:
|
|
68
|
+
getDefaultValue(...extraArgs: Args): V;
|
|
69
69
|
/**
|
|
70
70
|
* Helper method for cloning the map. Returns either the default value or a reference to the
|
|
71
71
|
* factory function.
|
|
72
72
|
*/
|
|
73
|
-
getConstructorArg(): V | FactoryFunction<V,
|
|
73
|
+
getConstructorArg(): V | FactoryFunction<V, Args>;
|
|
74
74
|
}
|
|
75
75
|
export {};
|
|
@@ -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
|
|
@@ -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
|
|
12
|
-
local
|
|
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,
|
|
56
|
+
restoreDefaults(nil, SaveDataKey.LEVEL)
|
|
56
57
|
end
|
|
57
58
|
function postNewRoomEarly(self)
|
|
58
|
-
restoreDefaults(nil,
|
|
59
|
+
restoreDefaults(nil, SaveDataKey.ROOM)
|
|
59
60
|
end
|
|
60
61
|
function restoreDefaultsAll(self)
|
|
61
|
-
restoreDefaults(nil,
|
|
62
|
-
restoreDefaults(nil,
|
|
63
|
-
restoreDefaults(nil,
|
|
62
|
+
restoreDefaults(nil, SaveDataKey.RUN)
|
|
63
|
+
restoreDefaults(nil, SaveDataKey.LEVEL)
|
|
64
|
+
restoreDefaults(nil, SaveDataKey.ROOM)
|
|
64
65
|
end
|
|
65
|
-
function restoreDefaults(self,
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.31",
|
|
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.
|
|
28
|
+
"isaac-typescript-definitions": "^2.0.48"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"isaacscript-lint": "^1.0.159",
|