isaacscript-common 1.2.215 → 1.2.218

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.
@@ -19,12 +19,12 @@ local getCharacterName = ____character.getCharacterName
19
19
  local ____gridEntity = require("functions.gridEntity")
20
20
  local spawnGridEntityWithVariant = ____gridEntity.spawnGridEntityWithVariant
21
21
  local ____log = require("functions.log")
22
+ local logEffects = ____log.logEffects
22
23
  local logEntities = ____log.logEntities
23
24
  local logGridEntities = ____log.logGridEntities
24
25
  local logRoom = ____log.logRoom
25
26
  local logSeedEffects = ____log.logSeedEffects
26
27
  local logSounds = ____log.logSounds
27
- local logTemporaryEffects = ____log.logTemporaryEffects
28
28
  local ____map = require("functions.map")
29
29
  local getMapPartialMatch = ____map.getMapPartialMatch
30
30
  local ____npc = require("functions.npc")
@@ -487,7 +487,7 @@ function ____exports.dungeon(self)
487
487
  end
488
488
  function ____exports.effects(self)
489
489
  local player = Isaac.GetPlayer()
490
- logTemporaryEffects(player)
490
+ logEffects(player)
491
491
  printConsole(nil, "Logged the player's effects to the \"log.txt\" file.")
492
492
  end
493
493
  function ____exports.eh(self, params)
@@ -8,9 +8,10 @@ local SerializationType = ____SerializationType.SerializationType
8
8
  local ____table = require("functions.table")
9
9
  local copyValuesToTable = ____table.copyValuesToTable
10
10
  local getNumbersFromTable = ____table.getNumbersFromTable
11
+ local ____userdata = require("functions.userdata")
12
+ local isUserdataObject = ____userdata.isUserdataObject
11
13
  local ____utils = require("functions.utils")
12
14
  local ensureAllCases = ____utils.ensureAllCases
13
- local isUserdataObject = ____utils.isUserdataObject
14
15
  function ____exports.isColor(self, object)
15
16
  return isUserdataObject(nil, object, OBJECT_NAME)
16
17
  end
@@ -14,6 +14,7 @@ export declare function logArray<T>(this: void, array: T[]): void;
14
14
  export declare function logColor(this: void, color: Color): void;
15
15
  /** Helper function for printing out every damage flag that is turned on. Useful when debugging. */
16
16
  export declare function logDamageFlags(this: void, flags: int): void;
17
+ export declare function logEffects(this: void, player: EntityPlayer): void;
17
18
  /** Helper function for printing out every entity (or filtered entity) in the current room. */
18
19
  export declare function logEntities(this: void, includeBackgroundEffects: boolean, entityTypeFilter?: EntityType | int): void;
19
20
  /** Helper function for printing out every entity flag that is turned on. Useful when debugging. */
@@ -56,7 +57,6 @@ export declare function logSounds(this: void): void;
56
57
  export declare function logTable(this: void, table: unknown, parentTables?: number): void;
57
58
  /** Helper function for printing out every tear flag that is turned on. Useful when debugging. */
58
59
  export declare function logTearFlags(this: void, flags: int): void;
59
- export declare function logTemporaryEffects(this: void, player: EntityPlayer): void;
60
60
  /** Helper function for printing out every use flag that is turned on. Useful when debugging. */
61
61
  export declare function logUseFlags(this: void, flags: int): void;
