isaacscript-common 1.2.202 → 1.2.203
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 +19 -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 +18 -51
- package/dist/functions/random.lua +27 -48
- package/dist/functions/rng.d.ts +44 -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 +23 -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
|
@@ -6,9 +6,7 @@ export declare class ModUpgraded implements Mod {
|
|
|
6
6
|
Name: string;
|
|
7
7
|
/** We store a copy of the original mod object so that we can re-implement its functions. */
|
|
8
8
|
Mod: Mod;
|
|
9
|
-
|
|
10
|
-
Verbose: boolean;
|
|
11
|
-
constructor(mod: Mod, verbose: boolean);
|
|
9
|
+
constructor(mod: Mod);
|
|
12
10
|
AddCallback<T extends ModCallbacks>(modCallbacks: T, ...args: AddCallbackParameters[T]): void;
|
|
13
11
|
HasData(): boolean;
|
|
14
12
|
LoadData(): string;
|
|
@@ -1,51 +1,17 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
-
local __TS__Spread = ____lualib.__TS__Spread
|
|
4
|
-
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
|
|
5
3
|
local ____exports = {}
|
|
6
|
-
local getCallbackName
|
|
7
|
-
local ____log = require("functions.log")
|
|
8
|
-
local getDebugPrependString = ____log.getDebugPrependString
|
|
9
4
|
local ____callbackRegisterFunctions = require("objects.callbackRegisterFunctions")
|
|
10
5
|
local CALLBACK_REGISTER_FUNCTIONS = ____callbackRegisterFunctions.CALLBACK_REGISTER_FUNCTIONS
|
|
11
|
-
function getCallbackName(self, callbackID)
|
|
12
|
-
for ____, ____value in ipairs(__TS__ObjectEntries(ModCallbacks)) do
|
|
13
|
-
local key = ____value[1]
|
|
14
|
-
local value = ____value[2]
|
|
15
|
-
if value == callbackID then
|
|
16
|
-
return key
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
return "MC_UNKNOWN"
|
|
20
|
-
end
|
|
21
6
|
____exports.ModUpgraded = __TS__Class()
|
|
22
7
|
local ModUpgraded = ____exports.ModUpgraded
|
|
23
8
|
ModUpgraded.name = "ModUpgraded"
|
|
24
|
-
function ModUpgraded.prototype.____constructor(self, mod
|
|
9
|
+
function ModUpgraded.prototype.____constructor(self, mod)
|
|
25
10
|
self.Name = mod.Name
|
|
26
11
|
self.Mod = mod
|
|
27
|
-
self.Verbose = verbose
|
|
28
12
|
end
|
|
29
13
|
function ModUpgraded.prototype.AddCallback(self, modCallbacks, ...)
|
|
30
|
-
|
|
31
|
-
if self.Verbose then
|
|
32
|
-
local callback = args[1]
|
|
33
|
-
local optionalArg = args[2]
|
|
34
|
-
local callbackName = getCallbackName(nil, modCallbacks)
|
|
35
|
-
local debugMsg = getDebugPrependString(nil, callbackName)
|
|
36
|
-
local function callbackWithLogger(____, ...)
|
|
37
|
-
Isaac.DebugString(debugMsg .. " - START")
|
|
38
|
-
local value = callback(nil, ...)
|
|
39
|
-
Isaac.DebugString((debugMsg .. " - END - ") .. tostring(value))
|
|
40
|
-
return value
|
|
41
|
-
end
|
|
42
|
-
self.Mod:AddCallback(modCallbacks, callbackWithLogger, optionalArg)
|
|
43
|
-
else
|
|
44
|
-
self.Mod:AddCallback(
|
|
45
|
-
modCallbacks,
|
|
46
|
-
__TS__Spread(args)
|
|
47
|
-
)
|
|
48
|
-
end
|
|
14
|
+
self.Mod:AddCallback(modCallbacks, ...)
|
|
49
15
|
end
|
|
50
16
|
function ModUpgraded.prototype.HasData(self)
|
|
51
17
|
return self.Mod:HasData()
|
|
@@ -10,6 +10,8 @@ export declare enum SerializationBrand {
|
|
|
10
10
|
SET = "__TSTL_SET",
|
|
11
11
|
CLASS = "__TSTL_CLASS",
|
|
12
12
|
OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS",
|
|
13
|
+
COLOR = "__COLOR",
|
|
14
|
+
RNG = "__RNG",
|
|
13
15
|
VECTOR = "__VECTOR"
|
|
14
16
|
}
|
|
15
17
|
export declare function isSerializationBrand(key: AnyNotNil): boolean;
|
|
@@ -11,6 +11,8 @@ ____exports.SerializationBrand.MAP = "__TSTL_MAP"
|
|
|
11
11
|
____exports.SerializationBrand.SET = "__TSTL_SET"
|
|
12
12
|
____exports.SerializationBrand.CLASS = "__TSTL_CLASS"
|
|
13
13
|
____exports.SerializationBrand.OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS"
|
|
14
|
+
____exports.SerializationBrand.COLOR = "__COLOR"
|
|
15
|
+
____exports.SerializationBrand.RNG = "__RNG"
|
|
14
16
|
____exports.SerializationBrand.VECTOR = "__VECTOR"
|
|
15
17
|
local SERIALIZATION_BRANDS = getEnumValues(nil, ____exports.SerializationBrand)
|
|
16
18
|
local SERIALIZATION_BRAND_SET = __TS__New(Set, SERIALIZATION_BRANDS)
|
|
@@ -14,15 +14,12 @@ import { JSONRoom } from "../types/JSONRoom";
|
|
|
14
14
|
* const firstJSONRoom = customRooms.rooms.room[0];
|
|
15
15
|
* deployJSONRoom(firstJSONRoom);
|
|
16
16
|
* ```
|
|
17
|
-
* @param
|
|
18
|
-
* Default is `
|
|
17
|
+
* @param rng Optional. Specifies the RNG object that will be used for spawning every entity in the
|
|
18
|
+
* room. Default is `newRNG()`.
|
|
19
19
|
* @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
|
|
20
20
|
* what the function is doing. Default is false.
|
|
21
|
-
* @returns Before using the seed for spawning each entity, it is iterated with `nextSeed`. The
|
|
22
|
-
* function returns the final iterated seed after spawning everything, which can be used in
|
|
23
|
-
* subsequent room deployments.
|
|
24
21
|
*/
|
|
25
|
-
export declare function deployJSONRoom(jsonRoom: JSONRoom,
|
|
22
|
+
export declare function deployJSONRoom(jsonRoom: JSONRoom, rng?: RNG, verbose?: boolean): void;
|
|
26
23
|
/**
|
|
27
24
|
* Helper function to deconstruct a vanilla room and set up a custom room in its place.
|
|
28
25
|
* Specifically, this will clear the current room of all entities and grid entities, and then spawn
|
|
@@ -42,15 +39,12 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: Seed, verbose?
|
|
|
42
39
|
* const jsonRooms = customRooms.rooms.room;
|
|
43
40
|
* deployRandomJSONRoom(jsonRooms);
|
|
44
41
|
* ```
|
|
45
|
-
* @param
|
|
46
|
-
* that, it is also used for spawning every entity in the room. Default is `
|
|
42
|
+
* @param rng Optional. Specifies the RNG object that will be used for determining the random room.
|
|
43
|
+
* After that, it is also used for spawning every entity in the room. Default is `newRNG()`.
|
|
47
44
|
* @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
|
|
48
45
|
* what the function is doing. Default is false.
|
|
49
|
-
* @returns Before using the seed for spawning each entity, it is iterated with `nextSeed`. The
|
|
50
|
-
* function returns the final iterated seed after spawning everything, which can be used in
|
|
51
|
-
* subsequent room deployments.
|
|
52
46
|
*/
|
|
53
|
-
export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[],
|
|
47
|
+
export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], rng?: RNG, verbose?: boolean): void;
|
|
54
48
|
/**
|
|
55
49
|
* Helper function to remove all naturally spawning entities and grid entities from a room. Notably,
|
|
56
50
|
* this will not remove players (1), tears (2), familiars (3), lasers (7), knives (8),
|
|
@@ -32,9 +32,8 @@ local ____npc = require("functions.npc")
|
|
|
32
32
|
local getNPCs = ____npc.getNPCs
|
|
33
33
|
local ____pickups = require("functions.pickups")
|
|
34
34
|
local removeAllPickups = ____pickups.removeAllPickups
|
|
35
|
-
local
|
|
36
|
-
local
|
|
37
|
-
local nextSeed = ____random.nextSeed
|
|
35
|
+
local ____rng = require("functions.rng")
|
|
36
|
+
local newRNG = ____rng.newRNG
|
|
38
37
|
local ____roomData = require("functions.roomData")
|
|
39
38
|
local getRoomListIndex = ____roomData.getRoomListIndex
|
|
40
39
|
local ____rooms = require("functions.rooms")
|
|
@@ -137,7 +136,7 @@ function fillRoomWithDecorations(self)
|
|
|
137
136
|
::__continue30::
|
|
138
137
|
end
|
|
139
138
|
end
|
|
140
|
-
function spawnAllEntities(self, jsonRoom,
|
|
139
|
+
function spawnAllEntities(self, jsonRoom, rng, verbose)
|
|
141
140
|
if verbose == nil then
|
|
142
141
|
verbose = false
|
|
143
142
|
end
|
|
@@ -184,7 +183,6 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
|
|
|
184
183
|
y
|
|
185
184
|
)
|
|
186
185
|
else
|
|
187
|
-
seed = nextSeed(nil, seed)
|
|
188
186
|
if verbose then
|
|
189
187
|
log(((((((((("Spawning normal entity " .. tostring(entityType)) .. ".") .. tostring(variant)) .. ".") .. tostring(subType)) .. " at: (") .. tostring(x)) .. ", ") .. tostring(y)) .. ")")
|
|
190
188
|
end
|
|
@@ -195,7 +193,7 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
|
|
|
195
193
|
subType,
|
|
196
194
|
x,
|
|
197
195
|
y,
|
|
198
|
-
|
|
196
|
+
rng
|
|
199
197
|
)
|
|
200
198
|
local npc = entity:ToNPC()
|
|
201
199
|
if npc ~= nil and npc.CanShutDoors then
|
|
@@ -211,7 +209,6 @@ function spawnAllEntities(self, jsonRoom, seed, verbose)
|
|
|
211
209
|
elseif verbose then
|
|
212
210
|
log("Leaving the room cleared since there were no battle NPCs spawned.")
|
|
213
211
|
end
|
|
214
|
-
return seed
|
|
215
212
|
end
|
|
216
213
|
function spawnGridEntityForJSONRoom(self, xmlEntityType, xmlEntityVariant, x, y)
|
|
217
214
|
local room = game:GetRoom()
|
|
@@ -233,7 +230,7 @@ function spawnGridEntityForJSONRoom(self, xmlEntityType, xmlEntityVariant, x, y)
|
|
|
233
230
|
end
|
|
234
231
|
return gridEntity
|
|
235
232
|
end
|
|
236
|
-
function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y,
|
|
233
|
+
function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y, rng)
|
|
237
234
|
local room = game:GetRoom()
|
|
238
235
|
local roomType = room:GetType()
|
|
239
236
|
local position = gridToPos(nil, x, y)
|
|
@@ -244,10 +241,12 @@ function spawnNormalEntityForJSONRoom(self, entityType, variant, subType, x, y,
|
|
|
244
241
|
nil,
|
|
245
242
|
subType,
|
|
246
243
|
position,
|
|
247
|
-
|
|
244
|
+
rng,
|
|
248
245
|
options
|
|
249
246
|
)
|
|
250
247
|
else
|
|
248
|
+
rng:Next()
|
|
249
|
+
local seed = rng:GetSeed()
|
|
251
250
|
entity = game:Spawn(
|
|
252
251
|
entityType,
|
|
253
252
|
variant,
|
|
@@ -404,9 +403,9 @@ function ____exports.deployJSONRoomInit(self, mod)
|
|
|
404
403
|
saveDataManager(nil, "deployJSONRoom", v)
|
|
405
404
|
mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, postNewRoom)
|
|
406
405
|
end
|
|
407
|
-
function ____exports.deployJSONRoom(self, jsonRoom,
|
|
408
|
-
if
|
|
409
|
-
|
|
406
|
+
function ____exports.deployJSONRoom(self, jsonRoom, rng, verbose)
|
|
407
|
+
if rng == nil then
|
|
408
|
+
rng = newRNG(nil)
|
|
410
409
|
end
|
|
411
410
|
if verbose == nil then
|
|
412
411
|
verbose = false
|
|
@@ -422,26 +421,25 @@ function ____exports.deployJSONRoom(self, jsonRoom, seed, verbose)
|
|
|
422
421
|
if verbose then
|
|
423
422
|
log("Starting to spawn all of the new entities and grid entities.")
|
|
424
423
|
end
|
|
425
|
-
|
|
424
|
+
spawnAllEntities(nil, jsonRoom, rng, verbose)
|
|
426
425
|
if verbose then
|
|
427
426
|
log("Finished spawning all of the new entities and grid entities.")
|
|
428
427
|
end
|
|
429
428
|
fixPitGraphics(nil)
|
|
430
429
|
fillRoomWithDecorations(nil)
|
|
431
|
-
return newSeed
|
|
432
430
|
end
|
|
433
|
-
function ____exports.deployRandomJSONRoom(self, jsonRooms,
|
|
434
|
-
if
|
|
435
|
-
|
|
431
|
+
function ____exports.deployRandomJSONRoom(self, jsonRooms, rng, verbose)
|
|
432
|
+
if rng == nil then
|
|
433
|
+
rng = newRNG(nil)
|
|
436
434
|
end
|
|
437
435
|
if verbose == nil then
|
|
438
436
|
verbose = false
|
|
439
437
|
end
|
|
440
438
|
errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
|
|
441
|
-
local randomJSONRoom = getRandomJSONRoom(nil, jsonRooms,
|
|
439
|
+
local randomJSONRoom = getRandomJSONRoom(nil, jsonRooms, rng, verbose)
|
|
442
440
|
if verbose then
|
|
443
441
|
log((((((("Randomly chose JSON room " .. randomJSONRoom["$"].type) .. ".") .. randomJSONRoom["$"].variant) .. ".") .. randomJSONRoom["$"].subtype) .. " with name: ") .. randomJSONRoom["$"].name)
|
|
444
442
|
end
|
|
445
|
-
return ____exports.deployJSONRoom(nil, randomJSONRoom,
|
|
443
|
+
return ____exports.deployJSONRoom(nil, randomJSONRoom, rng, verbose)
|
|
446
444
|
end
|
|
447
445
|
return ____exports
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/// <reference types="typescript-to-lua/language-extensions" />
|
|
2
2
|
/**
|
|
3
|
-
* merge takes the values from a new table and recursively merges them into an old object
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* merge takes the values from a new table and recursively merges them into an old object (while
|
|
4
|
+
* performing appropriate deserialization).
|
|
5
|
+
*
|
|
6
|
+
* It supports the following object types:
|
|
7
|
+
*
|
|
8
|
+
* - `LuaTable` / basic TSTL objects
|
|
9
|
+
* - TSTL `Map`
|
|
10
|
+
* - TSTL `Set`
|
|
11
|
+
* - TSTL classes
|
|
12
|
+
* - `DefaultMap`
|
|
13
|
+
* - Isaac `RNG` objects
|
|
14
|
+
* - Isaac `Vector` objects
|
|
6
15
|
*
|
|
7
16
|
* Since it is common for a variable to have a type of `something | null`, we must iterate over the
|
|
8
17
|
* new object and copy over all of the values. (A value of null transpiles to nil, which means the
|
|
@@ -3,7 +3,7 @@ local Map = ____lualib.Map
|
|
|
3
3
|
local __TS__InstanceOf = ____lualib.__TS__InstanceOf
|
|
4
4
|
local Set = ____lualib.Set
|
|
5
5
|
local ____exports = {}
|
|
6
|
-
local mergeArray, mergeTSTLObject, mergeTable,
|
|
6
|
+
local mergeArray, mergeTSTLObject, mergeTable, tryDeserializeIsaacClass
|
|
7
7
|
local ____SerializationBrand = require("enums.private.SerializationBrand")
|
|
8
8
|
local isSerializationBrand = ____SerializationBrand.isSerializationBrand
|
|
9
9
|
local SerializationBrand = ____SerializationBrand.SerializationBrand
|
|
@@ -13,15 +13,18 @@ local ____array = require("functions.array")
|
|
|
13
13
|
local isArray = ____array.isArray
|
|
14
14
|
local ____deepCopy = require("functions.deepCopy")
|
|
15
15
|
local deepCopy = ____deepCopy.deepCopy
|
|
16
|
-
local isSerializedVector = ____deepCopy.isSerializedVector
|
|
17
16
|
local ____log = require("functions.log")
|
|
18
17
|
local log = ____log.log
|
|
18
|
+
local ____rng = require("functions.rng")
|
|
19
|
+
local copyRNG = ____rng.copyRNG
|
|
20
|
+
local isSerializedRNG = ____rng.isSerializedRNG
|
|
19
21
|
local ____table = require("functions.table")
|
|
20
22
|
local clearTable = ____table.clearTable
|
|
21
23
|
local ____utils = require("functions.utils")
|
|
22
24
|
local getTraversalDescription = ____utils.getTraversalDescription
|
|
23
25
|
local ____vector = require("functions.vector")
|
|
24
|
-
local
|
|
26
|
+
local copyVector = ____vector.copyVector
|
|
27
|
+
local isSerializedVector = ____vector.isSerializedVector
|
|
25
28
|
local ____constants = require("features.saveDataManager.constants")
|
|
26
29
|
local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
|
|
27
30
|
function ____exports.merge(self, oldObject, newTable, traversalDescription)
|
|
@@ -100,7 +103,9 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
|
|
|
100
103
|
if isSerializationBrand(nil, key) then
|
|
101
104
|
goto __continue23
|
|
102
105
|
end
|
|
103
|
-
|
|
106
|
+
local deserializedIsaacClass = tryDeserializeIsaacClass(nil, value)
|
|
107
|
+
if deserializedIsaacClass ~= nil then
|
|
108
|
+
oldTable[key] = deserializedIsaacClass
|
|
104
109
|
goto __continue23
|
|
105
110
|
end
|
|
106
111
|
local valueType = type(value)
|
|
@@ -123,13 +128,13 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
|
|
|
123
128
|
::__continue23::
|
|
124
129
|
end
|
|
125
130
|
end
|
|
126
|
-
function
|
|
127
|
-
if
|
|
128
|
-
return
|
|
131
|
+
function tryDeserializeIsaacClass(self, value)
|
|
132
|
+
if isSerializedVector(nil, value) then
|
|
133
|
+
return copyVector(nil, value, SerializationType.DESERIALIZE)
|
|
129
134
|
end
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return
|
|
135
|
+
if isSerializedRNG(nil, value) then
|
|
136
|
+
return copyRNG(nil, value, SerializationType.DESERIALIZE)
|
|
137
|
+
end
|
|
138
|
+
return nil
|
|
134
139
|
end
|
|
135
140
|
return ____exports
|
|
@@ -43,20 +43,20 @@ export declare function getLastElement<T>(array: T[]): T;
|
|
|
43
43
|
* Helper function to get a random element from the provided array.
|
|
44
44
|
*
|
|
45
45
|
* @param array The array to get an element from.
|
|
46
|
-
* @param
|
|
46
|
+
* @param rng Optional. The RNG object used to select the random element. Default is `newRNG()`.
|
|
47
47
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
48
48
|
*/
|
|
49
|
-
export declare function getRandomArrayElement<T>(array: T[] | readonly T[],
|
|
49
|
+
export declare function getRandomArrayElement<T>(array: T[] | readonly T[], rng?: RNG, exceptions?: T[] | readonly T[]): T;
|
|
50
50
|
/**
|
|
51
51
|
* Helper function to get a random element from the provided array. Once the random element is
|
|
52
52
|
* decided, it is then removed from the array (in-place).
|
|
53
53
|
*
|
|
54
54
|
* @param array The array to get an element from.
|
|
55
|
-
* @param
|
|
55
|
+
* @param rng Optional. The RNG object used to select the random element. Default is `newRNG()`.
|
|
56
56
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
57
57
|
*/
|
|
58
|
-
export declare function getRandomArrayElementAndRemove<T>(array: T[],
|
|
59
|
-
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[],
|
|
58
|
+
export declare function getRandomArrayElementAndRemove<T>(array: T[], rng?: RNG, exceptions?: T[] | readonly T[]): T;
|
|
59
|
+
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], rng?: RNG): int;
|
|
60
60
|
/**
|
|
61
61
|
* Initializes an array with all elements containing the specified default value.
|
|
62
62
|
*
|
|
@@ -80,11 +80,11 @@ export declare function isArrayInArray<T>(arrayToMatch: T[] | readonly T[], pare
|
|
|
80
80
|
*
|
|
81
81
|
* From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
82
82
|
*/
|
|
83
|
-
export declare function shuffleArray<T>(originalArray: T[] | readonly T[],
|
|
83
|
+
export declare function shuffleArray<T>(originalArray: T[] | readonly T[], rng?: RNG): T[];
|
|
84
84
|
/**
|
|
85
85
|
* Shuffles the provided array in-place using the Fisher-Yates algorithm.
|
|
86
86
|
*
|
|
87
87
|
* From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
88
88
|
*/
|
|
89
|
-
export declare function shuffleArrayInPlace<T>(array: T[],
|
|
89
|
+
export declare function shuffleArrayInPlace<T>(array: T[], rng?: RNG): void;
|
|
90
90
|
export declare function sumArray(array: number[] | readonly number[]): number;
|
package/dist/functions/array.lua
CHANGED
|
@@ -11,29 +11,28 @@ local __TS__ArrayReduce = ____lualib.__TS__ArrayReduce
|
|
|
11
11
|
local ____exports = {}
|
|
12
12
|
local ____random = require("functions.random")
|
|
13
13
|
local getRandomInt = ____random.getRandomInt
|
|
14
|
-
local
|
|
15
|
-
local
|
|
14
|
+
local ____rng = require("functions.rng")
|
|
15
|
+
local newRNG = ____rng.newRNG
|
|
16
16
|
local ____utils = require("functions.utils")
|
|
17
17
|
local ____repeat = ____utils["repeat"]
|
|
18
|
-
function ____exports.getRandomArrayIndex(self, array,
|
|
19
|
-
if
|
|
20
|
-
|
|
18
|
+
function ____exports.getRandomArrayIndex(self, array, rng)
|
|
19
|
+
if rng == nil then
|
|
20
|
+
rng = newRNG(nil)
|
|
21
21
|
end
|
|
22
22
|
if #array == 0 then
|
|
23
23
|
error("Failed to get a random array index since the provided array is empty.")
|
|
24
24
|
end
|
|
25
|
-
return getRandomInt(nil, 0, #array - 1,
|
|
25
|
+
return getRandomInt(nil, 0, #array - 1, rng)
|
|
26
26
|
end
|
|
27
|
-
function ____exports.shuffleArrayInPlace(self, array,
|
|
28
|
-
if
|
|
29
|
-
|
|
27
|
+
function ____exports.shuffleArrayInPlace(self, array, rng)
|
|
28
|
+
if rng == nil then
|
|
29
|
+
rng = newRNG(nil)
|
|
30
30
|
end
|
|
31
31
|
local currentIndex = #array
|
|
32
32
|
local randomIndex
|
|
33
33
|
while currentIndex > 0 do
|
|
34
34
|
currentIndex = currentIndex - 1
|
|
35
|
-
|
|
36
|
-
randomIndex = ____exports.getRandomArrayIndex(nil, array, seed)
|
|
35
|
+
randomIndex = ____exports.getRandomArrayIndex(nil, array, rng)
|
|
37
36
|
local ____temp_0 = {array[randomIndex + 1], array[currentIndex + 1]}
|
|
38
37
|
array[currentIndex + 1] = ____temp_0[1]
|
|
39
38
|
array[randomIndex + 1] = ____temp_0[2]
|
|
@@ -116,9 +115,9 @@ end
|
|
|
116
115
|
function ____exports.getLastElement(self, array)
|
|
117
116
|
return array[#array]
|
|
118
117
|
end
|
|
119
|
-
function ____exports.getRandomArrayElement(self, array,
|
|
120
|
-
if
|
|
121
|
-
|
|
118
|
+
function ____exports.getRandomArrayElement(self, array, rng, exceptions)
|
|
119
|
+
if rng == nil then
|
|
120
|
+
rng = newRNG(nil)
|
|
122
121
|
end
|
|
123
122
|
if exceptions == nil then
|
|
124
123
|
exceptions = {}
|
|
@@ -131,17 +130,17 @@ function ____exports.getRandomArrayElement(self, array, seed, exceptions)
|
|
|
131
130
|
array,
|
|
132
131
|
table.unpack(exceptions)
|
|
133
132
|
)
|
|
134
|
-
local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions,
|
|
133
|
+
local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions, rng)
|
|
135
134
|
return arrayWithoutExceptions[randomIndex + 1]
|
|
136
135
|
end
|
|
137
|
-
function ____exports.getRandomArrayElementAndRemove(self, array,
|
|
138
|
-
if
|
|
139
|
-
|
|
136
|
+
function ____exports.getRandomArrayElementAndRemove(self, array, rng, exceptions)
|
|
137
|
+
if rng == nil then
|
|
138
|
+
rng = newRNG(nil)
|
|
140
139
|
end
|
|
141
140
|
if exceptions == nil then
|
|
142
141
|
exceptions = {}
|
|
143
142
|
end
|
|
144
|
-
local randomArrayElement = ____exports.getRandomArrayElement(nil, array,
|
|
143
|
+
local randomArrayElement = ____exports.getRandomArrayElement(nil, array, rng, exceptions)
|
|
145
144
|
____exports.arrayRemoveInPlace(nil, array, randomArrayElement)
|
|
146
145
|
return randomArrayElement
|
|
147
146
|
end
|
|
@@ -193,12 +192,12 @@ function ____exports.isArrayInArray(self, arrayToMatch, parentArray)
|
|
|
193
192
|
function(____, element) return ____exports.arrayEquals(nil, element, arrayToMatch) end
|
|
194
193
|
)
|
|
195
194
|
end
|
|
196
|
-
function ____exports.shuffleArray(self, originalArray,
|
|
197
|
-
if
|
|
198
|
-
|
|
195
|
+
function ____exports.shuffleArray(self, originalArray, rng)
|
|
196
|
+
if rng == nil then
|
|
197
|
+
rng = newRNG(nil)
|
|
199
198
|
end
|
|
200
199
|
local array = ____exports.copyArray(nil, originalArray)
|
|
201
|
-
____exports.shuffleArrayInPlace(nil, array,
|
|
200
|
+
____exports.shuffleArrayInPlace(nil, array, rng)
|
|
202
201
|
return array
|
|
203
202
|
end
|
|
204
203
|
function ____exports.sumArray(self, array)
|
|
@@ -43,25 +43,24 @@ export declare function getMaxCards(): int;
|
|
|
43
43
|
* - any objects like Dice Shard
|
|
44
44
|
* - any modded cards.
|
|
45
45
|
*
|
|
46
|
-
* @param
|
|
46
|
+
* @param rng Optional. The RNG object with which to select the random card. Default is `newRNG()`.
|
|
47
47
|
* @param exceptions Optional. An array of cards to not select.
|
|
48
48
|
*/
|
|
49
|
-
export declare function getRandomCard(
|
|
49
|
+
export declare function getRandomCard(rng?: RNG, exceptions?: Card[]): Card;
|
|
50
50
|
/**
|
|
51
51
|
* @param cardType The card type that represents the pool of cards to select from.
|
|
52
|
-
* @param
|
|
52
|
+
* @param rng Optional. The RNG object with which to select the random card. Default is `newRNG()`.
|
|
53
53
|
* @param exceptions Optional. An array of cards to not select.
|
|
54
54
|
*/
|
|
55
|
-
export declare function getRandomCardOfType(cardType: CardType,
|
|
55
|
+
export declare function getRandomCardOfType(cardType: CardType, rng?: RNG, exceptions?: Card[]): Card;
|
|
56
56
|
/**
|
|
57
57
|
* Has an equal chance of returning any rune (e.g. Rune of Hagalaz, Blank Rune, Black Rune, Soul of
|
|
58
58
|
* Isaac, etc.). This will never return a Rune Shard.
|
|
59
59
|
*
|
|
60
|
-
* @param
|
|
61
|
-
* `getRandomSeed()`.
|
|
60
|
+
* @param rng Optional. The RNG object with which to select the random rune. Default is `newRNG()`.
|
|
62
61
|
* @param exceptions Optional. An array of runes to not select.
|
|
63
62
|
*/
|
|
64
|
-
export declare function getRandomRune(
|
|
63
|
+
export declare function getRandomRune(rng?: RNG, exceptions?: Card[]): Card;
|
|
65
64
|
/**
|
|
66
65
|
* Returns true for cards that have the following card type:
|
|
67
66
|
* - CardType.TAROT
|
package/dist/functions/cards.lua
CHANGED
|
@@ -20,8 +20,8 @@ local CARD_TYPES = ____cardTypes.CARD_TYPES
|
|
|
20
20
|
local DEFAULT_CARD_TYPE = ____cardTypes.DEFAULT_CARD_TYPE
|
|
21
21
|
local ____math = require("functions.math")
|
|
22
22
|
local range = ____math.range
|
|
23
|
-
local
|
|
24
|
-
local
|
|
23
|
+
local ____rng = require("functions.rng")
|
|
24
|
+
local newRNG = ____rng.newRNG
|
|
25
25
|
local ____set = require("functions.set")
|
|
26
26
|
local addSetsToSet = ____set.addSetsToSet
|
|
27
27
|
local getRandomSetElement = ____set.getRandomSetElement
|
|
@@ -100,35 +100,35 @@ function ____exports.getCardName(self, card)
|
|
|
100
100
|
end
|
|
101
101
|
return DEFAULT_CARD_NAME
|
|
102
102
|
end
|
|
103
|
-
function ____exports.getRandomCard(self,
|
|
104
|
-
if
|
|
105
|
-
|
|
103
|
+
function ____exports.getRandomCard(self, rng, exceptions)
|
|
104
|
+
if rng == nil then
|
|
105
|
+
rng = newRNG(nil)
|
|
106
106
|
end
|
|
107
107
|
if exceptions == nil then
|
|
108
108
|
exceptions = {}
|
|
109
109
|
end
|
|
110
|
-
return getRandomSetElement(nil, CARD_SET,
|
|
110
|
+
return getRandomSetElement(nil, CARD_SET, rng, exceptions)
|
|
111
111
|
end
|
|
112
|
-
function ____exports.getRandomCardOfType(self, cardType,
|
|
113
|
-
if
|
|
114
|
-
|
|
112
|
+
function ____exports.getRandomCardOfType(self, cardType, rng, exceptions)
|
|
113
|
+
if rng == nil then
|
|
114
|
+
rng = newRNG(nil)
|
|
115
115
|
end
|
|
116
116
|
if exceptions == nil then
|
|
117
117
|
exceptions = {}
|
|
118
118
|
end
|
|
119
119
|
local cardSet = ____exports.getCardsOfType(nil, cardType)
|
|
120
|
-
return getRandomSetElement(nil, cardSet,
|
|
120
|
+
return getRandomSetElement(nil, cardSet, rng, exceptions)
|
|
121
121
|
end
|
|
122
|
-
function ____exports.getRandomRune(self,
|
|
123
|
-
if
|
|
124
|
-
|
|
122
|
+
function ____exports.getRandomRune(self, rng, exceptions)
|
|
123
|
+
if rng == nil then
|
|
124
|
+
rng = newRNG(nil)
|
|
125
125
|
end
|
|
126
126
|
if exceptions == nil then
|
|
127
127
|
exceptions = {}
|
|
128
128
|
end
|
|
129
129
|
local runesSet = ____exports.getCardsOfType(nil, CardType.RUNE)
|
|
130
130
|
runesSet:delete(Card.RUNE_SHARD)
|
|
131
|
-
return getRandomSetElement(nil, runesSet,
|
|
131
|
+
return getRandomSetElement(nil, runesSet, rng, exceptions)
|
|
132
132
|
end
|
|
133
133
|
function ____exports.isCard(self, card)
|
|
134
134
|
return CARD_SET:has(card)
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/// <reference types="isaac-typescript-definitions" />
|
|
2
|
-
|
|
2
|
+
/// <reference types="typescript-to-lua/language-extensions" />
|
|
3
|
+
import { SerializationType } from "../enums/SerializationType";
|
|
4
|
+
declare type SerializedColor = LuaTable<string, string | number>;
|
|
5
|
+
interface CopyColorReturn {
|
|
6
|
+
[SerializationType.NONE]: Color;
|
|
7
|
+
[SerializationType.SERIALIZE]: SerializedColor;
|
|
8
|
+
[SerializationType.DESERIALIZE]: Color;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to copy a `Color` object.
|
|
12
|
+
*
|
|
13
|
+
* @param color The Color object to copy. In the case of deserialization, this will actually be a
|
|
14
|
+
* Lua table instead of an instantiated Color class.
|
|
15
|
+
* @param serializationType Default is `SerializationType.NONE`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function copyColor<C extends Color | SerializedColor, S extends SerializationType>(color: C, serializationType: S): CopyColorReturn[S];
|
|
3
18
|
export declare function copyKColor(kColor: KColor): KColor;
|
|
4
19
|
export declare function getDefaultColor(): Color;
|
|
5
20
|
export declare function getDefaultKColor(): KColor;
|
|
21
|
+
/** Helper function to check if something is an instantiated Color object. */
|
|
22
|
+
export declare function isColor(object: unknown): object is Color;
|
|
23
|
+
export {};
|