isaacscript-common 1.2.17 → 1.2.18

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.
@@ -0,0 +1,6 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Returns a set containing every collectible type with the given cache flag, including modded
4
+ * items.
5
+ */
6
+ export declare function getCollectiblesForCacheFlag(cacheFlag: CacheFlag): Set<CollectibleType | int>;
@@ -0,0 +1,41 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____lualib = require("lualib_bundle")
3
+ local Map = ____lualib.Map
4
+ local __TS__New = ____lualib.__TS__New
5
+ local Set = ____lualib.Set
6
+ local ____exports = {}
7
+ local ____collectibles = require("functions.collectibles")
8
+ local collectibleHasCacheFlag = ____collectibles.collectibleHasCacheFlag
9
+ local getMaxCollectibleID = ____collectibles.getMaxCollectibleID
10
+ local ____set = require("functions.set")
11
+ local copySet = ____set.copySet
12
+ local ____util = require("functions.util")
13
+ local getEnumValues = ____util.getEnumValues
14
+ local CACHE_FLAG_TO_COLLECTIBLES_MAP = __TS__New(Map)
15
+ local function initCacheFlagMap(self)
16
+ local maxCollectibleID = getMaxCollectibleID(nil)
17
+ for ____, cacheFlag in ipairs(getEnumValues(nil, CacheFlag)) do
18
+ local collectiblesSet = __TS__New(Set)
19
+ do
20
+ local collectibleType = 1
21
+ while collectibleType <= maxCollectibleID do
22
+ if collectibleHasCacheFlag(nil, collectibleType, cacheFlag) then
23
+ collectiblesSet:add(collectibleType)
24
+ end
25
+ collectibleType = collectibleType + 1
26
+ end
27
+ end
28
+ CACHE_FLAG_TO_COLLECTIBLES_MAP:set(cacheFlag, collectiblesSet)
29
+ end
30
+ end
31
+ function ____exports.getCollectiblesForCacheFlag(self, cacheFlag)
32
+ if CACHE_FLAG_TO_COLLECTIBLES_MAP.size == 0 then
33
+ initCacheFlagMap(nil)
34
+ end
35
+ local collectiblesSet = CACHE_FLAG_TO_COLLECTIBLES_MAP:get(cacheFlag)
36
+ if collectiblesSet == nil then
37
+ return __TS__New(Set)
38
+ end
39
+ return copySet(nil, collectiblesSet)
40
+ end
41
+ return ____exports
@@ -1,7 +1,7 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ export declare function getCollectibleTypesForTransformation(playerForm: PlayerForm): Set<PlayerForm>;
2
3
  /** Returns the number of items that a player has towards a particular transformation. */
3
4
  export declare function getPlayerNumTransformationCollectibles(player: EntityPlayer, playerForm: PlayerForm): int;
4
- export declare function getTransformationsForItem(collectibleType: CollectibleType | int): PlayerForm[];
5
5
  /**
6
6
  * Helper function to get a transformation name from a PlayerForm enum.
7
7
  *
@@ -12,3 +12,4 @@ export declare function getTransformationsForItem(collectibleType: CollectibleTy
12
12
  * ```
13
13
  */
14
14
  export declare function getTransformationName(transformation: PlayerForm): string;
15
+ export declare function getTransformationsForCollectibleType(collectibleType: CollectibleType | int): Set<PlayerForm>;
@@ -1,37 +1,104 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local Map = ____lualib.Map
4
+ local __TS__New = ____lualib.__TS__New
4
5
  local Set = ____lualib.Set
6
+ local __TS__Iterator = ____lualib.__TS__Iterator
5
7
  local ____exports = {}
6
- local ____transformationMaps = require("maps.transformationMaps")
7
- local ITEM_TO_TRANSFORMATION_MAP = ____transformationMaps.ITEM_TO_TRANSFORMATION_MAP
8
- local TRANSFORMATIONS_NOT_BASED_ON_ITEMS = ____transformationMaps.TRANSFORMATIONS_NOT_BASED_ON_ITEMS
9
- local TRANSFORMATION_TO_ITEMS_MAP = ____transformationMaps.TRANSFORMATION_TO_ITEMS_MAP
10
8
  local ____transformationNameMap = require("maps.transformationNameMap")
