isaacscript-common 6.23.0 → 7.1.1
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/postPlayerChangeHealth.lua +8 -1
- package/dist/callbacks/postPlayerChangeStat.d.ts +3 -0
- package/dist/callbacks/postPlayerChangeStat.d.ts.map +1 -0
- package/dist/callbacks/postPlayerChangeStat.lua +88 -0
- package/dist/callbacks/subscriptions/postPlayerChangeHealth.d.ts +2 -2
- package/dist/callbacks/subscriptions/postPlayerChangeHealth.d.ts.map +1 -1
- package/dist/callbacks/subscriptions/postPlayerChangeHealth.lua +9 -2
- package/dist/callbacks/subscriptions/postPlayerChangeStat.d.ts +12 -0
- package/dist/callbacks/subscriptions/postPlayerChangeStat.d.ts.map +1 -0
- package/dist/callbacks/subscriptions/postPlayerChangeStat.lua +35 -0
- package/dist/classes/DefaultMap.d.ts +3 -3
- package/dist/classes/DefaultMap.d.ts.map +1 -1
- package/dist/classes/DefaultMap.lua +37 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.lua +1 -1
- package/dist/enums/ModCallbackCustom.d.ts +70 -39
- package/dist/enums/ModCallbackCustom.d.ts.map +1 -1
- package/dist/enums/ModCallbackCustom.lua +37 -35
- package/dist/enums/StatType.d.ts +28 -0
- package/dist/enums/StatType.d.ts.map +1 -0
- package/dist/enums/StatType.lua +28 -0
- package/dist/enums/index.d.ts +1 -0
- package/dist/enums/index.d.ts.map +1 -1
- package/dist/enums/index.lua +8 -0
- package/dist/enums/private/CopyableIsaacAPIClassType.d.ts +5 -1
- package/dist/enums/private/CopyableIsaacAPIClassType.d.ts.map +1 -1
- package/dist/enums/private/CopyableIsaacAPIClassType.lua +3 -1
- package/dist/enums/private/SerializationBrand.d.ts +1 -0
- package/dist/enums/private/SerializationBrand.d.ts.map +1 -1
- package/dist/enums/private/SerializationBrand.lua +1 -0
- package/dist/features/customStage/versusScreen.lua +2 -2
- package/dist/features/disableInputs.d.ts +1 -1
- package/dist/features/disableInputs.d.ts.map +1 -1
- package/dist/features/runInNFrames.lua +1 -6
- package/dist/features/runNextRoom.lua +1 -6
- package/dist/features/saveDataManager/exports.d.ts +1 -1
- package/dist/features/saveDataManager/exports.d.ts.map +1 -1
- package/dist/features/saveDataManager/merge.d.ts +1 -0
- package/dist/features/saveDataManager/merge.d.ts.map +1 -1
- package/dist/features/saveDataManager/merge.lua +1 -0
- package/dist/functions/bitSet128.d.ts +25 -0
- package/dist/functions/bitSet128.d.ts.map +1 -0
- package/dist/functions/bitSet128.lua +71 -0
- package/dist/functions/collectibles.d.ts +2 -2
- package/dist/functions/collectibles.lua +2 -2
- package/dist/functions/color.d.ts +1 -1
- package/dist/functions/color.d.ts.map +1 -1
- package/dist/functions/color.lua +2 -2
- package/dist/functions/deepCopy.d.ts +1 -0
- package/dist/functions/deepCopy.d.ts.map +1 -1
- package/dist/functions/deepCopy.lua +2 -1
- package/dist/functions/familiars.d.ts +4 -4
- package/dist/functions/familiars.lua +4 -4
- package/dist/functions/flag.d.ts +1 -1
- package/dist/functions/flag.lua +1 -1
- package/dist/functions/index.d.ts +2 -0
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.lua +16 -0
- package/dist/functions/jsonRoom.lua +4 -4
- package/dist/functions/kColor.d.ts +1 -1
- package/dist/functions/kColor.d.ts.map +1 -1
- package/dist/functions/kColor.lua +2 -2
- package/dist/functions/log.lua +1 -1
- package/dist/functions/npcs.d.ts +2 -2
- package/dist/functions/npcs.lua +2 -2
- package/dist/functions/playerIndex.d.ts +1 -1
- package/dist/functions/playerIndex.lua +1 -1
- package/dist/functions/playerStats.d.ts +6 -0
- package/dist/functions/playerStats.d.ts.map +1 -0
- package/dist/functions/playerStats.lua +21 -0
- package/dist/functions/players.d.ts +1 -1
- package/dist/functions/players.lua +1 -1
- package/dist/functions/rng.d.ts +1 -1
- package/dist/functions/rng.d.ts.map +1 -1
- package/dist/functions/rng.lua +2 -2
- package/dist/functions/roomTransition.d.ts +1 -1
- package/dist/functions/roomTransition.lua +1 -1
- package/dist/functions/rooms.d.ts +1 -1
- package/dist/functions/rooms.lua +1 -1
- package/dist/functions/sprites.d.ts +3 -3
- package/dist/functions/sprites.lua +3 -3
- package/dist/functions/tears.d.ts +5 -4
- package/dist/functions/tears.d.ts.map +1 -1
- package/dist/functions/tears.lua +5 -4
- package/dist/functions/utils.d.ts +4 -1
- package/dist/functions/utils.d.ts.map +1 -1
- package/dist/functions/utils.lua +4 -1
- package/dist/functions/vector.d.ts +1 -1
- package/dist/functions/vector.d.ts.map +1 -1
- package/dist/functions/vector.lua +2 -2
- package/dist/initCustomCallbacks.d.ts.map +1 -1
- package/dist/initCustomCallbacks.lua +3 -0
- package/dist/interfaces/SaveData.d.ts +17 -10
- package/dist/interfaces/SaveData.d.ts.map +1 -1
- package/dist/interfaces/SaveData.lua +66 -0
- package/dist/interfaces/StatTypeType.d.ts +17 -0
- package/dist/interfaces/StatTypeType.d.ts.map +1 -0
- package/dist/interfaces/StatTypeType.lua +4 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/private/AddCallbackParameterCustom.d.ts +2 -0
- package/dist/interfaces/private/AddCallbackParameterCustom.d.ts.map +1 -1
- package/dist/objects/callbackRegisterFunctions.d.ts.map +1 -1
- package/dist/objects/callbackRegisterFunctions.lua +3 -0
- package/dist/objects/isaacAPIClassTypeToBrand.d.ts.map +1 -1
- package/dist/objects/isaacAPIClassTypeToBrand.lua +7 -1
- package/dist/objects/isaacAPIClassTypeToFunctions.d.ts.map +1 -1
- package/dist/objects/isaacAPIClassTypeToFunctions.lua +12 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/callbacks/postPlayerChangeHealth.ts +7 -1
- package/src/callbacks/postPlayerChangeStat.ts +110 -0
- package/src/callbacks/subscriptions/postPlayerChangeHealth.ts +5 -1
- package/src/callbacks/subscriptions/postPlayerChangeStat.ts +55 -0
- package/src/classes/DefaultMap.ts +36 -7
- package/src/core/constants.ts +1 -1
- package/src/enums/ModCallbackCustom.ts +36 -4
- package/src/enums/StatType.ts +47 -0
- package/src/enums/index.ts +1 -0
- package/src/enums/indexTypeDoc.ts +1 -0
- package/src/enums/private/CopyableIsaacAPIClassType.ts +5 -1
- package/src/enums/private/SerializationBrand.ts +1 -0
- package/src/features/customStage/versusScreen.ts +2 -2
- package/src/features/disableInputs.ts +3 -9
- package/src/features/runInNFrames.ts +1 -1
- package/src/features/runNextRoom.ts +1 -1
- package/src/features/saveDataManager/exports.ts +1 -1
- package/src/features/saveDataManager/merge.ts +1 -0
- package/src/functions/bitSet128.ts +96 -0
- package/src/functions/collectibles.ts +2 -2
- package/src/functions/color.ts +3 -2
- package/src/functions/deepCopy.ts +2 -1
- package/src/functions/familiars.ts +4 -4
- package/src/functions/flag.ts +1 -1
- package/src/functions/index.ts +2 -0
- package/src/functions/indexTypeDoc.ts +2 -0
- package/src/functions/jsonRoom.ts +4 -4
- package/src/functions/kColor.ts +2 -2
- package/src/functions/log.ts +1 -1
- package/src/functions/npcs.ts +2 -2
- package/src/functions/playerIndex.ts +1 -1
- package/src/functions/playerStats.ts +25 -0
- package/src/functions/players.ts +1 -1
- package/src/functions/rng.ts +2 -2
- package/src/functions/roomTransition.ts +1 -1
- package/src/functions/rooms.ts +1 -1
- package/src/functions/sprites.ts +3 -3
- package/src/functions/tears.ts +5 -4
- package/src/functions/utils.ts +5 -1
- package/src/functions/vector.ts +2 -2
- package/src/initCustomCallbacks.ts +2 -0
- package/src/interfaces/SaveData.ts +224 -26
- package/src/interfaces/StatTypeType.ts +17 -0
- package/src/interfaces/index.ts +1 -0
- package/src/interfaces/indexTypeDoc.ts +1 -0
- package/src/interfaces/private/AddCallbackParameterCustom.ts +2 -0
- package/src/objects/callbackRegisterFunctions.ts +2 -0
- package/src/objects/isaacAPIClassTypeToBrand.ts +1 -0
- package/src/objects/isaacAPIClassTypeToFunctions.ts +12 -0
- package/src/types/index.ts +0 -1
- package/src/types/indexTypeDoc.ts +0 -1
- package/dist/types/AnyClass.d.ts +0 -2
- package/dist/types/AnyClass.d.ts.map +0 -1
- package/dist/types/AnyClass.lua +0 -2
- package/src/types/AnyClass.ts +0 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { TearFlag } from "isaac-typescript-definitions";
|
|
2
|
+
import { DefaultMap } from "../classes/DefaultMap";
|
|
3
|
+
import { ModUpgraded } from "../classes/ModUpgraded";
|
|
4
|
+
import { StatType } from "../enums";
|
|
5
|
+
import { ModCallbackCustom } from "../enums/ModCallbackCustom";
|
|
6
|
+
import { saveDataManager } from "../features/saveDataManager/exports";
|
|
7
|
+
import {
|
|
8
|
+
colorEquals,
|
|
9
|
+
getPlayerStat,
|
|
10
|
+
isBitSet128,
|
|
11
|
+
isBoolean,
|
|
12
|
+
isColor,
|
|
13
|
+
isNumber,
|
|
14
|
+
} from "../functions";
|
|
15
|
+
import { getEnumValues } from "../functions/enums";
|
|
16
|
+
import { getPlayerIndex } from "../functions/playerIndex";
|
|
17
|
+
import { PlayerIndex } from "../types/PlayerIndex";
|
|
18
|
+
import {
|
|
19
|
+
postPlayerChangeStatFire,
|
|
20
|
+
postPlayerChangeStatHasSubscriptions,
|
|
21
|
+
} from "./subscriptions/postPlayerChangeStat";
|
|
22
|
+
|
|
23
|
+
type PossibleStatType = number | boolean | BitFlags<TearFlag> | Color;
|
|
24
|
+
|
|
25
|
+
const v = {
|
|
26
|
+
run: {
|
|
27
|
+
playersStatMap: new DefaultMap<
|
|
28
|
+
PlayerIndex,
|
|
29
|
+
Map<StatType, PossibleStatType>
|
|
30
|
+
>(() => new Map()),
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function postPlayerChangeStatInit(mod: ModUpgraded): void {
|
|
35
|
+
saveDataManager("postPlayerChangeStat", v, hasSubscriptions);
|
|
36
|
+
|
|
37
|
+
mod.AddCallbackCustom(
|
|
38
|
+
ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED,
|
|
39
|
+
postPEffectUpdateReordered,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function hasSubscriptions() {
|
|
44
|
+
return postPlayerChangeStatHasSubscriptions();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED
|
|
48
|
+
function postPEffectUpdateReordered(player: EntityPlayer) {
|
|
49
|
+
if (!hasSubscriptions()) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// We call the "getPlayerIndex" function with the "differentiateForgottenAndSoul" argument. If we
|
|
54
|
+
// don't differentiate between The Forgotten and The Soul, the callback will fire every time the
|
|
55
|
+
// player switches between the two.
|
|
56
|
+
const playerIndex = getPlayerIndex(player, true);
|
|
57
|
+
const playerStatMap = v.run.playersStatMap.getAndSetDefault(playerIndex);
|
|
58
|
+
|
|
59
|
+
for (const statType of getEnumValues(StatType)) {
|
|
60
|
+
const storedStatValue = playerStatMap.get(statType);
|
|
61
|
+
const currentStatValue = getPlayerStat(player, statType);
|
|
62
|
+
playerStatMap.set(statType, currentStatValue);
|
|
63
|
+
|
|
64
|
+
if (storedStatValue === undefined) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!statEquals(storedStatValue, currentStatValue)) {
|
|
69
|
+
const isNumberStat =
|
|
70
|
+
isNumber(storedStatValue) && isNumber(currentStatValue);
|
|
71
|
+
const difference = isNumberStat ? currentStatValue - storedStatValue : 0;
|
|
72
|
+
postPlayerChangeStatFire(
|
|
73
|
+
player,
|
|
74
|
+
statType,
|
|
75
|
+
difference,
|
|
76
|
+
storedStatValue,
|
|
77
|
+
currentStatValue,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function statEquals(
|
|
84
|
+
oldValue: PossibleStatType,
|
|
85
|
+
newValue: PossibleStatType,
|
|
86
|
+
): boolean {
|
|
87
|
+
const isNumberStat = isNumber(oldValue) && isNumber(newValue);
|
|
88
|
+
if (isNumberStat) {
|
|
89
|
+
return oldValue === newValue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const isBooleanStat = isBoolean(oldValue) && isBoolean(newValue);
|
|
93
|
+
if (isBooleanStat) {
|
|
94
|
+
return oldValue === newValue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const isBitSet128Stat = isBitSet128(oldValue) && isBitSet128(newValue);
|
|
98
|
+
if (isBitSet128Stat) {
|
|
99
|
+
return oldValue === newValue; // The class has the "__eq" meta-method.
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const isColorStat = isColor(oldValue) && isColor(newValue);
|
|
103
|
+
if (isColorStat) {
|
|
104
|
+
return colorEquals(oldValue, newValue);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
error(
|
|
108
|
+
'Failed to determine the type of a stat in the "POST_PLAYER_CHANGE_STAT" callback.',
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -6,6 +6,8 @@ export type PostPlayerChangeHealthRegisterParameters = [
|
|
|
6
6
|
player: EntityPlayer,
|
|
7
7
|
healthType: HealthType,
|
|
8
8
|
difference: int,
|
|
9
|
+
oldValue: int,
|
|
10
|
+
newValue: int,
|
|
9
11
|
) => void,
|
|
10
12
|
playerVariant?: PlayerVariant,
|
|
11
13
|
character?: PlayerType,
|
|
@@ -27,6 +29,8 @@ export function postPlayerChangeHealthFire(
|
|
|
27
29
|
player: EntityPlayer,
|
|
28
30
|
healthType: HealthType,
|
|
29
31
|
difference: int,
|
|
32
|
+
oldValue: int,
|
|
33
|
+
newValue: int,
|
|
30
34
|
): void {
|
|
31
35
|
const character = player.GetPlayerType();
|
|
32
36
|
|
|
@@ -41,6 +45,6 @@ export function postPlayerChangeHealthFire(
|
|
|
41
45
|
continue;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
callback(player, healthType, difference);
|
|
48
|
+
callback(player, healthType, difference, oldValue, newValue);
|
|
45
49
|
}
|
|
46
50
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PlayerType,
|
|
3
|
+
PlayerVariant,
|
|
4
|
+
TearFlag,
|
|
5
|
+
} from "isaac-typescript-definitions";
|
|
6
|
+
import { StatType } from "../../enums/StatType";
|
|
7
|
+
import { StatTypeType } from "../../interfaces/StatTypeType";
|
|
8
|
+
|
|
9
|
+
export type PostPlayerChangeStatRegisterParameters = [
|
|
10
|
+
callback: (
|
|
11
|
+
player: EntityPlayer,
|
|
12
|
+
statType: StatType,
|
|
13
|
+
difference: int,
|
|
14
|
+
oldValue: number | boolean | BitFlags<TearFlag> | Color | Vector,
|
|
15
|
+
newValue: number | boolean | BitFlags<TearFlag> | Color | Vector,
|
|
16
|
+
) => void,
|
|
17
|
+
playerVariant?: PlayerVariant,
|
|
18
|
+
character?: PlayerType,
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const subscriptions: PostPlayerChangeStatRegisterParameters[] = [];
|
|
22
|
+
|
|
23
|
+
export function postPlayerChangeStatHasSubscriptions(): boolean {
|
|
24
|
+
return subscriptions.length > 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function postPlayerChangeStatRegister(
|
|
28
|
+
...args: PostPlayerChangeStatRegisterParameters
|
|
29
|
+
): void {
|
|
30
|
+
subscriptions.push(args);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function postPlayerChangeStatFire<T extends StatType>(
|
|
34
|
+
player: EntityPlayer,
|
|
35
|
+
statType: T,
|
|
36
|
+
difference: int,
|
|
37
|
+
oldValue: StatTypeType[T],
|
|
38
|
+
newValue: StatTypeType[T],
|
|
39
|
+
): void {
|
|
40
|
+
const character = player.GetPlayerType();
|
|
41
|
+
|
|
42
|
+
for (const [callback, playerVariant, callbackCharacter] of subscriptions) {
|
|
43
|
+
// Handle the optional 2nd callback argument.
|
|
44
|
+
if (playerVariant !== undefined && playerVariant !== player.Variant) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Handle the optional 3rd callback argument.
|
|
49
|
+
if (callbackCharacter !== undefined && callbackCharacter !== character) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
callback(player, statType, difference, oldValue, newValue);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -5,9 +5,7 @@ import { isFunction, isPrimitive } from "../functions/types";
|
|
|
5
5
|
* A function that creates the default value for your `DefaultMap`. For example, if it was a
|
|
6
6
|
* `DefaultMap` containing maps, the factory function would be: `() => new Map()`
|
|
7
7
|
*/
|
|
8
|
-
export type FactoryFunction<V, Args extends unknown[]> = (
|
|
9
|
-
...extraArgs: Args
|
|
10
|
-
) => V;
|
|
8
|
+
export type FactoryFunction<V, Args extends unknown[]> = (...args: Args) => V;
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* `DefaultMap` is a data structure that makes working with default values easier.
|
|
@@ -127,13 +125,13 @@ export class DefaultMap<Key, Value, Args extends unknown[] = []> extends Map<
|
|
|
127
125
|
* If the key exists, this will return the same thing as the normal `Map.get` method. Otherwise,
|
|
128
126
|
* it will set a default value for the provided key, and then return the default value.
|
|
129
127
|
*/
|
|
130
|
-
getAndSetDefault(key: Key, ...
|
|
128
|
+
getAndSetDefault(key: Key, ...args: Args): Value {
|
|
131
129
|
const value = super.get(key);
|
|
132
130
|
if (value !== undefined) {
|
|
133
131
|
return value;
|
|
134
132
|
}
|
|
135
133
|
|
|
136
|
-
const defaultValue = this.getDefaultValue(...
|
|
134
|
+
const defaultValue = this.getDefaultValue(...args);
|
|
137
135
|
this.set(key, defaultValue);
|
|
138
136
|
return defaultValue;
|
|
139
137
|
}
|
|
@@ -142,13 +140,13 @@ export class DefaultMap<Key, Value, Args extends unknown[] = []> extends Map<
|
|
|
142
140
|
* Returns the default value to be used for a new key. (If a factory function was provided during
|
|
143
141
|
* instantiation, this will execute the factory function.)
|
|
144
142
|
*/
|
|
145
|
-
getDefaultValue(...
|
|
143
|
+
getDefaultValue(...args: Args): Value {
|
|
146
144
|
if (this.defaultValue !== undefined) {
|
|
147
145
|
return this.defaultValue;
|
|
148
146
|
}
|
|
149
147
|
|
|
150
148
|
if (this.defaultValueFactory !== undefined) {
|
|
151
|
-
return this.defaultValueFactory(...
|
|
149
|
+
return this.defaultValueFactory(...args);
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
error("A DefaultMap was incorrectly instantiated.");
|
|
@@ -170,3 +168,34 @@ export class DefaultMap<Key, Value, Args extends unknown[] = []> extends Map<
|
|
|
170
168
|
error("A DefaultMap was incorrectly instantiated.");
|
|
171
169
|
}
|
|
172
170
|
}
|
|
171
|
+
|
|
172
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
173
|
+
function test() {
|
|
174
|
+
// Boolean
|
|
175
|
+
const myDefaultMapBoolean = new DefaultMap<string, boolean>(false);
|
|
176
|
+
const myDefaultMapBooleanFactory = new DefaultMap<string, boolean>(
|
|
177
|
+
() => false,
|
|
178
|
+
);
|
|
179
|
+
const myDefaultMapBooleanWithoutParams = new DefaultMap(false);
|
|
180
|
+
|
|
181
|
+
// Number
|
|
182
|
+
const myDefaultMapNumber = new DefaultMap<string, number>(123);
|
|
183
|
+
const myDefaultMapNumberFactory = new DefaultMap<string, number>(() => 123);
|
|
184
|
+
const myDefaultMapNumberWithoutParams = new DefaultMap(123);
|
|
185
|
+
|
|
186
|
+
// String
|
|
187
|
+
const myDefaultMapString = new DefaultMap<string, string>("foo");
|
|
188
|
+
const myDefaultMapStringFactory = new DefaultMap<string, string>(() => "foo");
|
|
189
|
+
const myDefaultMapStringWithoutParams = new DefaultMap("foo");
|
|
190
|
+
|
|
191
|
+
// Array
|
|
192
|
+
const myDefaultMapArray = new DefaultMap<string, string[]>(() => []);
|
|
193
|
+
const myDefaultMapArrayWithoutParams = new DefaultMap(() => []);
|
|
194
|
+
|
|
195
|
+
// Map
|
|
196
|
+
const myDefaultMapMap = new DefaultMap<string, Map<string, string>>(
|
|
197
|
+
() => new Map(),
|
|
198
|
+
);
|
|
199
|
+
const myDefaultMapMapWithoutParams = new DefaultMap(() => new Map());
|
|
200
|
+
}
|
|
201
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
package/src/core/constants.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const BLIND_ITEM_PNG_PATH = "gfx/items/collectibles/questionmark.png";
|
|
|
36
36
|
/** Bombs explode when their frame count is equal to this value. */
|
|
37
37
|
export const BOMB_EXPLODE_FRAME = 45;
|
|
38
38
|
|
|
39
|
-
/** This is the initial value of the `EntityPickup.Wait`
|
|
39
|
+
/** This is the initial value of the `EntityPickup.Wait` field after a collectible is spawned. */
|
|
40
40
|
export const COLLECTIBLE_INITIAL_WAIT = 20;
|
|
41
41
|
|
|
42
42
|
export const DEFAULT_ITEM_POOL_TYPE = ItemPoolType.TREASURE;
|
|
@@ -798,8 +798,8 @@ export enum ModCallbackCustom {
|
|
|
798
798
|
POST_PIT_UPDATE,
|
|
799
799
|
|
|
800
800
|
/**
|
|
801
|
-
* Fires from the `POST_PEFFECT_UPDATE` callback when a player
|
|
802
|
-
*
|
|
801
|
+
* Fires from the `POST_PEFFECT_UPDATE` callback when a player's health (i.e. hearts) is different
|
|
802
|
+
* than what it was on the previous frame. For more information, see the `PlayerHealth` enum.
|
|
803
803
|
*
|
|
804
804
|
* - When registering the callback, takes an optional second argument that will make the callback
|
|
805
805
|
* only fire if the player matches the `PlayerVariant` provided.
|
|
@@ -811,15 +811,47 @@ export enum ModCallbackCustom {
|
|
|
811
811
|
* player: EntityPlayer,
|
|
812
812
|
* healthType: HealthType,
|
|
813
813
|
* difference: int,
|
|
814
|
+
* oldValue: int,
|
|
815
|
+
* newValue: int,
|
|
814
816
|
* ): void {}
|
|
815
817
|
* ```
|
|
816
818
|
*/
|
|
817
819
|
POST_PLAYER_CHANGE_HEALTH,
|
|
818
820
|
|
|
821
|
+
/**
|
|
822
|
+
* Fires from the `POST_PEFFECT_UPDATE` callback when one of the player's stats change from what
|
|
823
|
+
* they were on the previous frame.
|
|
824
|
+
*
|
|
825
|
+
* The type of `oldValue` and `newValue` will depend on what kind of stat it is. For example,
|
|
826
|
+
* `StatType.FLYING` will be a boolean. (You can use the "Types" helper functions to narrow the
|
|
827
|
+
* type.)
|
|
828
|
+
*
|
|
829
|
+
* For `StatType.TEAR_FLAG`, `StatType.TEAR_COLOR`, `StatType.FLYING`, and `StatType.SIZE`, the
|
|
830
|
+
* `difference` argument will always be a value of 0, since the type of these stats are not
|
|
831
|
+
* numbers. (For these cases, you should examine the `oldValue` and `newValue` arguments
|
|
832
|
+
* accordingly.)
|
|
833
|
+
*
|
|
834
|
+
* - When registering the callback, takes an optional second argument that will make the callback
|
|
835
|
+
* only fire if the player matches the `PlayerVariant` provided.
|
|
836
|
+
* - When registering the callback, takes an optional third argument that will make the callback
|
|
837
|
+
* only fire if the player matches the `PlayerType` provided.
|
|
838
|
+
*
|
|
839
|
+
* ```ts
|
|
840
|
+
* function postPlayerChangeStat(
|
|
841
|
+
* player: EntityPlayer,
|
|
842
|
+
* statType: StatType,
|
|
843
|
+
* difference: int,
|
|
844
|
+
* oldValue: number | boolean | BitFlags<TearFlag> | Color | Vector,
|
|
845
|
+
* newValue: number | boolean | BitFlags<TearFlag> | Color | Vector,
|
|
846
|
+
* ): void {}
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
POST_PLAYER_CHANGE_STAT,
|
|
850
|
+
|
|
819
851
|
/**
|
|
820
852
|
* Fires from the `POST_PEFFECT_UPDATE` callback when a player entity changes its player type
|
|
821
|
-
* (i.e. character). For example, it will fire after using
|
|
822
|
-
* Shadow collectible, etc.
|
|
853
|
+
* (i.e. character) from what it was on the previous frame. For example, it will fire after using
|
|
854
|
+
* Clicker, after dying with the Judas' Shadow collectible, etc.
|
|
823
855
|
*
|
|
824
856
|
* Notably, it does not fire after the player uses the Flip item or the Esau Jr. item, because
|
|
825
857
|
* those items cause separate player entities to be created. Use the `POST_FLIP` and
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** This represents the kinds of stats that a player can have. */
|
|
2
|
+
export enum StatType {
|
|
3
|
+
/** Corresponds to `CacheFlag.DAMAGE` (1 << 0) and `EntityPlayer.Damage`. */
|
|
4
|
+
DAMAGE,
|
|
5
|
+
|
|
6
|
+
/** Corresponds to `CacheFlag.FIRE_DELAY` (1 << 1) and `EntityPlayer.MaxFireDelay`. */
|
|
7
|
+
FIRE_DELAY,
|
|
8
|
+
|
|
9
|
+
/** Corresponds to `CacheFlag.SHOT_SPEED` (1 << 2) and `EntityPlayer.ShotSpeed`. */
|
|
10
|
+
SHOT_SPEED,
|
|
11
|
+
|
|
12
|
+
/** Corresponds to `CacheFlag.RANGE` (1 << 3) and `EntityPlayer.TearHeight`. */
|
|
13
|
+
TEAR_HEIGHT,
|
|
14
|
+
|
|
15
|
+
/** Corresponds to `CacheFlag.RANGE` (1 << 3) and `EntityPlayer.TearRange`. */
|
|
16
|
+
TEAR_RANGE,
|
|
17
|
+
|
|
18
|
+
/** Corresponds to `CacheFlag.RANGE` (1 << 3) and `EntityPlayer.TearFallingAcceleration`. */
|
|
19
|
+
TEAR_FALLING_ACCELERATION,
|
|
20
|
+
|
|
21
|
+
/** Corresponds to `CacheFlag.RANGE` (1 << 3) and `EntityPlayer.TearFallingSpeed`. */
|
|
22
|
+
TEAR_FALLING_SPEED,
|
|
23
|
+
|
|
24
|
+
/** Corresponds to `CacheFlag.SPEED` (1 << 4) and `EntityPlayer.MoveSpeed`. */
|
|
25
|
+
MOVE_SPEED,
|
|
26
|
+
|
|
27
|
+
/** Corresponds to `CacheFlag.TEAR_FLAG` (1 << 5) and `EntityPlayer.TearFlags`. */
|
|
28
|
+
TEAR_FLAG,
|
|
29
|
+
|
|
30
|
+
/** Corresponds to `CacheFlag.TEAR_COLOR` (1 << 6) and `EntityPlayer.TearColor`. */
|
|
31
|
+
TEAR_COLOR,
|
|
32
|
+
|
|
33
|
+
/** Corresponds to `CacheFlag.FLYING` (1 << 7) and `EntityPlayer.CanFly`. */
|
|
34
|
+
FLYING,
|
|
35
|
+
|
|
36
|
+
// - `CacheFlag.WEAPON` (1 << 8) does not have a corresponding `EntityPlayer` field.
|
|
37
|
+
// - `CacheFlag.FAMILIARS` (1 << 9) does not have a corresponding `EntityPlayer` field.
|
|
38
|
+
|
|
39
|
+
/** Corresponds to `CacheFlag.LUCK` (1 << 10) and `EntityPlayer.Luck`. */
|
|
40
|
+
LUCK,
|
|
41
|
+
|
|
42
|
+
// - `CacheFlag.SIZE` (1 << 12) does not have a corresponding `EntityPlayer` field. (After picking
|
|
43
|
+
// up Magic Mushroom, the values of `EntityPlayer.Size` and `EntityPlayer.SizeMulti` do not
|
|
44
|
+
// change.)
|
|
45
|
+
// - `CacheFlag.COLOR` (1 << 12) does not have a corresponding `EntityPlayer` field.
|
|
46
|
+
// - `CacheFlag.PICKUP_VISION` (1 << 13) does not have a corresponding `EntityPlayer` field.
|
|
47
|
+
}
|
package/src/enums/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* - This must match the JSDoc comments for `deepCopy` and `merge`.
|
|
3
|
+
* - This must match the `SerializableIsaacAPIClass` type union.
|
|
4
|
+
*/
|
|
2
5
|
export enum CopyableIsaacAPIClassType {
|
|
6
|
+
BIT_SET_128 = "BitSet128",
|
|
3
7
|
COLOR = "Color",
|
|
4
8
|
K_COLOR = "KColor",
|
|
5
9
|
RNG = "RNG",
|
|
@@ -76,13 +76,13 @@ const versusScreenSprite = Sprite();
|
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Unfortunately, we must split the background layer into an entirely different sprite so that we
|
|
79
|
-
* can color it with the `Color`
|
|
79
|
+
* can color it with the `Color` field.
|
|
80
80
|
*/
|
|
81
81
|
const versusScreenBackgroundSprite = Sprite();
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* Unfortunately, we must split the dirt layer into an entirely different sprite so that we can
|
|
85
|
-
* color it with the `Color`
|
|
85
|
+
* color it with the `Color` field.
|
|
86
86
|
*/
|
|
87
87
|
const versusScreenDirtSpotSprite = Sprite();
|
|
88
88
|
|
|
@@ -12,16 +12,10 @@ const FEATURE_NAME = "disableInputs";
|
|
|
12
12
|
const v = {
|
|
13
13
|
run: {
|
|
14
14
|
/** Indexed by the requesting feature key. */
|
|
15
|
-
disableInputsWithWhitelistMap: new Map<
|
|
16
|
-
string,
|
|
17
|
-
Set<ButtonAction> | ReadonlySet<ButtonAction>
|
|
18
|
-
>(),
|
|
15
|
+
disableInputsWithWhitelistMap: new Map<string, ReadonlySet<ButtonAction>>(),
|
|
19
16
|
|
|
20
17
|
/** Indexed by the requesting feature key. */
|
|
21
|
-
enableInputsWithBlacklistMap: new Map<
|
|
22
|
-
string,
|
|
23
|
-
Set<ButtonAction> | ReadonlySet<ButtonAction>
|
|
24
|
-
>(),
|
|
18
|
+
enableInputsWithBlacklistMap: new Map<string, ReadonlySet<ButtonAction>>(),
|
|
25
19
|
},
|
|
26
20
|
};
|
|
27
21
|
|
|
@@ -154,7 +148,7 @@ export function enableAllInputsExceptFor(
|
|
|
154
148
|
*/
|
|
155
149
|
export function disableAllInputsExceptFor(
|
|
156
150
|
key: string,
|
|
157
|
-
whitelist: Set<ButtonAction>,
|
|
151
|
+
whitelist: Set<ButtonAction> | ReadonlySet<ButtonAction>,
|
|
158
152
|
): void {
|
|
159
153
|
errorIfFeaturesNotInitialized(FEATURE_NAME);
|
|
160
154
|
|
|
@@ -31,7 +31,7 @@ const v = {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export function runInNFramesInit(mod: Mod): void {
|
|
34
|
-
saveDataManager(FEATURE_NAME, v,
|
|
34
|
+
saveDataManager(FEATURE_NAME, v, false); // Functions are not serializable.
|
|
35
35
|
|
|
36
36
|
mod.AddCallback(ModCallback.POST_UPDATE, postUpdate); // 1
|
|
37
37
|
mod.AddCallback(ModCallback.POST_RENDER, postRender); // 2
|
|
@@ -13,7 +13,7 @@ const v = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export function runNextRoomInit(mod: ModUpgraded): void {
|
|
16
|
-
saveDataManager(FEATURE_NAME, v,
|
|
16
|
+
saveDataManager(FEATURE_NAME, v, false); // Functions are not serializable.
|
|
17
17
|
|
|
18
18
|
mod.AddCallbackCustom(
|
|
19
19
|
ModCallbackCustom.POST_NEW_ROOM_REORDERED,
|
|
@@ -113,7 +113,7 @@ export function saveDataManager<Persistent, Run, Level>(
|
|
|
113
113
|
): void;
|
|
114
114
|
export function saveDataManager(
|
|
115
115
|
key: string, // This is the overload for the case when saving data is disabled.
|
|
116
|
-
v: SaveData
|
|
116
|
+
v: SaveData,
|
|
117
117
|
conditionalFunc: false,
|
|
118
118
|
): void;
|
|
119
119
|
export function saveDataManager<Persistent, Run, Level>(
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SerializationBrand } from "../enums/private/SerializationBrand";
|
|
2
|
+
import { isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
3
|
+
import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
|
|
4
|
+
import { isTable } from "./types";
|
|
5
|
+
|
|
6
|
+
export type SerializedBitSet128 = LuaMap<string, unknown> & {
|
|
7
|
+
readonly __serializedBitSet128Brand: symbol;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const OBJECT_NAME = "BitSet128";
|
|
11
|
+
const KEYS = ["l", "h"];
|
|
12
|
+
|
|
13
|
+
/** Helper function to copy a `BitSet128` Isaac API class. */
|
|
14
|
+
export function copyBitSet128(bitSet128: BitSet128): BitSet128 {
|
|
15
|
+
if (!isBitSet128(bitSet128)) {
|
|
16
|
+
error(
|
|
17
|
+
`Failed to copy a ${OBJECT_NAME} object since the provided object was not a userdata ${OBJECT_NAME} class.`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const lowBits = bitSet128.l;
|
|
22
|
+
const highBits = bitSet128.h;
|
|
23
|
+
|
|
24
|
+
return BitSet128(lowBits, highBits);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Helper function to convert a `SerializedBitSet128` object to a normal `BitSet128` object. (This
|
|
29
|
+
* is used by the save data manager when reading data from the "save#.dat" file.)
|
|
30
|
+
*/
|
|
31
|
+
export function deserializeBitSet128(
|
|
32
|
+
bitSet128: SerializedBitSet128,
|
|
33
|
+
): BitSet128 {
|
|
34
|
+
if (!isTable(bitSet128)) {
|
|
35
|
+
error(
|
|
36
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object was not a Lua table.`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const [l, h] = getNumbersFromTable(
|
|
41
|
+
bitSet128 as LuaMap<string, unknown>,
|
|
42
|
+
OBJECT_NAME,
|
|
43
|
+
...KEYS,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (l === undefined) {
|
|
47
|
+
error(
|
|
48
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: l`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (h === undefined) {
|
|
52
|
+
error(
|
|
53
|
+
`Failed to deserialize a ${OBJECT_NAME} object since the provided object did not have a value for: h`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return BitSet128(l, h);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Helper function to check if something is an instantiated `BitSet128` object. */
|
|
61
|
+
export function isBitSet128(object: unknown): object is BitSet128 {
|
|
62
|
+
return isIsaacAPIClassOfType(object, OBJECT_NAME);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Used to determine is the given table is a serialized `BitSet128` object created by the save data
|
|
67
|
+
* manager and/or the `deepCopy` function.
|
|
68
|
+
*/
|
|
69
|
+
export function isSerializedBitSet128(
|
|
70
|
+
object: unknown,
|
|
71
|
+
): object is SerializedBitSet128 {
|
|
72
|
+
if (!isTable(object)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
tableHasKeys(object, ...KEYS) && object.has(SerializationBrand.BIT_SET_128)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Helper function to convert a `BitSet128` object to a `SerializedBitSet128` object. (This is used
|
|
83
|
+
* by the save data manager when writing data from the "save#.dat" file.)
|
|
84
|
+
*/
|
|
85
|
+
export function serializeBitSet128(bitSet128: BitSet128): SerializedBitSet128 {
|
|
86
|
+
if (!isBitSet128(bitSet128)) {
|
|
87
|
+
error(
|
|
88
|
+
`Failed to serialize a ${OBJECT_NAME} object since the provided object was not a userdata ${OBJECT_NAME} class.`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const bitSet128Table = new LuaMap<string, unknown>();
|
|
93
|
+
copyValuesToTable(bitSet128, KEYS, bitSet128Table);
|
|
94
|
+
bitSet128Table.set(SerializationBrand.BIT_SET_128, "");
|
|
95
|
+
return bitSet128Table as SerializedBitSet128;
|
|
96
|
+
}
|
|
@@ -614,8 +614,8 @@ export function setCollectibleSprite(
|
|
|
614
614
|
}
|
|
615
615
|
|
|
616
616
|
/**
|
|
617
|
-
* Helper function to change the collectible on a pedestal. Simply updating the `SubType`
|
|
618
|
-
*
|
|
617
|
+
* Helper function to change the collectible on a pedestal. Simply updating the `SubType` field is
|
|
618
|
+
* not sufficient because the sprite will not change.
|
|
619
619
|
*/
|
|
620
620
|
export function setCollectibleSubType(
|
|
621
621
|
collectible: EntityPickup,
|
package/src/functions/color.ts
CHANGED
|
@@ -9,8 +9,8 @@ export type SerializedColor = LuaMap<string, unknown> & {
|
|
|
9
9
|
readonly __serializedColorBrand: symbol;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
const KEYS = ["R", "G", "B", "A", "RO", "GO", "BO"];
|
|
13
12
|
const OBJECT_NAME = "Color";
|
|
13
|
+
const KEYS = ["R", "G", "B", "A", "RO", "GO", "BO"];
|
|
14
14
|
|
|
15
15
|
export function colorEquals(color1: Color, color2: Color): boolean {
|
|
16
16
|
return isaacAPIClassEquals(color1, color2, KEYS);
|
|
@@ -91,7 +91,7 @@ export function getRandomColor(
|
|
|
91
91
|
return Color(r, g, b, alpha);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/** Helper function to check if something is an instantiated Color object. */
|
|
94
|
+
/** Helper function to check if something is an instantiated `Color` object. */
|
|
95
95
|
export function isColor(object: unknown): object is Color {
|
|
96
96
|
return isIsaacAPIClassOfType(object, OBJECT_NAME);
|
|
97
97
|
}
|
|
@@ -107,6 +107,7 @@ export function isSerializedColor(object: unknown): object is SerializedColor {
|
|
|
107
107
|
|
|
108
108
|
return tableHasKeys(object, ...KEYS) && object.has(SerializationBrand.COLOR);
|
|
109
109
|
}
|
|
110
|
+
|
|
110
111
|
/**
|
|
111
112
|
* Helper function to convert a `Color` object to a `SerializedColor` object. (This is used by the
|
|
112
113
|
* save data manager when writing data from the "save#.dat" file.)
|
|
@@ -42,6 +42,7 @@ const COPYABLE_ISAAC_API_CLASS_TYPES_SET = new Set<string>(
|
|
|
42
42
|
* - TSTL `Set`
|
|
43
43
|
* - TSTL classes
|
|
44
44
|
* - `DefaultMap`
|
|
45
|
+
* - Isaac `BitSet128` objects
|
|
45
46
|
* - Isaac `Color` objects
|
|
46
47
|
* - Isaac `KColor` objects
|
|
47
48
|
* - Isaac `RNG` objects
|
|
@@ -233,7 +234,7 @@ function deepCopyDefaultMap(
|
|
|
233
234
|
// throw a run-time error to immediately alert the end-user that their data structure is
|
|
234
235
|
// invalid.
|
|
235
236
|
error(
|
|
236
|
-
|
|
237
|
+
"Failed to deep copy a DefaultMap because it was instantiated with a factory function and was also inside of an array, map, or set. For more information, see: https://isaacscript.github.io/main/gotchas#failed-to-deep-copy-a-defaultmap",
|
|
237
238
|
);
|
|
238
239
|
} else {
|
|
239
240
|
// In most cases, the DefaultMap will be attached to a normal table element. In this case, if
|