isaacscript-common 5.0.0 → 5.0.3
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/functions/array.d.ts +3 -1
- package/functions/array.lua +13 -2
- package/functions/charge.d.ts +7 -3
- package/functions/charge.lua +15 -11
- package/functions/random.d.ts +2 -1
- package/functions/random.lua +3 -2
- package/objects/roomShapeToDoorSlotCoordinates.d.ts +5 -0
- package/objects/roomShapeToDoorSlotCoordinates.lua +0 -0
- package/package.json +2 -2
package/functions/array.d.ts
CHANGED
|
@@ -117,8 +117,10 @@ export declare function getRandomArrayElementAndRemove<T>(array: T[], seedOrRNG?
|
|
|
117
117
|
* @param array The array to get the index from.
|
|
118
118
|
* @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
119
119
|
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
120
|
+
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
121
|
+
* index. Default is an empty array.
|
|
120
122
|
*/
|
|
121
|
-
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seedOrRNG?: Seed | RNG): int;
|
|
123
|
+
export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seedOrRNG?: Seed | RNG, exceptions?: int[] | readonly int[]): int;
|
|
122
124
|
/**
|
|
123
125
|
* Initializes an array with all elements containing the specified default value.
|
|
124
126
|
*
|
package/functions/array.lua
CHANGED
|
@@ -32,14 +32,25 @@ local ____repeat = ____utils["repeat"]
|
|
|
32
32
|
-- @param array The array to get the index from.
|
|
33
33
|
-- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
34
34
|
-- `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
35
|
-
|
|
35
|
+
-- @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
36
|
+
-- index. Default is an empty array.
|
|
37
|
+
function ____exports.getRandomArrayIndex(self, array, seedOrRNG, exceptions)
|
|
36
38
|
if seedOrRNG == nil then
|
|
37
39
|
seedOrRNG = getRandomSeed(nil)
|
|
38
40
|
end
|
|
41
|
+
if exceptions == nil then
|
|
42
|
+
exceptions = {}
|
|
43
|
+
end
|
|
39
44
|
if #array == 0 then
|
|
40
45
|
error("Failed to get a random array index since the provided array is empty.")
|
|
41
46
|
end
|
|
42
|
-
return getRandomInt(
|
|
47
|
+
return getRandomInt(
|
|
48
|
+
nil,
|
|
49
|
+
0,
|
|
50
|
+
#array - 1,
|
|
51
|
+
seedOrRNG,
|
|
52
|
+
exceptions
|
|
53
|
+
)
|
|
43
54
|
end
|
|
44
55
|
--- Shuffles the provided array in-place using the Fisher-Yates algorithm.
|
|
45
56
|
--
|
package/functions/charge.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ActiveSlot } from "isaac-typescript-definitions";
|
|
2
2
|
/**
|
|
3
|
-
* Helper function to add a charge to the player's active item. Will
|
|
4
|
-
* effect, depending on whether the charge is partially full or completely full.
|
|
3
|
+
* Helper function to add a charge to the player's active item. Will flash the HUD and play the
|
|
4
|
+
* appropriate sound effect, depending on whether the charge is partially full or completely full.
|
|
5
|
+
*
|
|
6
|
+
* If the player's active item is already fully charged, then this function will return 0 and not
|
|
7
|
+
* flash the HUD or play a sound effect.
|
|
5
8
|
*
|
|
6
9
|
* This function will take the following things into account:
|
|
7
10
|
* - The Battery
|
|
@@ -12,7 +15,8 @@ import { ActiveSlot } from "isaac-typescript-definitions";
|
|
|
12
15
|
* @param numCharges Optional. The amount of charges to grant. Default is 1.
|
|
13
16
|
* @param playSoundEffect Optional. Whether to play a charge-related sound effect. Default is true.
|
|
14
17
|
* @returns The amount of charges that were actually granted. For example, if the active item was
|
|
15
|
-
*
|
|
18
|
+
* only one away from a full charge, but the `numCharges` provided to this function was 2,
|
|
19
|
+
* then this function would return 1.
|
|
16
20
|
*/
|
|
17
21
|
export declare function addCharge(player: EntityPlayer, activeSlot: ActiveSlot, numCharges?: number, playSoundEffect?: boolean): int;
|
|
18
22
|
/**
|
package/functions/charge.lua
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
local ____exports = {}
|
|
2
|
-
local getClampedChargesToAdd,
|
|
2
|
+
local getClampedChargesToAdd, getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
|
|
3
3
|
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
4
4
|
local ActiveSlot = ____isaac_2Dtypescript_2Ddefinitions.ActiveSlot
|
|
5
5
|
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
|
|
@@ -14,8 +14,11 @@ local ____playerIndex = require("functions.playerIndex")
|
|
|
14
14
|
local getPlayers = ____playerIndex.getPlayers
|
|
15
15
|
local ____roomShape = require("functions.roomShape")
|
|
16
16
|
local getRoomShapeCharges = ____roomShape.getRoomShapeCharges
|
|
17
|
-
--- Helper function to add a charge to the player's active item. Will
|
|
18
|
-
-- effect, depending on whether the charge is partially full or completely full.
|
|
17
|
+
--- Helper function to add a charge to the player's active item. Will flash the HUD and play the
|
|
18
|
+
-- appropriate sound effect, depending on whether the charge is partially full or completely full.
|
|
19
|
+
--
|
|
20
|
+
-- If the player's active item is already fully charged, then this function will return 0 and not
|
|
21
|
+
-- flash the HUD or play a sound effect.
|
|
19
22
|
--
|
|
20
23
|
-- This function will take the following things into account:
|
|
21
24
|
-- - The Battery
|
|
@@ -26,7 +29,8 @@ local getRoomShapeCharges = ____roomShape.getRoomShapeCharges
|
|
|
26
29
|
-- @param numCharges Optional. The amount of charges to grant. Default is 1.
|
|
27
30
|
-- @param playSoundEffect Optional. Whether to play a charge-related sound effect. Default is true.
|
|
28
31
|
-- @returns The amount of charges that were actually granted. For example, if the active item was
|
|
29
|
-
--
|
|
32
|
+
-- only one away from a full charge, but the `numCharges` provided to this function was 2,
|
|
33
|
+
-- then this function would return 1.
|
|
30
34
|
function ____exports.addCharge(self, player, activeSlot, numCharges, playSoundEffect)
|
|
31
35
|
if numCharges == nil then
|
|
32
36
|
numCharges = 1
|
|
@@ -35,9 +39,9 @@ function ____exports.addCharge(self, player, activeSlot, numCharges, playSoundEf
|
|
|
35
39
|
playSoundEffect = true
|
|
36
40
|
end
|
|
37
41
|
local hud = game:GetHUD()
|
|
38
|
-
local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
|
|
39
42
|
local chargesToAdd = getClampedChargesToAdd(nil, player, activeSlot, numCharges)
|
|
40
|
-
local modifiedChargesToAdd =
|
|
43
|
+
local modifiedChargesToAdd = getChargesToAddWithAAAModifier(nil, player, activeSlot, chargesToAdd)
|
|
44
|
+
local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
|
|
41
45
|
local newCharge = totalCharge + modifiedChargesToAdd
|
|
42
46
|
if newCharge == totalCharge then
|
|
43
47
|
return 0
|
|
@@ -101,7 +105,7 @@ function getClampedChargesToAdd(self, player, activeSlot, numCharges)
|
|
|
101
105
|
end
|
|
102
106
|
return numCharges
|
|
103
107
|
end
|
|
104
|
-
function
|
|
108
|
+
function getChargesToAddWithAAAModifier(self, player, activeSlot, chargesToAdd)
|
|
105
109
|
local activeItem = player:GetActiveItem(activeSlot)
|
|
106
110
|
local activeCharge = player:GetActiveCharge(activeSlot)
|
|
107
111
|
local batteryCharge = player:GetBatteryCharge(activeSlot)
|
|
@@ -112,10 +116,10 @@ function getNumChargesWithAAAModifier(self, player, activeSlot, chargesToAdd)
|
|
|
112
116
|
return chargesToAdd
|
|
113
117
|
end
|
|
114
118
|
if not hasBattery and activeCharge + chargesToAdd == maxCharges - 1 then
|
|
115
|
-
return
|
|
119
|
+
return chargesToAdd + 1
|
|
116
120
|
end
|
|
117
121
|
if hasBattery and batteryCharge + chargesToAdd == maxCharges - 1 then
|
|
118
|
-
return
|
|
122
|
+
return chargesToAdd + 1
|
|
119
123
|
end
|
|
120
124
|
return chargesToAdd
|
|
121
125
|
end
|
|
@@ -141,9 +145,9 @@ function shouldPlayFullRechargeSound(self, player, activeSlot)
|
|
|
141
145
|
local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
|
|
142
146
|
local maxCharges = getCollectibleMaxCharges(nil, activeItem)
|
|
143
147
|
if not hasBattery then
|
|
144
|
-
return
|
|
148
|
+
return activeCharge == maxCharges
|
|
145
149
|
end
|
|
146
|
-
return
|
|
150
|
+
return batteryCharge == maxCharges or activeCharge == maxCharges and batteryCharge == 0
|
|
147
151
|
end
|
|
148
152
|
--- Helper function to add a charge to a player's active item(s), emulating what happens when a room
|
|
149
153
|
-- is cleared.
|
package/functions/random.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare function getRandomFloat(min: int, max: int, seedOrRNG?: Seed | RN
|
|
|
42
42
|
* `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
43
43
|
* @param exceptions Optional. An array of elements that will be skipped over when getting the
|
|
44
44
|
* random integer. For example, a min of 1, a max of 4, and an exceptions array of
|
|
45
|
-
* `[2]` would cause the function to return either 1, 3, or 4.
|
|
45
|
+
* `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
|
|
46
|
+
* array.
|
|
46
47
|
*/
|
|
47
48
|
export declare function getRandomInt(min: int, max: int, seedOrRNG?: Seed | RNG, exceptions?: int[] | readonly int[]): int;
|
package/functions/random.lua
CHANGED
|
@@ -59,7 +59,8 @@ end
|
|
|
59
59
|
-- `RNG.Next` method will be called. Default is `getRandomSeed()`.
|
|
60
60
|
-- @param exceptions Optional. An array of elements that will be skipped over when getting the
|
|
61
61
|
-- random integer. For example, a min of 1, a max of 4, and an exceptions array of
|
|
62
|
-
-- `[2]` would cause the function to return either 1, 3, or 4.
|
|
62
|
+
-- `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
|
|
63
|
+
-- array.
|
|
63
64
|
function ____exports.getRandomInt(self, min, max, seedOrRNG, exceptions)
|
|
64
65
|
if seedOrRNG == nil then
|
|
65
66
|
seedOrRNG = getRandomSeed(nil)
|
|
@@ -80,7 +81,7 @@ function ____exports.getRandomInt(self, min, max, seedOrRNG, exceptions)
|
|
|
80
81
|
do
|
|
81
82
|
randomInt = rng:RandomInt(max - min + 1) + min
|
|
82
83
|
end
|
|
83
|
-
until exceptionsSet:has(randomInt)
|
|
84
|
+
until not exceptionsSet:has(randomInt)
|
|
84
85
|
return randomInt
|
|
85
86
|
end
|
|
86
87
|
return ____exports
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
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": "^3.0.
|
|
25
|
+
"isaac-typescript-definitions": "^3.0.18"
|
|
26
26
|
}
|
|
27
27
|
}
|