11
9
  local TRANSFORMATION_NAME_MAP = ____transformationNameMap.TRANSFORMATION_NAME_MAP
12
- local ____array = require("functions.array")
13
- local arrayCopy = ____array.arrayCopy
10
+ local ____collectibles = require("functions.collectibles")
11
+ local collectibleHasTag = ____collectibles.collectibleHasTag
12
+ local getMaxCollectibleID = ____collectibles.getMaxCollectibleID
13
+ local ____set = require("functions.set")
14
+ local copySet = ____set.copySet
15
+ local TRANSFORMATION_TO_TAG_MAP = __TS__New(Map, {
16
+ {PlayerForm.PLAYERFORM_GUPPY, 32},
17
+ {PlayerForm.PLAYERFORM_LORD_OF_THE_FLIES, 64},
18
+ {PlayerForm.PLAYERFORM_MUSHROOM, 256},
19
+ {PlayerForm.PLAYERFORM_ANGEL, 1024},
20
+ {PlayerForm.PLAYERFORM_BOB, 128},
21
+ {PlayerForm.PLAYERFORM_DRUGS, 2},
22
+ {PlayerForm.PLAYERFORM_MOM, 4},
23
+ {PlayerForm.PLAYERFORM_BABY, 512},
24
+ {PlayerForm.PLAYERFORM_EVIL_ANGEL, 2048},
25
+ {PlayerForm.PLAYERFORM_POOP, 4096},
26
+ {PlayerForm.PLAYERFORM_BOOK_WORM, 8192},
27
+ {PlayerForm.PLAYERFORM_SPIDERBABY, 16384}
28
+ })
29
+ local TRANSFORMATIONS_NOT_BASED_ON_ITEMS = __TS__New(Set, {PlayerForm.PLAYERFORM_ADULTHOOD, PlayerForm.PLAYERFORM_STOMPY, PlayerForm.PLAYERFORM_FLIGHT})
30
+ local TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP = __TS__New(Map)
31
+ local COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP = __TS__New(Map)
32
+ local function initMaps(self)
33
+ local maxCollectibleID = getMaxCollectibleID(nil)
34
+ for ____, playerForm in __TS__Iterator(TRANSFORMATION_TO_TAG_MAP:keys()) do
35
+ TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP:set(
36
+ playerForm,
37
+ __TS__New(Set)
38
+ )
39
+ end
40
+ do
41
+ local collectibleType = 1
42
+ while collectibleType <= maxCollectibleID do
43
+ for ____, ____value in __TS__Iterator(TRANSFORMATION_TO_TAG_MAP:entries()) do
44
+ local playerForm = ____value[1]
45
+ local tag = ____value[2]
46
+ do
47
+ if not collectibleHasTag(nil, collectibleType, tag) then
48
+ goto __continue6
49
+ end
50
+ local collectibleTypesSet = TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP:get(playerForm)
51
+ if collectibleTypesSet == nil then
52
+ error("Failed to get the collectible types for transformation: " .. tostring(playerForm))
53
+ end
54
+ collectibleTypesSet:add(collectibleType)
55
+ local transformations = COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP:get(collectibleType)
56
+ if transformations == nil then
57
+ transformations = __TS__New(Set)
58
+ COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP:set(collectibleType, transformations)
59
+ end
60
+ transformations:add(playerForm)
61
+ end
62
+ ::__continue6::
63
+ end
64
+ collectibleType = collectibleType + 1
65
+ end
66
+ end
67
+ end
68
+ function ____exports.getCollectibleTypesForTransformation(self, playerForm)
69
+ if TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP.size == 0 then
70
+ initMaps(nil)
71
+ end
72
+ local collectibleTypes = TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP:get(playerForm)
73
+ return collectibleTypes == nil and __TS__New(Set) or copySet(nil, collectibleTypes)
74
+ end
14
75
  function ____exports.getPlayerNumTransformationCollectibles(self, player, playerForm)
15
76
  if TRANSFORMATIONS_NOT_BASED_ON_ITEMS:has(playerForm) then
