isaacscript-common 1.2.8 → 1.2.12

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,8 +5,8 @@ local __TS__New = ____lualib.__TS__New
5
5
  local ____exports = {}
6
6
  local ____collectibles = require("functions.collectibles")
7
7
  local getMaxCollectibleID = ____collectibles.getMaxCollectibleID
8
- local ____util = require("functions.util")
9
- local copySet = ____util.copySet
8
+ local ____set = require("functions.set")
9
+ local copySet = ____set.copySet
10
10
  local COLLECTIBLE_SET = __TS__New(Set)
11
11
  local function initCollectibleSet(self)
12
12
  local itemConfig = Isaac.GetItemConfig()
@@ -8,9 +8,10 @@ local ____exports = {}
8
8
  local twoDimensionalSort
9
9
  local ____log = require("functions.log")
10
10
  local log = ____log.log
11
+ local ____set = require("functions.set")
12
+ local addSetsToSet = ____set.addSetsToSet
13
+ local copySet = ____set.copySet
11
14
  local ____util = require("functions.util")
12
- local addSetsToSet = ____util.addSetsToSet
13
- local copySet = ____util.copySet
14
15
  local isLuaDebugEnabled = ____util.isLuaDebugEnabled
15
16
  function twoDimensionalSort(self, a, b)
16
17
  if a[1] == b[1] then
@@ -131,6 +131,12 @@ export declare function getPlayerIndexVanilla(playerToFind: EntityPlayer): int |
131
131
  * Does not account for Broken Hearts; use the `getPlayerAvailableHeartSlots()` function for that.
132
132
  */
133
133
  export declare function getPlayerMaxHeartContainers(player: EntityPlayer): int;
134
+ /**
135
+ * Helper function to get the proper name of the player. Use this instead of the
136
+ * `EntityPlayer.GetName` method because it accounts for Blue Baby, Lazarus II, and Tainted
137
+ * characters.
138
+ */
139
+ export declare function getPlayerName(player: EntityPlayer): string;
134
140
  /**
135
141
  * Returns the combined value of all of the player's red hearts, soul/black hearts, and bone hearts,
136
142
  * minus the value of the player's rotten hearts.
@@ -207,6 +213,8 @@ export declare function isLost(player: EntityPlayer): boolean;
207
213
  * Deals. (e.g. The Lost, Tainted Lost, etc.)
208
214
  */
209
215
  export declare function canTakeFreeDevilDeals(player: EntityPlayer): boolean;
216
+ /** Helper function for detecting if a player is one of the Tainted characters. */
217
+ export declare function isTainted(player: EntityPlayer): boolean;
210
218
  /** Helper function for detecting when a player is Tainted Lazarus or Dead Tainted Lazarus. */
211
219
  export declare function isTaintedLazarus(player: EntityPlayer): boolean;
212
220
  export declare function removeCollectibleCostume(player: EntityPlayer, collectibleType: CollectibleType | int): void;
@@ -9,7 +9,7 @@ local __TS__Iterator = ____lualib.__TS__Iterator
9
9
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
10
10
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
11
11
  local ____exports = {}
12
- local EXCLUDED_CHARACTERS
12
+ local getAdjustedPlayerName, EXCLUDED_CHARACTERS
13
13
  local ____constants = require("constants")
14
14
  local CHARACTERS_WITH_BLACK_HEART_FROM_ETERNAL_HEART = ____constants.CHARACTERS_WITH_BLACK_HEART_FROM_ETERNAL_HEART
15
15
  local CHARACTERS_WITH_FREE_DEVIL_DEALS = ____constants.CHARACTERS_WITH_FREE_DEVIL_DEALS
@@ -30,6 +30,8 @@ local ____collectibleSet = require("functions.collectibleSet")
30
30
  local getCollectibleSet = ____collectibleSet.getCollectibleSet
31
31
  local ____util = require("functions.util")
32
32
  local ensureAllCases = ____util.ensureAllCases
33
+ local stringContains = ____util.stringContains
34
+ local trimPrefix = ____util.trimPrefix
33
35
  function ____exports.getCharacterMaxHeartContainers(self, character)
34
36
  if character == PlayerType.PLAYER_KEEPER then
35
37
  return 3
@@ -66,6 +68,53 @@ function ____exports.getPlayerMaxHeartContainers(self, player)
66
68
  end
67
69
  return maxHeartContainers
68
70
  end
