isaacscript-common 1.0.540 → 1.0.544

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.
@@ -1,11 +1,11 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /**
3
- * Helper function to get a card name from a Card.
3
+ * Helper function to get a card description from a Card enum value.
4
4
  *
5
5
  * Example:
6
6
  * ```
7
7
  * const card = Card.CARD_FOOL;
8
- * const cardName = getCardName(card); // cardName is "0 - The Fool"
8
+ * const cardDescription = getCardDescription(card); // cardDescription is "Where journey begins"
9
9
  * ```
10
10
  */
11
11
  export declare function getCardDescription(card: Card | int): string;
@@ -152,6 +152,13 @@ export declare function getSlots(matchingVariant?: number, matchingSubType?: num
152
152
  * ```
153
153
  */
154
154
  export declare function getTears(matchingVariant?: number, matchingSubType?: number): EntityTear[];
155
+ /**
156
+ * Helper function to measure an entity's velocity to see if it is moving.
157
+ *
158
+ * @param entity The entity whose velocity to measure.
159
+ * @param threshold Optional. The threshold from 0 to consider to be moving. 0.01 by default.
160
+ */
161
+ export declare function isEntityMoving(entity: Entity, threshold?: number): boolean;
155
162
  /**
156
163
  * Helper function to remove all of the entities in the supplied array.
157
164
  *
@@ -210,6 +210,12 @@ function ____exports.getTears(self, matchingVariant, matchingSubType)
210
210
  end
211
211
  return tears
212
212
  end
213
+ function ____exports.isEntityMoving(self, entity, threshold)
214
+ if threshold == nil then
215
+ threshold = 0.01
216
+ end
217
+ return entity.Velocity:Length() >= threshold
218
+ end
213
219
  function ____exports.removeEntities(self, entities, cap)
214
220
  local numEntitiesRemoved = 0
215
221
  do
@@ -1,6 +1,6 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /**
3
- * Helper function to get a pill effect name from a PillEffect.
3
+ * Helper function to get a pill effect name from a PillEffect enum value.
4
4
  *
5
5
  * Example:
6
6
  * ```
@@ -6,7 +6,7 @@ local ____sprite = require("functions.sprite")
6
6
  local getFinalFrameOfAnimation = ____sprite.getFinalFrameOfAnimation
7
7
  local ____trinketGive = require("functions.trinketGive")
8
8
  local giveTrinketsBack = ____trinketGive.giveTrinketsBack
9
- local temporarilyRemoveTrinkets = ____trinketGive.temporarilyRemoveTrinkets
9
+ local temporarilyRemoveTrinket = ____trinketGive.temporarilyRemoveTrinket
10
10
  function ____exports.willMysteriousPaperRevive(self, player)
11
11
  local game = Game()
12
12
  local gameFrameCount = game:GetFrameCount()
@@ -17,7 +17,7 @@ function ____exports.willMysteriousPaperRevive(self, player)
17
17
  return (frameOfDeath % 4) == 3
18
18
  end
19
19
  function ____exports.willPlayerRevive(self, player)
20
- local trinketSituation = temporarilyRemoveTrinkets(nil, player, TrinketType.TRINKET_MYSTERIOUS_PAPER)
20
+ local trinketSituation = temporarilyRemoveTrinket(nil, player, TrinketType.TRINKET_MYSTERIOUS_PAPER)
21
21
  local willRevive = player:WillPlayerRevive() or ((trinketSituation ~= nil) and ____exports.willMysteriousPaperRevive(nil, player))
22
22
  giveTrinketsBack(nil, player, trinketSituation)
23
23
  return willRevive
@@ -2,3 +2,13 @@
2
2
  /** Returns the number of items that a player has towards a particular transformation. */
3
3
  export declare function getPlayerNumTransformationCollectibles(player: EntityPlayer, playerForm: PlayerForm): int;
4
4
  export declare function getTransformationsForItem(collectibleType: CollectibleType | int): Set<PlayerForm>;
5
+ /**
6
+ * Helper function to get a transformation name from a PlayerForm enum.
7
+ *
8
+ * Example:
9
+ * ```
10
+ * const transformationName = getTransformationName(PlayerForm.PLAYERFORM_LORD_OF_THE_FLIES);
11
+ * // transformationName is "Beelzebub"
12
+ * ```
13
+ */
14
+ export declare function getTransformationName(transformation: PlayerForm): string;
@@ -1,10 +1,12 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  require("lualib_bundle");
3
3
  local ____exports = {}
4
- local ____transformationMap = require("maps.transformationMap")
5
- local ITEM_TO_TRANSFORMATION_MAP = ____transformationMap.ITEM_TO_TRANSFORMATION_MAP
6
- local TRANSFORMATIONS_NOT_BASED_ON_ITEMS = ____transformationMap.TRANSFORMATIONS_NOT_BASED_ON_ITEMS
7
- local TRANSFORMATION_TO_ITEMS_MAP = ____transformationMap.TRANSFORMATION_TO_ITEMS_MAP
4
+ local ____transformationMaps = require("maps.transformationMaps")
5
+ local ITEM_TO_TRANSFORMATION_MAP = ____transformationMaps.ITEM_TO_TRANSFORMATION_MAP
6
+ local TRANSFORMATIONS_NOT_BASED_ON_ITEMS = ____transformationMaps.TRANSFORMATIONS_NOT_BASED_ON_ITEMS
7
+ local TRANSFORMATION_TO_ITEMS_MAP = ____transformationMaps.TRANSFORMATION_TO_ITEMS_MAP
8
+ local ____transformationNameMap = require("maps.transformationNameMap")
9
+ local TRANSFORMATION_NAME_MAP = ____transformationNameMap.TRANSFORMATION_NAME_MAP
8
10
  local ____util = require("functions.util")
9
11
  local copySet = ____util.copySet
10
12
  function ____exports.getPlayerNumTransformationCollectibles(self, player, playerForm)
@@ -31,4 +33,9 @@ function ____exports.getTransformationsForItem(self, collectibleType)
31
33
  local transformations = ITEM_TO_TRANSFORMATION_MAP:get(collectibleType)
32
34
  return ((transformations == nil) and __TS__New(Set)) or copySet(nil, transformations)
33
35
  end
36
+ function ____exports.getTransformationName(self, transformation)
37
+ local defaultName = "Unknown"
38
+ local transformationName = TRANSFORMATION_NAME_MAP:get(transformation)
39
+ return ((transformationName == nil) and defaultName) or transformationName
40
+ end
34
41
  return ____exports
@@ -1,21 +1,24 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
- export interface TrinketSituation {
3
- trinketTypeRemoved: TrinketType | int;
4
- trinket1: TrinketType | int;
5
- trinket2: TrinketType | int;
6
- numSmeltedTrinkets: int;
7
- }
2
+ import { TrinketSituation } from "../types/TrinketSituation";
8
3
  /**
9
- * Helper function to temporarily remove a trinket from the player. Use this in combination with the
10
- * `giveTrinketBack` function to take away and give back a trinket on the same frame. This function
11
- * correctly handles multiple trinket slots and ensures that all copies of the trinket are removed,
12
- * including smelted trinkets.
4
+ * Helper function to temporarily remove a specific kind of trinket from the player. Use this in
5
+ * combination with the `giveTrinketBack` function to take away and give back a trinket on the same
6
+ * frame. This function correctly handles multiple trinket slots and ensures that all copies of the
7
+ * trinket are removed, including smelted trinkets.
13
8
  *
14
9
  * Note that for simplicity, this function assumes that all smelted trinkets are non-golden.
15
10
  *
16
- * @returns Null if the player does not have the trinket, or TrinketSituation if they do.
11
+ * @returns Undefined if the player does not have the trinket, or TrinketSituation if they do.
17
12
  */
18
- export declare function temporarilyRemoveTrinkets(player: EntityPlayer, trinketType: TrinketType | int): TrinketSituation | undefined;
13
+ export declare function temporarilyRemoveTrinket(player: EntityPlayer, trinketType: TrinketType | int): TrinketSituation | undefined;
14
+ /**
15
+ * Helper function to temporarily removes a player's held trinkets, if any. This will not remove any
16
+ * smelted trinkets. Use this in combination with the `giveTrinketBack` function to take away and
17
+ * give back trinkets on the same frame.
18
+ *
19
+ * @returns Undefined if the player does not have any trinkets, or TrinketSituation if they do.
20
+ */
21
+ export declare function temporarilyRemoveTrinkets(player: EntityPlayer): TrinketSituation | undefined;
19
22
  /**
20
23
  * Helper function to restore the player's trinkets back to the way they were before the
21
24
  * `temporarilyRemoveTrinket` function was used. It will re-smelt any smelted trinkets that were
@@ -2,7 +2,7 @@
2
2
  local ____exports = {}
3
3
  local ____constants = require("constants")
4
4
  local GOLDEN_TRINKET_SHIFT = ____constants.GOLDEN_TRINKET_SHIFT
5
- function ____exports.temporarilyRemoveTrinkets(self, player, trinketType)
5
+ function ____exports.temporarilyRemoveTrinket(self, player, trinketType)
6
6
  if not player:HasTrinket(trinketType) then
7
7
  return nil
8
8
  end
@@ -24,6 +24,20 @@ function ____exports.temporarilyRemoveTrinkets(self, player, trinketType)
24
24
  end
25
25
  return {trinketTypeRemoved = trinketType, trinket1 = trinket1, trinket2 = trinket2, numSmeltedTrinkets = numSmeltedTrinkets}
26
26
  end
27
+ function ____exports.temporarilyRemoveTrinkets(self, player)
28
+ local trinket1 = player:GetTrinket(0)
29
+ local trinket2 = player:GetTrinket(1)
30
+ if (trinket1 == TrinketType.TRINKET_NULL) and (trinket2 == TrinketType.TRINKET_NULL) then
31
+ return nil
32
+ end
33
+ if trinket1 ~= TrinketType.TRINKET_NULL then
34
+ player:TryRemoveTrinket(trinket1)
35
+ end
36
+ if trinket2 ~= TrinketType.TRINKET_NULL then
37
+ player:TryRemoveTrinket(trinket2)
38
+ end
39
+ return {trinketTypeRemoved = TrinketType.TRINKET_NULL, trinket1 = trinket1, trinket2 = trinket2, numSmeltedTrinkets = 0}
40
+ end
27
41
  function ____exports.giveTrinketsBack(self, player, trinketSituation)
28
42
  if trinketSituation == nil then
29
43
  return
@@ -41,3 +41,14 @@ export declare function getTrinketName(trinketType: TrinketType | int): string;
41
41
  */
42
42
  export declare function hasOpenTrinketSlot(player: EntityPlayer): boolean;
43
43
  export declare function isGoldenTrinket(trinketType: TrinketType | int): boolean;
44
+ /**
45
+ * Helper function to smelt a trinket. Before smelting, this function will automatically remove the
46
+ * trinkets that the player is holding, if any, and then give them back after the new trinket is
47
+ * smelted.
48
+ *
49
+ * @param player The player to smelt the trinkets to.
50
+ * @param trinketType The trinket type to smelt.
51
+ * @param numTrinkets Optional. If specified, will smelt the given number of trinkets. Use this to
52
+ * avoid calling this function multiple times. 1 by default.
53
+ */
54
+ export declare function smeltTrinket(player: EntityPlayer, trinketType: TrinketType | int, numTrinkets?: number): void;
@@ -7,6 +7,9 @@ local ____trinketDescriptionMap = require("maps.trinketDescriptionMap")
7
7
  local TRINKET_DESCRIPTION_MAP = ____trinketDescriptionMap.TRINKET_DESCRIPTION_MAP
8
8
  local ____trinketNameMap = require("maps.trinketNameMap")
9
9
  local TRINKET_NAME_MAP = ____trinketNameMap.TRINKET_NAME_MAP
10
+ local ____trinketGive = require("functions.trinketGive")
11
+ local giveTrinketsBack = ____trinketGive.giveTrinketsBack
12
+ local temporarilyRemoveTrinkets = ____trinketGive.temporarilyRemoveTrinkets
10
13
  function ____exports.getMaxTrinketID(self)
11
14
  local itemConfig = Isaac.GetItemConfig()
12
15
  return itemConfig:GetTrinkets().Size - 1
@@ -86,4 +89,19 @@ end
86
89
  function ____exports.isGoldenTrinket(self, trinketType)
87
90
  return trinketType > GOLDEN_TRINKET_SHIFT
88
91
  end
92
+ function ____exports.smeltTrinket(self, player, trinketType, numTrinkets)
93
+ if numTrinkets == nil then
94
+ numTrinkets = 1
95
+ end
96
+ local trinketSituation = temporarilyRemoveTrinkets(nil, player)
97
+ do
98
+ local i = 0
99
+ while i < numTrinkets do
100
+ player:AddTrinket(trinketType)
101
+ player:UseActiveItem(CollectibleType.COLLECTIBLE_SMELTER, false, false, true, false)
102
+ i = i + 1
103
+ end
104
+ end
105
+ giveTrinketsBack(nil, player, trinketSituation)
106
+ end
89
107
  return ____exports
package/dist/index.d.ts CHANGED
@@ -56,7 +56,8 @@ export * from "./maps/collectibleNameMap";
56
56
  export * from "./maps/gridEntityXMLMap";
57
57
  export * from "./maps/pillEffectNameMap";
58
58
  export * from "./maps/roomShapeToTopLeftWallGridIndexMap";
59
- export * from "./maps/transformationMap";
59
+ export * from "./maps/transformationMaps";
60
+ export * from "./maps/transformationNameMap";
60
61
  export * from "./maps/trinketNameMap";
61
62
  export * from "./sets/cards";
62
63
  export * from "./types/CallbackParametersCustom";
@@ -72,4 +73,5 @@ export * from "./types/PickingUpItem";
72
73
  export * from "./types/PlayerHealth";
73
74
  export * from "./types/PocketItemDescription";
74
75
  export * from "./types/PocketItemType";
76
+ export * from "./types/TrinketSituation";
75
77
  export * from "./upgradeMod";
package/dist/index.lua CHANGED
@@ -455,7 +455,15 @@ do
455
455
  end
456
456
  end
457
457
  do
458
- local ____export = require("maps.transformationMap")
458
+ local ____export = require("maps.transformationMaps")
459
+ for ____exportKey, ____exportValue in pairs(____export) do
460
+ if ____exportKey ~= "default" then
461
+ ____exports[____exportKey] = ____exportValue
462
+ end
463
+ end
464
+ end
465
+ do
466
+ local ____export = require("maps.transformationNameMap")
459
467
  for ____exportKey, ____exportValue in pairs(____export) do
460
468
  if ____exportKey ~= "default" then
461
469
  ____exports[____exportKey] = ____exportValue
@@ -0,0 +1,5 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ export declare const TRANSFORMATION_TO_TAG_MAP: Map<PlayerForm, ItemConfigTag>;
3
+ export declare const TRANSFORMATIONS_NOT_BASED_ON_ITEMS: Set<PlayerForm>;
4
+ export declare const TRANSFORMATION_TO_ITEMS_MAP: Map<PlayerForm, Set<number>>;
5
+ export declare const ITEM_TO_TRANSFORMATION_MAP: Map<number, Set<PlayerForm>>;
@@ -0,0 +1,56 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ require("lualib_bundle");
3
+ local ____exports = {}
4
+ local initMaps
5
+ local ____collectibles = require("functions.collectibles")
6
+ local collectibleHasTag = ____collectibles.collectibleHasTag
7
+ local getMaxCollectibleID = ____collectibles.getMaxCollectibleID
8
+ function initMaps(self)
9
+ for ____, playerForm in __TS__Iterator(
10
+ ____exports.TRANSFORMATION_TO_TAG_MAP:keys()
11
+ ) do
12
+ ____exports.TRANSFORMATION_TO_ITEMS_MAP:set(
13
+ playerForm,
14
+ __TS__New(Set)
15
+ )
16
+ end
17
+ do
18
+ local collectibleType = 1
19
+ while collectibleType <= getMaxCollectibleID(nil) do
20
+ for ____, ____value in __TS__Iterator(
21
+ ____exports.TRANSFORMATION_TO_TAG_MAP:entries()
22
+ ) do
23
+ local playerForm
24
+ playerForm = ____value[1]
25
+ local tag
26
+ tag = ____value[2]
27
+ do
28
+ if not collectibleHasTag(nil, collectibleType, tag) then
29
+ goto __continue5
30
+ end
31
+ local items = ____exports.TRANSFORMATION_TO_ITEMS_MAP:get(playerForm)
32
+ if items == nil then
33
+ error(
34
+ "Failed to get the items for transformation: " .. tostring(playerForm)
35
+ )
36
+ end
37
+ items:add(collectibleType)
38
+ local transformations = ____exports.ITEM_TO_TRANSFORMATION_MAP:get(collectibleType)
39
+ if transformations == nil then
40
+ transformations = __TS__New(Set)
41
+ ____exports.ITEM_TO_TRANSFORMATION_MAP:set(collectibleType, transformations)
42
+ end
43
+ transformations:add(playerForm)
44
+ end
45
+ ::__continue5::
46
+ end
47
+ collectibleType = collectibleType + 1
48
+ end
49
+ end
50
+ end
51
+ ____exports.TRANSFORMATION_TO_TAG_MAP = __TS__New(Map, {{PlayerForm.PLAYERFORM_GUPPY, 32}, {PlayerForm.PLAYERFORM_LORD_OF_THE_FLIES, 64}, {PlayerForm.PLAYERFORM_MUSHROOM, 256}, {PlayerForm.PLAYERFORM_ANGEL, 1024}, {PlayerForm.PLAYERFORM_BOB, 128}, {PlayerForm.PLAYERFORM_DRUGS, 2}, {PlayerForm.PLAYERFORM_MOM, 4}, {PlayerForm.PLAYERFORM_BABY, 512}, {PlayerForm.PLAYERFORM_EVIL_ANGEL, 2048}, {PlayerForm.PLAYERFORM_POOP, 4096}, {PlayerForm.PLAYERFORM_BOOK_WORM, 8192}, {PlayerForm.PLAYERFORM_SPIDERBABY, 16384}})
52
+ ____exports.TRANSFORMATIONS_NOT_BASED_ON_ITEMS = __TS__New(Set, {PlayerForm.PLAYERFORM_ADULTHOOD, PlayerForm.PLAYERFORM_STOMPY, PlayerForm.PLAYERFORM_FLIGHT})
53
+ ____exports.TRANSFORMATION_TO_ITEMS_MAP = __TS__New(Map)
54
+ ____exports.ITEM_TO_TRANSFORMATION_MAP = __TS__New(Map)
55
+ initMaps(nil)
56
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ export declare const TRANSFORMATION_NAME_MAP: Map<PlayerForm, string>;
@@ -0,0 +1,5 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ require("lualib_bundle");
3
+ local ____exports = {}
4
+ ____exports.TRANSFORMATION_NAME_MAP = __TS__New(Map, {{PlayerForm.PLAYERFORM_GUPPY, "Guppy"}, {PlayerForm.PLAYERFORM_LORD_OF_THE_FLIES, "Beelzebub"}, {PlayerForm.PLAYERFORM_MUSHROOM, "Fun Guy"}, {PlayerForm.PLAYERFORM_ANGEL, "Seraphim"}, {PlayerForm.PLAYERFORM_BOB, "Bob"}, {PlayerForm.PLAYERFORM_DRUGS, "Spun"}, {PlayerForm.PLAYERFORM_MOM, "Yes Mother?"}, {PlayerForm.PLAYERFORM_BABY, "Conjoined"}, {PlayerForm.PLAYERFORM_EVIL_ANGEL, "Leviathan"}, {PlayerForm.PLAYERFORM_POOP, "Oh Crap"}, {PlayerForm.PLAYERFORM_BOOK_WORM, "Bookworm"}, {PlayerForm.PLAYERFORM_ADULTHOOD, "Adult"}, {PlayerForm.PLAYERFORM_SPIDERBABY, "Spider Baby"}, {PlayerForm.PLAYERFORM_STOMPY, "Stompy"}, {PlayerForm.PLAYERFORM_FLIGHT, "Flight"}})
5
+ return ____exports
@@ -0,0 +1,7 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ export interface TrinketSituation {
3
+ trinketTypeRemoved: TrinketType | int;
4
+ trinket1: TrinketType | int;
5
+ trinket2: TrinketType | int;
6
+ numSmeltedTrinkets: int;
7
+ }
@@ -0,0 +1,3 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ return ____exports
@@ -54,6 +54,8 @@ local ____postSlotRenderBroken = require("callbacks.postSlotRenderBroken")
54
54
  local postSlotRenderBrokenCallbacksInit = ____postSlotRenderBroken.postSlotRenderBrokenCallbacksInit
55
55
  local ____postTearInitLate = require("callbacks.postTearInitLate")
56
56
  local postTearInitLateCallbackInit = ____postTearInitLate.postTearInitLateCallbackInit
57
+ local ____postTearInitVeryLate = require("callbacks.postTearInitVeryLate")
58
+ local postTearInitVeryLateCallbackInit = ____postTearInitVeryLate.postTearInitVeryLateCallbackInit
57
59
  local ____postTransformation = require("callbacks.postTransformation")
58
60
  local postTransformationCallbackInit = ____postTransformation.postTransformationCallbackInit
59
61
  local ____preNewLevel = require("callbacks.preNewLevel")
@@ -89,6 +91,7 @@ function initCustomCallbacks(self, mod)
89
91
  postPlayerReorderedCallbacksInit(nil, mod)
90
92
  postPlayerInitLateCallbackInit(nil, mod)
91
93
  postTearInitLateCallbackInit(nil, mod)
94
+ postTearInitVeryLateCallbackInit(nil, mod)
92
95
  postFamiliarInitLateCallbackInit(nil, mod)
93
96
  postBombInitLateCallbackInit(nil, mod)
94
97
  postPickupInitLateCallbackInit(nil, mod)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.0.540",
3
+ "version": "1.0.544",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,8 +25,8 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "isaac-typescript-definitions": "^1.0.302",
29
- "isaacscript-lint": "^1.0.72",
28
+ "isaac-typescript-definitions": "^1.0.306",
29
+ "isaacscript-lint": "^1.0.73",
30
30
  "typedoc": "^0.22.10",
31
31
  "typescript": "4.4.4",
32
32
  "typescript-to-lua": "1.1.1"