isaacscript-common 9.19.3 → 10.0.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/index.d.ts +8 -6
- package/dist/isaacscript-common.lua +83 -55
- package/dist/lualib_bundle.lua +53 -37
- package/dist/package.lua +2 -2
- package/dist/src/features/saveDataManager/load.d.ts +1 -1
- package/dist/src/features/saveDataManager/maps.d.ts +1 -1
- package/dist/src/features/saveDataManager/merge.d.ts +1 -1
- package/dist/src/features/saveDataManager/save.d.ts +1 -1
- package/dist/src/functions/bitSet128.d.ts +1 -1
- package/dist/src/functions/bitSet128.d.ts.map +1 -1
- package/dist/src/functions/bitSet128.lua +2 -2
- package/dist/src/functions/color.d.ts +1 -1
- package/dist/src/functions/color.d.ts.map +1 -1
- package/dist/src/functions/color.lua +2 -2
- package/dist/src/functions/entities.d.ts +1 -1
- package/dist/src/functions/globals.d.ts +1 -1
- package/dist/src/functions/jsonHelpers.d.ts +1 -1
- package/dist/src/functions/kColor.d.ts +1 -1
- package/dist/src/functions/kColor.d.ts.map +1 -1
- package/dist/src/functions/kColor.lua +2 -2
- package/dist/src/functions/log.d.ts +2 -2
- package/dist/src/functions/log.d.ts.map +1 -1
- package/dist/src/functions/positionVelocity.d.ts +3 -1
- package/dist/src/functions/positionVelocity.d.ts.map +1 -1
- package/dist/src/functions/positionVelocity.lua +9 -1
- package/dist/src/functions/rng.d.ts +1 -1
- package/dist/src/functions/table.d.ts +4 -4
- package/dist/src/functions/table.d.ts.map +1 -1
- package/dist/src/functions/table.lua +8 -4
- package/dist/src/functions/tstlClass.d.ts +1 -1
- package/dist/src/functions/types.d.ts +1 -1
- package/dist/src/functions/vector.d.ts +1 -1
- package/dist/src/functions/vector.d.ts.map +1 -1
- package/dist/src/functions/vector.lua +2 -2
- package/dist/src/interfaces/private/TSTLClassMetatable.d.ts +1 -1
- package/dist/src/types/SerializedIsaacAPIClass.d.ts +1 -1
- package/dist/src/types/TSTLClass.d.ts +1 -1
- package/package.json +2 -2
- package/src/functions/bitSet128.ts +6 -2
- package/src/functions/color.ts +6 -2
- package/src/functions/kColor.ts +6 -2
- package/src/functions/log.ts +8 -6
- package/src/functions/positionVelocity.ts +10 -0
- package/src/functions/table.ts +15 -6
- package/src/functions/vector.ts +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.1",
|
|
4
4
|
"description": "Helper functions and features for IsaacScript mods.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"main": "dist/src/index",
|
|
23
23
|
"types": "dist/src/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"isaac-typescript-definitions": "^
|
|
25
|
+
"isaac-typescript-definitions": "^7.0.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { SerializationBrand } from "../enums/private/SerializationBrand";
|
|
2
2
|
import { isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
copyUserdataValuesToTable,
|
|
5
|
+
getNumbersFromTable,
|
|
6
|
+
tableHasKeys,
|
|
7
|
+
} from "./table";
|
|
4
8
|
import { isTable } from "./types";
|
|
5
9
|
|
|
6
10
|
export type SerializedBitSet128 = LuaMap<string, unknown> & {
|
|
@@ -86,7 +90,7 @@ export function serializeBitSet128(bitSet128: BitSet128): SerializedBitSet128 {
|
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
const bitSet128Table = new LuaMap<string, unknown>();
|
|
89
|
-
|
|
93
|
+
copyUserdataValuesToTable(bitSet128, KEYS, bitSet128Table);
|
|
90
94
|
bitSet128Table.set(SerializationBrand.BIT_SET_128, "");
|
|
91
95
|
return bitSet128Table as SerializedBitSet128;
|
|
92
96
|
}
|
package/src/functions/color.ts
CHANGED
|
@@ -2,7 +2,11 @@ import { SerializationBrand } from "../enums/private/SerializationBrand";
|
|
|
2
2
|
import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
3
3
|
import { getRandom } from "./random";
|
|
4
4
|
import { getRandomSeed, isRNG, newRNG } from "./rng";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
copyUserdataValuesToTable,
|
|
7
|
+
getNumbersFromTable,
|
|
8
|
+
tableHasKeys,
|
|
9
|
+
} from "./table";
|
|
6
10
|
import { isTable } from "./types";
|
|
7
11
|
|
|
8
12
|
export type SerializedColor = LuaMap<string, unknown> & {
|
|
@@ -120,7 +124,7 @@ export function serializeColor(color: Color): SerializedColor {
|
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
const colorTable = new LuaMap<string, unknown>();
|
|
123
|
-
|
|
127
|
+
copyUserdataValuesToTable(color, KEYS, colorTable);
|
|
124
128
|
colorTable.set(SerializationBrand.COLOR, "");
|
|
125
129
|
return colorTable as SerializedColor;
|
|
126
130
|
}
|
package/src/functions/kColor.ts
CHANGED
|
@@ -2,7 +2,11 @@ import { SerializationBrand } from "../enums/private/SerializationBrand";
|
|
|
2
2
|
import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
3
3
|
import { getRandom } from "./random";
|
|
4
4
|
import { getRandomSeed, isRNG, newRNG } from "./rng";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
copyUserdataValuesToTable,
|
|
7
|
+
getNumbersFromTable,
|
|
8
|
+
tableHasKeys,
|
|
9
|
+
} from "./table";
|
|
6
10
|
import { isTable } from "./types";
|
|
7
11
|
|
|
8
12
|
export type SerializedKColor = LuaMap<string, unknown> & {
|
|
@@ -117,7 +121,7 @@ export function serializeKColor(kColor: KColor): SerializedKColor {
|
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
const kColorTable = new LuaMap<string, unknown>();
|
|
120
|
-
|
|
124
|
+
copyUserdataValuesToTable(kColor, KEYS, kColorTable);
|
|
121
125
|
kColorTable.set(SerializationBrand.K_COLOR, "");
|
|
122
126
|
return kColorTable as SerializedKColor;
|
|
123
127
|
}
|
package/src/functions/log.ts
CHANGED
|
@@ -402,7 +402,7 @@ export function logTable(luaTable: unknown, parentTables = 0): void {
|
|
|
402
402
|
* Helper function to print out the differences between the entries of two tables. Note that this
|
|
403
403
|
* will only do a shallow comparison.
|
|
404
404
|
*/
|
|
405
|
-
export function logTableDifferences<K, V>(
|
|
405
|
+
export function logTableDifferences<K extends AnyNotNil, V>(
|
|
406
406
|
table1: LuaMap<K, V>,
|
|
407
407
|
table2: LuaMap<K, V>,
|
|
408
408
|
): void {
|
|
@@ -420,13 +420,17 @@ export function logTableDifferences<K, V>(
|
|
|
420
420
|
|
|
421
421
|
for (const key of keys) {
|
|
422
422
|
if (!table1KeysSet.has(key)) {
|
|
423
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
423
424
|
log(` Table 1 is missing key: ${key}`);
|
|
424
425
|
} else if (!table2KeysSet.has(key)) {
|
|
426
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
425
427
|
log(` Table 2 is missing key: ${key}`);
|
|
426
428
|
} else {
|
|
427
|
-
const value1 = table1.get(key
|
|
428
|
-
|
|
429
|
+
const value1 = table1.get(key);
|
|
430
|
+
|
|
431
|
+
const value2 = table2.get(key);
|
|
429
432
|
if (value1 !== value2) {
|
|
433
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
430
434
|
log(` ${key} --> "${value1}" versus "${value2}"`);
|
|
431
435
|
}
|
|
432
436
|
}
|
|
@@ -453,9 +457,7 @@ export function logUserdata(userdata: unknown): void {
|
|
|
453
457
|
return;
|
|
454
458
|
}
|
|
455
459
|
|
|
456
|
-
const metatable = getmetatable(userdata)
|
|
457
|
-
| LuaMap<AnyNotNil, unknown>
|
|
458
|
-
| undefined;
|
|
460
|
+
const metatable = getmetatable(userdata);
|
|
459
461
|
if (metatable === undefined) {
|
|
460
462
|
log("Userdata: [no metatable]");
|
|
461
463
|
return;
|
|
@@ -47,10 +47,13 @@ export function anyPlayerCloserThan(
|
|
|
47
47
|
* @param startingPosition The position to start searching from. If this position is not overlapping
|
|
48
48
|
* with anything, then it will be returned.
|
|
49
49
|
* @param avoidActiveEntities Optional. Default is false.
|
|
50
|
+
* @param minimumDistance Optional. If specified, will ensure that the randomly generated position
|
|
51
|
+
* is equal to or greater than the distance provided.
|
|
50
52
|
*/
|
|
51
53
|
export function findFreePosition(
|
|
52
54
|
startingPosition: Vector,
|
|
53
55
|
avoidActiveEntities = false,
|
|
56
|
+
minimumDistance?: float,
|
|
54
57
|
): Vector {
|
|
55
58
|
const room = game.GetRoom();
|
|
56
59
|
const heavenDoors = getEffects(
|
|
@@ -79,6 +82,13 @@ export function findFreePosition(
|
|
|
79
82
|
continue;
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
if (minimumDistance !== undefined) {
|
|
86
|
+
const distance = startingPosition.Distance(position);
|
|
87
|
+
if (distance < minimumDistance) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
82
92
|
return position;
|
|
83
93
|
}
|
|
84
94
|
|
package/src/functions/table.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBoolean, isNumber, isString } from "./types";
|
|
1
|
+
import { isBoolean, isNumber, isString, isUserdata } from "./types";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* In a `Map`, you can use the `clear` method to delete every element. However, in a `LuaMap`, the
|
|
@@ -10,16 +10,25 @@ export function clearTable(luaMap: LuaMap<AnyNotNil, unknown>): void {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
/** Helper function to copy specific values from a object to a table. */
|
|
14
|
-
export function
|
|
13
|
+
/** Helper function to copy specific values from a userdata object (e.g. `Vector`) to a table. */
|
|
14
|
+
export function copyUserdataValuesToTable(
|
|
15
15
|
object: unknown,
|
|
16
16
|
keys: string[],
|
|
17
17
|
luaMap: LuaMap<string, unknown>,
|
|
18
18
|
): void {
|
|
19
|
-
|
|
19
|
+
if (!isUserdata(object)) {
|
|
20
|
+
error(
|
|
21
|
+
`Failed to copy an object values to a table, since the object was of type: ${type(
|
|
22
|
+
object,
|
|
23
|
+
)}`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// We can access values on userdata objects similar to a normal table.
|
|
28
|
+
const userdata = object as unknown as LuaMap<AnyNotNil, unknown>;
|
|
20
29
|
|
|
21
30
|
for (const key of keys) {
|
|
22
|
-
const value =
|
|
31
|
+
const value = userdata.get(key);
|
|
23
32
|
luaMap.set(key, value);
|
|
24
33
|
}
|
|
25
34
|
}
|
|
@@ -142,7 +151,7 @@ export function getStringsFromTable(
|
|
|
142
151
|
* false in situations where iterating randomly would not matter and you need the
|
|
143
152
|
* extra performance.
|
|
144
153
|
*/
|
|
145
|
-
export function iterateTableInOrder<K, V>(
|
|
154
|
+
export function iterateTableInOrder<K extends AnyNotNil, V>(
|
|
146
155
|
luaMap: LuaMap<K, V>,
|
|
147
156
|
func: (key: K, value: V) => void,
|
|
148
157
|
inOrder = true,
|
package/src/functions/vector.ts
CHANGED
|
@@ -4,7 +4,11 @@ import { angleToDirection } from "./direction";
|
|
|
4
4
|
import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
5
5
|
import { getRandomFloat } from "./random";
|
|
6
6
|
import { getRandomSeed, isRNG, newRNG } from "./rng";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
copyUserdataValuesToTable,
|
|
9
|
+
getNumbersFromTable,
|
|
10
|
+
tableHasKeys,
|
|
11
|
+
} from "./table";
|
|
8
12
|
import { isTable } from "./types";
|
|
9
13
|
|
|
10
14
|
export type SerializedVector = LuaMap<string, unknown> & {
|
|
@@ -104,7 +108,7 @@ export function serializeVector(vector: Vector): SerializedVector {
|
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
const vectorTable = new LuaMap<string, unknown>();
|
|
107
|
-
|
|
111
|
+
copyUserdataValuesToTable(vector, KEYS, vectorTable);
|
|
108
112
|
vectorTable.set(SerializationBrand.VECTOR, "");
|
|
109
113
|
return vectorTable as SerializedVector;
|
|
110
114
|
}
|