71
+ function getAdjustedPlayerName(self, player)
72
+ local character = player:GetPlayerType()
73
+ repeat
74
+ local ____switch71 = character
75
+ local ____cond71 = ____switch71 == PlayerType.PLAYER_BLUEBABY or ____switch71 == PlayerType.PLAYER_BLUEBABY_B
76
+ if ____cond71 then
77
+ do
78
+ return "Blue Baby"
79
+ end
80
+ end
81
+ ____cond71 = ____cond71 or ____switch71 == PlayerType.PLAYER_LAZARUS2
82
+ if ____cond71 then
83
+ do
84
+ return "Lazarus II"
85
+ end
86
+ end
87
+ ____cond71 = ____cond71 or ____switch71 == PlayerType.PLAYER_BLACKJUDAS
88
+ if ____cond71 then
89
+ do
90
+ return "Dark Judas"
91
+ end
92
+ end
93
+ ____cond71 = ____cond71 or ____switch71 == PlayerType.PLAYER_JACOB
94
+ if ____cond71 then
95
+ do
96
+ return "Jacob & Esau"
97
+ end
98
+ end
99
+ ____cond71 = ____cond71 or ____switch71 == PlayerType.PLAYER_LAZARUS2_B
100
+ if ____cond71 then
101
+ do
102
+ return "Dead Tainted Lazarus"
103
+ end
104
+ end
105
+ ____cond71 = ____cond71 or ____switch71 == PlayerType.PLAYER_JACOB2_B
106
+ if ____cond71 then
107
+ do
108
+ return "Dead Tainted Jacob"
109
+ end
110
+ end
111
+ do
112
+ do
113
+ return player:GetName()
114
+ end
115
+ end
116
+ until true
117
+ end
69
118
  function ____exports.getPlayers(self, performExclusions)
70
119
  if performExclusions == nil then
71
120
  performExclusions = false
@@ -78,18 +127,18 @@ function ____exports.getPlayers(self, performExclusions)
78
127
  do
79
128
  local player = Isaac.GetPlayer(i)
80
129
  if player == nil then
81
- goto __continue70
130
+ goto __continue81
82
131
  end
83
132
  if ____exports.isChildPlayer(nil, player) then
84
- goto __continue70
133
+ goto __continue81
85
134
  end
86
135
  local character = player:GetPlayerType()
87
136
  if performExclusions and EXCLUDED_CHARACTERS:has(character) then
88
- goto __continue70
137
+ goto __continue81
89
138
  end
90
139
  __TS__ArrayPush(players, player)
91
140
  end
92
- ::__continue70::
141
+ ::__continue81::
93
142
  i = i + 1
94
143
  end
95
144
  end
@@ -98,6 +147,10 @@ end
98
147
  function ____exports.isChildPlayer(self, player)
99
148
  return player.Parent ~= nil
100
149
  end
150
+ function ____exports.isTainted(self, player)
151
+ local character = player:GetPlayerType()
152
+ return character >= PlayerType.PLAYER_ISAAC_B
153
+ end
101
154
  EXCLUDED_CHARACTERS = __TS__New(Set, {PlayerType.PLAYER_ESAU, PlayerType.PLAYER_THESOUL_B})
102
155
  function ____exports.addCollectibleCostume(self, player, collectibleType)
103
156
  local itemConfig = Isaac.GetItemConfig()
@@ -307,6 +360,14 @@ function ____exports.getPlayerIndexVanilla(self, playerToFind)
307
360
  end
308
361
  return nil
309
362
  end
363
+ function ____exports.getPlayerName(self, player)
364
+ local adjustedName = getAdjustedPlayerName(nil, player)
365
+ if not ____exports.isTainted(nil, player) then
366
+ return adjustedName
367
+ end
368
+ local baseName = trimPrefix(nil, adjustedName, "The ")
369
+ return stringContains(nil, baseName, "Tainted") and baseName or "Tainted " .. baseName
370
+ end
310
371
  function ____exports.getPlayerNumHitsRemaining(self, player)
311
372
  local hearts = player:GetHearts()
312
373
  local soulHearts = player:GetSoulHearts()
@@ -463,9 +524,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
463
524
  itemPool:RemoveCollectible(collectibleType)
464
525
  end
465
526
  repeat
466
- local ____switch109 = activeSlot
467
- local ____cond109 = ____switch109 == ActiveSlot.SLOT_PRIMARY
468
- if ____cond109 then
527
+ local ____switch121 = activeSlot
528
+ local ____cond121 = ____switch121 == ActiveSlot.SLOT_PRIMARY
529
+ if ____cond121 then
469
530
  do
470
531
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
471
532
  player:RemoveCollectible(primaryCollectibleType)
