isaacscript-common 1.2.201 → 1.2.204
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/classes/ModUpgraded.d.ts +1 -3
- package/dist/classes/ModUpgraded.lua +2 -36
- package/dist/enums/private/SerializationBrand.d.ts +2 -0
- package/dist/enums/private/SerializationBrand.lua +2 -0
- package/dist/features/deployJSONRoom.d.ts +6 -12
- package/dist/features/deployJSONRoom.lua +17 -19
- package/dist/features/saveDataManager/merge.d.ts +12 -3
- package/dist/features/saveDataManager/merge.lua +16 -11
- package/dist/functions/array.d.ts +7 -7
- package/dist/functions/array.lua +22 -23
- package/dist/functions/cards.d.ts +6 -7
- package/dist/functions/cards.lua +14 -14
- package/dist/functions/color.d.ts +20 -1
- package/dist/functions/color.lua +89 -10
- package/dist/functions/deepCopy.d.ts +8 -12
- package/dist/functions/deepCopy.lua +13 -29
- package/dist/functions/doors.d.ts +4 -0
- package/dist/functions/doors.lua +12 -2
- package/dist/functions/entity.lua +4 -4
- package/dist/functions/jsonRoom.d.ts +1 -1
- package/dist/functions/jsonRoom.lua +6 -5
- package/dist/functions/map.d.ts +0 -12
- package/dist/functions/map.lua +0 -23
- package/dist/functions/random.d.ts +25 -31
- package/dist/functions/random.lua +34 -33
- package/dist/functions/rng.d.ts +45 -0
- package/dist/functions/rng.lua +106 -0
- package/dist/functions/roomData.d.ts +5 -0
- package/dist/functions/roomData.lua +31 -4
- package/dist/functions/set.d.ts +2 -2
- package/dist/functions/set.lua +6 -6
- package/dist/functions/spawnCollectible.d.ts +3 -3
- package/dist/functions/spawnCollectible.lua +11 -12
- package/dist/functions/table.d.ts +30 -0
- package/dist/functions/table.lua +73 -1
- package/dist/functions/utils.d.ts +5 -0
- package/dist/functions/utils.lua +12 -0
- package/dist/functions/vector.d.ts +24 -3
- package/dist/functions/vector.lua +72 -21
- package/dist/index.d.ts +1 -0
- package/dist/index.lua +8 -0
- package/dist/objects/roomShapeToDoorSlots.d.ts +4 -0
- package/dist/objects/roomShapeToDoorSlots.lua +44 -0
- package/dist/upgradeMod.d.ts +1 -3
- package/dist/upgradeMod.lua +2 -5
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
2
|
+
local ____exports = {}
|
|
3
|
+
local RECOMMENDED_SHIFT_IDX, OBJECT_NAME
|
|
4
|
+
local ____SerializationBrand = require("enums.private.SerializationBrand")
|
|
5
|
+
local SerializationBrand = ____SerializationBrand.SerializationBrand
|
|
6
|
+
local ____SerializationType = require("enums.SerializationType")
|
|
7
|
+
local SerializationType = ____SerializationType.SerializationType
|
|
8
|
+
local ____table = require("functions.table")
|
|
9
|
+
local getNumbersFromTable = ____table.getNumbersFromTable
|
|
10
|
+
local tableHasKeys = ____table.tableHasKeys
|
|
11
|
+
local ____utils = require("functions.utils")
|
|
12
|
+
local ensureAllCases = ____utils.ensureAllCases
|
|
13
|
+
local isUserdataObject = ____utils.isUserdataObject
|
|
14
|
+
function ____exports.getRandomSeed(self)
|
|
15
|
+
local randomNumber = Random()
|
|
16
|
+
local safeRandomNumber = randomNumber == 0 and 1 or randomNumber
|
|
17
|
+
return safeRandomNumber
|
|
18
|
+
end
|
|
19
|
+
function ____exports.isRNG(self, object)
|
|
20
|
+
return isUserdataObject(nil, object, OBJECT_NAME)
|
|
21
|
+
end
|
|
22
|
+
function ____exports.newRNG(self, seed)
|
|
23
|
+
if seed == nil then
|
|
24
|
+
seed = ____exports.getRandomSeed(nil)
|
|
25
|
+
end
|
|
26
|
+
if seed == 0 then
|
|
27
|
+
error("You cannot initialize an RNG object with a seed of 0, or the game will crash.")
|
|
28
|
+
end
|
|
29
|
+
local rng = RNG()
|
|
30
|
+
rng:SetSeed(seed, RECOMMENDED_SHIFT_IDX)
|
|
31
|
+
return rng
|
|
32
|
+
end
|
|
33
|
+
RECOMMENDED_SHIFT_IDX = 35
|
|
34
|
+
local KEYS = {"seed"}
|
|
35
|
+
OBJECT_NAME = "RNG"
|
|
36
|
+
function ____exports.copyRNG(self, rng, serializationType)
|
|
37
|
+
if serializationType == nil then
|
|
38
|
+
serializationType = SerializationType.NONE
|
|
39
|
+
end
|
|
40
|
+
repeat
|
|
41
|
+
local ____switch3 = serializationType
|
|
42
|
+
local ____cond3 = ____switch3 == SerializationType.NONE
|
|
43
|
+
if ____cond3 then
|
|
44
|
+
do
|
|
45
|
+
if not ____exports.isRNG(nil, rng) then
|
|
46
|
+
error(((("Failed to copy a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
|
|
47
|
+
end
|
|
48
|
+
local seed = rng:GetSeed()
|
|
49
|
+
return ____exports.newRNG(nil, seed)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
____cond3 = ____cond3 or ____switch3 == SerializationType.SERIALIZE
|
|
53
|
+
if ____cond3 then
|
|
54
|
+
do
|
|
55
|
+
if not ____exports.isRNG(nil, rng) then
|
|
56
|
+
error(((("Failed to serialize a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
|
|
57
|
+
end
|
|
58
|
+
local seed = rng:GetSeed()
|
|
59
|
+
local rngTable = {}
|
|
60
|
+
rngTable.seed = seed
|
|
61
|
+
rngTable[SerializationBrand.RNG] = ""
|
|
62
|
+
return rngTable
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
|
|
66
|
+
if ____cond3 then
|
|
67
|
+
do
|
|
68
|
+
local rngType = type(rng)
|
|
69
|
+
if ____exports.isRNG(nil, rng) or rngType ~= "table" then
|
|
70
|
+
error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
|
|
71
|
+
end
|
|
72
|
+
local seedNumber = table.unpack(getNumbersFromTable(
|
|
73
|
+
nil,
|
|
74
|
+
rng,
|
|
75
|
+
OBJECT_NAME,
|
|
76
|
+
table.unpack(KEYS)
|
|
77
|
+
))
|
|
78
|
+
local seed = seedNumber
|
|
79
|
+
return ____exports.newRNG(nil, seed)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
do
|
|
83
|
+
do
|
|
84
|
+
return ensureAllCases(nil, serializationType)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
until true
|
|
88
|
+
end
|
|
89
|
+
function ____exports.isSerializedRNG(self, object)
|
|
90
|
+
local objectType = type(object)
|
|
91
|
+
if objectType ~= "table" then
|
|
92
|
+
return false
|
|
93
|
+
end
|
|
94
|
+
local ____table = object
|
|
95
|
+
return tableHasKeys(
|
|
96
|
+
nil,
|
|
97
|
+
____table,
|
|
98
|
+
table.unpack(KEYS)
|
|
99
|
+
) and ____table[SerializationBrand.RNG] ~= nil
|
|
100
|
+
end
|
|
101
|
+
function ____exports.nextSeed(self, seed)
|
|
102
|
+
local rng = ____exports.newRNG(nil, seed)
|
|
103
|
+
rng:Next()
|
|
104
|
+
return rng:GetSeed()
|
|
105
|
+
end
|
|
106
|
+
return ____exports
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
* `RoomDescriptor` object that you are retrieving.
|
|
5
5
|
*/
|
|
6
6
|
export declare function getCurrentRoomDescriptorReadOnly(): RoomDescriptorReadOnly;
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to get the set of allowed door slots for the room at the supplied grid index.
|
|
9
|
+
* This corresponds to the doors that are enabled in the STB/XML file for the room.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getRoomAllowedDoors(roomGridIndex?: int): Set<DoorSlot>;
|
|
7
12
|
/**
|
|
8
13
|
* Helper function to get the room data for the provided room.
|
|
9
14
|
*
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local Set = ____lualib.Set
|
|
3
|
+
local __TS__New = ____lualib.__TS__New
|
|
2
4
|
local ____exports = {}
|
|
3
5
|
local ____cachedClasses = require("cachedClasses")
|
|
4
6
|
local game = ____cachedClasses.game
|
|
7
|
+
local ____flag = require("functions.flag")
|
|
8
|
+
local hasFlag = ____flag.hasFlag
|
|
9
|
+
local ____utils = require("functions.utils")
|
|
10
|
+
local getEnumValues = ____utils.getEnumValues
|
|
5
11
|
function ____exports.getCurrentRoomDescriptorReadOnly(self)
|
|
6
12
|
local level = game:GetLevel()
|
|
7
13
|
return level:GetCurrentRoomDesc()
|
|
8
14
|
end
|
|
15
|
+
function ____exports.getRoomData(self, roomGridIndex)
|
|
16
|
+
local roomDescriptor = ____exports.getRoomDescriptor(nil, roomGridIndex)
|
|
17
|
+
return roomDescriptor.Data
|
|
18
|
+
end
|
|
9
19
|
function ____exports.getRoomDescriptor(self, roomGridIndex)
|
|
10
20
|
local level = game:GetLevel()
|
|
11
21
|
if roomGridIndex == nil then
|
|
@@ -22,9 +32,26 @@ function ____exports.getRoomGridIndex(self)
|
|
|
22
32
|
local roomDescriptor = ____exports.getCurrentRoomDescriptorReadOnly(nil)
|
|
23
33
|
return roomDescriptor.SafeGridIndex
|
|
24
34
|
end
|
|
25
|
-
function ____exports.
|
|
26
|
-
local
|
|
27
|
-
|
|
35
|
+
function ____exports.getRoomAllowedDoors(self, roomGridIndex)
|
|
36
|
+
local allowedDoors = __TS__New(Set)
|
|
37
|
+
local roomData = ____exports.getRoomData(nil, roomGridIndex)
|
|
38
|
+
if roomData == nil then
|
|
39
|
+
return allowedDoors
|
|
40
|
+
end
|
|
41
|
+
local doorSlots = getEnumValues(nil, DoorSlot)
|
|
42
|
+
for ____, doorSlot in ipairs(doorSlots) do
|
|
43
|
+
do
|
|
44
|
+
if doorSlot == DoorSlot.NO_DOOR_SLOT or doorSlot == DoorSlot.NUM_DOOR_SLOTS then
|
|
45
|
+
goto __continue5
|
|
46
|
+
end
|
|
47
|
+
local doorSlotFlag = 1 << doorSlot
|
|
48
|
+
if hasFlag(nil, roomData.Doors, doorSlotFlag) then
|
|
49
|
+
allowedDoors:add(doorSlot)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
::__continue5::
|
|
53
|
+
end
|
|
54
|
+
return allowedDoors
|
|
28
55
|
end
|
|
29
56
|
function ____exports.getRoomListIndex(self, roomGridIndex)
|
|
30
57
|
local roomDescriptor = ____exports.getRoomDescriptor(nil, roomGridIndex)
|
package/dist/functions/set.d.ts
CHANGED
|
@@ -25,10 +25,10 @@ export declare function deleteSetsFromSet<T>(mainSet: Set<T>, ...setsToRemove: A
|
|
|
25
25
|
* Helper function to get a random element from the provided set.
|
|
26
26
|
*
|
|
27
27
|
* @param set The set to get an element from.
|
|
28
|
-
* @param
|
|
28
|
+
* @param rng Optional. The RNG object used to select the random element. Default is `newRNG()`.
|
|
29
29
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
30
30
|
*/
|
|
31
|
-
export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>,
|
|
31
|
+
export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>, rng?: RNG, exceptions?: T[] | readonly T[]): T;
|
|
32
32
|
/**
|
|
33
33
|
* Helper function to get a sorted array based on the contents of a set.
|
|
34
34
|
*
|
package/dist/functions/set.lua
CHANGED
|
@@ -7,8 +7,8 @@ local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
|
7
7
|
local ____exports = {}
|
|
8
8
|
local ____array = require("functions.array")
|
|
9
9
|
local getRandomArrayElement = ____array.getRandomArrayElement
|
|
10
|
-
local
|
|
11
|
-
local
|
|
10
|
+
local ____rng = require("functions.rng")
|
|
11
|
+
local newRNG = ____rng.newRNG
|
|
12
12
|
function ____exports.getSortedSetValues(self, set)
|
|
13
13
|
local values = set:values()
|
|
14
14
|
local array = {__TS__Spread(values)}
|
|
@@ -48,14 +48,14 @@ function ____exports.deleteSetsFromSet(self, mainSet, ...)
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
|
-
function ____exports.getRandomSetElement(self, set,
|
|
52
|
-
if
|
|
53
|
-
|
|
51
|
+
function ____exports.getRandomSetElement(self, set, rng, exceptions)
|
|
52
|
+
if rng == nil then
|
|
53
|
+
rng = newRNG(nil)
|
|
54
54
|
end
|
|
55
55
|
if exceptions == nil then
|
|
56
56
|
exceptions = {}
|
|
57
57
|
end
|
|
58
58
|
local array = ____exports.getSortedSetValues(nil, set)
|
|
59
|
-
return getRandomArrayElement(nil, array,
|
|
59
|
+
return getRandomArrayElement(nil, array, rng, exceptions)
|
|
60
60
|
end
|
|
61
61
|
return ____exports
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @param collectibleType The collectible type to spawn.
|
|
9
9
|
* @param position The position to spawn the collectible at.
|
|
10
|
-
* @param
|
|
10
|
+
* @param rng Optional. Default is `newRNG()`.
|
|
11
11
|
* @param options Optional. Set to true to make the collectible a "There's Options" style
|
|
12
12
|
* collectible. Default is false.
|
|
13
13
|
* @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
|
|
14
14
|
* Tainted Keeper. Default is false.
|
|
15
15
|
*/
|
|
16
|
-
export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector,
|
|
16
|
+
export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector, rng?: RNG, options?: boolean, forceFreeItem?: boolean): EntityPickup;
|
|
17
17
|
/**
|
|
18
18
|
* Helper function to spawn an empty collectible. Doing this is tricky since spawning a collectible
|
|
19
19
|
* with `CollectibleType.COLLECTIBLE_NULL` will result in spawning a collectible with a random type
|
|
@@ -22,4 +22,4 @@ export declare function spawnCollectible(collectibleType: CollectibleType | int,
|
|
|
22
22
|
* Instead, this function arbitrarily spawns a collectible with
|
|
23
23
|
* `CollectibleType.COLLECTIBLE_SAD_ONION`, and then converts it to an empty pedestal afterward.
|
|
24
24
|
*/
|
|
25
|
-
export declare function spawnEmptyCollectible(position: Vector,
|
|
25
|
+
export declare function spawnEmptyCollectible(position: Vector, rng?: RNG): EntityPickup;
|
|
@@ -11,11 +11,11 @@ local isQuestCollectible = ____collectibles.isQuestCollectible
|
|
|
11
11
|
local setCollectibleEmpty = ____collectibles.setCollectibleEmpty
|
|
12
12
|
local ____player = require("functions.player")
|
|
13
13
|
local anyPlayerIs = ____player.anyPlayerIs
|
|
14
|
-
local
|
|
15
|
-
local
|
|
16
|
-
function ____exports.spawnCollectible(self, collectibleType, position,
|
|
17
|
-
if
|
|
18
|
-
|
|
14
|
+
local ____rng = require("functions.rng")
|
|
15
|
+
local newRNG = ____rng.newRNG
|
|
16
|
+
function ____exports.spawnCollectible(self, collectibleType, position, rng, options, forceFreeItem)
|
|
17
|
+
if rng == nil then
|
|
18
|
+
rng = newRNG(nil)
|
|
19
19
|
end
|
|
20
20
|
if options == nil then
|
|
21
21
|
options = false
|
|
@@ -23,9 +23,8 @@ function ____exports.spawnCollectible(self, collectibleType, position, seed, opt
|
|
|
23
23
|
if forceFreeItem == nil then
|
|
24
24
|
forceFreeItem = false
|
|
25
25
|
end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
end
|
|
26
|
+
rng:Next()
|
|
27
|
+
local seed = rng:GetSeed()
|
|
29
28
|
local collectible = game:Spawn(
|
|
30
29
|
EntityType.ENTITY_PICKUP,
|
|
31
30
|
100,
|
|
@@ -50,15 +49,15 @@ function ____exports.spawnCollectible(self, collectibleType, position, seed, opt
|
|
|
50
49
|
end
|
|
51
50
|
return collectible
|
|
52
51
|
end
|
|
53
|
-
function ____exports.spawnEmptyCollectible(self, position,
|
|
54
|
-
if
|
|
55
|
-
|
|
52
|
+
function ____exports.spawnEmptyCollectible(self, position, rng)
|
|
53
|
+
if rng == nil then
|
|
54
|
+
rng = newRNG(nil)
|
|
56
55
|
end
|
|
57
56
|
local collectible = ____exports.spawnCollectible(
|
|
58
57
|
nil,
|
|
59
58
|
CollectibleType.COLLECTIBLE_SAD_ONION,
|
|
60
59
|
position,
|
|
61
|
-
|
|
60
|
+
rng,
|
|
62
61
|
false,
|
|
63
62
|
true
|
|
64
63
|
)
|
|
@@ -4,3 +4,33 @@
|
|
|
4
4
|
* `clear` method does not exist. Use this helper function as a drop-in replacement for this.
|
|
5
5
|
*/
|
|
6
6
|
export declare function clearTable(table: LuaTable): void;
|
|
7
|
+
/** Helper function to copy specific values from a object to a table. */
|
|
8
|
+
export declare function copyValuesToTable(object: unknown, keys: string[], table: LuaTable<string, string | number>): void;
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to safely get boolean values from a Lua table. Will throw an error if the
|
|
11
|
+
* specific value does not exist on the table.
|
|
12
|
+
*
|
|
13
|
+
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getBooleansFromTable(table: LuaTable<string, string | number>, objectName: string, ...keys: string[]): boolean[];
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to safely get number values from a Lua table. Will throw an error if the specific
|
|
18
|
+
* value does not exist on the table or if it cannot be converted to a number.
|
|
19
|
+
*
|
|
20
|
+
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getNumbersFromTable(table: LuaTable<string, string | number>, objectName: string, ...keys: string[]): number[];
|
|
23
|
+
/**
|
|
24
|
+
* Helper function to safely get string values from a Lua table. Will throw an error if the specific
|
|
25
|
+
* value does not exist on the table.
|
|
26
|
+
*
|
|
27
|
+
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getStringsFromTable(table: LuaTable<string, string | number>, objectName: string, ...keys: string[]): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Helper function to check if a Lua table has all of the provided keys.
|
|
32
|
+
*
|
|
33
|
+
* This function is variadic, meaning that you can specify as many arguments as you want to check
|
|
34
|
+
* for.
|
|
35
|
+
*/
|
|
36
|
+
export declare function tableHasKeys(table: LuaTable, ...keys: string[]): boolean;
|
package/dist/functions/table.lua
CHANGED
|
@@ -1,8 +1,80 @@
|
|
|
1
|
-
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__ArrayPush = ____lualib.__TS__ArrayPush
|
|
3
|
+
local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
4
|
+
local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
|
|
2
5
|
local ____exports = {}
|
|
3
6
|
function ____exports.clearTable(self, ____table)
|
|
4
7
|
for key in pairs(____table) do
|
|
5
8
|
____table[key] = nil
|
|
6
9
|
end
|
|
7
10
|
end
|
|
11
|
+
function ____exports.copyValuesToTable(self, object, keys, ____table)
|
|
12
|
+
local otherTable = object
|
|
13
|
+
for ____, key in ipairs(keys) do
|
|
14
|
+
local value = otherTable[key]
|
|
15
|
+
____table[key] = value
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
function ____exports.getBooleansFromTable(self, ____table, objectName, ...)
|
|
19
|
+
local keys = {...}
|
|
20
|
+
local booleans = {}
|
|
21
|
+
for ____, key in ipairs(keys) do
|
|
22
|
+
local value = ____table[key]
|
|
23
|
+
if value == nil then
|
|
24
|
+
error(((("Failed to find a value for \"" .. key) .. "\" in a table representing a \"") .. objectName) .. "\" object.")
|
|
25
|
+
end
|
|
26
|
+
if type(value) == "boolean" then
|
|
27
|
+
__TS__ArrayPush(booleans, value)
|
|
28
|
+
else
|
|
29
|
+
error((((("Failed to get the boolean for the \"" .. key) .. "\" value of a table representing a \"") .. objectName) .. "\" object because the type was: ") .. __TS__TypeOf(value))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
return booleans
|
|
33
|
+
end
|
|
34
|
+
function ____exports.getNumbersFromTable(self, ____table, objectName, ...)
|
|
35
|
+
local keys = {...}
|
|
36
|
+
local numbers = {}
|
|
37
|
+
for ____, key in ipairs(keys) do
|
|
38
|
+
local value = ____table[key]
|
|
39
|
+
if value == nil then
|
|
40
|
+
error(((("Failed to find a value for \"" .. key) .. "\" in a table representing a \"") .. objectName) .. "\" object.")
|
|
41
|
+
end
|
|
42
|
+
if type(value) == "number" then
|
|
43
|
+
__TS__ArrayPush(numbers, value)
|
|
44
|
+
elseif type(value) == "string" then
|
|
45
|
+
local number = tonumber(value)
|
|
46
|
+
if number == nil then
|
|
47
|
+
error((((("Failed to convert the \"" .. key) .. "\" value of a table representing a \"") .. objectName) .. "\" object to a number: ") .. value)
|
|
48
|
+
end
|
|
49
|
+
__TS__ArrayPush(numbers, number)
|
|
50
|
+
else
|
|
51
|
+
error((((("Failed to get the number for the \"" .. key) .. "\" value of a table representing a \"") .. objectName) .. "\" object because the type was: ") .. __TS__TypeOf(value))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
return numbers
|
|
55
|
+
end
|
|
56
|
+
function ____exports.getStringsFromTable(self, ____table, objectName, ...)
|
|
57
|
+
local keys = {...}
|
|
58
|
+
local strings = {}
|
|
59
|
+
for ____, key in ipairs(keys) do
|
|
60
|
+
local value = ____table[key]
|
|
61
|
+
if value == nil then
|
|
62
|
+
error(((("Failed to find a value for \"" .. key) .. "\" in a table representing a \"") .. objectName) .. "\" object.")
|
|
63
|
+
end
|
|
64
|
+
if type(value) == "string" then
|
|
65
|
+
__TS__ArrayPush(strings, value)
|
|
66
|
+
else
|
|
67
|
+
local ____string = tostring(value)
|
|
68
|
+
__TS__ArrayPush(strings, ____string)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
return strings
|
|
72
|
+
end
|
|
73
|
+
function ____exports.tableHasKeys(self, ____table, ...)
|
|
74
|
+
local keys = {...}
|
|
75
|
+
return __TS__ArrayEvery(
|
|
76
|
+
keys,
|
|
77
|
+
function(____, key) return ____table[key] ~= nil end
|
|
78
|
+
)
|
|
79
|
+
end
|
|
8
80
|
return ____exports
|
|
@@ -93,6 +93,11 @@ export declare function hexToKColor(hexString: string, alpha: float): KColor;
|
|
|
93
93
|
* is enabled or not.
|
|
94
94
|
*/
|
|
95
95
|
export declare function isLuaDebugEnabled(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Helper function to check if the something is an instantiated class from the Isaac API. (All
|
|
98
|
+
* classes from the Isaac API have a type of "userdata" in Lua.)
|
|
99
|
+
*/
|
|
100
|
+
export declare function isUserdataObject(object: unknown, objectName: string): boolean;
|
|
96
101
|
/**
|
|
97
102
|
* Helper function to print something to the in-game console. Use this instead of invoking the
|
|
98
103
|
* `Isaac.ConsoleOutput` method directly because it will automatically insert a newline at the end
|
package/dist/functions/utils.lua
CHANGED
|
@@ -66,6 +66,18 @@ end
|
|
|
66
66
|
function ____exports.isLuaDebugEnabled(self)
|
|
67
67
|
return package ~= nil
|
|
68
68
|
end
|
|
69
|
+
function ____exports.isUserdataObject(self, object, objectName)
|
|
70
|
+
local objectType = type(object)
|
|
71
|
+
if objectType ~= "userdata" then
|
|
72
|
+
return false
|
|
73
|
+
end
|
|
74
|
+
local metatable = getmetatable(object)
|
|
75
|
+
if metatable == nil then
|
|
76
|
+
return false
|
|
77
|
+
end
|
|
78
|
+
local vectorMetatable = metatable
|
|
79
|
+
return vectorMetatable.__type == objectName
|
|
80
|
+
end
|
|
69
81
|
function ____exports.printConsole(self, msg)
|
|
70
82
|
Isaac.ConsoleOutput(msg .. "\n")
|
|
71
83
|
end
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
/// <reference types="isaac-typescript-definitions" />
|
|
2
2
|
/// <reference types="typescript-to-lua/language-extensions" />
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { SerializationType } from "../enums/SerializationType";
|
|
4
|
+
declare type SerializedVector = LuaTable<string, string | number>;
|
|
5
|
+
interface CopyVectorReturn {
|
|
6
|
+
[SerializationType.NONE]: Vector;
|
|
7
|
+
[SerializationType.SERIALIZE]: SerializedVector;
|
|
8
|
+
[SerializationType.DESERIALIZE]: Vector;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to copy a `Vector` object.
|
|
12
|
+
*
|
|
13
|
+
* @param vector The vector to copy. In the case of deserialization, this will actually be a Lua
|
|
14
|
+
* table instead of an instantiated Vector class.
|
|
15
|
+
* @param serializationType Default is `SerializationType.NONE`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function copyVector<V extends Vector | SerializedVector, S extends SerializationType>(vector: V, serializationType: S): CopyVectorReturn[S];
|
|
18
|
+
export declare function copyVector<V extends Vector | SerializedVector>(vector: V): CopyVectorReturn[SerializationType.NONE];
|
|
5
19
|
export declare function directionToVector(direction: Direction): Vector;
|
|
6
20
|
/**
|
|
7
21
|
* Helper function to get a new vector of length 1. Using this is safer than using the `Vector.One`
|
|
@@ -13,6 +27,13 @@ export declare function getOneVector(): Vector;
|
|
|
13
27
|
* variable because the variable can be overwritten or modified.
|
|
14
28
|
*/
|
|
15
29
|
export declare function getZeroVector(): Vector;
|
|
16
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Used to determine is the given table is a serialized Vector created by the save data manager
|
|
32
|
+
* and/or the `deepCopy` function.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isSerializedVector(object: unknown): object is SerializedVector;
|
|
35
|
+
/** Helper function to check if something is an instantiated Vector object. */
|
|
36
|
+
export declare function isVector(object: unknown): object is Vector;
|
|
17
37
|
/** Helper function for finding out which way a vector is pointing. */
|
|
18
38
|
export declare function vectorToDirection(vector: Vector): Direction;
|
|
39
|
+
export {};
|
|
@@ -1,22 +1,73 @@
|
|
|
1
1
|
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
2
2
|
local ____exports = {}
|
|
3
|
+
local OBJECT_NAME
|
|
4
|
+
local ____SerializationBrand = require("enums.private.SerializationBrand")
|
|
5
|
+
local SerializationBrand = ____SerializationBrand.SerializationBrand
|
|
6
|
+
local ____SerializationType = require("enums.SerializationType")
|
|
7
|
+
local SerializationType = ____SerializationType.SerializationType
|
|
3
8
|
local ____directionToVector = require("objects.directionToVector")
|
|
4
9
|
local DIRECTION_TO_VECTOR = ____directionToVector.DIRECTION_TO_VECTOR
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
local ____table = require("functions.table")
|
|
11
|
+
local copyValuesToTable = ____table.copyValuesToTable
|
|
12
|
+
local getNumbersFromTable = ____table.getNumbersFromTable
|
|
13
|
+
local tableHasKeys = ____table.tableHasKeys
|
|
14
|
+
local ____utils = require("functions.utils")
|
|
15
|
+
local ensureAllCases = ____utils.ensureAllCases
|
|
16
|
+
local isUserdataObject = ____utils.isUserdataObject
|
|
17
|
+
function ____exports.isVector(self, object)
|
|
18
|
+
return isUserdataObject(nil, object, OBJECT_NAME)
|
|
7
19
|
end
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
local yString = vectorTable.Y
|
|
15
|
-
local y = tonumber(yString)
|
|
16
|
-
if y == nil then
|
|
17
|
-
error("Failed to read the Y value of a serialized vector.")
|
|
20
|
+
local KEYS = {"X", "Y"}
|
|
21
|
+
OBJECT_NAME = "Vector"
|
|
22
|
+
function ____exports.copyVector(self, vector, serializationType)
|
|
23
|
+
if serializationType == nil then
|
|
24
|
+
serializationType = SerializationType.NONE
|
|
18
25
|
end
|
|
19
|
-
|
|
26
|
+
repeat
|
|
27
|
+
local ____switch3 = serializationType
|
|
28
|
+
local ____cond3 = ____switch3 == SerializationType.NONE
|
|
29
|
+
if ____cond3 then
|
|
30
|
+
do
|
|
31
|
+
if not ____exports.isVector(nil, vector) then
|
|
32
|
+
error(((("Failed to copy a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
|
|
33
|
+
end
|
|
34
|
+
return Vector(vector.X, vector.Y)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
____cond3 = ____cond3 or ____switch3 == SerializationType.SERIALIZE
|
|
38
|
+
if ____cond3 then
|
|
39
|
+
do
|
|
40
|
+
if not ____exports.isVector(nil, vector) then
|
|
41
|
+
error(((("Failed to serialize a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
|
|
42
|
+
end
|
|
43
|
+
local vectorTable = {}
|
|
44
|
+
copyValuesToTable(nil, vector, KEYS, vectorTable)
|
|
45
|
+
vectorTable[SerializationBrand.VECTOR] = ""
|
|
46
|
+
return vectorTable
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
|
|
50
|
+
if ____cond3 then
|
|
51
|
+
do
|
|
52
|
+
local vectorType = type(vector)
|
|
53
|
+
if ____exports.isVector(nil, vector) or vectorType ~= "table" then
|
|
54
|
+
error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
|
|
55
|
+
end
|
|
56
|
+
local x, y = table.unpack(getNumbersFromTable(
|
|
57
|
+
nil,
|
|
58
|
+
vector,
|
|
59
|
+
OBJECT_NAME,
|
|
60
|
+
table.unpack(KEYS)
|
|
61
|
+
))
|
|
62
|
+
return Vector(x, y)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
do
|
|
66
|
+
do
|
|
67
|
+
return ensureAllCases(nil, serializationType)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
until true
|
|
20
71
|
end
|
|
21
72
|
function ____exports.directionToVector(self, direction)
|
|
22
73
|
return DIRECTION_TO_VECTOR[direction]
|
|
@@ -27,17 +78,17 @@ end
|
|
|
27
78
|
function ____exports.getZeroVector(self)
|
|
28
79
|
return Vector(0, 0)
|
|
29
80
|
end
|
|
30
|
-
function ____exports.
|
|
81
|
+
function ____exports.isSerializedVector(self, object)
|
|
31
82
|
local objectType = type(object)
|
|
32
|
-
if objectType ~= "
|
|
33
|
-
return false
|
|
34
|
-
end
|
|
35
|
-
local metatable = getmetatable(object)
|
|
36
|
-
if metatable == nil then
|
|
83
|
+
if objectType ~= "table" then
|
|
37
84
|
return false
|
|
38
85
|
end
|
|
39
|
-
local
|
|
40
|
-
return
|
|
86
|
+
local ____table = object
|
|
87
|
+
return tableHasKeys(
|
|
88
|
+
nil,
|
|
89
|
+
____table,
|
|
90
|
+
table.unpack(KEYS)
|
|
91
|
+
) and ____table[SerializationBrand.VECTOR] ~= nil
|
|
41
92
|
end
|
|
42
93
|
function ____exports.vectorToDirection(self, vector)
|
|
43
94
|
local degrees = vector:GetAngleDegrees()
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export * from "./functions/pocketItems";
|
|
|
69
69
|
export * from "./functions/positionVelocity";
|
|
70
70
|
export * from "./functions/random";
|
|
71
71
|
export * from "./functions/revive";
|
|
72
|
+
export * from "./functions/rng";
|
|
72
73
|
export * from "./functions/roomData";
|
|
73
74
|
export * from "./functions/rooms";
|
|
74
75
|
export * from "./functions/run";
|
package/dist/index.lua
CHANGED
|
@@ -552,6 +552,14 @@ do
|
|
|
552
552
|
end
|
|
553
553
|
end
|
|
554
554
|
end
|
|
555
|
+
do
|
|
556
|
+
local ____export = require("functions.rng")
|
|
557
|
+
for ____exportKey, ____exportValue in pairs(____export) do
|
|
558
|
+
if ____exportKey ~= "default" then
|
|
559
|
+
____exports[____exportKey] = ____exportValue
|
|
560
|
+
end
|
|
561
|
+
end
|
|
562
|
+
end
|
|
555
563
|
do
|
|
556
564
|
local ____export = require("functions.roomData")
|
|
557
565
|
for ____exportKey, ____exportValue in pairs(____export) do
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local Set = ____lualib.Set
|
|
3
|
+
local __TS__New = ____lualib.__TS__New
|
|
4
|
+
local ____exports = {}
|
|
5
|
+
local ALL_DOOR_SLOTS_SET = __TS__New(Set, {
|
|
6
|
+
DoorSlot.LEFT0,
|
|
7
|
+
DoorSlot.UP0,
|
|
8
|
+
DoorSlot.RIGHT0,
|
|
9
|
+
DoorSlot.DOWN0,
|
|
10
|
+
DoorSlot.LEFT1,
|
|
11
|
+
DoorSlot.UP1,
|
|
12
|
+
DoorSlot.RIGHT1,
|
|
13
|
+
DoorSlot.DOWN1
|
|
14
|
+
})
|
|
15
|
+
____exports.ROOM_SHAPE_TO_DOOR_SLOTS = {
|
|
16
|
+
[RoomShape.ROOMSHAPE_1x1] = __TS__New(Set, {DoorSlot.LEFT0, DoorSlot.UP0, DoorSlot.RIGHT0, DoorSlot.DOWN0}),
|
|
17
|
+
[RoomShape.ROOMSHAPE_IH] = __TS__New(Set, {DoorSlot.LEFT0, DoorSlot.RIGHT0}),
|
|
18
|
+
[RoomShape.ROOMSHAPE_IV] = __TS__New(Set, {DoorSlot.UP0, DoorSlot.DOWN0}),
|
|
19
|
+
[RoomShape.ROOMSHAPE_1x2] = __TS__New(Set, {
|
|
20
|
+
DoorSlot.LEFT0,
|
|
21
|
+
DoorSlot.UP0,
|
|
22
|
+
DoorSlot.RIGHT0,
|
|
23
|
+
DoorSlot.DOWN0,
|
|
24
|
+
DoorSlot.LEFT1,
|
|
25
|
+
DoorSlot.RIGHT1
|
|
26
|
+
}),
|
|
27
|
+
[RoomShape.ROOMSHAPE_IIV] = __TS__New(Set, {DoorSlot.UP0, DoorSlot.DOWN0}),
|
|
28
|
+
[RoomShape.ROOMSHAPE_2x1] = __TS__New(Set, {
|
|
29
|
+
DoorSlot.LEFT0,
|
|
30
|
+
DoorSlot.UP0,
|
|
31
|
+
DoorSlot.RIGHT0,
|
|
32
|
+
DoorSlot.DOWN0,
|
|
33
|
+
DoorSlot.UP1,
|
|
34
|
+
DoorSlot.DOWN1
|
|
35
|
+
}),
|
|
36
|
+
[RoomShape.ROOMSHAPE_IIH] = __TS__New(Set, {DoorSlot.LEFT0, DoorSlot.RIGHT0}),
|
|
37
|
+
[RoomShape.ROOMSHAPE_2x2] = ALL_DOOR_SLOTS_SET,
|
|
38
|
+
[RoomShape.ROOMSHAPE_LTL] = ALL_DOOR_SLOTS_SET,
|
|
39
|
+
[RoomShape.ROOMSHAPE_LTR] = ALL_DOOR_SLOTS_SET,
|
|
40
|
+
[RoomShape.ROOMSHAPE_LBL] = ALL_DOOR_SLOTS_SET,
|
|
41
|
+
[RoomShape.ROOMSHAPE_LBR] = ALL_DOOR_SLOTS_SET,
|
|
42
|
+
[RoomShape.NUM_ROOMSHAPES] = nil
|
|
43
|
+
}
|
|
44
|
+
return ____exports
|