isaacscript-common 1.0.602 → 1.0.606

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,14 @@
1
+ /// <reference types="typescript-to-lua/language-extensions" />
2
+ /**
3
+ * Helper function to get a set containing all of the global variable names that are contained
4
+ * within the Isaac environment by default.
5
+ *
6
+ * Returns a slightly different set depending on whether the "--luadebug" flag is enabled or not.
7
+ */
8
+ export declare function getDefaultGlobals(): Set<string>;
9
+ /**
10
+ * Helper function to get an array of any added global variables in the Isaac Lua environment.
11
+ * Returns an array of key/value tuples.
12
+ */
13
+ export declare function getNewGlobals(): [AnyNotNil, unknown][];
14
+ export declare function logNewGlobals(): void;
@@ -0,0 +1,221 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ require("lualib_bundle");
3
+ local ____exports = {}
4
+ local twoDimensionalSort
5
+ local ____log = require("functions.log")
6
+ local log = ____log.log
7
+ local ____util = require("functions.util")
8
+ local addSetsToSet = ____util.addSetsToSet
9
+ local copySet = ____util.copySet
10
+ local isLuaDebugEnabled = ____util.isLuaDebugEnabled
11
+ function twoDimensionalSort(self, a, b)
12
+ if a[1] == b[1] then
13
+ return 0
14
+ end
15
+ return a[1] < b[1] and -1 or 1
16
+ end
17
+ local DEFAULT_GLOBALS = __TS__New(Set, {
18
+ "ActionTriggers",
19
+ "ActiveSlot",
20
+ "BabySubType",
21
+ "BackdropType",
22
+ "BatterySubType",
23
+ "BedSubType",
24
+ "BitSet128",
25
+ "BombSubType",
26
+ "BombVariant",
27
+ "ButtonAction",
28
+ "CacheFlag",
29
+ "Card",
30
+ "Challenge",
31
+ "ChampionColor",
32
+ "ChestSubType",
33
+ "CoinSubType",
34
+ "CollectibleType",
35
+ "Color",
36
+ "CppContainer",
37
+ "DamageFlag",
38
+ "Difficulty",
39
+ "Direction",
40
+ "DoorSlot",
41
+ "DoorState",
42
+ "DoorVariant",
43
+ "EffectVariant",
44
+ "Entity",
45
+ "EntityBomb",
46
+ "EntityCollisionClass",
47
+ "EntityEffect",
48
+ "EntityFamiliar",
49
+ "EntityFlag",
50
+ "EntityGridCollisionClass",
51
+ "EntityKnife",
52
+ "EntityLaser",
53
+ "EntityNPC",
54
+ "EntityPartition",
55
+ "EntityPickup",
56
+ "EntityPlayer",
57
+ "EntityProjectile",
58
+ "EntityPtr",
59
+ "EntityRef",
60
+ "EntityTear",
61
+ "EntityType",
62
+ "FamiliarVariant",
63
+ "Font",
64
+ "Game",
65
+ "GameStateFlag",
66
+ "GetPtrHash",
67
+ "GridCollisionClass",
68
+ "GridEntity",
69
+ "GridEntityDesc",
70
+ "GridEntityDoor",
71
+ "GridEntityPit",
72
+ "GridEntityPoop",
73
+ "GridEntityPressurePlate",
74
+ "GridEntityRock",
75
+ "GridEntitySpikes",
76
+ "GridEntityTNT",
77
+ "GridEntityType",
78
+ "GridRooms",
79
+ "HUD",
80
+ "HeartSubType",
81
+ "Input",
82
+ "InputHook",
83
+ "Isaac",
84
+ "ItemConfig",
85
+ "ItemPool",
86
+ "ItemPoolType",
87
+ "ItemType",
88
+ "KColor",
89
+ "KeySubType",
90
+ "Keyboard",
91
+ "LaserOffset",
92
+ "LaserSubType",
93
+ "Level",
94
+ "LevelCurse",
95
+ "LevelStage",
96
+ "LevelStateFlag",
97
+ "LocustSubtypes",
98
+ "ModCallbacks",
99
+ "Mouse",
100
+ "Music",
101
+ "MusicManager",
102
+ "NpcState",
103
+ "NullItemID",
104
+ "Options",
105
+ "PathFinder",
106
+ "PickupPrice",
107
+ "PickupVariant",
108
+ "PillColor",
109
+ "PillEffect",
110
+ "PlayerForm",
111
+ "PlayerSpriteLayer",
112
+ "PlayerType",
113
+ "PlayerTypes",
114
+ "PoopPickupSubType",
115
+ "PoopSpellType",
116
+ "ProjectileFlags",
117
+ "ProjectileParams",
118
+ "ProjectileVariant",
119
+ "QueueItemData",
120
+ "REPENTANCE",
121
+ "RNG",
122
+ "Random",
123
+ "RandomVector",
124
+ "RegisterMod",
125
+ "RenderMode",
126
+ "Room",
127
+ "RoomConfig",
128
+ "RoomDescriptor",
129
+ "RoomShape",
130
+ "RoomTransitionAnim",
131
+ "RoomType",
132
+ "SFXManager",
133
+ "SackSubType",
134
+ "SeedEffect",
135
+ "Seeds",
136
+ "ShockwaveParams",
137
+ "SkinColor",
138
+ "SortingLayer",
139
+ "SoundEffect",
140
+ "Sprite",
141
+ "StageType",
142
+ "StartDebug",
143
+ "TearFlags",
144
+ "TearParams",
145
+ "TearVariant",
146
+ "TemporaryEffect",
147
+ "TemporaryEffects",
148
+ "TrinketType",
149
+ "UseFlag",
150
+ "Vector",
151
+ "WeaponType",
152
+ "_G",
153
+ "_VERSION",
154
+ "assert",
155
+ "collectgarbage",
156
+ "coroutine",
157
+ "dofile",
158
+ "error",
159
+ "getmetatable",
160
+ "include",
161
+ "ipairs",
162
+ "load",
163
+ "loadfile",
164
+ "math",
165
+ "next",
166
+ "pairs",
167
+ "pcall",
168
+ "print",
169
+ "rawequal",
170
+ "rawget",
171
+ "rawlen",
172
+ "rawset",
173
+ "require",
174
+ "select",
175
+ "setmetatable",
176
+ "string",
177
+ "table",
178
+ "tonumber",
179
+ "tostring",
180
+ "type",
181
+ "utf8",
182
+ "xpcall"
183
+ })
184
+ local LUA_DEBUG_ADDED_GLOBALS = __TS__New(Set, {"debug", "io", "os", "package"})
185
+ local RACING_PLUS_SANDBOX_ADDED_GLOBALS = __TS__New(Set, {"sandboxTraceback", "sandboxGetTraceback", "getParentFunctionDescription"})
186
+ function ____exports.getDefaultGlobals(self)
187
+ local defaultGlobals = copySet(nil, DEFAULT_GLOBALS)
188
+ if isLuaDebugEnabled(nil) then
189
+ addSetsToSet(nil, defaultGlobals, LUA_DEBUG_ADDED_GLOBALS)
190
+ end
191
+ addSetsToSet(nil, defaultGlobals, RACING_PLUS_SANDBOX_ADDED_GLOBALS)
192
+ return defaultGlobals
193
+ end
194
+ function ____exports.getNewGlobals(self)
195
+ local defaultGlobals = ____exports.getDefaultGlobals(nil)
196
+ local newGlobals = {}
197
+ for key, value in pairs(_G) do
198
+ if not defaultGlobals:has(key) then
199
+ local keyValueTuple = {key, value}
200
+ __TS__ArrayPush(newGlobals, keyValueTuple)
201
+ end
202
+ end
203
+ __TS__ArraySort(newGlobals, twoDimensionalSort)
204
+ return newGlobals
205
+ end
206
+ function ____exports.logNewGlobals(self)
207
+ local newGlobals = ____exports.getNewGlobals(nil)
208
+ log("List of added global variables in the Isaac environment:")
209
+ if #newGlobals == 0 then
210
+ log("- n/a (no extra global variables found)")
211
+ end
212
+ do
213
+ local i = 0
214
+ while i < #newGlobals do
215
+ local key, value = table.unpack(newGlobals[i + 1])
216
+ log((((tostring(i + 1) .. ") ") .. tostring(key)) .. " - ") .. tostring(value))
217
+ i = i + 1
218
+ end
219
+ end
220
+ end
221
+ return ____exports
@@ -11,6 +11,8 @@ local LOST_STYLE_PLAYER_TYPES = ____constants.LOST_STYLE_PLAYER_TYPES
11
11
  local MAX_PLAYER_HEART_CONTAINERS = ____constants.MAX_PLAYER_HEART_CONTAINERS
