isaacscript-common 6.13.0 → 6.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/callbacks/postGridEntityCustomCollision.d.ts +2 -0
- package/dist/callbacks/postGridEntityCustomCollision.d.ts.map +1 -0
- package/dist/callbacks/postGridEntityCustomCollision.lua +71 -0
- package/dist/callbacks/postGridEntityCustomRender.lua +0 -7
- package/dist/callbacks/postGridEntityCustomUpdate.lua +0 -7
- package/dist/callbacks/subscriptions/postGridEntityCustomBroken.d.ts +6 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomBroken.d.ts.map +1 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomBroken.lua +29 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomCollision.d.ts +6 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomCollision.d.ts.map +1 -0
- package/dist/callbacks/subscriptions/postGridEntityCustomCollision.lua +29 -0
- package/dist/enums/ModCallbackCustom.d.ts +96 -62
- package/dist/enums/ModCallbackCustom.d.ts.map +1 -1
- package/dist/enums/ModCallbackCustom.lua +64 -60
- package/dist/enums/private/SerializationBrand.d.ts +1 -1
- package/dist/enums/private/SerializationBrand.lua +1 -1
- package/dist/features/customGridEntity.d.ts +7 -3
- package/dist/features/customGridEntity.d.ts.map +1 -1
- package/dist/features/customGridEntity.lua +67 -7
- package/dist/features/extraConsoleCommands/exports.d.ts +4 -3
- package/dist/features/extraConsoleCommands/exports.d.ts.map +1 -1
- package/dist/features/extraConsoleCommands/exports.lua +4 -3
- package/dist/features/extraConsoleCommands/init.lua +1 -0
- package/dist/functions/collectibles.d.ts +6 -2
- package/dist/functions/collectibles.d.ts.map +1 -1
- package/dist/functions/collectibles.lua +4 -2
- package/dist/functions/color.d.ts +20 -14
- package/dist/functions/color.d.ts.map +1 -1
- package/dist/functions/color.lua +78 -73
- package/dist/functions/deepCopy.d.ts.map +1 -1
- package/dist/functions/deepCopy.lua +22 -1
- package/dist/functions/gridEntities.d.ts +2 -36
- package/dist/functions/gridEntities.d.ts.map +1 -1
- package/dist/functions/gridEntities.lua +2 -78
- package/dist/functions/isaacAPIClass.d.ts +1 -1
- package/dist/functions/isaacAPIClass.d.ts.map +1 -1
- package/dist/functions/itemPool.d.ts +10 -0
- package/dist/functions/itemPool.d.ts.map +1 -0
- package/dist/functions/itemPool.lua +116 -0
- package/dist/functions/kColor.d.ts +20 -14
- package/dist/functions/kColor.d.ts.map +1 -1
- package/dist/functions/kColor.lua +65 -60
- package/dist/functions/mergeTests.lua +2 -2
- package/dist/functions/npcs.d.ts +1 -29
- package/dist/functions/npcs.d.ts.map +1 -1
- package/dist/functions/npcs.lua +0 -45
- package/dist/functions/projectiles.d.ts +32 -0
- package/dist/functions/projectiles.d.ts.map +1 -0
- package/dist/functions/projectiles.lua +73 -0
- package/dist/functions/random.d.ts +1 -1
- package/dist/functions/random.lua +1 -1
- package/dist/functions/rng.d.ts +11 -15
- package/dist/functions/rng.d.ts.map +1 -1
- package/dist/functions/rng.lua +32 -52
- package/dist/functions/rockAlt.d.ts +48 -0
- package/dist/functions/rockAlt.d.ts.map +1 -0
- package/dist/functions/rockAlt.lua +365 -0
- package/dist/functions/saveFile.d.ts +8 -7
- package/dist/functions/saveFile.d.ts.map +1 -1
- package/dist/functions/saveFile.lua +10 -96
- package/dist/functions/serialization.d.ts +26 -7
- package/dist/functions/serialization.d.ts.map +1 -1
- package/dist/functions/serialization.lua +51 -19
- package/dist/functions/table.d.ts +2 -2
- package/dist/functions/table.lua +2 -2
- package/dist/functions/trinketGive.d.ts +13 -0
- package/dist/functions/trinketGive.d.ts.map +1 -1
- package/dist/functions/trinketGive.lua +16 -0
- package/dist/functions/tstlClass.d.ts +1 -1
- package/dist/functions/tstlClass.d.ts.map +1 -1
- package/dist/functions/vector.d.ts +21 -14
- package/dist/functions/vector.d.ts.map +1 -1
- package/dist/functions/vector.lua +58 -54
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.lua +16 -0
- package/dist/initCustomCallbacks.d.ts.map +1 -1
- package/dist/initCustomCallbacks.lua +3 -0
- package/dist/interfaces/AddCallbackParameterCustom.d.ts +4 -0
- package/dist/interfaces/AddCallbackParameterCustom.d.ts.map +1 -1
- package/dist/objects/callbackRegisterFunctions.d.ts.map +1 -1
- package/dist/objects/callbackRegisterFunctions.lua +6 -0
- package/dist/objects/isaacAPIClassTypeToFunctions.d.ts +12 -0
- package/dist/objects/isaacAPIClassTypeToFunctions.d.ts.map +1 -0
- package/dist/objects/isaacAPIClassTypeToFunctions.lua +25 -0
- package/dist/types/{private/IsaacAPIClass.d.ts → IsaacAPIClass.d.ts} +0 -0
- package/dist/types/IsaacAPIClass.d.ts.map +1 -0
- package/dist/types/{private/IsaacAPIClass.lua → IsaacAPIClass.lua} +0 -0
- package/dist/types/{private/SerializedIsaacAPIClass.d.ts → SerializedIsaacAPIClass.d.ts} +0 -0
- package/dist/types/SerializedIsaacAPIClass.d.ts.map +1 -0
- package/dist/types/{private/SerializedIsaacAPIClass.lua → SerializedIsaacAPIClass.lua} +0 -0
- package/dist/types/{private/TSTLClass.d.ts → TSTLClass.d.ts} +0 -0
- package/dist/types/TSTLClass.d.ts.map +1 -0
- package/dist/types/{private/TSTLClass.lua → TSTLClass.lua} +0 -0
- package/package.json +2 -2
- package/src/callbacks/postGridEntityCustomCollision.ts +74 -0
- package/src/callbacks/postGridEntityCustomRender.ts +1 -17
- package/src/callbacks/postGridEntityCustomUpdate.ts +1 -17
- package/src/callbacks/subscriptions/postGridEntityCustomBroken.ts +41 -0
- package/src/callbacks/subscriptions/postGridEntityCustomCollision.ts +43 -0
- package/src/enums/ModCallbackCustom.ts +38 -2
- package/src/enums/private/SerializationBrand.ts +1 -1
- package/src/features/customGridEntity.ts +78 -2
- package/src/features/extraConsoleCommands/exports.ts +4 -3
- package/src/features/extraConsoleCommands/init.ts +1 -0
- package/src/features/extraConsoleCommands/listCommands.ts +2 -2
- package/src/functions/collectibles.ts +6 -2
- package/src/functions/color.ts +89 -87
- package/src/functions/deepCopy.ts +15 -2
- package/src/functions/gridEntities.ts +2 -77
- package/src/functions/isaacAPIClass.ts +1 -1
- package/src/functions/itemPool.ts +153 -0
- package/src/functions/kColor.ts +87 -84
- package/src/functions/mergeTests.ts +2 -2
- package/src/functions/npcs.ts +1 -58
- package/src/functions/projectiles.ts +78 -0
- package/src/functions/random.ts +1 -1
- package/src/functions/rng.ts +45 -65
- package/src/functions/rockAlt.ts +396 -0
- package/src/functions/saveFile.ts +13 -119
- package/src/functions/serialization.ts +81 -25
- package/src/functions/table.ts +2 -2
- package/src/functions/trinketGive.ts +21 -0
- package/src/functions/tstlClass.ts +1 -1
- package/src/functions/vector.ts +78 -74
- package/src/index.ts +2 -0
- package/src/initCustomCallbacks.ts +2 -0
- package/src/interfaces/AddCallbackParameterCustom.ts +4 -0
- package/src/objects/callbackRegisterFunctions.ts +6 -0
- package/src/objects/isaacAPIClassTypeToFunctions.ts +63 -0
- package/src/types/{private/IsaacAPIClass.ts → IsaacAPIClass.ts} +0 -0
- package/src/types/{private/SerializedIsaacAPIClass.ts → SerializedIsaacAPIClass.ts} +0 -0
- package/src/types/{private/TSTLClass.ts → TSTLClass.ts} +0 -0
- package/dist/objects/isaacAPIClassTypeToCopyFunction.d.ts +0 -6
- package/dist/objects/isaacAPIClassTypeToCopyFunction.d.ts.map +0 -1
- package/dist/objects/isaacAPIClassTypeToCopyFunction.lua +0 -13
- package/dist/objects/serializedIsaacAPIClassTypeToIdentityFunction.d.ts +0 -5
- package/dist/objects/serializedIsaacAPIClassTypeToIdentityFunction.d.ts.map +0 -1
- package/dist/objects/serializedIsaacAPIClassTypeToIdentityFunction.lua +0 -13
- package/dist/types/private/IsaacAPIClass.d.ts.map +0 -1
- package/dist/types/private/SerializedIsaacAPIClass.d.ts.map +0 -1
- package/dist/types/private/TSTLClass.d.ts.map +0 -1
- package/src/objects/isaacAPIClassTypeToCopyFunction.ts +0 -18
- package/src/objects/serializedIsaacAPIClassTypeToIdentityFunction.ts +0 -14
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
local ____exports = {}
|
|
2
|
+
local ____CopyableIsaacAPIClassType = require("enums.private.CopyableIsaacAPIClassType")
|
|
3
|
+
local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
|
|
4
|
+
local ____color = require("functions.color")
|
|
5
|
+
local copyColor = ____color.copyColor
|
|
6
|
+
local deserializeColor = ____color.deserializeColor
|
|
7
|
+
local isSerializedColor = ____color.isSerializedColor
|
|
8
|
+
local serializeColor = ____color.serializeColor
|
|
9
|
+
local ____kColor = require("functions.kColor")
|
|
10
|
+
local copyKColor = ____kColor.copyKColor
|
|
11
|
+
local deserializeKColor = ____kColor.deserializeKColor
|
|
12
|
+
local isSerializedKColor = ____kColor.isSerializedKColor
|
|
13
|
+
local serializeKColor = ____kColor.serializeKColor
|
|
14
|
+
local ____rng = require("functions.rng")
|
|
15
|
+
local copyRNG = ____rng.copyRNG
|
|
16
|
+
local deserializeRNG = ____rng.deserializeRNG
|
|
17
|
+
local isSerializedRNG = ____rng.isSerializedRNG
|
|
18
|
+
local serializeRNG = ____rng.serializeRNG
|
|
19
|
+
local ____vector = require("functions.vector")
|
|
20
|
+
local copyVector = ____vector.copyVector
|
|
21
|
+
local deserializeVector = ____vector.deserializeVector
|
|
22
|
+
local isSerializedVector = ____vector.isSerializedVector
|
|
23
|
+
local serializeVector = ____vector.serializeVector
|
|
24
|
+
____exports.ISAAC_API_CLASS_TYPE_TO_FUNCTIONS = {[CopyableIsaacAPIClassType.COLOR] = {isSerialized = isSerializedColor, copy = copyColor, serialize = serializeColor, deserialize = deserializeColor}, [CopyableIsaacAPIClassType.K_COLOR] = {isSerialized = isSerializedKColor, copy = copyKColor, serialize = serializeKColor, deserialize = deserializeKColor}, [CopyableIsaacAPIClassType.RNG] = {isSerialized = isSerializedRNG, copy = copyRNG, serialize = serializeRNG, deserialize = deserializeRNG}, [CopyableIsaacAPIClassType.VECTOR] = {isSerialized = isSerializedVector, copy = copyVector, serialize = serializeVector, deserialize = deserializeVector}}
|
|
25
|
+
return ____exports
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsaacAPIClass.d.ts","sourceRoot":"","sources":["../../src/types/IsaacAPIClass.ts"],"names":[],"mappings":";AAAA,oBAAY,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACpD,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;CACvC,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SerializedIsaacAPIClass.d.ts","sourceRoot":"","sources":["../../src/types/SerializedIsaacAPIClass.ts"],"names":[],"mappings":";AAAA,oBAAY,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC9D,QAAQ,CAAC,8BAA8B,EAAE,MAAM,CAAC;CACjD,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TSTLClass.d.ts","sourceRoot":"","sources":["../../src/types/TSTLClass.ts"],"names":[],"mappings":";AAAA,oBAAY,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG;IACnD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC,CAAC"}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.16.0",
|
|
4
4
|
"description": "Helper functions and features for IsaacScript mods.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"main": "dist/index",
|
|
23
23
|
"types": "dist/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"isaac-typescript-definitions": "^3.0
|
|
25
|
+
"isaac-typescript-definitions": "^3.1.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { GridCollisionClass, ModCallback } from "isaac-typescript-definitions";
|
|
2
|
+
import { DefaultMap } from "../classes/DefaultMap";
|
|
3
|
+
import { ModUpgraded } from "../classes/ModUpgraded";
|
|
4
|
+
import { getCustomGridEntities } from "../features/customGridEntity";
|
|
5
|
+
import { saveDataManager } from "../features/saveDataManager/exports";
|
|
6
|
+
import { getCollidingEntitiesWithGridEntity } from "../functions/gridEntities";
|
|
7
|
+
import {
|
|
8
|
+
postGridEntityCustomCollisionFire,
|
|
9
|
+
postGridEntityCustomCollisionHasSubscriptions,
|
|
10
|
+
} from "./subscriptions/postGridEntityCustomCollision";
|
|
11
|
+
|
|
12
|
+
const v = {
|
|
13
|
+
room: {
|
|
14
|
+
/** Indexed by grid entity pointer hash. */
|
|
15
|
+
collidingEntitiesMap: new DefaultMap<PtrHash, Set<PtrHash>>(
|
|
16
|
+
() => new Set(),
|
|
17
|
+
),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export function postGridEntityCustomCollisionInit(mod: ModUpgraded): void {
|
|
23
|
+
saveDataManager("postGridEntityCustomCollisionInit", v, hasSubscriptions);
|
|
24
|
+
|
|
25
|
+
mod.AddCallback(ModCallback.POST_UPDATE, postUpdate); // 1
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function hasSubscriptions() {
|
|
29
|
+
return postGridEntityCustomCollisionHasSubscriptions();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ModCallback.POST_UPDATE (1)
|
|
33
|
+
function postUpdate() {
|
|
34
|
+
if (!hasSubscriptions()) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const customGridEntities = getCustomGridEntities();
|
|
39
|
+
for (const [gridEntity, data] of customGridEntities) {
|
|
40
|
+
if (gridEntity.CollisionClass === GridCollisionClass.NONE) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The following code is copied from the `POST_GRID_ENTITY_COLLISION` callback.
|
|
45
|
+
const gridEntityPtrHash = GetPtrHash(gridEntity);
|
|
46
|
+
const oldCollidingEntities =
|
|
47
|
+
v.room.collidingEntitiesMap.getAndSetDefault(gridEntityPtrHash);
|
|
48
|
+
|
|
49
|
+
// Check for new colliding entities.
|
|
50
|
+
const collidingEntities = getCollidingEntitiesWithGridEntity(gridEntity);
|
|
51
|
+
for (const entity of collidingEntities) {
|
|
52
|
+
const entityPtrHash = GetPtrHash(entity);
|
|
53
|
+
if (!oldCollidingEntities.has(entityPtrHash)) {
|
|
54
|
+
oldCollidingEntities.add(entityPtrHash);
|
|
55
|
+
postGridEntityCustomCollisionFire(
|
|
56
|
+
gridEntity,
|
|
57
|
+
data.gridEntityTypeCustom,
|
|
58
|
+
entity,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Remove old colliding entities.
|
|
64
|
+
const collidingEntitiesPtrHashes = collidingEntities.map((entity) =>
|
|
65
|
+
GetPtrHash(entity),
|
|
66
|
+
);
|
|
67
|
+
const collidingEntitiesPtrHashSet = new Set(collidingEntitiesPtrHashes);
|
|
68
|
+
for (const oldCollidingEntityPtrHash of oldCollidingEntities.values()) {
|
|
69
|
+
if (!collidingEntitiesPtrHashSet.has(oldCollidingEntityPtrHash)) {
|
|
70
|
+
oldCollidingEntities.delete(oldCollidingEntityPtrHash);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModCallback } from "isaac-typescript-definitions";
|
|
2
2
|
import { ModUpgraded } from "../classes/ModUpgraded";
|
|
3
3
|
import { getCustomGridEntities } from "../features/customGridEntity";
|
|
4
|
-
import { saveDataManager } from "../features/saveDataManager/exports";
|
|
5
4
|
import {
|
|
6
5
|
postGridEntityCustomRenderFire,
|
|
7
6
|
postGridEntityCustomRenderHasSubscriptions,
|
|
8
7
|
} from "./subscriptions/postGridEntityCustomRender";
|
|
9
8
|
|
|
10
|
-
type GridEntityTuple = [
|
|
11
|
-
gridEntityType: GridEntityType,
|
|
12
|
-
gridEntityVariant: int,
|
|
13
|
-
state: int,
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
const v = {
|
|
17
|
-
room: {
|
|
18
|
-
/** Indexed by grid index. */
|
|
19
|
-
initializedGridEntities: new Map<int, GridEntityTuple>(),
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
9
|
/** @internal */
|
|
24
10
|
export function postGridEntityCustomRenderInit(mod: ModUpgraded): void {
|
|
25
|
-
saveDataManager("postGridEntityCustomRender", v, hasSubscriptions);
|
|
26
|
-
|
|
27
11
|
mod.AddCallback(ModCallback.POST_RENDER, postRender); // 2
|
|
28
12
|
}
|
|
29
13
|
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModCallback } from "isaac-typescript-definitions";
|
|
2
2
|
import { ModUpgraded } from "../classes/ModUpgraded";
|
|
3
3
|
import { getCustomGridEntities } from "../features/customGridEntity";
|
|
4
|
-
import { saveDataManager } from "../features/saveDataManager/exports";
|
|
5
4
|
import {
|
|
6
5
|
postGridEntityCustomUpdateFire,
|
|
7
6
|
postGridEntityCustomUpdateHasSubscriptions,
|
|
8
7
|
} from "./subscriptions/postGridEntityCustomUpdate";
|
|
9
8
|
|
|
10
|
-
type GridEntityTuple = [
|
|
11
|
-
gridEntityType: GridEntityType,
|
|
12
|
-
gridEntityVariant: int,
|
|
13
|
-
state: int,
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
const v = {
|
|
17
|
-
room: {
|
|
18
|
-
/** Indexed by grid index. */
|
|
19
|
-
initializedGridEntities: new Map<int, GridEntityTuple>(),
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
9
|
/** @internal */
|
|
24
10
|
export function postGridEntityCustomUpdateInit(mod: ModUpgraded): void {
|
|
25
|
-
saveDataManager("postGridEntityCustomUpdate", v, hasSubscriptions);
|
|
26
|
-
|
|
27
11
|
mod.AddCallback(ModCallback.POST_UPDATE, postUpdate); // 1
|
|
28
12
|
}
|
|
29
13
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GridEntityType } from "isaac-typescript-definitions";
|
|
2
|
+
|
|
3
|
+
export type PostGridEntityCustomBrokenRegisterParameters = [
|
|
4
|
+
callback: (
|
|
5
|
+
gridEntity: GridEntity,
|
|
6
|
+
gridEntityTypeCustom: GridEntityType,
|
|
7
|
+
) => void,
|
|
8
|
+
gridEntityTypeCustom?: GridEntityType,
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const subscriptions: PostGridEntityCustomBrokenRegisterParameters[] = [];
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
export function postGridEntityCustomBrokenHasSubscriptions(): boolean {
|
|
15
|
+
return subscriptions.length > 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** @internal */
|
|
19
|
+
export function postGridEntityCustomBrokenRegister(
|
|
20
|
+
...args: PostGridEntityCustomBrokenRegisterParameters
|
|
21
|
+
): void {
|
|
22
|
+
subscriptions.push(args);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export function postGridEntityCustomBrokenFire(
|
|
27
|
+
gridEntity: GridEntity,
|
|
28
|
+
gridEntityTypeCustom: GridEntityType,
|
|
29
|
+
): void {
|
|
30
|
+
for (const [callback, callbackGridEntityTypeCustom] of subscriptions) {
|
|
31
|
+
// Handle the optional 2nd callback argument.
|
|
32
|
+
if (
|
|
33
|
+
callbackGridEntityTypeCustom !== undefined &&
|
|
34
|
+
callbackGridEntityTypeCustom !== gridEntityTypeCustom
|
|
35
|
+
) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
callback(gridEntity, gridEntityTypeCustom);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { GridEntityType } from "isaac-typescript-definitions";
|
|
2
|
+
|
|
3
|
+
export type PostGridEntityCustomCollisionRegisterParameters = [
|
|
4
|
+
callback: (
|
|
5
|
+
gridEntity: GridEntity,
|
|
6
|
+
gridEntityTypeCustom: GridEntityType,
|
|
7
|
+
entity: Entity,
|
|
8
|
+
) => void,
|
|
9
|
+
gridEntityTypeCustom?: GridEntityType,
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const subscriptions: PostGridEntityCustomCollisionRegisterParameters[] = [];
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export function postGridEntityCustomCollisionHasSubscriptions(): boolean {
|
|
16
|
+
return subscriptions.length > 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @internal */
|
|
20
|
+
export function postGridEntityCustomCollisionRegister(
|
|
21
|
+
...args: PostGridEntityCustomCollisionRegisterParameters
|
|
22
|
+
): void {
|
|
23
|
+
subscriptions.push(args);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @internal */
|
|
27
|
+
export function postGridEntityCustomCollisionFire(
|
|
28
|
+
gridEntity: GridEntity,
|
|
29
|
+
gridEntityTypeCustom: GridEntityType,
|
|
30
|
+
entity: Entity,
|
|
31
|
+
): void {
|
|
32
|
+
for (const [callback, callbackGridEntityTypeCustom] of subscriptions) {
|
|
33
|
+
// Handle the optional 2nd callback argument.
|
|
34
|
+
if (
|
|
35
|
+
callbackGridEntityTypeCustom !== undefined &&
|
|
36
|
+
callbackGridEntityTypeCustom !== gridEntityTypeCustom
|
|
37
|
+
) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
callback(gridEntity, gridEntityTypeCustom, entity);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -363,6 +363,42 @@ export enum ModCallbackCustom {
|
|
|
363
363
|
*/
|
|
364
364
|
POST_GRID_ENTITY_COLLISION,
|
|
365
365
|
|
|
366
|
+
/**
|
|
367
|
+
* Fires from the `POST_UPDATE` callback when a grid entity created with the
|
|
368
|
+
* `spawnCustomGridEntity` helper function is hit by an explosion.
|
|
369
|
+
*
|
|
370
|
+
* In most cases, you will want to remove the grid entity inside of this callback in order to
|
|
371
|
+
* prevent further "broken" callbacks from firing. (This would not be the case if you were trying
|
|
372
|
+
* to emulate a super tinted rock that takes multiple explosions to destroy, for example.)
|
|
373
|
+
*
|
|
374
|
+
* When registering the callback, takes an optional second argument that will make the callback
|
|
375
|
+
* only fire if it matches the `GridEntityType` provided.
|
|
376
|
+
*
|
|
377
|
+
* ```ts
|
|
378
|
+
* function postGridEntityCustomBroken(
|
|
379
|
+
* gridEntity: GridEntity,
|
|
380
|
+
* gridEntityTypeCustom: GridEntityType,
|
|
381
|
+
* ): void {}
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
POST_GRID_ENTITY_CUSTOM_BROKEN,
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Fires from the `POST_UPDATE` callback a new entity collides with a grid entity created with the
|
|
388
|
+
* `spawnCustomGridEntity` helper function.
|
|
389
|
+
*
|
|
390
|
+
* When registering the callback, takes an optional second argument that will make the callback
|
|
391
|
+
* only fire if it matches the `GridEntityType` provided.
|
|
392
|
+
*
|
|
393
|
+
* ```ts
|
|
394
|
+
* function postGridEntityCustomRender(
|
|
395
|
+
* gridEntity: GridEntity,
|
|
396
|
+
* gridEntityTypeCustom: GridEntityType,
|
|
397
|
+
* ): void {}
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
POST_GRID_ENTITY_CUSTOM_COLLISION,
|
|
401
|
+
|
|
366
402
|
/**
|
|
367
403
|
* Fires from the `POST_RENDER` callback on every frame that a grid entity created with the
|
|
368
404
|
* `spawnCustomGridEntity` helper function exists.
|
|
@@ -371,7 +407,7 @@ export enum ModCallbackCustom {
|
|
|
371
407
|
* only fire if it matches the `GridEntityType` provided.
|
|
372
408
|
*
|
|
373
409
|
* ```ts
|
|
374
|
-
* function
|
|
410
|
+
* function postGridEntityCustomRender(
|
|
375
411
|
* gridEntity: GridEntity,
|
|
376
412
|
* gridEntityTypeCustom: GridEntityType,
|
|
377
413
|
* ): void {}
|
|
@@ -387,7 +423,7 @@ export enum ModCallbackCustom {
|
|
|
387
423
|
* only fire if it matches the `GridEntityType` provided.
|
|
388
424
|
*
|
|
389
425
|
* ```ts
|
|
390
|
-
* function
|
|
426
|
+
* function postGridEntityCustomUpdate(
|
|
391
427
|
* gridEntity: GridEntity,
|
|
392
428
|
* gridEntityTypeCustom: GridEntityType,
|
|
393
429
|
* ): void {}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* During serialization, we write an arbitrary string key to the object with a value of an empty
|
|
3
3
|
* string. This is used during deserialization to instantiate the correct type of object.
|
|
4
4
|
*
|
|
5
|
-
* Note that we do not bother branding TSTL classes because we have no way to
|
|
5
|
+
* Note that we do not bother branding TSTL classes because we have no way to run the proper
|
|
6
6
|
* constructor during deserialization.
|
|
7
7
|
*/
|
|
8
8
|
export enum SerializationBrand {
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ActiveSlot,
|
|
3
3
|
CollectibleType,
|
|
4
|
+
DamageFlag,
|
|
5
|
+
EntityType,
|
|
4
6
|
GridCollisionClass,
|
|
5
7
|
GridEntityType,
|
|
6
8
|
ModCallback,
|
|
7
9
|
UseFlag,
|
|
8
10
|
} from "isaac-typescript-definitions";
|
|
9
11
|
import { game } from "../cachedClasses";
|
|
12
|
+
import { postGridEntityCustomBrokenFire } from "../callbacks/subscriptions/postGridEntityCustomBroken";
|
|
10
13
|
import { DefaultMap } from "../classes/DefaultMap";
|
|
11
14
|
import { ModUpgraded } from "../classes/ModUpgraded";
|
|
12
15
|
import { DecorationVariant } from "../enums/DecorationVariant";
|
|
13
16
|
import { ModCallbackCustom } from "../enums/ModCallbackCustom";
|
|
14
17
|
import { errorIfFeaturesNotInitialized } from "../featuresInitialized";
|
|
18
|
+
import { spawnNPC } from "../functions/entitiesSpecific";
|
|
19
|
+
import { hasFlag } from "../functions/flag";
|
|
15
20
|
import {
|
|
16
21
|
removeGridEntity,
|
|
17
22
|
spawnGridEntityWithVariant,
|
|
@@ -33,6 +38,7 @@ const v = {
|
|
|
33
38
|
},
|
|
34
39
|
|
|
35
40
|
room: {
|
|
41
|
+
dummyPtrHashes: new Set<PtrHash>(),
|
|
36
42
|
manuallyUsingShovel: false,
|
|
37
43
|
},
|
|
38
44
|
};
|
|
@@ -41,6 +47,12 @@ const v = {
|
|
|
41
47
|
export function customGridEntityInit(mod: ModUpgraded): void {
|
|
42
48
|
saveDataManager(FEATURE_NAME, v);
|
|
43
49
|
|
|
50
|
+
mod.AddCallback(
|
|
51
|
+
ModCallback.ENTITY_TAKE_DMG,
|
|
52
|
+
entityTakeDmgDummy,
|
|
53
|
+
EntityType.DUMMY,
|
|
54
|
+
); // 11
|
|
55
|
+
|
|
44
56
|
mod.AddCallback(
|
|
45
57
|
ModCallback.PRE_USE_ITEM,
|
|
46
58
|
preUseItemWeNeedToGoDeeper,
|
|
@@ -53,6 +65,51 @@ export function customGridEntityInit(mod: ModUpgraded): void {
|
|
|
53
65
|
);
|
|
54
66
|
}
|
|
55
67
|
|
|
68
|
+
// ModCallback.ENTITY_TAKE_DMG (11)
|
|
69
|
+
// EntityType.DUMMY (964)
|
|
70
|
+
function entityTakeDmgDummy(
|
|
71
|
+
tookDamage: Entity,
|
|
72
|
+
_damageAmount: float,
|
|
73
|
+
damageFlags: BitFlags<DamageFlag>,
|
|
74
|
+
_damageSource: EntityRef,
|
|
75
|
+
_damageCountdownFrames: int,
|
|
76
|
+
): boolean | undefined {
|
|
77
|
+
const ptrHash = GetPtrHash(tookDamage);
|
|
78
|
+
if (!v.room.dummyPtrHashes.has(ptrHash)) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!hasFlag(damageFlags, DamageFlag.EXPLOSION)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const room = game.GetRoom();
|
|
87
|
+
const roomListIndex = getRoomListIndex();
|
|
88
|
+
const roomCustomGridEntities = v.level.customGridEntities.get(roomListIndex);
|
|
89
|
+
if (roomCustomGridEntities === undefined) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const gridIndex = room.GetGridIndex(tookDamage.Position);
|
|
94
|
+
const data = roomCustomGridEntities.get(gridIndex);
|
|
95
|
+
if (data === undefined) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const gridEntity = room.GetGridEntity(gridIndex);
|
|
100
|
+
if (gridEntity === undefined) {
|
|
101
|
+
error(
|
|
102
|
+
`Failed to get the grid entity for a custom grid entity that broke at grid index: ${gridIndex}`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
postGridEntityCustomBrokenFire(gridEntity, data.gridEntityTypeCustom);
|
|
107
|
+
|
|
108
|
+
// Even though the custom grid entity is now broke, we do not want to remove it, as the end-user
|
|
109
|
+
// could intend for it to persist with different graphics.
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
56
113
|
// ModCallback.PRE_USE_ITEM (23)
|
|
57
114
|
// CollectibleType.WE_NEED_TO_GO_DEEPER (84)
|
|
58
115
|
function preUseItemWeNeedToGoDeeper(
|
|
@@ -161,6 +218,10 @@ function postNewRoomReordered() {
|
|
|
161
218
|
* @param defaultAnimation Optional. The name of the animation to play after the sprite is
|
|
162
219
|
* initialized and after the player re-enters a room with this grid entity
|
|
163
220
|
* in it. If not specified, the default animation in the anm2 will be used.
|
|
221
|
+
* @param breakable Optional. Whether or not an explosion will be able to break this grid entity.
|
|
222
|
+
* False by default. Use the `POST_GRID_ENTITY_CUSTOM_BROKEN` callback to detect
|
|
223
|
+
* when it breaks. Due to technical limitations, you can only set the grid entity
|
|
224
|
+
* to be breakable if it has a collision class.
|
|
164
225
|
*/
|
|
165
226
|
export function spawnCustomGridEntity(
|
|
166
227
|
gridEntityTypeCustom: GridEntityType,
|
|
@@ -168,9 +229,16 @@ export function spawnCustomGridEntity(
|
|
|
168
229
|
gridCollisionClass: GridCollisionClass,
|
|
169
230
|
anm2Path: string,
|
|
170
231
|
defaultAnimation?: string,
|
|
232
|
+
breakable = false,
|
|
171
233
|
): GridEntity {
|
|
172
234
|
errorIfFeaturesNotInitialized(FEATURE_NAME);
|
|
173
235
|
|
|
236
|
+
if (breakable && gridCollisionClass === GridCollisionClass.NONE) {
|
|
237
|
+
error(
|
|
238
|
+
"Failed to spawn a custom grid entity because it is not possible to have breakable custom grid entities with a collision class of: GridCollisionClass.NONE (0)",
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
174
242
|
const room = game.GetRoom();
|
|
175
243
|
const roomListIndex = getRoomListIndex();
|
|
176
244
|
const gridIndex = isVector(gridIndexOrPosition)
|
|
@@ -215,6 +283,14 @@ export function spawnCustomGridEntity(
|
|
|
215
283
|
v.level.customGridEntities.getAndSetDefault(roomListIndex);
|
|
216
284
|
roomCustomGridEntities.set(gridIndex, customGridEntityData);
|
|
217
285
|
|
|
286
|
+
// We check to see if an explosion touches a custom grid entity by spawning a Dummy on top, and
|
|
287
|
+
// the monitoring for explosions in the `ENTITY_TAKE_DMG` callback.
|
|
288
|
+
if (breakable) {
|
|
289
|
+
const position = room.GetGridPosition(gridIndex);
|
|
290
|
+
const dummy = spawnNPC(EntityType.DUMMY, 0, 0, position);
|
|
291
|
+
dummy.Visible = false;
|
|
292
|
+
}
|
|
293
|
+
|
|
218
294
|
return decoration;
|
|
219
295
|
}
|
|
220
296
|
|
|
@@ -228,8 +304,8 @@ export function spawnCustomGridEntity(
|
|
|
228
304
|
* Default is true. This is generally a good idea because if the room is not
|
|
229
305
|
* updated, you will be unable to spawn another grid entity on the same tile until
|
|
230
306
|
* a frame has passed. However, doing this is expensive, since it involves a call
|
|
231
|
-
* to `Isaac.GetRoomEntities`, so set it to false if you need to
|
|
232
|
-
*
|
|
307
|
+
* to `Isaac.GetRoomEntities`, so set it to false if you need to run this function
|
|
308
|
+
* multiple times.
|
|
233
309
|
* @returns The grid entity that was removed. Returns undefined if no grid entity was found at the
|
|
234
310
|
* given location or if the given grid entity was not a custom grid entity.
|
|
235
311
|
*/
|
|
@@ -24,9 +24,10 @@ export function enableExtraConsoleCommands(mod: ModUpgraded): void {
|
|
|
24
24
|
*
|
|
25
25
|
* The standard library comes with many existing console commands that are useful for debugging, but
|
|
26
26
|
* you can also add your own commands that are useful for your particular mod. It's easier to add
|
|
27
|
-
* commands to the existing command system than to add logic manually to the
|
|
27
|
+
* commands to the existing command system than to add your own logic manually to the `EXECUTE_CMD`
|
|
28
|
+
* callback.
|
|
28
29
|
*
|
|
29
|
-
* Before using this function, you must first
|
|
30
|
+
* Before using this function, you must first run the `enableExtraConsoleCommands` function.
|
|
30
31
|
*/
|
|
31
32
|
export function addConsoleCommand(
|
|
32
33
|
commandName: string,
|
|
@@ -59,7 +60,7 @@ export function addConsoleCommand(
|
|
|
59
60
|
* The standard library comes with many existing console commands that are useful for debugging. If
|
|
60
61
|
* you want to disable one of them, use this function.
|
|
61
62
|
*
|
|
62
|
-
* Before using this function, you must first
|
|
63
|
+
* Before using this function, you must first run the `enableExtraConsoleCommands` function.
|
|
63
64
|
*/
|
|
64
65
|
export function removeConsoleCommand(commandName: string): void {
|
|
65
66
|
if (!isExtraConsoleCommandsInitialized()) {
|
|
@@ -267,6 +267,7 @@ function initMap() {
|
|
|
267
267
|
"tearsDisplay",
|
|
268
268
|
commandsDisplay.tearsDisplay,
|
|
269
269
|
);
|
|
270
|
+
extraConsoleCommandsFunctionMap.set("tests", commands.tests);
|
|
270
271
|
extraConsoleCommandsFunctionMap.set("tntDisplay", commandsDisplay.tntDisplay);
|
|
271
272
|
extraConsoleCommandsFunctionMap.set(
|
|
272
273
|
"tntsDisplay",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* `enableExtraConsoleCommands`. (See the "Extra Console Commands (Init)" page for more details.)
|
|
16
16
|
*
|
|
17
17
|
* Each command has a corresponding function of the same name, but these functions are not actually
|
|
18
|
-
* exported for end-user consumption (
|
|
19
|
-
* names of the functions are not very descriptive)
|
|
18
|
+
* exported for end-user consumption. (This is to cut down on namespace conflicts and because the
|
|
19
|
+
* names of the functions are not very descriptive.)
|
|
20
20
|
*
|
|
21
21
|
* @module
|
|
22
22
|
*/
|
|
@@ -323,6 +323,10 @@ export function getCollectibleName(collectibleType: CollectibleType): string {
|
|
|
323
323
|
return DEFAULT_COLLECTIBLE_NAME;
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
/**
|
|
327
|
+
* Helper function to get the "pedestal type" of a collectible. For example, it might be sitting on
|
|
328
|
+
* top of a broken Blood Donation Machine, or it might be sitting on top of an opened Spiked Chest.
|
|
329
|
+
*/
|
|
326
330
|
export function getCollectiblePedestalType(
|
|
327
331
|
collectible: EntityPickup,
|
|
328
332
|
): CollectiblePedestalType {
|
|
@@ -338,8 +342,8 @@ export function getCollectiblePedestalType(
|
|
|
338
342
|
}
|
|
339
343
|
|
|
340
344
|
/**
|
|
341
|
-
* Helper function to get
|
|
342
|
-
* type was not valid.
|
|
345
|
+
* Helper function to get a collectible's quality. For example, Mom's Knife has a quality of 4.
|
|
346
|
+
* Returns 0 if the provided collectible type was not valid.
|
|
343
347
|
*/
|
|
344
348
|
export function getCollectibleQuality(collectibleType: CollectibleType): int {
|
|
345
349
|
const itemConfigItem = itemConfig.GetCollectible(collectibleType);
|