16
77
  error(("The transformation of " .. tostring(playerForm)) .. " cannot be tracked by this function.")
17
78
  end
18
- local itemsForTransformation = TRANSFORMATION_TO_ITEMS_MAP:get(playerForm)
79
+ if TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP.size == 0 then
80
+ initMaps(nil)
81
+ end
82
+ local itemsForTransformation = TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP:get(playerForm)
19
83
  if itemsForTransformation == nil then
20
84
  error(("The transformation of " .. tostring(playerForm)) .. " is not a valid value of the PlayerForm enum.")
21
85
  end
22
86
  local numCollectibles = 0
23
- for ____, collectibleType in ipairs(itemsForTransformation) do
87
+ for ____, collectibleType in __TS__Iterator(itemsForTransformation:values()) do
24
88
  numCollectibles = numCollectibles + player:GetCollectibleNum(collectibleType)
25
89
  end
26
90
  return numCollectibles
27
91
  end
28
- function ____exports.getTransformationsForItem(self, collectibleType)
29
- local transformations = ITEM_TO_TRANSFORMATION_MAP:get(collectibleType)
30
- return transformations == nil and ({}) or arrayCopy(nil, transformations)
31
- end
32
92
  function ____exports.getTransformationName(self, transformation)
33
93
  local defaultName = "Unknown"
34
94
  local transformationName = TRANSFORMATION_NAME_MAP:get(transformation)
35
95
  return transformationName == nil and defaultName or transformationName
36
96
  end
97
+ function ____exports.getTransformationsForCollectibleType(self, collectibleType)
98
+ if COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP.size == 0 then
99
+ initMaps(nil)
100
+ end
101
+ local transformations = COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP:get(collectibleType)
102
+ return transformations == nil and __TS__New(Set) or copySet(nil, transformations)
103
+ end
37
104
  return ____exports
@@ -1,9 +1,6 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /// <reference types="typescript-to-lua/language-extensions" />
3
- /**
4
- * Using a Map constructor to copy a Map does not seem to work properly, so use this helper function
5
- * instead.
6
- */
3
+ /** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
7
4
  export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
8
5
  /**
9
6
  * Helper function to get type safety on a switch statement.
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from "./functions/bitwise";
13
13
  export * from "./functions/cards";
14
14
  export * from "./functions/challenges";
15
15
  export * from "./functions/charge";
16
+ export * from "./functions/collectibleCacheFlag";
16
17
  export * from "./functions/collectibles";
17
18
  export * from "./functions/collectibleSet";
18
19
  export * from "./functions/color";
@@ -61,7 +62,6 @@ export * from "./maps/pillEffectClassMap";
61
62
  export * from "./maps/pillEffectNameMap";
62
63
  export * from "./maps/pillEffectTypeMap";
63
64
  export * from "./maps/roomShapeToTopLeftWallGridIndexMap";
64
- export * from "./maps/transformationMaps";
65
65
  export * from "./maps/transformationNameMap";
66
66
  export * from "./maps/trinketNameMap";
67
67
  export * from "./sets/cards";
package/dist/index.lua CHANGED
@@ -116,6 +116,14 @@ do
116
116
  end
117
117
  end
118
118
  end
119
+ do
120
+ local ____export = require("functions.collectibleCacheFlag")
121
+ for ____exportKey, ____exportValue in pairs(____export) do
122
+ if ____exportKey ~= "default" then
123
+ ____exports[____exportKey] = ____exportValue
124
+ end
125
+ end
126
+ end
119
127
  do
120
128
  local ____export = require("functions.collectibles")
121
129
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -494,14 +502,6 @@ do
494
502
  end
495
503
  end
496
504
  end
497
- do
498
- local ____export = require("maps.transformationMaps")
499
- for ____exportKey, ____exportValue in pairs(____export) do
500
- if ____exportKey ~= "default" then
501
- ____exports[____exportKey] = ____exportValue
502
- end
503
- end
504
- end
505
505
  do
506
506
  local ____export = require("maps.transformationNameMap")
507
507
  for ____exportKey, ____exportValue in pairs(____export) do
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.17",
3
+ "version": "1.2.18",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",