@@ -474,8 +535,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
474
535
  break
475
536
  end
476
537
  end
477
- ____cond109 = ____cond109 or ____switch109 == ActiveSlot.SLOT_SECONDARY
478
- if ____cond109 then
538
+ ____cond121 = ____cond121 or ____switch121 == ActiveSlot.SLOT_SECONDARY
539
+ if ____cond121 then
479
540
  do
480
541
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
481
542
  player:RemoveCollectible(primaryCollectibleType)
@@ -490,16 +551,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
490
551
  break
491
552
  end
492
553
  end
493
- ____cond109 = ____cond109 or ____switch109 == ActiveSlot.SLOT_POCKET
494
- if ____cond109 then
554
+ ____cond121 = ____cond121 or ____switch121 == ActiveSlot.SLOT_POCKET
555
+ if ____cond121 then
495
556
  do
496
557
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
497
558
  player:SetActiveCharge(charge, activeSlot)
498
559
  break
499
560
  end
500
561
  end
501
- ____cond109 = ____cond109 or ____switch109 == ActiveSlot.SLOT_POCKET2
502
- if ____cond109 then
562
+ ____cond121 = ____cond121 or ____switch121 == ActiveSlot.SLOT_POCKET2
563
+ if ____cond121 then
503
564
  do
504
565
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
505
566
  break
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Helper function to add all of the contents of one set to another set. The first set passed will
3
+ * be modified in place.
4
+ *
5
+ * This function is variadic, meaning that you can specify N sets to add to the first set.
6
+ */
7
+ export declare function addSetsToSet<T>(mainSet: Set<T>, ...setsToAdd: Array<Set<T>>): void;
8
+ /** Helper function to copy a set. (You can also use a Set constructor to accomplish this task.) */
9
+ export declare function copySet<T>(oldSet: Set<T>): Set<T>;
10
+ /**
11
+ * Helper function to create a new set that is the composition of two or more sets.
12
+ *
13
+ * This function is variadic, meaning that you can specify N sets.
14
+ */
15
+ export declare function combineSets<T>(...sets: Array<Set<T>>): Set<T>;
@@ -0,0 +1,32 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____lualib = require("lualib_bundle")
3
+ local Set = ____lualib.Set
4
+ local __TS__Iterator = ____lualib.__TS__Iterator
5
+ local __TS__New = ____lualib.__TS__New
6
+ local ____exports = {}
7
+ function ____exports.addSetsToSet(self, mainSet, ...)
8
+ local setsToAdd = {...}
9
+ for ____, set in ipairs(setsToAdd) do
10
+ for ____, value in __TS__Iterator(set:values()) do
11
+ mainSet:add(value)
12
+ end
13
+ end
14
+ end
15
+ function ____exports.copySet(self, oldSet)
16
+ local newSet = __TS__New(Set)
17
+ for ____, value in __TS__Iterator(oldSet:values()) do
18
+ newSet:add(value)
19
+ end
20
+ return newSet
21
+ end
22
+ function ____exports.combineSets(self, ...)
23
+ local sets = {...}
24
+ local newSet = __TS__New(Set)
25
+ for ____, set in ipairs(sets) do
26
+ for ____, value in __TS__Iterator(set:values()) do
27
+ newSet:add(value)
28
+ end
29
+ end
30
+ return newSet
31
+ end
32
+ return ____exports
@@ -3,10 +3,10 @@ local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local ____exports = {}
6
+ local ____set = require("functions.set")
7
+ local copySet = ____set.copySet
6
8
  local ____trinkets = require("functions.trinkets")
7
9
  local getMaxTrinketID = ____trinkets.getMaxTrinketID
8
- local ____util = require("functions.util")
9
- local copySet = ____util.copySet
10
10
  local TRINKET_SET = __TS__New(Set)
11
11
  local function initTrinketSet(self)
12
12
  local itemConfig = Isaac.GetItemConfig()
@@ -1,28 +1,10 @@
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;
10
3
  /**
11
4
  * Using a Map constructor to copy a Map does not seem to work properly, so use this helper function
12
5
  * instead.
13
6
  */
14
7
  export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
15
- /**
16
- * Using a Set constructor to copy a Set does not seem to work properly, so use this helper function
17
- * instead.
18
- */
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>;
26
8
  /**
27
9
  * Helper function to get type safety on a switch statement.
28
10
  * Very useful to be future-safe against people adding values to a type or an enum.
@@ -98,8 +80,11 @@ export declare function onSetSeed(): boolean;
98
80
  * message (which `Isaac.ConsoleOutput()` does not do by default).
99
81
  */
