isaacscript-common 1.2.120 → 1.2.123
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/features/deployJSONRoom.d.ts +2 -2
- package/dist/functions/array.d.ts +6 -7
- package/dist/functions/array.lua +14 -4
- package/dist/functions/cards.d.ts +3 -3
- package/dist/functions/jsonRoom.d.ts +1 -1
- package/dist/functions/map.d.ts +18 -0
- package/dist/functions/map.lua +14 -0
- package/dist/functions/player.d.ts +5 -0
- package/dist/functions/player.lua +13 -9
- package/dist/functions/random.d.ts +5 -5
- package/dist/functions/set.d.ts +2 -1
- package/dist/functions/spawnCollectible.d.ts +2 -2
- package/package.json +2 -2
|
@@ -22,7 +22,7 @@ import { JSONRoom } from "../types/JSONRoom";
|
|
|
22
22
|
* function returns the final iterated seed after spawning everything, which can be used in
|
|
23
23
|
* subsequent room deployments.
|
|
24
24
|
*/
|
|
25
|
-
export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?:
|
|
25
|
+
export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: Seed, verbose?: boolean): Seed;
|
|
26
26
|
/**
|
|
27
27
|
* Helper function to deconstruct a vanilla room and set up a custom room in its place.
|
|
28
28
|
* Specifically, this will clear the current room of all entities and grid entities, and then spawn
|
|
@@ -50,7 +50,7 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: number, verbos
|
|
|
50
50
|
* function returns the final iterated seed after spawning everything, which can be used in
|
|
51
51
|
* subsequent room deployments.
|
|
52
52
|
*/
|
|
53
|
-
export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?:
|
|
53
|
+
export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?: Seed, verbose?: boolean): Seed;
|
|
54
54
|
/**
|
|
55
55
|
* Helper function to remove all naturally spawning entities and grid entities from a room. Notably,
|
|
56
56
|
* this will not remove players (1), tears (2), familiars (3), lasers (7), knives (8),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="isaac-typescript-definitions" />
|
|
2
|
-
/// <reference types="typescript-to-lua/language-extensions" />
|
|
3
2
|
/**
|
|
4
3
|
* Helper function for determining if two arrays contain the exact same elements. Note that this
|
|
5
4
|
* only performs a shallow comparison.
|
|
@@ -39,13 +38,13 @@ export declare function isArrayInArray<T>(arrayToMatch: T[] | readonly T[], pare
|
|
|
39
38
|
*
|
|
40
39
|
* From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
41
40
|
*/
|
|
42
|
-
export declare function shuffleArray<T>(originalArray: T[] | readonly T[], seed?:
|
|
41
|
+
export declare function shuffleArray<T>(originalArray: T[] | readonly T[], seed?: Seed): T[];
|
|
43
42
|
/**
|
|
44
43
|
* Shuffles the provided array in-place using the Fisher-Yates algorithm.
|
|
45
44
|
*
|
|
46
45
|
* From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
47
46
|
*/
|
|
48
|
-
export declare function shuffleArrayInPlace<T>(array: T[], seed?:
|
|
47
|
+
export declare function shuffleArrayInPlace<T>(array: T[], seed?: Seed): void;
|
|
49
48
|
export declare function sumArray(array: number[] | readonly number[]): number;
|
|
50
49
|
export declare function arrayToString<T>(array: T[]): string;
|
|
51
50
|
/**
|
|
@@ -70,7 +69,7 @@ export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: T
|
|
|
70
69
|
* @param seed Optional. The seed used to select the random element. Default is `Random()`.
|
|
71
70
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
72
71
|
*/
|
|
73
|
-
export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed?:
|
|
72
|
+
export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed?: Seed, exceptions?: T[] | readonly T[]): T;
|
|
74
73
|
/**
|
|
75
74
|
* Helper function to get a random element from the provided array. Once the random element is
|
|
76
75
|
* decided, it is then removed from the array (in-place).
|
|
@@ -79,8 +78,8 @@ export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed
|
|
|
79
78
|
* @param seed Optional. The seed used to select the random element. Default is `Random()`.
|
|
80
79
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
81
80
|
*/
|
|
82
|
-
export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?:
|
|
83
|
-
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seed?:
|
|
81
|
+
export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?: Seed, exceptions?: T[] | readonly T[]): T;
|
|
82
|
+
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seed?: Seed): int;
|
|
84
83
|
/**
|
|
85
84
|
* Since Lua uses tables for every non-primitive data structure, it is non-trivial to determine if a
|
|
86
85
|
* particular table is being used as an array. isArray returns true if:
|
|
@@ -88,4 +87,4 @@ export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seed?:
|
|
|
88
87
|
* - the table contains all numerical indexes that are contiguous, starting at 1
|
|
89
88
|
* - the table has no keys (i.e. an "empty" table)
|
|
90
89
|
*/
|
|
91
|
-
export declare function isArray(
|
|
90
|
+
export declare function isArray(thing: unknown): boolean;
|
package/dist/functions/array.lua
CHANGED
|
@@ -155,6 +155,9 @@ function ____exports.getRandomArrayElement(self, array, seed, exceptions)
|
|
|
155
155
|
if exceptions == nil then
|
|
156
156
|
exceptions = {}
|
|
157
157
|
end
|
|
158
|
+
if #array == 0 then
|
|
159
|
+
error("Failed to get a random array element since the provided array is empty.")
|
|
160
|
+
end
|
|
158
161
|
local arrayWithoutExceptions = ____exports.arrayRemove(
|
|
159
162
|
nil,
|
|
160
163
|
array,
|
|
@@ -174,22 +177,29 @@ function ____exports.getRandomArrayElementAndRemove(self, array, seed, exception
|
|
|
174
177
|
____exports.arrayRemoveInPlace(nil, array, randomArrayElement)
|
|
175
178
|
return randomArrayElement
|
|
176
179
|
end
|
|
177
|
-
function ____exports.isArray(self,
|
|
178
|
-
|
|
180
|
+
function ____exports.isArray(self, thing)
|
|
181
|
+
if type(thing) ~= "table" then
|
|
182
|
+
return false
|
|
183
|
+
end
|
|
184
|
+
local thingTable = thing
|
|
185
|
+
local metatable = getmetatable(thingTable)
|
|
179
186
|
if metatable ~= nil then
|
|
180
187
|
return false
|
|
181
188
|
end
|
|
182
189
|
local numEntries = 0
|
|
183
|
-
for key in pairs(
|
|
190
|
+
for key in pairs(thingTable) do
|
|
184
191
|
numEntries = numEntries + 1
|
|
185
192
|
if type(key) ~= "number" then
|
|
186
193
|
return false
|
|
187
194
|
end
|
|
188
195
|
end
|
|
196
|
+
if numEntries == 0 then
|
|
197
|
+
return true
|
|
198
|
+
end
|
|
189
199
|
do
|
|
190
200
|
local i = 1
|
|
191
201
|
while i <= numEntries do
|
|
192
|
-
local element =
|
|
202
|
+
local element = thingTable[i]
|
|
193
203
|
if element == nil then
|
|
194
204
|
return false
|
|
195
205
|
end
|
|
@@ -40,13 +40,13 @@ export declare function getMaxCards(): int;
|
|
|
40
40
|
* @param seed Optional. The seed with which to select the random card. Default is `Random()`.
|
|
41
41
|
* @param exceptions Optional. An array of cards to not select.
|
|
42
42
|
*/
|
|
43
|
-
export declare function getRandomCard(seed?:
|
|
43
|
+
export declare function getRandomCard(seed?: Seed, exceptions?: Card[]): Card;
|
|
44
44
|
/**
|
|
45
45
|
* @param cardType The card type that represents the pool of cards to select from.
|
|
46
46
|
* @param seed Optional. The seed with which to select the random card. Default is `Random()`.
|
|
47
47
|
* @param exceptions Optional. An array of cards to not select.
|
|
48
48
|
*/
|
|
49
|
-
export declare function getRandomCardOfType(cardType: CardType, seed?:
|
|
49
|
+
export declare function getRandomCardOfType(cardType: CardType, seed?: Seed, exceptions?: Card[]): Card;
|
|
50
50
|
/**
|
|
51
51
|
* Has an equal chance of returning any rune (e.g. Rune of Hagalaz, Blank Rune, Black Rune, Soul of
|
|
52
52
|
* Isaac, etc.). This will never return a Rune Shard.
|
|
@@ -54,7 +54,7 @@ export declare function getRandomCardOfType(cardType: CardType, seed?: number, e
|
|
|
54
54
|
* @param seed Optional. The seed with which to select the random rune. Default is `Random()`.
|
|
55
55
|
* @param exceptions Optional. An array of runes to not select.
|
|
56
56
|
*/
|
|
57
|
-
export declare function getRandomRune(seed?:
|
|
57
|
+
export declare function getRandomRune(seed?: Seed, exceptions?: Card[]): Card;
|
|
58
58
|
/**
|
|
59
59
|
* Returns true for cards that have the following card type:
|
|
60
60
|
* - CardType.TAROT
|
|
@@ -9,4 +9,4 @@ export declare function getJSONRoomsOfSubType(jsonRooms: JSONRoom[], subType: in
|
|
|
9
9
|
* properly account for each room weight using the algorithm from:
|
|
10
10
|
* https://stackoverflow.com/questions/1761626/weighted-random-numbers
|
|
11
11
|
*/
|
|
12
|
-
export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], seed?:
|
|
12
|
+
export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], seed?: Seed, verbose?: boolean): JSONRoom;
|
package/dist/functions/map.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
+
/// <reference types="isaac-typescript-definitions" />
|
|
2
|
+
import { DefaultMap } from "../types/DefaultMap";
|
|
3
|
+
import { PlayerIndex } from "../types/PlayerIndex";
|
|
1
4
|
/** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
|
|
2
5
|
export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
|
|
6
|
+
/**
|
|
7
|
+
* Helper function to make using default maps with an index of `PlayerIndex` easier. Use this
|
|
8
|
+
* instead of the `DefaultMap.getAndSetDefault` method.
|
|
9
|
+
*/
|
|
10
|
+
export declare function defaultMapGetPlayer<V>(map: DefaultMap<PlayerIndex, V>, player: EntityPlayer): V | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
|
|
13
|
+
* `Map.get` method.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mapGetPlayer<V>(map: Map<PlayerIndex, V>, player: EntityPlayer): V | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
|
|
18
|
+
* `Map.set` method.
|
|
19
|
+
*/
|
|
20
|
+
export declare function mapSetPlayer<V>(map: Map<PlayerIndex, V>, player: EntityPlayer, value: V): void;
|
package/dist/functions/map.lua
CHANGED
|
@@ -4,6 +4,8 @@ local Map = ____lualib.Map
|
|
|
4
4
|
local __TS__New = ____lualib.__TS__New
|
|
5
5
|
local __TS__Iterator = ____lualib.__TS__Iterator
|
|
6
6
|
local ____exports = {}
|
|
7
|
+
local ____player = require("functions.player")
|
|
8
|
+
local getPlayerIndex = ____player.getPlayerIndex
|
|
7
9
|
function ____exports.copyMap(self, oldMap)
|
|
8
10
|
local newMap = __TS__New(Map)
|
|
9
11
|
for ____, ____value in __TS__Iterator(oldMap:entries()) do
|
|
@@ -13,4 +15,16 @@ function ____exports.copyMap(self, oldMap)
|
|
|
13
15
|
end
|
|
14
16
|
return newMap
|
|
15
17
|
end
|
|
18
|
+
function ____exports.defaultMapGetPlayer(self, map, player)
|
|
19
|
+
local playerIndex = getPlayerIndex(nil, player)
|
|
20
|
+
return map:getAndSetDefault(playerIndex)
|
|
21
|
+
end
|
|
22
|
+
function ____exports.mapGetPlayer(self, map, player)
|
|
23
|
+
local playerIndex = getPlayerIndex(nil, player)
|
|
24
|
+
return map:get(playerIndex)
|
|
25
|
+
end
|
|
26
|
+
function ____exports.mapSetPlayer(self, map, player, value)
|
|
27
|
+
local playerIndex = getPlayerIndex(nil, player)
|
|
28
|
+
map:set(playerIndex, value)
|
|
29
|
+
end
|
|
16
30
|
return ____exports
|
|
@@ -250,6 +250,11 @@ export declare function isBethany(player: EntityPlayer): boolean;
|
|
|
250
250
|
* (For example, the Strawman Keeper.)
|
|
251
251
|
*/
|
|
252
252
|
export declare function isChildPlayer(player: EntityPlayer): boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Helper function for detecting when a player is Eden or Tainted Eden. Useful for situations where
|
|
255
|
+
* you want to know if the starting stats were randomized, for example.
|
|
256
|
+
*/
|
|
257
|
+
export declare function isEden(player: EntityPlayer): boolean;
|
|
253
258
|
export declare function isFirstPlayer(player: EntityPlayer): boolean;
|
|
254
259
|
/**
|
|
255
260
|
* Helper function for detecting when a player is Jacob or Esau. This will only match the
|
|
@@ -543,6 +543,10 @@ function ____exports.isBethany(self, player)
|
|
|
543
543
|
local character = player:GetPlayerType()
|
|
544
544
|
return character == PlayerType.PLAYER_BETHANY or character == PlayerType.PLAYER_BETHANY_B
|
|
545
545
|
end
|
|
546
|
+
function ____exports.isEden(self, player)
|
|
547
|
+
local character = player:GetPlayerType()
|
|
548
|
+
return character == PlayerType.PLAYER_EDEN or character == PlayerType.PLAYER_EDEN_B
|
|
549
|
+
end
|
|
546
550
|
function ____exports.isFirstPlayer(self, player)
|
|
547
551
|
return ____exports.getPlayerIndexVanilla(nil, player) == 0
|
|
548
552
|
end
|
|
@@ -603,9 +607,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
|
|
|
603
607
|
itemPool:RemoveCollectible(collectibleType)
|
|
604
608
|
end
|
|
605
609
|
repeat
|
|
606
|
-
local
|
|
607
|
-
local
|
|
608
|
-
if
|
|
610
|
+
local ____switch129 = activeSlot
|
|
611
|
+
local ____cond129 = ____switch129 == ActiveSlot.SLOT_PRIMARY
|
|
612
|
+
if ____cond129 then
|
|
609
613
|
do
|
|
610
614
|
if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
|
|
611
615
|
player:RemoveCollectible(primaryCollectibleType)
|
|
@@ -614,8 +618,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
|
|
|
614
618
|
break
|
|
615
619
|
end
|
|
616
620
|
end
|
|
617
|
-
|
|
618
|
-
if
|
|
621
|
+
____cond129 = ____cond129 or ____switch129 == ActiveSlot.SLOT_SECONDARY
|
|
622
|
+
if ____cond129 then
|
|
619
623
|
do
|
|
620
624
|
if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
|
|
621
625
|
player:RemoveCollectible(primaryCollectibleType)
|
|
@@ -630,16 +634,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
|
|
|
630
634
|
break
|
|
631
635
|
end
|
|
632
636
|
end
|
|
633
|
-
|
|
634
|
-
if
|
|
637
|
+
____cond129 = ____cond129 or ____switch129 == ActiveSlot.SLOT_POCKET
|
|
638
|
+
if ____cond129 then
|
|
635
639
|
do
|
|
636
640
|
player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
|
|
637
641
|
player:SetActiveCharge(charge, activeSlot)
|
|
638
642
|
break
|
|
639
643
|
end
|
|
640
644
|
end
|
|
641
|
-
|
|
642
|
-
if
|
|
645
|
+
____cond129 = ____cond129 or ____switch129 == ActiveSlot.SLOT_POCKET2
|
|
646
|
+
if ____cond129 then
|
|
643
647
|
do
|
|
644
648
|
player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
|
|
645
649
|
break
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* the high end. (This is because `RNG.RandomFloat()` can return a value of 0.999, but it will never
|
|
5
5
|
* return a value of exactly 1.)
|
|
6
6
|
*/
|
|
7
|
-
export declare function getRandom(seed?:
|
|
7
|
+
export declare function getRandom(seed?: Seed): float;
|
|
8
8
|
/**
|
|
9
9
|
* This returns a random float between min and max. It is inclusive on the low end, but exclusive on
|
|
10
10
|
* the high end. (This is because `RNG.RandomFloat()` can return a value of 0.999, but it will never
|
|
@@ -15,7 +15,7 @@ export declare function getRandom(seed?: number): float;
|
|
|
15
15
|
* const realNumberBetweenOneAndThree = getRandomFloat(1, 3, seed);
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
export declare function getRandomFloat(min: int, max: int, seed?:
|
|
18
|
+
export declare function getRandomFloat(min: int, max: int, seed?: Seed): float;
|
|
19
19
|
/**
|
|
20
20
|
* This returns a random integer between min and max, inclusive.
|
|
21
21
|
*
|
|
@@ -24,14 +24,14 @@ export declare function getRandomFloat(min: int, max: int, seed?: number): float
|
|
|
24
24
|
* const oneTwoOrThree = getRandomInt(1, 3, seed);
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
export declare function getRandomInt(min: int, max: int, seed?:
|
|
27
|
+
export declare function getRandomInt(min: int, max: int, seed?: Seed): int;
|
|
28
28
|
/**
|
|
29
29
|
* Helper function to get the next seed value.
|
|
30
30
|
*
|
|
31
31
|
* This function is useful because it is standard practice to work with seed values directly over
|
|
32
32
|
* RNG objects, since the latter are not serializable.
|
|
33
33
|
*/
|
|
34
|
-
export declare function nextSeed(seed:
|
|
34
|
+
export declare function nextSeed(seed: Seed): Seed;
|
|
35
35
|
/**
|
|
36
36
|
* Helper function to initialize an RNG object.
|
|
37
37
|
*
|
|
@@ -46,4 +46,4 @@ export declare function nextSeed(seed: int): int;
|
|
|
46
46
|
* (If you aren't initializing it with a seed, then don't use this function and instead simply call
|
|
47
47
|
* the `RNG()` constructor.)
|
|
48
48
|
*/
|
|
49
|
-
export declare function initRNG(seed?:
|
|
49
|
+
export declare function initRNG(seed?: Seed): RNG;
|
package/dist/functions/set.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="isaac-typescript-definitions" />
|
|
1
2
|
/**
|
|
2
3
|
* Helper function to add all of the values in one set to another set. The first set passed will be
|
|
3
4
|
* modified in place.
|
|
@@ -27,7 +28,7 @@ export declare function deleteSetsFromSet<T>(mainSet: Set<T>, ...setsToRemove: A
|
|
|
27
28
|
* @param seed Optional. The seed used to select the random element. Default is `Random()`.
|
|
28
29
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
29
30
|
*/
|
|
30
|
-
export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>, seed?:
|
|
31
|
+
export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>, seed?: Seed, exceptions?: T[] | readonly T[]): T;
|
|
31
32
|
/**
|
|
32
33
|
* Helper function to get a sorted array based on the contents of a set.
|
|
33
34
|
*
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
|
|
13
13
|
* Tainted Keeper. Default is false.
|
|
14
14
|
*/
|
|
15
|
-
export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector, seed?:
|
|
15
|
+
export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector, seed?: Seed, options?: boolean, forceFreeItem?: boolean): EntityPickup;
|
|
16
16
|
/**
|
|
17
17
|
* Helper function to spawn an empty collectible. Doing this is tricky since spawning a collectible
|
|
18
18
|
* with `CollectibleType.COLLECTIBLE_NULL` will result in spawning a collectible with a random type
|
|
@@ -21,4 +21,4 @@ export declare function spawnCollectible(collectibleType: CollectibleType | int,
|
|
|
21
21
|
* Instead, this function arbitrarily spawns a collectible with
|
|
22
22
|
* `CollectibleType.COLLECTIBLE_SAD_ONION`, and then converts it to an empty pedestal afterward.
|
|
23
23
|
*/
|
|
24
|
-
export declare function spawnEmptyCollectible(position: Vector, seed?:
|
|
24
|
+
export declare function spawnEmptyCollectible(position: Vector, seed?: Seed): EntityPickup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.123",
|
|
4
4
|
"description": "Helper functions for IsaacScript mods",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@zamiell/typescript-to-lua": "^1.4.2",
|
|
29
|
-
"isaac-typescript-definitions": "^1.0.
|
|
29
|
+
"isaac-typescript-definitions": "^1.0.360",
|
|
30
30
|
"isaacscript-lint": "^1.0.84",
|
|
31
31
|
"isaacscript-tsconfig": "^1.1.8",
|
|
32
32
|
"typedoc": "^0.22.13",
|