isaacscript-common 4.0.4 → 4.0.5

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, 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(____, player) return getPlayerCollectibleMap(nil, player) end
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
- /** Returns a set containing every modded collectible type in the game. */
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
- /** Returns a set containing every valid vanilla collectible type in the game. */
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 initCollectibleSets(self)
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 __continue3
26
+ goto __continue4
20
27
  end
21
- ALL_COLLECTIBLES_SET:add(collectibleType)
28
+ ALL_COLLECTIBLES_ARRAY[#ALL_COLLECTIBLES_ARRAY + 1] = collectibleType
22
29
  if collectibleType <= LAST_VANILLA_COLLECTIBLE_TYPE then
23
- VANILLA_COLLECTIBLES_SET:add(collectibleType)
30
+ VANILLA_COLLECTIBLES_ARRAY[#VANILLA_COLLECTIBLES_ARRAY + 1] = collectibleType
24
31
  else
25
- MODDED_COLLECTIBLES_SET:add(collectibleType)
32
+ MODDED_COLLECTIBLES_ARRAY[#MODDED_COLLECTIBLES_ARRAY + 1] = collectibleType
26
33
  end
27
34
  end
28
- ::__continue3::
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
- if ALL_COLLECTIBLES_SET.size == 0 then
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
- if ALL_COLLECTIBLES_SET.size == 0 then
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
- if ALL_COLLECTIBLES_SET.size == 0 then
48
- initCollectibleSets(nil)
49
- end
96
+ initCollectibleArraysAndSets(nil)
50
97
  return VANILLA_COLLECTIBLES_SET
51
98
  end
52
99
  return ____exports
@@ -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 getCollectibleSet = ____collectibleSet.getCollectibleSet
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 collectibleSet = getCollectibleSet(nil)
406
+ local collectibleArray = getCollectibleArray(nil)
408
407
  local collectibleMap = __TS__New(Map)
409
- for ____, collectibleType in __TS__Iterator(collectibleSet:values()) do
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.4",
3
+ "version": "4.0.5",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",