62
62
  /**
@@ -35,6 +35,8 @@ local ____set = require("functions.set")
35
35
  local getSortedSetValues = ____set.getSortedSetValues
36
36
  local ____trinkets = require("functions.trinkets")
37
37
  local getTrinketName = ____trinkets.getTrinketName
38
+ local ____userdata = require("functions.userdata")
39
+ local getUserdataType = ____userdata.getUserdataType
38
40
  local ____utils = require("functions.utils")
39
41
  local printConsole = ____utils.printConsole
40
42
  function ____exports.getDebugPrependString(self, msg, numParentFunctions)
@@ -78,14 +80,14 @@ function ____exports.logFlags(flags, flagEnum, description)
78
80
  for key, value in pairs(flagEnum) do
79
81
  do
80
82
  if type(value) ~= "number" then
81
- goto __continue35
83
+ goto __continue42
82
84
  end
83
85
  if hasFlag(nil, flags, value) then
84
86
  ____exports.log((((" Has flag: " .. tostring(key)) .. " (") .. tostring(value)) .. ")")
85
87
  hasNoFlags = false
86
88
  end
87
89
  end
88
- ::__continue35::
90
+ ::__continue42::
89
91
  end
90
92
  if hasNoFlags then
91
93
  ____exports.log(" n/a (no flags)")
@@ -112,6 +114,30 @@ end
112
114
  function ____exports.logDamageFlags(flags)
113
115
  ____exports.logFlags(flags, DamageFlag, "damage")
114
116
  end
117
+ function ____exports.logEffects(player)
118
+ local effects = getEffectsList(nil, player)
119
+ ____exports.log("Logging player effects:")
120
+ if #effects == 0 then
121
+ ____exports.log(" n/a (no effects)")
122
+ return
123
+ end
124
+ __TS__ArrayForEach(
125
+ effects,
126
+ function(____, effect, i)
127
+ if effect.Item:IsCollectible() then
128
+ local collectibleName = getCollectibleName(nil, effect.Item.ID)
129
+ ____exports.log(((" " .. tostring(i + 1)) .. ") Collectible: ") .. collectibleName)
130
+ elseif effect.Item:IsTrinket() then
131
+ local trinketName = getTrinketName(nil, effect.Item.ID)
132
+ ____exports.log(((" " .. tostring(i + 1)) .. ") Trinket: ") .. trinketName)
133
+ elseif effect.Item:IsNull() then
134
+ ____exports.log(((" " .. tostring(i + 1)) .. ") Null item: ") .. tostring(effect.Item.ID))
135
+ else
136
+ ____exports.log(((" " .. tostring(i + 1)) .. ") Unknown type of effect: ") .. tostring(effect.Item.ID))
137
+ end
138
+ end
139
+ )
140
+ end
115
141
  function ____exports.logEntities(includeBackgroundEffects, entityTypeFilter)
116
142
  local headerMsg = "Entities in the room"
117
143
  if entityTypeFilter ~= nil then
@@ -392,30 +418,6 @@ end
392
418
  function ____exports.logTearFlags(flags)
393
419
  ____exports.logFlags(flags, TearFlags, "tear")
394
420
  end
395
- function ____exports.logTemporaryEffects(player)
396
- local effects = getEffectsList(nil, player)
397
- ____exports.log("Logging player temporary effects:")
398
- if #effects == 0 then
399
- ____exports.log(" n/a (no temporary effects)")
400
- return
401
- end
402
- __TS__ArrayForEach(
403
- effects,
404
- function(____, effect, i)
405
- if effect.Item:IsCollectible() then
406
- local collectibleName = getCollectibleName(nil, effect.Item.ID)
407
- ____exports.log(((" " .. tostring(i + 1)) .. ") ") .. collectibleName)
408
- elseif effect.Item:IsTrinket() then
409
- local trinketName = getTrinketName(nil, effect.Item.ID)
410
- ____exports.log(((" " .. tostring(i + 1)) .. ") ") .. trinketName)
411
- elseif effect.Item:IsNull() then
412
- ____exports.log(((" " .. tostring(i + 1)) .. ") Null item: ") .. tostring(effect.Item.ID))
413
- else
414
- ____exports.log(((" " .. tostring(i + 1)) .. ") Unknown type of temporary effect: ") .. tostring(effect.Item.ID))
415
- end
416
- end
417
- )
418
- end
419
421
  function ____exports.logUseFlags(flags)
420
422
  ____exports.logFlags(flags, UseFlag, "use")
421
423
  end
@@ -430,7 +432,12 @@ function ____exports.logUserdata(userdata)
430
432
  ____exports.log("Userdata: [no metatable]")
431
433
  return
432
434
  end
433
- ____exports.log("Userdata: " .. metatable.__type)
435
+ local classType = getUserdataType(nil, userdata)
436
+ if classType == nil then
437
+ ____exports.log("Userdata: [no class type]")
438
+ else
439
+ ____exports.log("Userdata: " .. classType)
440
+ end
434
441
  ____exports.logTable(metatable)
435
442
  end
436
443
  function ____exports.logVector(vector)
@@ -442,6 +449,7 @@ function ____exports.setLogFunctionsGlobal(self)
442
449
  globals.logArray = ____exports.logArray
443
450
  globals.logColor = ____exports.logColor
444
451
  globals.logDamageFlags = ____exports.logDamageFlags
452
+ globals.logEffects = ____exports.logEffects
445
453
  globals.logEntities = ____exports.logEntities
446
454
  globals.logEntityID = ____exports.logEntityID
447
455
  globals.logEntityFlags = ____exports.logEntityFlags
@@ -459,7 +467,6 @@ function ____exports.setLogFunctionsGlobal(self)
459
467
  globals.logSounds = ____exports.logSounds
460
468
  globals.logTable = ____exports.logTable
461
469
  globals.logTearFlags = ____exports.logTearFlags
462
- globals.logTemporaryEffects = ____exports.logTemporaryEffects
463
470
  globals.logUseFlags = ____exports.logUseFlags
464
471
  globals.logUserdata = ____exports.logUserdata
465
472
  globals.logVector = ____exports.logVector
@@ -186,6 +186,13 @@ export declare function isActiveSlotEmpty(player: EntityPlayer, activeSlot: Acti
186
186
  * charges.
187
187
  */
