isaacscript-common 30.12.8 → 30.12.10
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/index.rollup.d.ts +36 -27
- package/dist/isaacscript-common.lua +11 -1
- package/dist/src/classes/ModFeature.d.ts +12 -14
- package/dist/src/classes/ModFeature.d.ts.map +1 -1
- package/dist/src/classes/ModFeature.lua +12 -14
- package/dist/src/classes/features/other/SaveDataManager.d.ts +8 -10
- package/dist/src/classes/features/other/SaveDataManager.d.ts.map +1 -1
- package/dist/src/functions/array.d.ts +12 -0
- package/dist/src/functions/array.d.ts.map +1 -1
- package/dist/src/functions/array.lua +19 -0
- package/dist/src/functions/modFeatures.d.ts +3 -3
- package/dist/src/functions/modFeatures.lua +3 -3
- package/package.json +2 -2
- package/src/classes/ModFeature.ts +12 -15
- package/src/classes/features/other/SaveDataManager.ts +8 -10
- package/src/functions/array.ts +27 -0
- package/src/functions/modFeatures.ts +3 -3
package/dist/index.rollup.d.ts
CHANGED
|
@@ -4199,6 +4199,19 @@ export declare function fillLevelWithRedRooms(): void;
|
|
|
4199
4199
|
*/
|
|
4200
4200
|
export declare function filter<T>(array: T[], func: (value: T, index: number, array: T[]) => boolean): T[];
|
|
4201
4201
|
|
|
4202
|
+
/**
|
|
4203
|
+
* Helper function to perform a map and a filter at the same time. Similar to `Array.map`, provide a
|
|
4204
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
4205
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
4206
|
+
*
|
|
4207
|
+
* This function is useful because a map will always produce an array with the same amount of
|
|
4208
|
+
* elements as the original array.
|
|
4209
|
+
*
|
|
4210
|
+
* This is named `filterMap` after the Rust function:
|
|
4211
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
4212
|
+
*/
|
|
4213
|
+
export declare function filterMap<OldT, NewT>(array: OldT[], func: (element: OldT) => NewT | undefined): NewT[];
|
|
4214
|
+
|
|
4202
4215
|
/**
|
|
4203
4216
|
* Helper function for non-TypeScript users to find an element in an array.
|
|
4204
4217
|
*
|
|
@@ -7566,16 +7579,16 @@ export declare function inHomeCloset(): boolean;
|
|
|
7566
7579
|
* For example:
|
|
7567
7580
|
*
|
|
7568
7581
|
* ```ts
|
|
7569
|
-
* const
|
|
7582
|
+
* const MOD_FEATURES = [
|
|
7570
7583
|
* MyFeature1,
|
|
7571
7584
|
* MyFeature2,
|
|
7572
7585
|
* MyFeature3,
|
|
7573
7586
|
* ] as const;
|
|
7574
|
-
* initModFeatures(mod,
|
|
7587
|
+
* initModFeatures(mod, MOD_FEATURES);
|
|
7575
7588
|
* ```
|
|
7576
7589
|
*
|
|
7577
7590
|
* @returns An array of the instantiated features in the same order that the constructors were
|
|
7578
|
-
* passed in.
|
|
7591
|
+
* passed in. (In most cases, you probably won't need the returned array.)
|
|
7579
7592
|
*/
|
|
7580
7593
|
export declare function initModFeatures<T extends ReadonlyArray<typeof ModFeature>>(mod: ModUpgraded, modFeatures: T): {
|
|
7581
7594
|
[K in keyof T]: InstanceType<T[K]>;
|
|
@@ -12798,24 +12811,22 @@ declare class ModdedElementSets extends Feature {
|
|
|
12798
12811
|
* mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
|
|
12799
12812
|
* that automatically subscribe to callbacks.
|
|
12800
12813
|
*
|
|
12801
|
-
*
|
|
12802
|
-
*
|
|
12814
|
+
* It is recommended that you use the `initModFeatures` helper function to instantiate all of your
|
|
12815
|
+
* mod classes (instead of instantiating them yourself). This is so that any attached `v` objects
|
|
12816
|
+
* are properly registered with the save data manager; see below.
|
|
12803
12817
|
*
|
|
12804
|
-
* If
|
|
12805
|
-
* register them with the save data manager yourself in your class constructor. (It can't be
|
|
12806
|
-
* automatically done because parent classes don't have access to child class properties.)
|
|
12818
|
+
* If you are manually instantiating a mod feature yourself, then:
|
|
12807
12819
|
*
|
|
12808
|
-
*
|
|
12809
|
-
*
|
|
12810
|
-
*
|
|
12820
|
+
* - You must pass your upgraded mod as the first argument to the constructor.
|
|
12821
|
+
* - In almost all cases, you will want the callback functions to be immediately subscribed after
|
|
12822
|
+
* instantiating the class. However, if this is not the case, you can pass `false` as the optional
|
|
12823
|
+
* second argument to the constructor.
|
|
12811
12824
|
*
|
|
12812
12825
|
* If your mod feature has a property called `v`, it will be assumed that these are variables that
|
|
12813
|
-
* should be managed by the save data manager.
|
|
12814
|
-
*
|
|
12815
|
-
*
|
|
12816
|
-
*
|
|
12817
|
-
* class is constructed. (This is because the parent class does not have access to the child's
|
|
12818
|
-
* properties upon first construction.)
|
|
12826
|
+
* should be managed by the save data manager. Unfortunately, due to technical limitations with
|
|
12827
|
+
* classes, this registration will only occur if you initialize the class with the `initModFeatures`
|
|
12828
|
+
* helper function. (This is because the parent class does not have access to the child's properties
|
|
12829
|
+
* upon first construction.)
|
|
12819
12830
|
*/
|
|
12820
12831
|
export declare class ModFeature {
|
|
12821
12832
|
private readonly mod;
|
|
@@ -15169,21 +15180,20 @@ declare class SaveDataManager extends Feature {
|
|
|
15169
15180
|
* desired).
|
|
15170
15181
|
* 2. Automatic saving and loading of all tracked data to the "save#.dat" file.
|
|
15171
15182
|
*
|
|
15172
|
-
* You
|
|
15173
|
-
* manage them for you. (See below for an example.)
|
|
15183
|
+
* You provide this function with an object containing your variables, and then it will
|
|
15184
|
+
* automatically manage them for you. (See below for an example.)
|
|
15174
15185
|
*
|
|
15175
15186
|
* In order to use this function, you must upgrade your mod with `ISCFeature.SAVE_DATA_MANAGER`.
|
|
15176
15187
|
* (Upgrade your mod before registering any of your own callbacks so that the save data manager
|
|
15177
15188
|
* will run before any of your code does.)
|
|
15178
15189
|
*
|
|
15179
15190
|
* The save data manager is meant to be called once for each feature of your mod. In other words,
|
|
15180
|
-
* you should not put all of the
|
|
15191
|
+
* you should not put all of the variables for your mod on the same object. Instead, scope your
|
|
15181
15192
|
* variables locally to a single file that contains a mod feature, and then call this function to
|
|
15182
15193
|
* register them. For example:
|
|
15183
15194
|
*
|
|
15184
15195
|
* ```ts
|
|
15185
15196
|
* // In file: feature1.ts
|
|
15186
|
-
* import { saveDataManager } from "isaacscript-common";
|
|
15187
15197
|
*
|
|
15188
15198
|
* // Declare local variables for this file or feature.
|
|
15189
15199
|
* const v = {
|
|
@@ -15207,13 +15217,12 @@ declare class SaveDataManager extends Feature {
|
|
|
15207
15217
|
* foo4: 0,
|
|
15208
15218
|
* },
|
|
15209
15219
|
* };
|
|
15210
|
-
* //
|
|
15220
|
+
* // The child objects of "persistent", "run", "level", and "room are optional; only create the
|
|
15221
|
+
* // ones that you need.
|
|
15211
15222
|
*
|
|
15212
|
-
* //
|
|
15213
|
-
* //
|
|
15214
|
-
*
|
|
15215
|
-
* saveDataManager("feature1", v);
|
|
15216
|
-
* }
|
|
15223
|
+
* // Now, give `v` to the save data manager, and it will automatically manage the variables for
|
|
15224
|
+
* // you.
|
|
15225
|
+
* mod.saveDataManager("feature1", v);
|
|
15217
15226
|
*
|
|
15218
15227
|
* // Elsewhere in the file, use your variables.
|
|
15219
15228
|
* function feature1Function() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
--[[
|
|
2
2
|
|
|
3
|
-
isaacscript-common 30.12.
|
|
3
|
+
isaacscript-common 30.12.10
|
|
4
4
|
|
|
5
5
|
This is the "isaacscript-common" library, which was created with the IsaacScript tool.
|
|
6
6
|
|
|
@@ -16854,6 +16854,16 @@ end
|
|
|
16854
16854
|
function ____exports.emptyArray(self, array)
|
|
16855
16855
|
__TS__ArraySplice(array, 0, #array)
|
|
16856
16856
|
end
|
|
16857
|
+
function ____exports.filterMap(self, array, func)
|
|
16858
|
+
local newArray = {}
|
|
16859
|
+
for ____, element in ipairs(array) do
|
|
16860
|
+
local newElement = func(nil, element)
|
|
16861
|
+
if newElement ~= nil then
|
|
16862
|
+
newArray[#newArray + 1] = newElement
|
|
16863
|
+
end
|
|
16864
|
+
end
|
|
16865
|
+
return newArray
|
|
16866
|
+
end
|
|
16857
16867
|
function ____exports.getArrayCombinations(self, array, includeEmptyArray, min, max)
|
|
16858
16868
|
if min == nil or min <= 0 then
|
|
16859
16869
|
min = 1
|
|
@@ -8,24 +8,22 @@ export declare const MOD_FEATURE_CUSTOM_CALLBACKS_KEY = "__customCallbacks";
|
|
|
8
8
|
* mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
|
|
9
9
|
* that automatically subscribe to callbacks.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* It is recommended that you use the `initModFeatures` helper function to instantiate all of your
|
|
12
|
+
* mod classes (instead of instantiating them yourself). This is so that any attached `v` objects
|
|
13
|
+
* are properly registered with the save data manager; see below.
|
|
13
14
|
*
|
|
14
|
-
* If
|
|
15
|
-
* register them with the save data manager yourself in your class constructor. (It can't be
|
|
16
|
-
* automatically done because parent classes don't have access to child class properties.)
|
|
15
|
+
* If you are manually instantiating a mod feature yourself, then:
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* - You must pass your upgraded mod as the first argument to the constructor.
|
|
18
|
+
* - In almost all cases, you will want the callback functions to be immediately subscribed after
|
|
19
|
+
* instantiating the class. However, if this is not the case, you can pass `false` as the optional
|
|
20
|
+
* second argument to the constructor.
|
|
21
21
|
*
|
|
22
22
|
* If your mod feature has a property called `v`, it will be assumed that these are variables that
|
|
23
|
-
* should be managed by the save data manager.
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* class is constructed. (This is because the parent class does not have access to the child's
|
|
28
|
-
* properties upon first construction.)
|
|
23
|
+
* should be managed by the save data manager. Unfortunately, due to technical limitations with
|
|
24
|
+
* classes, this registration will only occur if you initialize the class with the `initModFeatures`
|
|
25
|
+
* helper function. (This is because the parent class does not have access to the child's properties
|
|
26
|
+
* upon first construction.)
|
|
29
27
|
*/
|
|
30
28
|
export declare class ModFeature {
|
|
31
29
|
private readonly mod;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AASpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AACvD,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAyBpE
|
|
1
|
+
{"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AASpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AACvD,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAyBpE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAElC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,SAAS,CAAC,yBAAyB,EAC/B,CAAC,CAAC,CAAC,SAAS,OAAO,EACjB,OAAO,EAAE,CAAC,EACV,WAAW,EAAE,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,iBAAiB,EAC7D,GAAG,YAAY,EAAE,OAAO,EAAE,KACvB,OAAO,CAAC,GACb,IAAI,CAAQ;IAEhB;;;;;OAKG;IACI,WAAW,UAAS;gBAEf,GAAG,EAAE,WAAW,EAAE,IAAI,UAAO;IAQzC;;;;;OAKG;IACI,IAAI,CAAC,IAAI,UAAO,GAAG,IAAI;IAqB9B;;;;;OAKG;IACI,MAAM,IAAI,IAAI;CAGtB"}
|
|
@@ -163,24 +163,22 @@ WRAPPED_CUSTOM_CALLBACK_METHODS_KEY = "__wrappedCustomCallbacksMethods"
|
|
|
163
163
|
-- mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
|
|
164
164
|
-- that automatically subscribe to callbacks.
|
|
165
165
|
--
|
|
166
|
-
--
|
|
167
|
-
--
|
|
166
|
+
-- It is recommended that you use the `initModFeatures` helper function to instantiate all of your
|
|
167
|
+
-- mod classes (instead of instantiating them yourself). This is so that any attached `v` objects
|
|
168
|
+
-- are properly registered with the save data manager; see below.
|
|
168
169
|
--
|
|
169
|
-
-- If
|
|
170
|
-
-- register them with the save data manager yourself in your class constructor. (It can't be
|
|
171
|
-
-- automatically done because parent classes don't have access to child class properties.)
|
|
170
|
+
-- If you are manually instantiating a mod feature yourself, then:
|
|
172
171
|
--
|
|
173
|
-
--
|
|
174
|
-
--
|
|
175
|
-
--
|
|
172
|
+
-- - You must pass your upgraded mod as the first argument to the constructor.
|
|
173
|
+
-- - In almost all cases, you will want the callback functions to be immediately subscribed after
|
|
174
|
+
-- instantiating the class. However, if this is not the case, you can pass `false` as the optional
|
|
175
|
+
-- second argument to the constructor.
|
|
176
176
|
--
|
|
177
177
|
-- If your mod feature has a property called `v`, it will be assumed that these are variables that
|
|
178
|
-
-- should be managed by the save data manager.
|
|
179
|
-
--
|
|
180
|
-
--
|
|
181
|
-
--
|
|
182
|
-
-- class is constructed. (This is because the parent class does not have access to the child's
|
|
183
|
-
-- properties upon first construction.)
|
|
178
|
+
-- should be managed by the save data manager. Unfortunately, due to technical limitations with
|
|
179
|
+
-- classes, this registration will only occur if you initialize the class with the `initModFeatures`
|
|
180
|
+
-- helper function. (This is because the parent class does not have access to the child's properties
|
|
181
|
+
-- upon first construction.)
|
|
184
182
|
____exports.ModFeature = __TS__Class()
|
|
185
183
|
local ModFeature = ____exports.ModFeature
|
|
186
184
|
ModFeature.name = "ModFeature"
|
|
@@ -51,21 +51,20 @@ export declare class SaveDataManager extends Feature {
|
|
|
51
51
|
* desired).
|
|
52
52
|
* 2. Automatic saving and loading of all tracked data to the "save#.dat" file.
|
|
53
53
|
*
|
|
54
|
-
* You
|
|
55
|
-
* manage them for you. (See below for an example.)
|
|
54
|
+
* You provide this function with an object containing your variables, and then it will
|
|
55
|
+
* automatically manage them for you. (See below for an example.)
|
|
56
56
|
*
|
|
57
57
|
* In order to use this function, you must upgrade your mod with `ISCFeature.SAVE_DATA_MANAGER`.
|
|
58
58
|
* (Upgrade your mod before registering any of your own callbacks so that the save data manager
|
|
59
59
|
* will run before any of your code does.)
|
|
60
60
|
*
|
|
61
61
|
* The save data manager is meant to be called once for each feature of your mod. In other words,
|
|
62
|
-
* you should not put all of the
|
|
62
|
+
* you should not put all of the variables for your mod on the same object. Instead, scope your
|
|
63
63
|
* variables locally to a single file that contains a mod feature, and then call this function to
|
|
64
64
|
* register them. For example:
|
|
65
65
|
*
|
|
66
66
|
* ```ts
|
|
67
67
|
* // In file: feature1.ts
|
|
68
|
-
* import { saveDataManager } from "isaacscript-common";
|
|
69
68
|
*
|
|
70
69
|
* // Declare local variables for this file or feature.
|
|
71
70
|
* const v = {
|
|
@@ -89,13 +88,12 @@ export declare class SaveDataManager extends Feature {
|
|
|
89
88
|
* foo4: 0,
|
|
90
89
|
* },
|
|
91
90
|
* };
|
|
92
|
-
* //
|
|
91
|
+
* // The child objects of "persistent", "run", "level", and "room are optional; only create the
|
|
92
|
+
* // ones that you need.
|
|
93
93
|
*
|
|
94
|
-
* //
|
|
95
|
-
* //
|
|
96
|
-
*
|
|
97
|
-
* saveDataManager("feature1", v);
|
|
98
|
-
* }
|
|
94
|
+
* // Now, give `v` to the save data manager, and it will automatically manage the variables for
|
|
95
|
+
* // you.
|
|
96
|
+
* mod.saveDataManager("feature1", v);
|
|
99
97
|
*
|
|
100
98
|
* // Elsewhere in the file, use your variables.
|
|
101
99
|
* function feature1Function() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SaveDataManager.d.ts","sourceRoot":"","sources":["../../../../../src/classes/features/other/SaveDataManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAOzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAsBhD,qBAAa,eAAgB,SAAQ,OAAO;IAC1C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAM;IAE1B;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAE9D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAkC;IAEtE;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAGvC;IAEJ;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAkC;IAE9E;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAkC;IAGpE,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,qCAAqC,CAAS;IAmCtD,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAU1C;IAGF,OAAO,CAAC,QAAQ,CAAC,cAAc,CA0B7B;IAGF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAa1B;IAGF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAY3B;IAGF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAuB/B;IAEF
|
|
1
|
+
{"version":3,"file":"SaveDataManager.d.ts","sourceRoot":"","sources":["../../../../../src/classes/features/other/SaveDataManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAOzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EA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OAAO,CAAC,gCAAgC;IAgBxC;;;;;;;;;OASG;IAEI,mBAAmB,IAAI,IAAI;IAIlC;;;;;;OAMG;IAEI,mBAAmB,IAAI,IAAI;IAIlC;;;;;;;OAOG;IAEI,wBAAwB,IAAI,IAAI;IAIvC;;;;;;;;;;;OAWG;IAEI,4BAA4B,CAAC,GAAG,WAAW,EAAE,QAAQ,EAAE,GAAG,IAAI;IAcrE;;;;;OAKG;IAEI,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAoB/C;;;;;;;;;;;;;;;;;;;;;OAqBG;IAEI,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,WAAW,GAAG,IAAI;IAsB3E;;;;;;;;;;;;OAYG;IAEI,qBAAqB,IAAI,OAAO;IAKhC,6BAA6B,IAAI,IAAI;CAQ7C"}
|
|
@@ -93,6 +93,18 @@ export declare function combineArrays<T>(...arrays: Array<T[] | readonly T[]>):
|
|
|
93
93
|
export declare function copyArray<T>(oldArray: T[] | readonly T[], numElements?: int): T[];
|
|
94
94
|
/** Helper function to remove all of the elements in an array in-place. */
|
|
95
95
|
export declare function emptyArray<T>(array: T[]): void;
|
|
96
|
+
/**
|
|
97
|
+
* Helper function to perform a map and a filter at the same time. Similar to `Array.map`, provide a
|
|
98
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
99
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
100
|
+
*
|
|
101
|
+
* This function is useful because a map will always produce an array with the same amount of
|
|
102
|
+
* elements as the original array.
|
|
103
|
+
*
|
|
104
|
+
* This is named `filterMap` after the Rust function:
|
|
105
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
106
|
+
*/
|
|
107
|
+
export declare function filterMap<OldT, NewT>(array: OldT[], func: (element: OldT) => NewT | undefined): NewT[];
|
|
96
108
|
/**
|
|
97
109
|
* Helper function to get all possible combinations of the given array. This includes the
|
|
98
110
|
* combination of an empty array.
|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AG,GAAqB,GACtC,IAAI,CAWN;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,GAAG,MAAM,CAEpE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAM3E"}
|
|
@@ -290,6 +290,25 @@ end
|
|
|
290
290
|
function ____exports.emptyArray(self, array)
|
|
291
291
|
__TS__ArraySplice(array, 0, #array)
|
|
292
292
|
end
|
|
293
|
+
--- Helper function to perform a map and a filter at the same time. Similar to `Array.map`, provide a
|
|
294
|
+
-- function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
295
|
+
-- this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
296
|
+
--
|
|
297
|
+
-- This function is useful because a map will always produce an array with the same amount of
|
|
298
|
+
-- elements as the original array.
|
|
299
|
+
--
|
|
300
|
+
-- This is named `filterMap` after the Rust function:
|
|
301
|
+
-- https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
302
|
+
function ____exports.filterMap(self, array, func)
|
|
303
|
+
local newArray = {}
|
|
304
|
+
for ____, element in ipairs(array) do
|
|
305
|
+
local newElement = func(nil, element)
|
|
306
|
+
if newElement ~= nil then
|
|
307
|
+
newArray[#newArray + 1] = newElement
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
return newArray
|
|
311
|
+
end
|
|
293
312
|
--- Helper function to get all possible combinations of the given array. This includes the
|
|
294
313
|
-- combination of an empty array.
|
|
295
314
|
--
|
|
@@ -10,16 +10,16 @@ import type { ModUpgraded } from "../classes/ModUpgraded";
|
|
|
10
10
|
* For example:
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
|
-
* const
|
|
13
|
+
* const MOD_FEATURES = [
|
|
14
14
|
* MyFeature1,
|
|
15
15
|
* MyFeature2,
|
|
16
16
|
* MyFeature3,
|
|
17
17
|
* ] as const;
|
|
18
|
-
* initModFeatures(mod,
|
|
18
|
+
* initModFeatures(mod, MOD_FEATURES);
|
|
19
19
|
* ```
|
|
20
20
|
*
|
|
21
21
|
* @returns An array of the instantiated features in the same order that the constructors were
|
|
22
|
-
* passed in.
|
|
22
|
+
* passed in. (In most cases, you probably won't need the returned array.)
|
|
23
23
|
*/
|
|
24
24
|
export declare function initModFeatures<T extends ReadonlyArray<typeof ModFeature>>(mod: ModUpgraded, modFeatures: T): {
|
|
25
25
|
[K in keyof T]: InstanceType<T[K]>;
|
|
@@ -10,16 +10,16 @@ local ____exports = {}
|
|
|
10
10
|
-- For example:
|
|
11
11
|
--
|
|
12
12
|
-- ```ts
|
|
13
|
-
-- const
|
|
13
|
+
-- const MOD_FEATURES = [
|
|
14
14
|
-- MyFeature1,
|
|
15
15
|
-- MyFeature2,
|
|
16
16
|
-- MyFeature3,
|
|
17
17
|
-- ] as const;
|
|
18
|
-
-- initModFeatures(mod,
|
|
18
|
+
-- initModFeatures(mod, MOD_FEATURES);
|
|
19
19
|
-- ```
|
|
20
20
|
--
|
|
21
21
|
-- @returns An array of the instantiated features in the same order that the constructors were
|
|
22
|
-
-- passed in.
|
|
22
|
+
-- passed in. (In most cases, you probably won't need the returned array.)
|
|
23
23
|
function ____exports.initModFeatures(self, mod, modFeatures)
|
|
24
24
|
local instantiatedModFeatures = {}
|
|
25
25
|
for ____, modFeature in ipairs(modFeatures) do
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "30.12.
|
|
3
|
+
"version": "30.12.10",
|
|
4
4
|
"description": "Helper functions and features for IsaacScript mods.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"main": "dist/src/index",
|
|
26
26
|
"types": "dist/index.rollup.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"isaac-typescript-definitions": "^13.0.
|
|
28
|
+
"isaac-typescript-definitions": "^13.0.23"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -42,26 +42,23 @@ type ModFeatureConstructor = TSTLClassMetatable["constructor"] & {
|
|
|
42
42
|
* mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
|
|
43
43
|
* that automatically subscribe to callbacks.
|
|
44
44
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
45
|
+
* It is recommended that you use the `initModFeatures` helper function to instantiate all of your
|
|
46
|
+
* mod classes (instead of instantiating them yourself). This is so that any attached `v` objects
|
|
47
|
+
* are properly registered with the save data manager; see below.
|
|
47
48
|
*
|
|
48
|
-
* If
|
|
49
|
-
* register them with the save data manager yourself in your class constructor. (It can't be
|
|
50
|
-
* automatically done because parent classes don't have access to child class properties.)
|
|
49
|
+
* If you are manually instantiating a mod feature yourself, then:
|
|
51
50
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
51
|
+
* - You must pass your upgraded mod as the first argument to the constructor.
|
|
52
|
+
* - In almost all cases, you will want the callback functions to be immediately subscribed after
|
|
53
|
+
* instantiating the class. However, if this is not the case, you can pass `false` as the optional
|
|
54
|
+
* second argument to the constructor.
|
|
55
55
|
*
|
|
56
56
|
* If your mod feature has a property called `v`, it will be assumed that these are variables that
|
|
57
|
-
* should be managed by the save data manager.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* class is constructed. (This is because the parent class does not have access to the child's
|
|
62
|
-
* properties upon first construction.)
|
|
57
|
+
* should be managed by the save data manager. Unfortunately, due to technical limitations with
|
|
58
|
+
* classes, this registration will only occur if you initialize the class with the `initModFeatures`
|
|
59
|
+
* helper function. (This is because the parent class does not have access to the child's properties
|
|
60
|
+
* upon first construction.)
|
|
63
61
|
*/
|
|
64
|
-
|
|
65
62
|
export class ModFeature {
|
|
66
63
|
private readonly mod: ModUpgraded;
|
|
67
64
|
|
|
@@ -221,21 +221,20 @@ export class SaveDataManager extends Feature {
|
|
|
221
221
|
* desired).
|
|
222
222
|
* 2. Automatic saving and loading of all tracked data to the "save#.dat" file.
|
|
223
223
|
*
|
|
224
|
-
* You
|
|
225
|
-
* manage them for you. (See below for an example.)
|
|
224
|
+
* You provide this function with an object containing your variables, and then it will
|
|
225
|
+
* automatically manage them for you. (See below for an example.)
|
|
226
226
|
*
|
|
227
227
|
* In order to use this function, you must upgrade your mod with `ISCFeature.SAVE_DATA_MANAGER`.
|
|
228
228
|
* (Upgrade your mod before registering any of your own callbacks so that the save data manager
|
|
229
229
|
* will run before any of your code does.)
|
|
230
230
|
*
|
|
231
231
|
* The save data manager is meant to be called once for each feature of your mod. In other words,
|
|
232
|
-
* you should not put all of the
|
|
232
|
+
* you should not put all of the variables for your mod on the same object. Instead, scope your
|
|
233
233
|
* variables locally to a single file that contains a mod feature, and then call this function to
|
|
234
234
|
* register them. For example:
|
|
235
235
|
*
|
|
236
236
|
* ```ts
|
|
237
237
|
* // In file: feature1.ts
|
|
238
|
-
* import { saveDataManager } from "isaacscript-common";
|
|
239
238
|
*
|
|
240
239
|
* // Declare local variables for this file or feature.
|
|
241
240
|
* const v = {
|
|
@@ -259,13 +258,12 @@ export class SaveDataManager extends Feature {
|
|
|
259
258
|
* foo4: 0,
|
|
260
259
|
* },
|
|
261
260
|
* };
|
|
262
|
-
* //
|
|
261
|
+
* // The child objects of "persistent", "run", "level", and "room are optional; only create the
|
|
262
|
+
* // ones that you need.
|
|
263
263
|
*
|
|
264
|
-
* //
|
|
265
|
-
* //
|
|
266
|
-
*
|
|
267
|
-
* saveDataManager("feature1", v);
|
|
268
|
-
* }
|
|
264
|
+
* // Now, give `v` to the save data manager, and it will automatically manage the variables for
|
|
265
|
+
* // you.
|
|
266
|
+
* mod.saveDataManager("feature1", v);
|
|
269
267
|
*
|
|
270
268
|
* // Elsewhere in the file, use your variables.
|
|
271
269
|
* function feature1Function() {
|
package/src/functions/array.ts
CHANGED
|
@@ -232,6 +232,33 @@ export function emptyArray<T>(array: T[]): void {
|
|
|
232
232
|
array.splice(0, array.length);
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Helper function to perform a map and a filter at the same time. Similar to `Array.map`, provide a
|
|
237
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
238
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
239
|
+
*
|
|
240
|
+
* This function is useful because a map will always produce an array with the same amount of
|
|
241
|
+
* elements as the original array.
|
|
242
|
+
*
|
|
243
|
+
* This is named `filterMap` after the Rust function:
|
|
244
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
245
|
+
*/
|
|
246
|
+
export function filterMap<OldT, NewT>(
|
|
247
|
+
array: OldT[],
|
|
248
|
+
func: (element: OldT) => NewT | undefined,
|
|
249
|
+
): NewT[] {
|
|
250
|
+
const newArray: NewT[] = [];
|
|
251
|
+
|
|
252
|
+
for (const element of array) {
|
|
253
|
+
const newElement = func(element);
|
|
254
|
+
if (newElement !== undefined) {
|
|
255
|
+
newArray.push(newElement);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return newArray;
|
|
260
|
+
}
|
|
261
|
+
|
|
235
262
|
/**
|
|
236
263
|
* Helper function to get all possible combinations of the given array. This includes the
|
|
237
264
|
* combination of an empty array.
|
|
@@ -11,16 +11,16 @@ import type { ModUpgraded } from "../classes/ModUpgraded";
|
|
|
11
11
|
* For example:
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
|
-
* const
|
|
14
|
+
* const MOD_FEATURES = [
|
|
15
15
|
* MyFeature1,
|
|
16
16
|
* MyFeature2,
|
|
17
17
|
* MyFeature3,
|
|
18
18
|
* ] as const;
|
|
19
|
-
* initModFeatures(mod,
|
|
19
|
+
* initModFeatures(mod, MOD_FEATURES);
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
22
|
* @returns An array of the instantiated features in the same order that the constructors were
|
|
23
|
-
* passed in.
|
|
23
|
+
* passed in. (In most cases, you probably won't need the returned array.)
|
|
24
24
|
*/
|
|
25
25
|
export function initModFeatures<T extends ReadonlyArray<typeof ModFeature>>(
|
|
26
26
|
mod: ModUpgraded,
|