12
12
  local ____HealthType = require("types.HealthType")
13
13
  local HealthType = ____HealthType.HealthType
14
+ local ____array = require("functions.array")
15
+ local arraySum = ____array.arraySum
14
16
  local ____bitwise = require("functions.bitwise")
15
17
  local getKBitOfN = ____bitwise.getKBitOfN
16
18
  local getNumBitsOfN = ____bitwise.getNumBitsOfN
@@ -308,14 +310,14 @@ end
308
310
  function ____exports.getPlayersOfType(self, ...)
309
311
  local characters = {...}
310
312
  local charactersSet = __TS__New(Set, characters)
311
- local players = {}
312
- for ____, player in ipairs(____exports.getPlayers(nil)) do
313
- local character = player:GetPlayerType()
314
- if charactersSet:has(character) then
315
- __TS__ArrayPush(players, player)
313
+ local players = ____exports.getPlayers(nil)
314
+ return __TS__ArrayFilter(
315
+ players,
316
+ function(____, player)
317
+ local character = player:GetPlayerType()
318
+ return charactersSet:has(character)
316
319
  end
317
- end
318
- return players
320
+ )
319
321
  end
320
322
  function ____exports.getTotalCharge(self, player, activeSlot)
321
323
  local activeCharge = player:GetActiveCharge(activeSlot)