188
188
  export declare function isBethany(player: EntityPlayer): boolean;
189
+ /**
190
+ * Helper function to check if a player is a specific character (i.e. `PlayerType`).
191
+ *
192
+ * This function is variadic, meaning that you can supply as many characters as you want to check
193
+ * for. Returns true if the player is any of the supplied characters.
194
+ */
195
+ export declare function isCharacter(player: EntityPlayer, ...characters: Array<PlayerType | int>): boolean;
189
196
  /**
190
197
  * Helper function for detecting when a player is Eden or Tainted Eden. Useful for situations where
191
198
  * you want to know if the starting stats were randomized, for example.
@@ -411,6 +411,12 @@ function ____exports.isBethany(self, player)
411
411
  local character = player:GetPlayerType()
412
412
  return character == PlayerType.PLAYER_BETHANY or character == PlayerType.PLAYER_BETHANY_B
413
413
  end
414
+ function ____exports.isCharacter(self, player, ...)
415
+ local characters = {...}
416
+ local characterSet = __TS__New(Set, characters)
417
+ local character = player:GetPlayerType()
418
+ return characterSet:has(character)
419
+ end
414
420
  function ____exports.isEden(self, player)
415
421
  local character = player:GetPlayerType()
416
422
  return character == PlayerType.PLAYER_EDEN or character == PlayerType.PLAYER_EDEN_B
@@ -478,9 +484,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
478
484
  itemPool:RemoveCollectible(collectibleType)
479
485
  end
480
486
  repeat
481
- local ____switch100 = activeSlot
482
- local ____cond100 = ____switch100 == ActiveSlot.SLOT_PRIMARY
483
- if ____cond100 then
487
+ local ____switch101 = activeSlot
488
+ local ____cond101 = ____switch101 == ActiveSlot.SLOT_PRIMARY
489
+ if ____cond101 then
484
490
  do
485
491
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
486
492
  player:RemoveCollectible(primaryCollectibleType)
@@ -489,8 +495,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
489
495
  break
490
496
  end
491
497
  end
492
- ____cond100 = ____cond100 or ____switch100 == ActiveSlot.SLOT_SECONDARY
493
- if ____cond100 then
498
+ ____cond101 = ____cond101 or ____switch101 == ActiveSlot.SLOT_SECONDARY
499
+ if ____cond101 then
494
500
  do
495
501
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
496
502
  player:RemoveCollectible(primaryCollectibleType)
@@ -505,16 +511,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
505
511
  break
506
512
  end
507
513
  end
508
- ____cond100 = ____cond100 or ____switch100 == ActiveSlot.SLOT_POCKET
509
- if ____cond100 then
514
+ ____cond101 = ____cond101 or ____switch101 == ActiveSlot.SLOT_POCKET
515
+ if ____cond101 then
510
516
  do
511
517
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
512
518
  player:SetActiveCharge(charge, activeSlot)
513
519
  break
514
520
  end
515
521
  end
516
- ____cond100 = ____cond100 or ____switch100 == ActiveSlot.SLOT_POCKET2
517
- if ____cond100 then
522
+ ____cond101 = ____cond101 or ____switch101 == ActiveSlot.SLOT_POCKET2
523
+ if ____cond101 then
518
524
  do
519
525
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
520
526
  break
@@ -11,9 +11,10 @@ local SerializationType = ____SerializationType.SerializationType
11
11
  local ____table = require("functions.table")
12
12
  local getNumbersFromTable = ____table.getNumbersFromTable
13
13
  local tableHasKeys = ____table.tableHasKeys
14
+ local ____userdata = require("functions.userdata")
15
+ local isUserdataObject = ____userdata.isUserdataObject
14
16
  local ____utils = require("functions.utils")
15
17
  local ensureAllCases = ____utils.ensureAllCases
16
- local isUserdataObject = ____utils.isUserdataObject
17
18
  function ____exports.getRandomSeed(self)
18
19
  local randomNumber = Random()
19
20
  local safeRandomNumber = randomNumber == 0 and 1 or randomNumber
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Helper function to get the type of a userdata object from the Isaac API. This is contained within
3
+ * the "__type" metatable key.
4
+ *
5
+ * For example, a `Vector` class is userdata with a type of "Vector".
6
+ */
7
+ export declare function getUserdataType(object: unknown): string | undefined;
8
+ /**
9
+ * Helper function to check if something is an instantiated class from the Isaac API. (All classes
10
+ * from the Isaac API have a type of "userdata" in Lua with a metatable key of "__type".)
11
+ */
12
+ export declare function isUserdataObject(object: unknown, objectType: string): boolean;
@@ -0,0 +1,18 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ function ____exports.getUserdataType(self, object)
4
+ local objectType = type(object)
5
+ if objectType ~= "userdata" then
6
+ return nil
7
+ end
8
+ local metatable = getmetatable(object)
9
+ if metatable == nil then
10
+ return nil
11
+ end
12
+ return metatable.__type
13
+ end
14
+ function ____exports.isUserdataObject(self, object, objectType)
15
+ local userdataType = ____exports.getUserdataType(nil, object)
16
+ return userdataType == objectType or userdataType == "const " .. objectType
17
+ end
18
+ return ____exports
@@ -93,11 +93,6 @@ export declare function hexToKColor(hexString: string, alpha: float): KColor;
93
93
  * is enabled or not.
