isaacscript-common 4.0.4 → 4.1.0
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.
|
@@ -5,6 +5,7 @@ local __TS__Spread = ____lualib.__TS__Spread
|
|
|
5
5
|
local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
|
|
6
6
|
local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
|
|
7
7
|
local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
|
|
8
|
+
local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
8
9
|
local ____exports = {}
|
|
9
10
|
local hasSubscriptions, postPEffectUpdate, collectibleCountChanged, v
|
|
10
11
|
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
@@ -48,7 +49,7 @@ function postPEffectUpdate(self, player)
|
|
|
48
49
|
end
|
|
49
50
|
end
|
|
50
51
|
function collectibleCountChanged(self, player, numCollectiblesChanged, increased)
|
|
51
|
-
local oldCollectibleMap = defaultMapGetPlayer(nil, v.run.playersCollectibleMap, player
|
|
52
|
+
local oldCollectibleMap = defaultMapGetPlayer(nil, v.run.playersCollectibleMap, player)
|
|
52
53
|
local newCollectibleMap = getPlayerCollectibleMap(nil, player)
|
|
53
54
|
mapSetPlayer(nil, v.run.playersCollectibleMap, player, newCollectibleMap)
|
|
54
55
|
local ____array_0 = __TS__SparseArrayNew(__TS__Spread(oldCollectibleMap:keys()))
|
|
@@ -57,6 +58,7 @@ function collectibleCountChanged(self, player, numCollectiblesChanged, increased
|
|
|
57
58
|
__TS__Spread(newCollectibleMap:keys())
|
|
58
59
|
)
|
|
59
60
|
local collectibleTypes = {__TS__SparseArraySpread(____array_0)}
|
|
61
|
+
__TS__ArraySort(collectibleTypes)
|
|
60
62
|
local numFired = 0
|
|
61
63
|
for ____, collectibleType in ipairs(collectibleTypes) do
|
|
62
64
|
local oldNum = oldCollectibleMap:get(collectibleType) or 0
|
|
@@ -83,7 +85,7 @@ v = {run = {
|
|
|
83
85
|
playersCollectibleCount = __TS__New(Map),
|
|
84
86
|
playersCollectibleMap = __TS__New(
|
|
85
87
|
DefaultMap,
|
|
86
|
-
function(
|
|
88
|
+
function() return __TS__New(Map) end
|
|
87
89
|
)
|
|
88
90
|
}}
|
|
89
91
|
---
|
|
@@ -1,9 +1,44 @@
|
|
|
1
1
|
import { CollectibleType } from "isaac-typescript-definitions";
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array containing every valid collectible type in the game, including modded
|
|
4
|
+
* collectibles.
|
|
5
|
+
*
|
|
6
|
+
* Use this if you need to iterate over the collectibles in order. If you need to do O(1) lookups,
|
|
7
|
+
* then use the `getCollectibleArray` helper function instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getCollectibleArray(): readonly CollectibleType[];
|
|
2
10
|
/**
|
|
3
11
|
* Returns a set containing every valid collectible type in the game, including modded collectibles.
|
|
12
|
+
*
|
|
13
|
+
* Use this if you need to do O(1) lookups. If you need to iterate over the collectibles in order,
|
|
14
|
+
* then use the `getCollectibleArray` helper function instead.
|
|
4
15
|
*/
|
|
5
16
|
export declare function getCollectibleSet(): ReadonlySet<CollectibleType>;
|
|
6
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Returns an array containing every modded collectible type in the game.
|
|
19
|
+
*
|
|
20
|
+
* Use this if you need to iterate over the collectibles in order. If you need to do O(1) lookups,
|
|
21
|
+
* then use the `getModdedCollectibleSet` helper function instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getModdedCollectibleArray(): readonly CollectibleType[];
|
|
24
|
+
/**
|
|
25
|
+
* Returns a set containing every modded collectible type in the game.
|
|
26
|
+
*
|
|
27
|
+
* Use this if you need to do O(1) lookups. If you need to iterate over the collectibles in order,
|
|
28
|
+
* then use the `getModdedCollectibleArray` helper function instead.
|
|
29
|
+
*/
|
|
7
30
|
export declare function getModdedCollectibleSet(): ReadonlySet<CollectibleType>;
|
|
8
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Returns an array containing every valid vanilla collectible type in the game.
|
|
33
|
+
*
|
|
34
|
+
* Use this if you need to iterate over the collectibles in order. If you need to do O(1) lookups,
|
|
35
|
+
* then use the `getVanillaCollectibleSet` helper function instead.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getVanillaCollectibleArray(): readonly CollectibleType[];
|
|
38
|
+
/**
|
|
39
|
+
* Returns a set containing every valid vanilla collectible type in the game.
|
|
40
|
+
*
|
|
41
|
+
* Use this if you need to do O(1) lookups. If you need to iterate over the collectibles in order,
|
|
42
|
+
* then use the `getVanillaCollectibleArray` helper function instead.
|
|
43
|
+
*/
|
|
9
44
|
export declare function getVanillaCollectibleSet(): ReadonlySet<CollectibleType>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local Set = ____lualib.Set
|
|
3
3
|
local __TS__New = ____lualib.__TS__New
|
|
4
|
+
local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
4
5
|
local ____exports = {}
|
|
5
6
|
local ____cachedClasses = require("cachedClasses")
|
|
6
7
|
local itemConfig = ____cachedClasses.itemConfig
|
|
@@ -8,45 +9,91 @@ local ____constantsFirstLast = require("constantsFirstLast")
|
|
|
8
9
|
local LAST_VANILLA_COLLECTIBLE_TYPE = ____constantsFirstLast.LAST_VANILLA_COLLECTIBLE_TYPE
|
|
9
10
|
local ____collectibles = require("functions.collectibles")
|
|
10
11
|
local getCollectibleTypeRange = ____collectibles.getCollectibleTypeRange
|
|
12
|
+
local ALL_COLLECTIBLES_ARRAY = {}
|
|
13
|
+
local VANILLA_COLLECTIBLES_ARRAY = {}
|
|
14
|
+
local MODDED_COLLECTIBLES_ARRAY = {}
|
|
11
15
|
local ALL_COLLECTIBLES_SET = __TS__New(Set)
|
|
12
16
|
local VANILLA_COLLECTIBLES_SET = __TS__New(Set)
|
|
13
17
|
local MODDED_COLLECTIBLES_SET = __TS__New(Set)
|
|
14
|
-
local function
|
|
18
|
+
local function initCollectibleArraysAndSets(self)
|
|
19
|
+
if #ALL_COLLECTIBLES_ARRAY ~= 0 then
|
|
20
|
+
return
|
|
21
|
+
end
|
|
15
22
|
for ____, collectibleType in ipairs(getCollectibleTypeRange(nil)) do
|
|
16
23
|
do
|
|
17
24
|
local itemConfigItem = itemConfig:GetCollectible(collectibleType)
|
|
18
25
|
if itemConfigItem == nil then
|
|
19
|
-
goto
|
|
26
|
+
goto __continue4
|
|
20
27
|
end
|
|
21
|
-
|
|
28
|
+
ALL_COLLECTIBLES_ARRAY[#ALL_COLLECTIBLES_ARRAY + 1] = collectibleType
|
|
22
29
|
if collectibleType <= LAST_VANILLA_COLLECTIBLE_TYPE then
|
|
23
|
-
|
|
30
|
+
VANILLA_COLLECTIBLES_ARRAY[#VANILLA_COLLECTIBLES_ARRAY + 1] = collectibleType
|
|
24
31
|
else
|
|
25
|
-
|
|
32
|
+
MODDED_COLLECTIBLES_ARRAY[#MODDED_COLLECTIBLES_ARRAY + 1] = collectibleType
|
|
26
33
|
end
|
|
27
34
|
end
|
|
28
|
-
::
|
|
35
|
+
::__continue4::
|
|
36
|
+
end
|
|
37
|
+
__TS__ArraySort(ALL_COLLECTIBLES_ARRAY)
|
|
38
|
+
__TS__ArraySort(VANILLA_COLLECTIBLES_ARRAY)
|
|
39
|
+
__TS__ArraySort(MODDED_COLLECTIBLES_ARRAY)
|
|
40
|
+
for ____, collectibleType in ipairs(ALL_COLLECTIBLES_ARRAY) do
|
|
41
|
+
ALL_COLLECTIBLES_SET:add(collectibleType)
|
|
42
|
+
end
|
|
43
|
+
for ____, collectibleType in ipairs(VANILLA_COLLECTIBLES_ARRAY) do
|
|
44
|
+
VANILLA_COLLECTIBLES_SET:add(collectibleType)
|
|
29
45
|
end
|
|
46
|
+
for ____, collectibleType in ipairs(MODDED_COLLECTIBLES_ARRAY) do
|
|
47
|
+
MODDED_COLLECTIBLES_SET:add(collectibleType)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
--- Returns an array containing every valid collectible type in the game, including modded
|
|
51
|
+
-- collectibles.
|
|
52
|
+
--
|
|
53
|
+
-- Use this if you need to iterate over the collectibles in order. If you need to do O(1) lookups,
|
|
54
|
+
-- then use the `getCollectibleArray` helper function instead.
|
|
55
|
+
function ____exports.getCollectibleArray(self)
|
|
56
|
+
initCollectibleArraysAndSets(nil)
|
|
57
|
+
return ALL_COLLECTIBLES_ARRAY
|
|
30
58
|
end
|
|
31
59
|
--- Returns a set containing every valid collectible type in the game, including modded collectibles.
|
|
60
|
+
--
|
|
61
|
+
-- Use this if you need to do O(1) lookups. If you need to iterate over the collectibles in order,
|
|
62
|
+
-- then use the `getCollectibleArray` helper function instead.
|
|
32
63
|
function ____exports.getCollectibleSet(self)
|
|
33
|
-
|
|
34
|
-
initCollectibleSets(nil)
|
|
35
|
-
end
|
|
64
|
+
initCollectibleArraysAndSets(nil)
|
|
36
65
|
return ALL_COLLECTIBLES_SET
|
|
37
66
|
end
|
|
67
|
+
--- Returns an array containing every modded collectible type in the game.
|
|
68
|
+
--
|
|
69
|
+
-- Use this if you need to iterate over the collectibles in order. If you need to do O(1) lookups,
|
|
70
|
+
-- then use the `getModdedCollectibleSet` helper function instead.
|
|
71
|
+
function ____exports.getModdedCollectibleArray(self)
|
|
72
|
+
initCollectibleArraysAndSets(nil)
|
|
73
|
+
return MODDED_COLLECTIBLES_ARRAY
|
|
74
|
+
end
|
|
38
75
|
--- Returns a set containing every modded collectible type in the game.
|
|
76
|
+
--
|
|
77
|
+
-- Use this if you need to do O(1) lookups. If you need to iterate over the collectibles in order,
|
|
78
|
+
-- then use the `getModdedCollectibleArray` helper function instead.
|
|
39
79
|
function ____exports.getModdedCollectibleSet(self)
|
|
40
|
-
|
|
41
|
-
initCollectibleSets(nil)
|
|
42
|
-
end
|
|
80
|
+
initCollectibleArraysAndSets(nil)
|
|
43
81
|
return MODDED_COLLECTIBLES_SET
|
|
44
82
|
end
|
|
83
|
+
--- Returns an array containing every valid vanilla collectible type in the game.
|
|
84
|
+
--
|
|
85
|
+
-- Use this if you need to iterate over the collectibles in order. If you need to do O(1) lookups,
|
|
86
|
+
-- then use the `getVanillaCollectibleSet` helper function instead.
|
|
87
|
+
function ____exports.getVanillaCollectibleArray(self)
|
|
88
|
+
initCollectibleArraysAndSets(nil)
|
|
89
|
+
return VANILLA_COLLECTIBLES_ARRAY
|
|
90
|
+
end
|
|
45
91
|
--- Returns a set containing every valid vanilla collectible type in the game.
|
|
92
|
+
--
|
|
93
|
+
-- Use this if you need to do O(1) lookups. If you need to iterate over the collectibles in order,
|
|
94
|
+
-- then use the `getVanillaCollectibleArray` helper function instead.
|
|
46
95
|
function ____exports.getVanillaCollectibleSet(self)
|
|
47
|
-
|
|
48
|
-
initCollectibleSets(nil)
|
|
49
|
-
end
|
|
96
|
+
initCollectibleArraysAndSets(nil)
|
|
50
97
|
return VANILLA_COLLECTIBLES_SET
|
|
51
98
|
end
|
|
52
99
|
return ____exports
|
package/functions/enums.d.ts
CHANGED
|
@@ -55,6 +55,12 @@ export declare function getEnumLength<T>(transpiledEnum: T): int;
|
|
|
55
55
|
* https://isaacscript.github.io/gotchas#iterating-over-enums
|
|
56
56
|
*/
|
|
57
57
|
export declare function getEnumValues<T>(transpiledEnum: T): Array<T[keyof T]>;
|
|
58
|
+
/**
|
|
59
|
+
* Helper function to get the enum value with the highest value.
|
|
60
|
+
*
|
|
61
|
+
* Note that this is not necessarily the enum value that is declared last, since there is no way to
|
|
62
|
+
* infer that at run-time.
|
|
63
|
+
*/
|
|
58
64
|
export declare function getLastEnumValue<T>(transpiledEnum: T): T[keyof T];
|
|
59
65
|
/**
|
|
60
66
|
* Helper function to get a random value from the provided enum.
|
|
@@ -66,8 +72,9 @@ export declare function getLastEnumValue<T>(transpiledEnum: T): T[keyof T];
|
|
|
66
72
|
*/
|
|
67
73
|
export declare function getRandomEnumValue<T>(transpiledEnum: T, seedOrRNG?: Seed | RNG, exceptions?: Array<T[keyof T]> | ReadonlyArray<T[keyof T]>): T[keyof T];
|
|
68
74
|
/**
|
|
69
|
-
* Helper function to check every value of a custom enum for -1.
|
|
70
|
-
* because many methods of the Isaac class return -1 if they
|
|
75
|
+
* Helper function to check every value of a custom enum for -1. Will throw an run-time error if any
|
|
76
|
+
* -1 values are found. This is helpful because many methods of the Isaac class return -1 if they
|
|
77
|
+
* fail.
|
|
71
78
|
*
|
|
72
79
|
* For example:
|
|
73
80
|
*
|
|
@@ -80,3 +87,9 @@ export declare function getRandomEnumValue<T>(transpiledEnum: T, seedOrRNG?: See
|
|
|
80
87
|
* ```
|
|
81
88
|
*/
|
|
82
89
|
export declare function validateCustomEnum(transpiledEnumName: string, transpiledEnum: unknown): void;
|
|
90
|
+
/**
|
|
91
|
+
* Helper function to validate if every value in an enum is contiguous, starting at 0.
|
|
92
|
+
*
|
|
93
|
+
* This is useful to automate checking large enums for typos.
|
|
94
|
+
*/
|
|
95
|
+
export declare function validateEnumContiguous<T>(transpiledEnumName: string, transpiledEnum: T): void;
|
package/functions/enums.lua
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
3
3
|
local __TS__ArrayMap = ____lualib.__TS__ArrayMap
|
|
4
|
+
local Set = ____lualib.Set
|
|
5
|
+
local __TS__New = ____lualib.__TS__New
|
|
4
6
|
local ____exports = {}
|
|
5
7
|
local ____array = require("functions.array")
|
|
6
8
|
local getRandomArrayElement = ____array.getRandomArrayElement
|
|
@@ -8,6 +10,8 @@ local ____rng = require("functions.rng")
|
|
|
8
10
|
local getRandomSeed = ____rng.getRandomSeed
|
|
9
11
|
local ____types = require("functions.types")
|
|
10
12
|
local isString = ____types.isString
|
|
13
|
+
local ____utils = require("functions.utils")
|
|
14
|
+
local irange = ____utils.irange
|
|
11
15
|
--- TypeScriptToLua will transpile TypeScript enums to Lua tables that have a double mapping. Thus,
|
|
12
16
|
-- when you iterate over them, you will get both the names of the enums and the values of the enums,
|
|
13
17
|
-- in a random order. Use this helper function to get the entries of the enum with the reverse
|
|
@@ -101,6 +105,10 @@ function ____exports.getEnumValues(self, transpiledEnum)
|
|
|
101
105
|
end
|
|
102
106
|
)
|
|
103
107
|
end
|
|
108
|
+
--- Helper function to get the enum value with the highest value.
|
|
109
|
+
--
|
|
110
|
+
-- Note that this is not necessarily the enum value that is declared last, since there is no way to
|
|
111
|
+
-- infer that at run-time.
|
|
104
112
|
function ____exports.getLastEnumValue(self, transpiledEnum)
|
|
105
113
|
local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
|
|
106
114
|
local lastElement = enumValues[#enumValues]
|
|
@@ -125,8 +133,9 @@ function ____exports.getRandomEnumValue(self, transpiledEnum, seedOrRNG, excepti
|
|
|
125
133
|
local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
|
|
126
134
|
return getRandomArrayElement(nil, enumValues, seedOrRNG, exceptions)
|
|
127
135
|
end
|
|
128
|
-
--- Helper function to check every value of a custom enum for -1.
|
|
129
|
-
-- because many methods of the Isaac class return -1 if they
|
|
136
|
+
--- Helper function to check every value of a custom enum for -1. Will throw an run-time error if any
|
|
137
|
+
-- -1 values are found. This is helpful because many methods of the Isaac class return -1 if they
|
|
138
|
+
-- fail.
|
|
130
139
|
--
|
|
131
140
|
-- For example:
|
|
132
141
|
--
|
|
@@ -142,7 +151,26 @@ function ____exports.validateCustomEnum(self, transpiledEnumName, transpiledEnum
|
|
|
142
151
|
local key = ____value[1]
|
|
143
152
|
local value = ____value[2]
|
|
144
153
|
if value == -1 then
|
|
145
|
-
error((("Failed to find custom enum value: " .. transpiledEnumName) .. ".") .. key)
|
|
154
|
+
error((("Failed to find the custom enum value: " .. transpiledEnumName) .. ".") .. key)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
--- Helper function to validate if every value in an enum is contiguous, starting at 0.
|
|
159
|
+
--
|
|
160
|
+
-- This is useful to automate checking large enums for typos.
|
|
161
|
+
function ____exports.validateEnumContiguous(self, transpiledEnumName, transpiledEnum)
|
|
162
|
+
local values = ____exports.getEnumValues(nil, transpiledEnum)
|
|
163
|
+
local valuesSet = __TS__New(Set, values)
|
|
164
|
+
local lastValue = values[#values]
|
|
165
|
+
if lastValue == nil then
|
|
166
|
+
error("Failed to validate that an enum was contiguous, since the last value was undefined.")
|
|
167
|
+
end
|
|
168
|
+
if type(lastValue) ~= "number" then
|
|
169
|
+
error("Failed to validate that an enum was contiguous, since the last value was not a number.")
|
|
170
|
+
end
|
|
171
|
+
for ____, value in ipairs(irange(nil, lastValue)) do
|
|
172
|
+
if not valuesSet:has(value) then
|
|
173
|
+
error((("Failed to find a custom enum value of " .. tostring(value)) .. " for: ") .. transpiledEnumName)
|
|
146
174
|
end
|
|
147
175
|
end
|
|
148
176
|
end
|
package/functions/player.lua
CHANGED
|
@@ -5,7 +5,6 @@ local __TS__ArraySome = ____lualib.__TS__ArraySome
|
|
|
5
5
|
local __TS__ArrayFind = ____lualib.__TS__ArrayFind
|
|
6
6
|
local __TS__ArrayMap = ____lualib.__TS__ArrayMap
|
|
7
7
|
local Map = ____lualib.Map
|
|
8
|
-
local __TS__Iterator = ____lualib.__TS__Iterator
|
|
9
8
|
local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
|
|
10
9
|
local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
|
|
11
10
|
local ____exports = {}
|
|
@@ -39,7 +38,7 @@ local isVanillaCharacter = ____character.isVanillaCharacter
|
|
|
39
38
|
local ____collectibles = require("functions.collectibles")
|
|
40
39
|
local getCollectibleMaxCharges = ____collectibles.getCollectibleMaxCharges
|
|
41
40
|
local ____collectibleSet = require("functions.collectibleSet")
|
|
42
|
-
local
|
|
41
|
+
local getCollectibleArray = ____collectibleSet.getCollectibleArray
|
|
43
42
|
local ____enums = require("functions.enums")
|
|
44
43
|
local getEnumValues = ____enums.getEnumValues
|
|
45
44
|
local ____playerIndex = require("functions.playerIndex")
|
|
@@ -404,9 +403,9 @@ end
|
|
|
404
403
|
--- Iterates over every item in the game and returns a map containing the number of each item that
|
|
405
404
|
-- the player has.
|
|
406
405
|
function ____exports.getPlayerCollectibleMap(self, player)
|
|
407
|
-
local
|
|
406
|
+
local collectibleArray = getCollectibleArray(nil)
|
|
408
407
|
local collectibleMap = __TS__New(Map)
|
|
409
|
-
for ____, collectibleType in
|
|
408
|
+
for ____, collectibleType in ipairs(collectibleArray) do
|
|
410
409
|
local collectibleNum = player:GetCollectibleNum(collectibleType, true)
|
|
411
410
|
if collectibleNum > 0 then
|
|
412
411
|
collectibleMap:set(collectibleType, collectibleNum)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
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.7"
|
|
26
26
|
}
|
|
27
27
|
}
|