isaacscript-common 3.15.1 → 3.15.6
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/callbacks/postPlayerFatalDamage.lua +27 -1
- package/callbacks/postSlotDestroyed.lua +9 -7
- package/callbacks/subscriptions/postSlotDestroyed.d.ts +4 -2
- package/callbacks/subscriptions/postSlotDestroyed.lua +8 -4
- package/classes/DefaultMap.lua +6 -4
- package/enums/ModCallbackCustom.d.ts +10 -8
- package/enums/SlotDestructionType.d.ts +4 -0
- package/enums/SlotDestructionType.lua +7 -0
- package/features/deployJSONRoom.lua +62 -17
- package/features/saveDataManager/exports.lua +7 -6
- package/features/saveDataManager/load.lua +7 -5
- package/features/saveDataManager/main.lua +2 -2
- package/features/saveDataManager/merge.lua +12 -16
- package/features/saveDataManager/save.lua +2 -2
- package/features/saveDataManager/serializationBrand.lua +3 -1
- package/functions/array.d.ts +1 -0
- package/functions/array.lua +18 -12
- package/functions/color.lua +6 -7
- package/functions/deepCopy.lua +27 -24
- package/functions/deepCopyTests.lua +23 -27
- package/functions/entity.d.ts +4 -1
- package/functions/entity.lua +22 -25
- package/functions/enums.lua +3 -1
- package/functions/gridEntity.d.ts +3 -3
- package/functions/gridEntity.lua +7 -7
- package/functions/isaacAPIClass.lua +5 -3
- package/functions/jsonHelpers.d.ts +1 -1
- package/functions/jsonHelpers.lua +4 -4
- package/functions/kColor.lua +6 -7
- package/functions/log.d.ts +9 -2
- package/functions/log.lua +30 -21
- package/functions/rng.lua +10 -12
- package/functions/serialization.d.ts +1 -1
- package/functions/serialization.lua +9 -7
- package/functions/table.d.ts +14 -10
- package/functions/table.lua +54 -37
- package/functions/tstlClass.lua +6 -4
- package/functions/types.d.ts +10 -0
- package/functions/types.lua +25 -0
- package/functions/utils.d.ts +0 -2
- package/functions/utils.lua +0 -6
- package/functions/vector.lua +6 -7
- package/index.d.ts +1 -0
- package/index.lua +8 -0
- package/package.json +2 -2
package/functions/log.lua
CHANGED
|
@@ -5,6 +5,7 @@ local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
|
|
|
5
5
|
local Map = ____lualib.Map
|
|
6
6
|
local __TS__Spread = ____lualib.__TS__Spread
|
|
7
7
|
local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
8
|
+
local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
8
9
|
local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
|
|
9
10
|
local ____exports = {}
|
|
10
11
|
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
@@ -49,8 +50,13 @@ local getRoomListIndex = ____roomData.getRoomListIndex
|
|
|
49
50
|
local ____set = require("functions.set")
|
|
50
51
|
local combineSets = ____set.combineSets
|
|
51
52
|
local getSortedSetValues = ____set.getSortedSetValues
|
|
53
|
+
local ____table = require("functions.table")
|
|
54
|
+
local iterateTableInOrder = ____table.iterateTableInOrder
|
|
52
55
|
local ____trinkets = require("functions.trinkets")
|
|
53
56
|
local getTrinketName = ____trinkets.getTrinketName
|
|
57
|
+
local ____types = require("functions.types")
|
|
58
|
+
local isTable = ____types.isTable
|
|
59
|
+
local isUserdata = ____types.isUserdata
|
|
54
60
|
local ____utils = require("functions.utils")
|
|
55
61
|
local printConsole = ____utils.printConsole
|
|
56
62
|
local ____vector = require("functions.vector")
|
|
@@ -447,7 +453,12 @@ function ____exports.logSounds()
|
|
|
447
453
|
end
|
|
448
454
|
end
|
|
449
455
|
end
|
|
450
|
-
function
|
|
456
|
+
--- Helper function for logging every key and value of a table. This is a deep log; the function will
|
|
457
|
+
-- recursively call itself if it counters a table within a table.
|
|
458
|
+
--
|
|
459
|
+
-- This function will only work on tables that have string keys (because it logs the keys in order,
|
|
460
|
+
-- instead of randomly). It will throw a runtime error if it encounters a non-string key.
|
|
461
|
+
function ____exports.logTable(luaTable, parentTables)
|
|
451
462
|
if parentTables == nil then
|
|
452
463
|
parentTables = 0
|
|
453
464
|
end
|
|
@@ -459,31 +470,29 @@ function ____exports.logTable(____table, parentTables)
|
|
|
459
470
|
" ",
|
|
460
471
|
math.floor(numSpaces)
|
|
461
472
|
)
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
____exports.log(((indentation .. "n/a (encountered a variable of type \"") .. tableType) .. "\" instead of a table)")
|
|
473
|
+
if not isTable(nil, luaTable) then
|
|
474
|
+
____exports.log(((indentation .. "n/a (encountered a variable of type \"") .. __TS__TypeOf(luaTable)) .. "\" instead of a table)")
|
|
465
475
|
return
|
|
466
476
|
end
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
____exports.logTable(value, parentTables + 1)
|
|
477
|
+
iterateTableInOrder(
|
|
478
|
+
nil,
|
|
479
|
+
luaTable,
|
|
480
|
+
function(____, key, value)
|
|
481
|
+
____exports.log(((indentation .. tostring(key)) .. " --> ") .. tostring(value))
|
|
482
|
+
if isTable(nil, value) then
|
|
483
|
+
if key == "__class" then
|
|
484
|
+
____exports.log(indentation .. " (skipping enumerating this key to avoid infinite recursion)")
|
|
485
|
+
else
|
|
486
|
+
____exports.logTable(value, parentTables + 1)
|
|
487
|
+
end
|
|
479
488
|
end
|
|
480
489
|
end
|
|
481
|
-
|
|
482
|
-
____exports.log((indentation .. "The size of the table was: ") .. tostring(#
|
|
490
|
+
)
|
|
491
|
+
____exports.log((indentation .. "The size of the table was: ") .. tostring(#luaTable))
|
|
483
492
|
end
|
|
484
493
|
--- Helper function to print out the differences between the entries of two tables. Note that this
|
|
485
494
|
-- will only do a shallow comparison.
|
|
486
|
-
function ____exports.logTableDifferences(
|
|
495
|
+
function ____exports.logTableDifferences(table1, table2)
|
|
487
496
|
____exports.log("Comparing two Lua tables:")
|
|
488
497
|
local table1Keys = __TS__ObjectKeys(table1)
|
|
489
498
|
local table1KeysSet = __TS__New(Set, table1Keys)
|
|
@@ -517,8 +526,7 @@ end
|
|
|
517
526
|
--- Helper function to enumerate all of the properties of a "userdata" object (i.e. an object from
|
|
518
527
|
-- the Isaac API).
|
|
519
528
|
function ____exports.logUserdata(userdata)
|
|
520
|
-
|
|
521
|
-
if userdataType ~= "userdata" then
|
|
529
|
+
if isUserdata(nil, userdata) then
|
|
522
530
|
____exports.log("Userdata: [not userdata]")
|
|
523
531
|
return
|
|
524
532
|
end
|
|
@@ -569,6 +577,7 @@ function ____exports.setLogFunctionsGlobal(self)
|
|
|
569
577
|
globals.logSet = ____exports.logSet
|
|
570
578
|
globals.logSounds = ____exports.logSounds
|
|
571
579
|
globals.logTable = ____exports.logTable
|
|
580
|
+
globals.logTableDifferences = ____exports.logTableDifferences
|
|
572
581
|
globals.logTearFlags = ____exports.logTearFlags
|
|
573
582
|
globals.logUseFlags = ____exports.logUseFlags
|
|
574
583
|
globals.logUserdata = ____exports.logUserdata
|
package/functions/rng.lua
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
2
3
|
local __TS__ObjectValues = ____lualib.__TS__ObjectValues
|
|
3
4
|
local ____exports = {}
|
|
4
5
|
local RECOMMENDED_SHIFT_IDX, OBJECT_NAME
|
|
@@ -14,6 +15,8 @@ local isIsaacAPIClassOfType = ____isaacAPIClass.isIsaacAPIClassOfType
|
|
|
14
15
|
local ____table = require("functions.table")
|
|
15
16
|
local getNumbersFromTable = ____table.getNumbersFromTable
|
|
16
17
|
local tableHasKeys = ____table.tableHasKeys
|
|
18
|
+
local ____types = require("functions.types")
|
|
19
|
+
local isTable = ____types.isTable
|
|
17
20
|
local ____utils = require("functions.utils")
|
|
18
21
|
local ensureAllCases = ____utils.ensureAllCases
|
|
19
22
|
--- Helper function to get a random `Seed` value to be used in spawning entities and so on. Use this
|
|
@@ -86,8 +89,7 @@ function ____exports.copyRNG(self, rng, serializationType)
|
|
|
86
89
|
____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
|
|
87
90
|
if ____cond3 then
|
|
88
91
|
do
|
|
89
|
-
|
|
90
|
-
if ____exports.isRNG(nil, rng) or rngType ~= "table" then
|
|
92
|
+
if not isTable(nil, rng) then
|
|
91
93
|
error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
|
|
92
94
|
end
|
|
93
95
|
local seedNumber = table.unpack(getNumbersFromTable(
|
|
@@ -110,16 +112,14 @@ end
|
|
|
110
112
|
--- Used to determine is the given table is a serialized `RNG` object created by the save data
|
|
111
113
|
-- manager and/or the `deepCopy` function.
|
|
112
114
|
function ____exports.isSerializedRNG(self, object)
|
|
113
|
-
|
|
114
|
-
if objectType ~= "table" then
|
|
115
|
+
if not isTable(nil, object) then
|
|
115
116
|
return false
|
|
116
117
|
end
|
|
117
|
-
local ____table = object
|
|
118
118
|
return tableHasKeys(
|
|
119
119
|
nil,
|
|
120
|
-
|
|
120
|
+
object,
|
|
121
121
|
table.unpack(KEYS)
|
|
122
|
-
) and
|
|
122
|
+
) and object[SerializationBrand.RNG] ~= nil
|
|
123
123
|
end
|
|
124
124
|
function ____exports.rngEquals(self, rng1, rng2)
|
|
125
125
|
return isaacAPIClassEquals(nil, rng1, rng2, KEYS)
|
|
@@ -127,12 +127,10 @@ end
|
|
|
127
127
|
--- Helper function to iterate over the provided object and set the seed for all of the values that
|
|
128
128
|
-- are RNG objects equal to a particular seed.
|
|
129
129
|
function ____exports.setAllRNGToSeed(self, object, seed)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
error("Failed to iterate over the object containing RNG objects since the type of the provided object was: " .. objectType)
|
|
130
|
+
if not isTable(nil, object) then
|
|
131
|
+
error("Failed to iterate over the object containing RNG objects since the type of the provided object was: " .. __TS__TypeOf(object))
|
|
133
132
|
end
|
|
134
|
-
|
|
135
|
-
for ____, value in ipairs(__TS__ObjectValues(____table)) do
|
|
133
|
+
for ____, value in ipairs(__TS__ObjectValues(table)) do
|
|
136
134
|
if ____exports.isRNG(nil, value) then
|
|
137
135
|
____exports.setSeed(nil, value, seed)
|
|
138
136
|
end
|
|
@@ -5,7 +5,7 @@ export declare function copyIsaacAPIClass(isaacAPIClass: unknown, serializationT
|
|
|
5
5
|
* Deserialization is a special case, so we make a dedicated function for this.
|
|
6
6
|
*
|
|
7
7
|
* There is no need for a corresponding "serializeIsaacAPIClass" function because the
|
|
8
|
-
* "copyIsaacAPIClass" function can
|
|
8
|
+
* "copyIsaacAPIClass" function can handle all serialization types.
|
|
9
9
|
*/
|
|
10
10
|
export declare function deserializeIsaacAPIClass(serializedIsaacAPIClass: SerializedIsaacAPIClass): unknown;
|
|
11
11
|
export declare function isSerializedIsaacAPIClass(object: unknown): object is SerializedIsaacAPIClass;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
2
3
|
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
|
|
3
4
|
local __TS__ObjectValues = ____lualib.__TS__ObjectValues
|
|
4
5
|
local __TS__ArraySome = ____lualib.__TS__ArraySome
|
|
@@ -14,6 +15,9 @@ local ____serializedIsaacAPIClassTypeToIdentityFunction = require("objects.seria
|
|
|
14
15
|
local SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION = ____serializedIsaacAPIClassTypeToIdentityFunction.SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION
|
|
15
16
|
local ____isaacAPIClass = require("functions.isaacAPIClass")
|
|
16
17
|
local getIsaacAPIClassName = ____isaacAPIClass.getIsaacAPIClassName
|
|
18
|
+
local ____types = require("functions.types")
|
|
19
|
+
local isTable = ____types.isTable
|
|
20
|
+
local isUserdata = ____types.isUserdata
|
|
17
21
|
function getSerializedTableType(self, serializedIsaacAPIClass)
|
|
18
22
|
for ____, ____value in ipairs(__TS__ObjectEntries(ISAAC_API_CLASS_TYPE_TO_BRAND)) do
|
|
19
23
|
local copyableIsaacAPIClassType = ____value[1]
|
|
@@ -25,9 +29,8 @@ function getSerializedTableType(self, serializedIsaacAPIClass)
|
|
|
25
29
|
return nil
|
|
26
30
|
end
|
|
27
31
|
function ____exports.copyIsaacAPIClass(self, isaacAPIClass, serializationType)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
error("Failed to copy an Isaac API class since the provided object was of type: " .. objectType)
|
|
32
|
+
if not isUserdata(nil, isaacAPIClass) then
|
|
33
|
+
error("Failed to copy an Isaac API class since the provided object was of type: " .. __TS__TypeOf(isaacAPIClass))
|
|
31
34
|
end
|
|
32
35
|
local isaacAPIClassType = getIsaacAPIClassName(nil, isaacAPIClass)
|
|
33
36
|
if isaacAPIClassType == nil then
|
|
@@ -43,11 +46,10 @@ end
|
|
|
43
46
|
--- Deserialization is a special case, so we make a dedicated function for this.
|
|
44
47
|
--
|
|
45
48
|
-- There is no need for a corresponding "serializeIsaacAPIClass" function because the
|
|
46
|
-
-- "copyIsaacAPIClass" function can
|
|
49
|
+
-- "copyIsaacAPIClass" function can handle all serialization types.
|
|
47
50
|
function ____exports.deserializeIsaacAPIClass(self, serializedIsaacAPIClass)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
error("Failed to deserialize an Isaac API class since the provided object was of type: " .. objectType)
|
|
51
|
+
if not isTable(nil, serializedIsaacAPIClass) then
|
|
52
|
+
error("Failed to deserialize an Isaac API class since the provided object was of type: " .. __TS__TypeOf(serializedIsaacAPIClass))
|
|
51
53
|
end
|
|
52
54
|
local copyableIsaacAPIClassType = getSerializedTableType(nil, serializedIsaacAPIClass)
|
|
53
55
|
if copyableIsaacAPIClassType == nil then
|
package/functions/table.d.ts
CHANGED
|
@@ -3,46 +3,50 @@
|
|
|
3
3
|
* In a Map, you can use the `clear` method to delete every element. However, in a LuaTable, the
|
|
4
4
|
* `clear` method does not exist. Use this helper function as a drop-in replacement for this.
|
|
5
5
|
*/
|
|
6
|
-
export declare function clearTable(
|
|
6
|
+
export declare function clearTable(luaTable: LuaTable): void;
|
|
7
7
|
/** Helper function to copy specific values from a object to a table. */
|
|
8
|
-
export declare function copyValuesToTable(object: unknown, keys: string[],
|
|
8
|
+
export declare function copyValuesToTable(object: unknown, keys: string[], luaTable: LuaTable<string, unknown>): void;
|
|
9
9
|
/**
|
|
10
10
|
* Helper function to safely get boolean values from a Lua table. Will throw an error if the
|
|
11
11
|
* specific value does not exist on the table.
|
|
12
12
|
*
|
|
13
13
|
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
14
14
|
*/
|
|
15
|
-
export declare function getBooleansFromTable(
|
|
15
|
+
export declare function getBooleansFromTable(luaTable: LuaTable<string, unknown>, objectName: string, ...keys: string[]): boolean[];
|
|
16
16
|
/**
|
|
17
17
|
* Helper function to safely get number values from a Lua table. Will throw an error if the specific
|
|
18
18
|
* value does not exist on the table or if it cannot be converted to a number.
|
|
19
19
|
*
|
|
20
20
|
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
21
21
|
*/
|
|
22
|
-
export declare function getNumbersFromTable(
|
|
22
|
+
export declare function getNumbersFromTable(luaTable: LuaTable<string, unknown>, objectName: string, ...keys: string[]): number[];
|
|
23
23
|
/**
|
|
24
24
|
* Helper function to safely get string values from a Lua table. Will throw an error if the specific
|
|
25
25
|
* value does not exist on the table.
|
|
26
26
|
*
|
|
27
27
|
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
28
28
|
*/
|
|
29
|
-
export declare function getStringsFromTable(
|
|
29
|
+
export declare function getStringsFromTable(luaTable: LuaTable<string, unknown>, objectName: string, ...keys: string[]): string[];
|
|
30
30
|
/**
|
|
31
31
|
* Helper function to iterate over a table deterministically. This is useful because by default, the
|
|
32
32
|
* `pairs` function will return the keys of a Lua table in a random order.
|
|
33
33
|
*
|
|
34
34
|
* This function will sort the table entries based on the value of the key.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
36
|
+
* This function will only work on tables that have number keys or string keys. It will throw a
|
|
37
|
+
* runtime error if it encounters a key of another type.
|
|
38
|
+
*
|
|
39
|
+
* @param luaTable The table to iterate over.
|
|
37
40
|
* @param func The function to run for each iteration.
|
|
38
|
-
* @param
|
|
39
|
-
*
|
|
41
|
+
* @param inOrder Optional. Whether to iterate in order. True by default. You can dynamically set to
|
|
42
|
+
* false in situations where iterating randomly would not matter and you need the
|
|
43
|
+
* extra performance.
|
|
40
44
|
*/
|
|
41
|
-
export declare function
|
|
45
|
+
export declare function iterateTableInOrder<K, V>(luaTable: LuaTable<K, V>, func: (key: K, value: V) => void, inOrder?: boolean): void;
|
|
42
46
|
/**
|
|
43
47
|
* Helper function to check if a Lua table has all of the provided keys.
|
|
44
48
|
*
|
|
45
49
|
* This function is variadic, meaning that you can specify as many arguments as you want to check
|
|
46
50
|
* for.
|
|
47
51
|
*/
|
|
48
|
-
export declare function tableHasKeys(
|
|
52
|
+
export declare function tableHasKeys(luaTable: LuaTable<AnyNotNil, unknown>, ...keys: string[]): boolean;
|
package/functions/table.lua
CHANGED
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
3
|
-
local
|
|
3
|
+
local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
|
|
4
4
|
local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
|
|
5
|
+
local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
5
6
|
local ____exports = {}
|
|
6
|
-
local
|
|
7
|
-
local
|
|
7
|
+
local ____types = require("functions.types")
|
|
8
|
+
local isBoolean = ____types.isBoolean
|
|
9
|
+
local isNumber = ____types.isNumber
|
|
10
|
+
local isString = ____types.isString
|
|
8
11
|
--- In a Map, you can use the `clear` method to delete every element. However, in a LuaTable, the
|
|
9
12
|
-- `clear` method does not exist. Use this helper function as a drop-in replacement for this.
|
|
10
|
-
function ____exports.clearTable(self,
|
|
11
|
-
for key in pairs(
|
|
12
|
-
|
|
13
|
+
function ____exports.clearTable(self, luaTable)
|
|
14
|
+
for key in pairs(luaTable) do
|
|
15
|
+
luaTable[key] = nil
|
|
13
16
|
end
|
|
14
17
|
end
|
|
15
18
|
--- Helper function to copy specific values from a object to a table.
|
|
16
|
-
function ____exports.copyValuesToTable(self, object, keys,
|
|
19
|
+
function ____exports.copyValuesToTable(self, object, keys, luaTable)
|
|
17
20
|
local otherTable = object
|
|
18
21
|
for ____, key in ipairs(keys) do
|
|
19
22
|
local value = otherTable[key]
|
|
20
|
-
|
|
23
|
+
luaTable[key] = value
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
--- Helper function to safely get boolean values from a Lua table. Will throw an error if the
|
|
24
27
|
-- specific value does not exist on the table.
|
|
25
28
|
--
|
|
26
29
|
-- This function is variadic, meaning that you can specify N arguments to get N values.
|
|
27
|
-
function ____exports.getBooleansFromTable(self,
|
|
30
|
+
function ____exports.getBooleansFromTable(self, luaTable, objectName, ...)
|
|
28
31
|
local keys = {...}
|
|
29
32
|
local booleans = {}
|
|
30
33
|
for ____, key in ipairs(keys) do
|
|
31
|
-
local value =
|
|
34
|
+
local value = luaTable[key]
|
|
32
35
|
if value == nil then
|
|
33
36
|
error(((("Failed to find a value for \"" .. key) .. "\" in a table representing a \"") .. objectName) .. "\" object.")
|
|
34
37
|
end
|
|
35
|
-
if
|
|
38
|
+
if isBoolean(nil, value) then
|
|
36
39
|
booleans[#booleans + 1] = value
|
|
37
40
|
else
|
|
38
41
|
error((((("Failed to get the boolean for the \"" .. key) .. "\" value of a table representing a \"") .. objectName) .. "\" object because the type was: ") .. __TS__TypeOf(value))
|
|
@@ -44,17 +47,17 @@ end
|
|
|
44
47
|
-- value does not exist on the table or if it cannot be converted to a number.
|
|
45
48
|
--
|
|
46
49
|
-- This function is variadic, meaning that you can specify N arguments to get N values.
|
|
47
|
-
function ____exports.getNumbersFromTable(self,
|
|
50
|
+
function ____exports.getNumbersFromTable(self, luaTable, objectName, ...)
|
|
48
51
|
local keys = {...}
|
|
49
52
|
local numbers = {}
|
|
50
53
|
for ____, key in ipairs(keys) do
|
|
51
|
-
local value =
|
|
54
|
+
local value = luaTable[key]
|
|
52
55
|
if value == nil then
|
|
53
56
|
error(((("Failed to find a value for \"" .. key) .. "\" in a table representing a \"") .. objectName) .. "\" object.")
|
|
54
57
|
end
|
|
55
|
-
if
|
|
58
|
+
if isNumber(nil, value) then
|
|
56
59
|
numbers[#numbers + 1] = value
|
|
57
|
-
elseif
|
|
60
|
+
elseif isString(nil, value) then
|
|
58
61
|
local number = tonumber(value)
|
|
59
62
|
if number == nil then
|
|
60
63
|
error((((("Failed to convert the \"" .. key) .. "\" value of a table representing a \"") .. objectName) .. "\" object to a number: ") .. value)
|
|
@@ -70,15 +73,15 @@ end
|
|
|
70
73
|
-- value does not exist on the table.
|
|
71
74
|
--
|
|
72
75
|
-- This function is variadic, meaning that you can specify N arguments to get N values.
|
|
73
|
-
function ____exports.getStringsFromTable(self,
|
|
76
|
+
function ____exports.getStringsFromTable(self, luaTable, objectName, ...)
|
|
74
77
|
local keys = {...}
|
|
75
78
|
local strings = {}
|
|
76
79
|
for ____, key in ipairs(keys) do
|
|
77
|
-
local value =
|
|
80
|
+
local value = luaTable[key]
|
|
78
81
|
if value == nil then
|
|
79
82
|
error(((("Failed to find a value for \"" .. key) .. "\" in a table representing a \"") .. objectName) .. "\" object.")
|
|
80
83
|
end
|
|
81
|
-
if
|
|
84
|
+
if isString(nil, value) then
|
|
82
85
|
strings[#strings + 1] = value
|
|
83
86
|
else
|
|
84
87
|
local ____string = tostring(value)
|
|
@@ -92,41 +95,55 @@ end
|
|
|
92
95
|
--
|
|
93
96
|
-- This function will sort the table entries based on the value of the key.
|
|
94
97
|
--
|
|
95
|
-
--
|
|
98
|
+
-- This function will only work on tables that have number keys or string keys. It will throw a
|
|
99
|
+
-- runtime error if it encounters a key of another type.
|
|
100
|
+
--
|
|
101
|
+
-- @param luaTable The table to iterate over.
|
|
96
102
|
-- @param func The function to run for each iteration.
|
|
97
|
-
-- @param
|
|
98
|
-
--
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
-- @param inOrder Optional. Whether to iterate in order. True by default. You can dynamically set to
|
|
104
|
+
-- false in situations where iterating randomly would not matter and you need the
|
|
105
|
+
-- extra performance.
|
|
106
|
+
function ____exports.iterateTableInOrder(self, luaTable, func, inOrder)
|
|
107
|
+
if inOrder == nil then
|
|
108
|
+
inOrder = true
|
|
102
109
|
end
|
|
103
|
-
if not
|
|
104
|
-
for key, value in pairs(
|
|
110
|
+
if not inOrder then
|
|
111
|
+
for key, value in pairs(luaTable) do
|
|
105
112
|
func(nil, key, value)
|
|
106
113
|
end
|
|
107
114
|
return
|
|
108
115
|
end
|
|
109
|
-
local
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
local keys = __TS__ObjectKeys(luaTable)
|
|
117
|
+
local hasAllNumberKeys = __TS__ArrayEvery(
|
|
118
|
+
keys,
|
|
119
|
+
function(____, key) return isNumber(nil, key) end
|
|
120
|
+
)
|
|
121
|
+
local hasAllStringKeys = __TS__ArrayEvery(
|
|
122
|
+
keys,
|
|
123
|
+
function(____, key) return isString(nil, key) end
|
|
124
|
+
)
|
|
125
|
+
if not hasAllNumberKeys and not hasAllStringKeys then
|
|
126
|
+
for key, value in pairs(luaTable) do
|
|
127
|
+
func(nil, key, value)
|
|
128
|
+
end
|
|
129
|
+
return
|
|
113
130
|
end
|
|
114
|
-
__TS__ArraySort(
|
|
115
|
-
for ____,
|
|
116
|
-
local
|
|
117
|
-
local value =
|
|
118
|
-
func(nil,
|
|
131
|
+
__TS__ArraySort(keys)
|
|
132
|
+
for ____, key in ipairs(keys) do
|
|
133
|
+
local keyIndex = key
|
|
134
|
+
local value = luaTable[keyIndex]
|
|
135
|
+
func(nil, keyIndex, value)
|
|
119
136
|
end
|
|
120
137
|
end
|
|
121
138
|
--- Helper function to check if a Lua table has all of the provided keys.
|
|
122
139
|
--
|
|
123
140
|
-- This function is variadic, meaning that you can specify as many arguments as you want to check
|
|
124
141
|
-- for.
|
|
125
|
-
function ____exports.tableHasKeys(self,
|
|
142
|
+
function ____exports.tableHasKeys(self, luaTable, ...)
|
|
126
143
|
local keys = {...}
|
|
127
144
|
return __TS__ArrayEvery(
|
|
128
145
|
keys,
|
|
129
|
-
function(____, key) return
|
|
146
|
+
function(____, key) return luaTable[key] ~= nil end
|
|
130
147
|
)
|
|
131
148
|
end
|
|
132
149
|
return ____exports
|
package/functions/tstlClass.lua
CHANGED
|
@@ -3,6 +3,9 @@ local Set = ____lualib.Set
|
|
|
3
3
|
local __TS__New = ____lualib.__TS__New
|
|
4
4
|
local ____exports = {}
|
|
5
5
|
local newTSTLClassFromMetatable, VANILLA_TSTL_CLASSES
|
|
6
|
+
local ____types = require("functions.types")
|
|
7
|
+
local isString = ____types.isString
|
|
8
|
+
local isTable = ____types.isTable
|
|
6
9
|
--- Helper function to get the name of a TypeScriptToLua class. TSTL classes are Lua tables created
|
|
7
10
|
-- with the `__TS__Class` Lua function from the TSTL lualib. Their name is contained within
|
|
8
11
|
-- "constructor.name" metatable key.
|
|
@@ -12,7 +15,7 @@ local newTSTLClassFromMetatable, VANILLA_TSTL_CLASSES
|
|
|
12
15
|
-- Returns undefined if the object is not a table or if the aforementioned metatable key does not
|
|
13
16
|
-- exist.
|
|
14
17
|
function ____exports.getTSTLClassName(self, object)
|
|
15
|
-
if
|
|
18
|
+
if not isTable(nil, object) then
|
|
16
19
|
return nil
|
|
17
20
|
end
|
|
18
21
|
local metatable = getmetatable(object)
|
|
@@ -76,8 +79,7 @@ function ____exports.isUserDefinedTSTLClass(self, object)
|
|
|
76
79
|
if ____exports.isVanillaTSTLClass(nil, object) or ____exports.isIsaacScriptCommonClass(nil, object) then
|
|
77
80
|
return false
|
|
78
81
|
end
|
|
79
|
-
|
|
80
|
-
if objectType ~= "table" then
|
|
82
|
+
if not isTable(nil, object) then
|
|
81
83
|
return false
|
|
82
84
|
end
|
|
83
85
|
local metatable = getmetatable(object)
|
|
@@ -87,7 +89,7 @@ function ____exports.isUserDefinedTSTLClass(self, object)
|
|
|
87
89
|
local numKeys = 0
|
|
88
90
|
for key in pairs(metatable) do
|
|
89
91
|
numKeys = numKeys + 1
|
|
90
|
-
if
|
|
92
|
+
if not isString(nil, key) then
|
|
91
93
|
return false
|
|
92
94
|
end
|
|
93
95
|
if not TSTL_CLASS_METATABLE_KEYS:has(key) then
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="typescript-to-lua/language-extensions" />
|
|
2
|
+
/// <reference types="lua-types/5.3" />
|
|
3
|
+
export declare function isBoolean(variable: unknown): variable is boolean;
|
|
4
|
+
export declare function isFunction(variable: unknown): variable is Function;
|
|
5
|
+
export declare function isNumber(variable: unknown): variable is number;
|
|
6
|
+
/** Helper function to detect if a variable is a boolean, number, or string. */
|
|
7
|
+
export declare function isPrimitive(variable: unknown): variable is boolean | number | string;
|
|
8
|
+
export declare function isString(variable: unknown): variable is string;
|
|
9
|
+
export declare function isTable(variable: unknown): variable is LuaTable;
|
|
10
|
+
export declare function isUserdata(variable: unknown): variable is LuaUserdata;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
local ____exports = {}
|
|
2
|
+
function ____exports.isBoolean(self, variable)
|
|
3
|
+
return type(variable) == "boolean"
|
|
4
|
+
end
|
|
5
|
+
function ____exports.isFunction(self, variable)
|
|
6
|
+
return type(variable) == "function"
|
|
7
|
+
end
|
|
8
|
+
function ____exports.isNumber(self, variable)
|
|
9
|
+
return type(variable) == "number"
|
|
10
|
+
end
|
|
11
|
+
--- Helper function to detect if a variable is a boolean, number, or string.
|
|
12
|
+
function ____exports.isPrimitive(self, variable)
|
|
13
|
+
local variableType = type(variable)
|
|
14
|
+
return variableType == "boolean" or variableType == "number" or variableType == "string"
|
|
15
|
+
end
|
|
16
|
+
function ____exports.isString(self, variable)
|
|
17
|
+
return type(variable) == "string"
|
|
18
|
+
end
|
|
19
|
+
function ____exports.isTable(self, variable)
|
|
20
|
+
return type(variable) == "table"
|
|
21
|
+
end
|
|
22
|
+
function ____exports.isUserdata(self, variable)
|
|
23
|
+
return type(variable) == "userdata"
|
|
24
|
+
end
|
|
25
|
+
return ____exports
|
package/functions/utils.d.ts
CHANGED
|
@@ -66,8 +66,6 @@ export declare function hexToKColor(hexString: string, alpha: float): KColor;
|
|
|
66
66
|
* If only one argument is specified, then it will assume that the start is 0.
|
|
67
67
|
*/
|
|
68
68
|
export declare function irange(start: int, end?: int): int[];
|
|
69
|
-
/** Helper function to detect if a variable is a boolean, number, or string. */
|
|
70
|
-
export declare function isPrimitive(variable: unknown): boolean;
|
|
71
69
|
/**
|
|
72
70
|
* Since this is a UI element, we do not want to draw it in water reflections. `renderOffset` will
|
|
73
71
|
* be a non-zero value in reflections.
|
package/functions/utils.lua
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__StringReplace = ____lualib.__TS__StringReplace
|
|
3
3
|
local __TS__StringSubstr = ____lualib.__TS__StringSubstr
|
|
4
|
-
local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
5
4
|
local ____exports = {}
|
|
6
5
|
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
7
6
|
local RenderMode = ____isaac_2Dtypescript_2Ddefinitions.RenderMode
|
|
@@ -120,11 +119,6 @@ function ____exports.irange(self, start, ____end)
|
|
|
120
119
|
end
|
|
121
120
|
return array
|
|
122
121
|
end
|
|
123
|
-
--- Helper function to detect if a variable is a boolean, number, or string.
|
|
124
|
-
function ____exports.isPrimitive(self, variable)
|
|
125
|
-
local ____type = __TS__TypeOf(variable)
|
|
126
|
-
return ____type == "boolean" or ____type == "number" or ____type == "string"
|
|
127
|
-
end
|
|
128
122
|
--- Since this is a UI element, we do not want to draw it in water reflections. `renderOffset` will
|
|
129
123
|
-- be a non-zero value in reflections.
|
|
130
124
|
function ____exports.isReflectionRender(self)
|
package/functions/vector.lua
CHANGED
|
@@ -13,6 +13,8 @@ local ____table = require("functions.table")
|
|
|
13
13
|
local copyValuesToTable = ____table.copyValuesToTable
|
|
14
14
|
local getNumbersFromTable = ____table.getNumbersFromTable
|
|
15
15
|
local tableHasKeys = ____table.tableHasKeys
|
|
16
|
+
local ____types = require("functions.types")
|
|
17
|
+
local isTable = ____types.isTable
|
|
16
18
|
local ____utils = require("functions.utils")
|
|
17
19
|
local ensureAllCases = ____utils.ensureAllCases
|
|
18
20
|
--- Helper function to check if something is an instantiated Vector object.
|
|
@@ -56,8 +58,7 @@ function ____exports.copyVector(self, vector, serializationType)
|
|
|
56
58
|
____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
|
|
57
59
|
if ____cond3 then
|
|
58
60
|
do
|
|
59
|
-
|
|
60
|
-
if ____exports.isVector(nil, vector) or vectorType ~= "table" then
|
|
61
|
+
if not isTable(nil, vector) then
|
|
61
62
|
error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
|
|
62
63
|
end
|
|
63
64
|
local x, y = table.unpack(getNumbersFromTable(
|
|
@@ -85,16 +86,14 @@ end
|
|
|
85
86
|
--- Used to determine is the given table is a serialized `Vector` object created by the save data
|
|
86
87
|
-- manager and/or the `deepCopy` function.
|
|
87
88
|
function ____exports.isSerializedVector(self, object)
|
|
88
|
-
|
|
89
|
-
if objectType ~= "table" then
|
|
89
|
+
if not isTable(nil, object) then
|
|
90
90
|
return false
|
|
91
91
|
end
|
|
92
|
-
local ____table = object
|
|
93
92
|
return tableHasKeys(
|
|
94
93
|
nil,
|
|
95
|
-
|
|
94
|
+
object,
|
|
96
95
|
table.unpack(KEYS)
|
|
97
|
-
) and
|
|
96
|
+
) and object[SerializationBrand.VECTOR] ~= nil
|
|
98
97
|
end
|
|
99
98
|
function ____exports.vectorEquals(self, vector1, vector2)
|
|
100
99
|
return isaacAPIClassEquals(nil, vector1, vector2, KEYS)
|
package/index.d.ts
CHANGED
|
@@ -108,6 +108,7 @@ export * from "./functions/trinketCacheFlag";
|
|
|
108
108
|
export * from "./functions/trinketGive";
|
|
109
109
|
export * from "./functions/trinkets";
|
|
110
110
|
export * from "./functions/tstlClass";
|
|
111
|
+
export * from "./functions/types";
|
|
111
112
|
export * from "./functions/ui";
|
|
112
113
|
export * from "./functions/utils";
|
|
113
114
|
export * from "./functions/vector";
|
package/index.lua
CHANGED
|
@@ -854,6 +854,14 @@ do
|
|
|
854
854
|
end
|
|
855
855
|
end
|
|
856
856
|
end
|
|
857
|
+
do
|
|
858
|
+
local ____export = require("functions.types")
|
|
859
|
+
for ____exportKey, ____exportValue in pairs(____export) do
|
|
860
|
+
if ____exportKey ~= "default" then
|
|
861
|
+
____exports[____exportKey] = ____exportValue
|
|
862
|
+
end
|
|
863
|
+
end
|
|
864
|
+
end
|
|
857
865
|
do
|
|
858
866
|
local ____export = require("functions.ui")
|
|
859
867
|
for ____exportKey, ____exportValue in pairs(____export) do
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "3.15.
|
|
3
|
+
"version": "3.15.6",
|
|
4
4
|
"description": "Helper functions and features for IsaacScript mods.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"main": "index",
|
|
23
23
|
"types": "index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"isaac-typescript-definitions": "^2.2.
|
|
25
|
+
"isaac-typescript-definitions": "^2.2.3"
|
|
26
26
|
}
|
|
27
27
|
}
|