94
94
  */
95
95
  export declare function isLuaDebugEnabled(): boolean;
96
- /**
97
- * Helper function to check if the something is an instantiated class from the Isaac API. (All
98
- * classes from the Isaac API have a type of "userdata" in Lua.)
99
- */
100
- export declare function isUserdataObject(object: unknown, objectName: string): boolean;
101
96
  /**
102
97
  * Helper function to print something to the in-game console. Use this instead of invoking the
103
98
  * `Isaac.ConsoleOutput` method directly because it will automatically insert a newline at the end
@@ -66,18 +66,6 @@ end
66
66
  function ____exports.isLuaDebugEnabled(self)
67
67
  return package ~= nil
68
68
  end
69
- function ____exports.isUserdataObject(self, object, objectName)
70
- local objectType = type(object)
71
- if objectType ~= "userdata" then
72
- return false
73
- end
74
- local metatable = getmetatable(object)
75
- if metatable == nil then
76
- return false
77
- end
78
- local vectorMetatable = metatable
79
- return vectorMetatable.__type == objectName
80
- end
81
69
  function ____exports.printConsole(self, msg)
82
70
  Isaac.ConsoleOutput(msg .. "\n")
83
71
  end
@@ -11,9 +11,10 @@ local ____table = require("functions.table")
11
11
  local copyValuesToTable = ____table.copyValuesToTable
12
12
  local getNumbersFromTable = ____table.getNumbersFromTable
13
13
  local tableHasKeys = ____table.tableHasKeys
14
+ local ____userdata = require("functions.userdata")
15
+ local isUserdataObject = ____userdata.isUserdataObject
14
16
  local ____utils = require("functions.utils")
15
17
  local ensureAllCases = ____utils.ensureAllCases
16
- local isUserdataObject = ____utils.isUserdataObject
17
18
  function ____exports.isVector(self, object)
18
19
  return isUserdataObject(nil, object, OBJECT_NAME)
19
20
  end
package/dist/index.d.ts CHANGED
@@ -88,6 +88,7 @@ export * from "./functions/trinketGive";
88
88
  export * from "./functions/trinkets";
89
89
  export * from "./functions/trinketSet";
90
90
  export * from "./functions/ui";
91
+ export * from "./functions/userdata";
91
92
  export * from "./functions/utils";
92
93
  export * from "./functions/vector";
93
94
  export * from "./maps/cardMap";
package/dist/index.lua CHANGED
@@ -704,6 +704,14 @@ do
704
704
  end
705
705
  end
706
706
  end
707
+ do
708
+ local ____export = require("functions.userdata")
709
+ for ____exportKey, ____exportValue in pairs(____export) do
710
+ if ____exportKey ~= "default" then
711
+ ____exports[____exportKey] = ____exportValue
712
+ end
713
+ end
714
+ end
707
715
  do
708
716
  local ____export = require("functions.utils")
709
717
  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.215",
3
+ "version": "1.2.218",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",