100
82
  export declare function printConsole(msg: string): void;
83
+ export declare function stringContains(string: string, searchString: string): boolean;
101
84
  /**
102
85
  * In a Map, you can use the `clear` method to delete every element. However, in a LuaTable, the
103
86
  * `clear` method does not exist. Use this helper function as a drop-in replacement for this.
104
87
  */
105
88
  export declare function tableClear(table: LuaTable): void;
89
+ /** Helper function to trim a prefix from a string, if it exists. Returns the trimmed string. */
90
+ export declare function trimPrefix(string: string, prefix: string): string;
@@ -1,23 +1,16 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
- local Set = ____lualib.Set
4
- local __TS__Iterator = ____lualib.__TS__Iterator
5
3
  local Map = ____lualib.Map
6
4
  local __TS__New = ____lualib.__TS__New
5
+ local __TS__Iterator = ____lualib.__TS__Iterator
7
6
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
8
7
  local __TS__ArraySort = ____lualib.__TS__ArraySort
9
8
  local __TS__StringReplace = ____lualib.__TS__StringReplace
10
9
  local __TS__StringSubstr = ____lualib.__TS__StringSubstr
10
+ local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
11
+ local __TS__StringSlice = ____lualib.__TS__StringSlice
11
12
  local ____exports = {}
12
13
  local HEX_STRING_LENGTH = 6
13
- function ____exports.addSetsToSet(self, mainSet, ...)
14
- local setsToAdd = {...}
15
- for ____, set in ipairs(setsToAdd) do
16
- for ____, value in __TS__Iterator(set:values()) do
17
- mainSet:add(value)
18
- end
19
- end
20
- end
21
14
  function ____exports.copyMap(self, oldMap)
22
15
  local newMap = __TS__New(Map)
23
16
  for ____, ____value in __TS__Iterator(oldMap:entries()) do
@@ -27,23 +20,6 @@ function ____exports.copyMap(self, oldMap)
27
20
  end
28
21
  return newMap
29
22
  end
30
- function ____exports.copySet(self, oldSet)
31
- local newSet = __TS__New(Set)
32
- for ____, value in __TS__Iterator(oldSet:values()) do
33
- newSet:add(value)
34
- end
35
- return newSet
36
- end
37
- function ____exports.combineSets(self, ...)
38
- local sets = {...}
39
- local newSet = __TS__New(Set)
40
- for ____, set in ipairs(sets) do
41
- for ____, value in __TS__Iterator(set:values()) do
42
- newSet:add(value)
43
- end
44
- end
45
- return newSet
46
- end
47
23
  ____exports.ensureAllCases = function(____, obj) return obj end
48
24
  function ____exports.getEnumValues(self, transpiledEnum)
49
25
  local enumValues = {}
@@ -91,9 +67,18 @@ end
91
67
  function ____exports.printConsole(self, msg)
92
68
  Isaac.ConsoleOutput(msg .. "\n")
93
69
  end
70
+ function ____exports.stringContains(self, ____string, searchString)
71
+ return (string.find(____string, searchString, nil, true) or 0) - 1 ~= -1
72
+ end
94
73
  function ____exports.tableClear(self, ____table)
95
74
  for key in pairs(____table) do
96
75
  ____table[key] = nil
97
76
  end
98
77
  end
78
+ function ____exports.trimPrefix(self, ____string, prefix)
79
+ if not __TS__StringStartsWith(____string, prefix) then
80
+ return ____string
81
+ end
82
+ return __TS__StringSlice(____string, #prefix)
83
+ end
99
84
  return ____exports
package/dist/index.d.ts CHANGED
@@ -42,6 +42,7 @@ export * from "./functions/random";
42
42
  export * from "./functions/revive";
43
43
  export * from "./functions/rooms";
44
44
  export * from "./functions/seeds";
45
+ export * from "./functions/set";
45
46
  export * from "./functions/spawnCollectible";
46
47
  export * from "./functions/sprite";
47
48
  export * from "./functions/stage";
package/dist/index.lua CHANGED
@@ -342,6 +342,14 @@ do
342
342
  end
343
343
  end
344
344
  end
345
+ do
346
+ local ____export = require("functions.set")
347
+ for ____exportKey, ____exportValue in pairs(____export) do
348
+ if ____exportKey ~= "default" then
349
+ ____exports[____exportKey] = ____exportValue
350
+ end
351
+ end
352
+ end
345
353
  do
346
354
  local ____export = require("functions.spawnCollectible")
347
355
  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.8",
3
+ "version": "1.2.12",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",