@@ -323,11 +325,12 @@ function ____exports.getTotalCharge(self, player, activeSlot)
323
325
  return activeCharge + batteryCharge
324
326
  end
325
327
  function ____exports.getTotalPlayerCollectibles(self, collectibleType)
326
- local numCollectibles = 0
327
- for ____, player in ipairs(____exports.getPlayers(nil)) do
328
- numCollectibles = numCollectibles + player:GetCollectibleNum(collectibleType)
329
- end
330
- return numCollectibles
328
+ local players = ____exports.getPlayers(nil)
329
+ local numCollectiblesArray = __TS__ArrayMap(
330
+ players,
331
+ function(____, player) return player:GetCollectibleNum(collectibleType) end
332
+ )
333
+ return arraySum(nil, numCollectiblesArray)
331
334
  end
332
335
  function ____exports.hasLostCurse(self, player)
333
336
  local effects = player:GetEffects()
@@ -452,9 +455,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
452
455
  itemPool:RemoveCollectible(collectibleType)
453
456
  end
454
457
  repeat
455
- local ____switch112 = activeSlot
456
- local ____cond112 = ____switch112 == ActiveSlot.SLOT_PRIMARY
457
- if ____cond112 then
458
+ local ____switch109 = activeSlot
459
+ local ____cond109 = ____switch109 == ActiveSlot.SLOT_PRIMARY
460
+ if ____cond109 then
458
461
  do
459
462
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
460
463
  player:RemoveCollectible(primaryCollectibleType)
@@ -463,8 +466,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
463
466
  break
464
467
  end
465
468
  end
466
- ____cond112 = ____cond112 or ____switch112 == ActiveSlot.SLOT_SECONDARY
467
- if ____cond112 then
469
+ ____cond109 = ____cond109 or ____switch109 == ActiveSlot.SLOT_SECONDARY
470
+ if ____cond109 then
468
471
  do
469
472
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
470
473
  player:RemoveCollectible(primaryCollectibleType)
@@ -479,16 +482,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
479
482
  break
480
483
  end
481
484
  end
482
- ____cond112 = ____cond112 or ____switch112 == ActiveSlot.SLOT_POCKET
483
- if ____cond112 then
485
+ ____cond109 = ____cond109 or ____switch109 == ActiveSlot.SLOT_POCKET
486
+ if ____cond109 then
484
487
  do
485
488
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
486
489
  player:SetActiveCharge(charge, activeSlot)
487
490
  break
488
491
  end
489
492
  end
490
- ____cond112 = ____cond112 or ____switch112 == ActiveSlot.SLOT_POCKET2
491
- if ____cond112 then
493
+ ____cond109 = ____cond109 or ____switch109 == ActiveSlot.SLOT_POCKET2
494
+ if ____cond109 then
492
495
  do
493
496
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
494
497
  break
@@ -1,5 +1,12 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /// <reference types="typescript-to-lua/language-extensions" />
3
+ /**
4
+ * Helper function to add all of the contents of one set to another set. The first set passed will
5
+ * be modified in place.
6
+ *
7
+ * This function is variadic, meaning that you can specify N sets to add to the first set.
8
+ */
9
+ export declare function addSetsToSet<T>(mainSet: Set<T>, ...setsToAdd: Array<Set<T>>): void;
3
10
  /**
4
11
  * Using a Map constructor to copy a Map does not seem to work properly, so use this helper function
5
12
  * instead.
@@ -10,6 +17,12 @@ export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
10
17
  * instead.
11
18
  */
12
19
  export declare function copySet<T>(oldSet: Set<T>): Set<T>;
20
+ /**
21
+ * Helper function to create a new set that is the composition of two or more sets.
22
+ *
23
+ * This function is variadic, meaning that you can specify N sets.
24
+ */
25
+ export declare function combineSets<T>(...sets: Array<Set<T>>): Set<T>;
13
26
  /**
14
27
  * Helper function to get type safety on a switch statement.
15
28
  * Very useful to be future-safe against people adding values to a type or an enum.
@@ -2,6 +2,14 @@
2
2
  require("lualib_bundle");
3
3
  local ____exports = {}
4
4
  local HEX_STRING_LENGTH = 6
5
+ function ____exports.addSetsToSet(self, mainSet, ...)
6
+ local setsToAdd = {...}
7
+ for ____, set in ipairs(setsToAdd) do
8
+ for ____, value in __TS__Iterator(set:values()) do
9
+ mainSet:add(value)
10
+ end
11
+ end
12
+ end
5
13
  function ____exports.copyMap(self, oldMap)
6
14
  local newMap = __TS__New(Map)
7
15
  for ____, ____value in __TS__Iterator(oldMap:entries()) do
@@ -18,6 +26,16 @@ function ____exports.copySet(self, oldSet)
18
26
  end
19
27
  return newSet
20
28
  end
29
+ function ____exports.combineSets(self, ...)
30
+ local sets = {...}
31
+ local newSet = __TS__New(Set)
32
+ for ____, set in ipairs(sets) do
33
+ for ____, value in __TS__Iterator(set:values()) do
34
+ newSet:add(value)
35
+ end
36
+ end
37
+ return newSet
38
+ end
21
39
  ____exports.ensureAllCases = function(____, obj) return obj end
22
40
  function ____exports.getEnumValues(self, transpiledEnum)
23
41
  local enumValues = {}
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ export * from "./functions/doors";
23
23
  export * from "./functions/entity";
24
24
  export * from "./functions/familiars";
25
25
  export * from "./functions/flag";
26
+ export * from "./functions/globals";
26
27
  export * from "./functions/gridEntity";
27
28
  export * from "./functions/input";
28
29
  export * from "./functions/json";
package/dist/index.lua CHANGED
@@ -190,6 +190,14 @@ do
190
190
  end
191
191
  end
192
192
  end
193
+ do
194
+ local ____export = require("functions.globals")
195
+ for ____exportKey, ____exportValue in pairs(____export) do
196
+ if ____exportKey ~= "default" then
197
+ ____exports[____exportKey] = ____exportValue
198
+ end
199
+ end
200
+ end
193
201
  do
194
202
  local ____export = require("functions.gridEntity")
195
203
  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.0.602",
3
+ "version": "1.0.606",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,7 +25,7 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "isaac-typescript-definitions": "^1.0.332",
28
+ "isaac-typescript-definitions": "^1.0.333",
29
29
  "isaacscript-lint": "^1.0.79",
30
30
  "isaacscript-tsconfig": "^1.1.8",
31
31
  "typedoc": "^0.22.11",