isaacscript-common 1.0.459 → 1.0.463

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.
@@ -6,7 +6,8 @@ export declare function disableInputsInit(mod: ModUpgraded): void;
6
6
  export declare function enableAllInputs(): void;
7
7
  /**
8
8
  * Helper function to disable all inputs.
9
- * This is useful because `EntityPlayer.ControlsEnabled` is not very reliable.
9
+ * This is useful because `EntityPlayer.ControlsEnabled` can be changed by the game under certain
10
+ * conditions.
10
11
  *
11
12
  * Call `enableAllInputs()` to set things back to normal.
12
13
  *
@@ -16,7 +17,8 @@ export declare function enableAllInputs(): void;
16
17
  export declare function disableAllInputs(): void;
17
18
  /**
18
19
  * Helper function to enable all inputs besides the ones provided.
19
- * This is useful because `EntityPlayer.ControlsEnabled` is not very reliable.
20
+ * This is useful because `EntityPlayer.ControlsEnabled` can be changed by the game under certain
21
+ * conditions.
20
22
  *
21
23
  * Call `enableAllInputs()` to set things back to normal.
22
24
  *
@@ -26,7 +28,8 @@ export declare function disableAllInputs(): void;
26
28
  export declare function enableAllInputsExceptFor(blacklist: Set<ButtonAction>): void;
27
29
  /**
28
30
  * Helper function to disable all inputs besides the ones provided.
29
- * This is useful because `EntityPlayer.ControlsEnabled` is not very reliable.
31
+ * This is useful because `EntityPlayer.ControlsEnabled` can be changed by the game under certain
32
+ * conditions.
30
33
  *
31
34
  * Call `enableAllInputs()` to set things back to normal.
32
35
  *
@@ -37,7 +40,8 @@ export declare function disableAllInputsExceptFor(whitelist: Set<ButtonAction>):
37
40
  /**
38
41
  * Helper function to disable only the inputs used for moving the character (or moving the cursor in
39
42
  * the UI).
40
- * This is useful because `EntityPlayer.ControlsEnabled` is not very reliable.
43
+ * This is useful because `EntityPlayer.ControlsEnabled` can be changed by the game under certain
44
+ * conditions.
41
45
  *
42
46
  * Call `enableInputs()` to set things back to normal.
43
47
  *
@@ -47,7 +51,8 @@ export declare function disableAllInputsExceptFor(whitelist: Set<ButtonAction>):
47
51
  export declare function disableMovementInputs(): void;
48
52
  /**
49
53
  * Helper function to disable only the inputs used for shooting tears.
50
- * This is useful because `EntityPlayer.ControlsEnabled` is not very reliable.
54
+ * This is useful because `EntityPlayer.ControlsEnabled` can be changed by the game under certain
55
+ * conditions.
51
56
  *
52
57
  * Call `enableInputs()` to set things back to normal.
53
58
  *
@@ -12,7 +12,7 @@ function isActionTriggered(self, _entity, _inputHook, buttonAction)
12
12
  end
13
13
  return nil
14
14
  end
15
- local FEATURE_NAME = "Forgotten switcher"
15
+ local FEATURE_NAME = "forgotten switcher"
16
16
  local initialized = false
17
17
  v = {run = {shouldSwitch = false}}
18
18
  function ____exports.forgottenSwitchInit(self, mod)
@@ -0,0 +1,10 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ import { ModUpgraded } from "../types/ModUpgraded";
3
+ /** @hidden */
4
+ export declare function getCollectibleItemPoolTypeInit(mod: ModUpgraded): void;
5
+ /**
6
+ * Helper function to get the item pool type that a given collectible came from. Since there is no
7
+ * native method in the API to get this, IsaacScript listens in the PreGetCollectible callback for
8
+ * item pool types, and then assumes that the next spawned collectible will match.
9
+ */
10
+ export declare function getCollectibleItemPoolType(collectible: EntityPickup): ItemPoolType;
@@ -0,0 +1,64 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ require("lualib_bundle");
3
+ local ____exports = {}
4
+ local postPickupInitCollectible, preGetCollectible, v
5
+ local ____errors = require("errors")
6
+ local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
7
+ local ____array = require("functions.array")
8
+ local arrayEmpty = ____array.arrayEmpty
9
+ local ____rooms = require("functions.rooms")
10
+ local getRoomIndex = ____rooms.getRoomIndex
11
+ local getRoomItemPoolType = ____rooms.getRoomItemPoolType
12
+ local getRoomVisitedCount = ____rooms.getRoomVisitedCount
13
+ local ____exports = require("features.saveDataManager.exports")
14
+ local saveDataManager = ____exports.saveDataManager
15
+ function postPickupInitCollectible(self, pickup)
16
+ local itemPoolType = __TS__ArrayShift(v.run.collectibleQueue)
17
+ if itemPoolType == nil then
18
+ return
19
+ end
20
+ local ptrHash = GetPtrHash(pickup)
21
+ v.run.collectibleItemPoolTypeMap:set(ptrHash, itemPoolType)
22
+ end
23
+ function preGetCollectible(self, itemPoolType, _decrease, _seed)
24
+ local roomIndex = getRoomIndex(nil)
25
+ local roomVisitedCount = getRoomVisitedCount(nil)
26
+ if (roomIndex ~= v.run.currentRoomIndex) or (roomVisitedCount ~= v.run.currentRoomVisitedCount) then
27
+ v.run.currentRoomIndex = roomIndex
28
+ v.run.currentRoomVisitedCount = roomVisitedCount
29
+ arrayEmpty(nil, v.run.collectibleQueue)
30
+ v.run.collectibleItemPoolTypeMap:clear()
31
+ end
32
+ __TS__ArrayPush(v.run.collectibleQueue, itemPoolType)
33
+ end
34
+ local FEATURE_NAME = "get collectible item pool type"
35
+ local initialized = false
36
+ v = {
37
+ run = {
38
+ collectibleQueue = {},
39
+ collectibleItemPoolTypeMap = __TS__New(Map),
40
+ currentRoomIndex = nil,
41
+ currentRoomVisitedCount = nil
42
+ }
43
+ }
44
+ function ____exports.getCollectibleItemPoolTypeInit(self, mod)
45
+ initialized = true
46
+ saveDataManager(nil, "getCollectibleItemPoolType", v)
47
+ mod:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, postPickupInitCollectible, PickupVariant.PICKUP_COLLECTIBLE)
48
+ mod:AddCallback(ModCallbacks.MC_PRE_GET_COLLECTIBLE, preGetCollectible)
49
+ end
50
+ function ____exports.getCollectibleItemPoolType(self, collectible)
51
+ if not initialized then
52
+ local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
53
+ error(msg)
54
+ end
55
+ if (collectible.Type ~= EntityType.ENTITY_PICKUP) or (collectible.Variant ~= PickupVariant.PICKUP_COLLECTIBLE) then
56
+ error(
57
+ (((("The \"getCollectibleItemPoolType()\" function was given a non-collectible: " .. tostring(collectible.Type)) .. ".") .. tostring(collectible.Variant)) .. ".") .. tostring(collectible.SubType)
58
+ )
59
+ end
60
+ local ptrHash = GetPtrHash(collectible)
61
+ local itemPoolType = v.run.collectibleItemPoolTypeMap:get(ptrHash)
62
+ return ((itemPoolType == nil) and getRoomItemPoolType(nil)) or itemPoolType
63
+ end
64
+ return ____exports
@@ -62,7 +62,8 @@ import { SaveData } from "../../types/SaveData";
62
62
  *
63
63
  * @param key The name of the file or feature that is submitting data to be managed by the save data
64
64
  * manager. The save data manager will throw an error if the key is already registered.
65
- * @param saveData An object that corresponds to the `SaveData` interface.
65
+ * @param saveData An object that corresponds to the `SaveData` interface. The object is
66
+ * conventionally called "v" for brevity (which is short for "local variables").
66
67
  * @param conditionalFunc An optional function to run upon saving this key to disk. If the function
67
68
  * is false, the key will not be written to disk. This allows mod features to avoid cluttering the
68
69
  * "save#.dat" file with unnecessary keys.
@@ -1,9 +1,5 @@
1
1
  import { ModUpgraded } from "../../types/ModUpgraded";
2
- /** @hidden */
3
2
  export declare const FEATURE_NAME = "save data manager";
4
- /** @hidden */
5
3
  export declare function saveDataManagerInit(incomingMod: ModUpgraded): void;
6
- /** @hidden */
7
4
  export declare function isSaveDataManagerInitialized(): boolean;
8
- /** @hidden */
9
5
  export declare function forceSaveDataManagerSave(): void;
@@ -1,9 +1,4 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
- /**
3
- * Helper function to change the item on an item pedestal. Simply updating the SubType is not
4
- * sufficient because you also need to update the sprite.
5
- */
6
- export declare function changeCollectibleSubType(collectible: EntityPickup, newCollectibleType: CollectibleType | int): void;
7
2
  export declare function collectibleHasTag(collectibleType: CollectibleType | int, tag: ItemConfigTag): boolean;
8
3
  /**
9
4
  * Helper function to get the heart cost that a collectible item would be if it were being offered
@@ -47,5 +42,10 @@ export declare function removeAllCollectibles(): void;
47
42
  * Python program located at: https://github.com/Rchardon/RebirthItemTracker
48
43
  */
49
44
  export declare function removeCollectibleFromItemTracker(collectibleType: CollectibleType | int): void;
50
- export declare function setCollectibleBlind(pickup: EntityPickup): void;
51
- export declare function setCollectibleSprite(pickup: EntityPickup, pngPath: string): void;
45
+ export declare function setCollectibleBlind(collectible: EntityPickup): void;
46
+ export declare function setCollectibleSprite(collectible: EntityPickup, pngPath: string): void;
47
+ /**
48
+ * Helper function to change the collectible on a pedestal. Simply updating the SubType property is
49
+ * not sufficient because the sprite will not change.
50
+ */
51
+ export declare function setCollectibleSubType(collectible: EntityPickup, newCollectibleType: CollectibleType | int): void;
@@ -6,30 +6,19 @@ local ____collectibleNameMap = require("collectibleNameMap")
6
6
  local COLLECTIBLE_NAME_MAP = ____collectibleNameMap.COLLECTIBLE_NAME_MAP
7
7
  local ____entity = require("functions.entity")
8
8
  local removeAllMatchingEntities = ____entity.removeAllMatchingEntities
9
- function ____exports.setCollectibleSprite(self, pickup, pngPath)
10
- if pickup.Variant ~= PickupVariant.PICKUP_COLLECTIBLE then
9
+ function ____exports.setCollectibleSprite(self, collectible, pngPath)
10
+ if collectible.Variant ~= PickupVariant.PICKUP_COLLECTIBLE then
11
11
  error(
12
- "You cannot set a collectible sprite for pickups of variant: " .. tostring(pickup.Variant)
12
+ "You cannot set a collectible sprite for pickups of variant: " .. tostring(collectible.Variant)
13
13
  )
14
14
  end
15
- local sprite = pickup:GetSprite()
15
+ local sprite = collectible:GetSprite()
16
16
  sprite:ReplaceSpritesheet(COLLECTIBLE_SPRITE_LAYER, pngPath)
17
17
  sprite:LoadGraphics()
18
18
  end
19
19
  COLLECTIBLE_SPRITE_LAYER = 1
20
20
  local BLIND_ITEM_PNG_PATH = "gfx/items/collectibles/questionmark.png"
21
21
  local GLITCHED_ITEM_THRESHOLD = 4000000000
22
- function ____exports.changeCollectibleSubType(self, collectible, newCollectibleType)
23
- collectible.SubType = newCollectibleType
24
- local itemConfig = Isaac.GetItemConfig()
25
- local itemConfigItem = itemConfig:GetCollectible(newCollectibleType)
26
- if itemConfigItem == nil then
27
- error(
28
- "Failed to get the item config for: " .. tostring(newCollectibleType)
29
- )
30
- end
31
- ____exports.setCollectibleSprite(nil, collectible, itemConfigItem.GfxFileName)
32
- end
33
22
  function ____exports.collectibleHasTag(self, collectibleType, tag)
34
23
  local itemConfig = Isaac.GetItemConfig()
35
24
  local itemConfigItem = itemConfig:GetCollectible(collectibleType)
@@ -132,7 +121,20 @@ function ____exports.removeCollectibleFromItemTracker(self, collectibleType)
132
121
  ((("Removing collectible " .. tostring(collectibleType)) .. " (") .. collectibleName) .. ") on player 0 (Player)"
133
122
  )
134
123
  end
135
- function ____exports.setCollectibleBlind(self, pickup)
136
- ____exports.setCollectibleSprite(nil, pickup, BLIND_ITEM_PNG_PATH)
124
+ function ____exports.setCollectibleBlind(self, collectible)
125
+ if collectible.Variant ~= PickupVariant.PICKUP_COLLECTIBLE then
126
+ error(
127
+ "You cannot set a collectible to be blind for pickups of variant: " .. tostring(collectible.Variant)
128
+ )
129
+ end
130
+ ____exports.setCollectibleSprite(nil, collectible, BLIND_ITEM_PNG_PATH)
131
+ end
132
+ function ____exports.setCollectibleSubType(self, collectible, newCollectibleType)
133
+ if collectible.Variant ~= PickupVariant.PICKUP_COLLECTIBLE then
134
+ error(
135
+ "You cannot set a collectible sub type for pickups of variant: " .. tostring(collectible.Variant)
136
+ )
137
+ end
138
+ collectible:Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, newCollectibleType, true, true, true)
137
139
  end
138
140
  return ____exports
@@ -14,12 +14,12 @@ import { PocketItemDescription } from "../types/PocketItemDescription";
14
14
  export declare type PlayerIndex = int & {
15
15
  __playerIndexBrand: unknown;
16
16
  };
17
- export declare function addCollectibleCostume(player: EntityPlayer, collectibleType: CollectibleType): void;
18
- export declare function addTrinketCostume(player: EntityPlayer, trinketType: TrinketType): void;
17
+ export declare function addCollectibleCostume(player: EntityPlayer, collectibleType: CollectibleType | int): void;
18
+ export declare function addTrinketCostume(player: EntityPlayer, trinketType: TrinketType | int): void;
19
19
  /** Iterates over all players and checks if any player is close enough to the specified position. */
20
20
  export declare function anyPlayerCloserThan(position: Vector, distance: float): boolean;
21
- export declare function anyPlayerHasCollectible(collectibleType: CollectibleType): boolean;
22
- export declare function anyPlayerHasTrinket(trinketType: TrinketType): boolean;
21
+ export declare function anyPlayerHasCollectible(collectibleType: CollectibleType | int): boolean;
22
+ export declare function anyPlayerHasTrinket(trinketType: TrinketType | int): boolean;
23
23
  export declare function anyPlayerIs(matchingCharacter: PlayerType): boolean;
24
24
  /**
25
25
  * Helper function to get how long Azazel's Brimstone laser should be. You can pass either an
@@ -134,7 +134,7 @@ export declare function getTotalCharge(player: EntityPlayer, activeSlot: ActiveS
134
134
  * Returns the total number of collectibles amongst all players. For example, if player 1 has 1 Sad
135
135
  * Onion and player 2 has 2 Sad Onions, then this function would return 3.
136
136
  */
137
- export declare function getTotalPlayerCollectibles(collectibleType: CollectibleType): int;
137
+ export declare function getTotalPlayerCollectibles(collectibleType: CollectibleType | int): int;
138
138
  /** After touching a white fire, a player will turn into The Lost until they clear a room. */
139
139
  export declare function hasLostCurse(player: EntityPlayer): boolean;
140
140
  /**
@@ -188,7 +188,7 @@ export declare function isKeeper(player: EntityPlayer): boolean;
188
188
  export declare function isLost(player: EntityPlayer): boolean;
189
189
  /** Helper function for detecting when a player is Tainted Lazarus or Dead Tainted Lazarus. */
190
190
  export declare function isTaintedLazarus(player: EntityPlayer): boolean;
191
- export declare function removeCollectibleCostume(player: EntityPlayer, collectibleType: CollectibleType): void;
191
+ export declare function removeCollectibleCostume(player: EntityPlayer, collectibleType: CollectibleType | int): void;
192
192
  /**
193
193
  * Helper function to remove the Dead Eye multiplier from a player.
194
194
  *
@@ -196,7 +196,7 @@ export declare function removeCollectibleCostume(player: EntityPlayer, collectib
196
196
  * chance of working, so this function calls it 100 times to be safe.
197
197
  */
198
198
  export declare function removeDeadEyeMultiplier(player: EntityPlayer): void;
199
- export declare function removeTrinketCostume(player: EntityPlayer, trinketType: TrinketType): void;
199
+ export declare function removeTrinketCostume(player: EntityPlayer, trinketType: TrinketType | int): void;
200
200
  /**
201
201
  * If you want to stop the player from shooting without the blindfold costume, then simply call
202
202
  * `player.TryRemoveNullCostume(NullItemID.ID_BLINDFOLD)` after invoking this function.
@@ -15,7 +15,7 @@ export interface TrinketSituation {
15
15
  *
16
16
  * @returns Null if the player does not have the trinket, or TrinketSituation if they do.
17
17
  */
18
- export declare function temporarilyRemoveTrinkets(player: EntityPlayer, trinketType: TrinketType): TrinketSituation | undefined;
18
+ export declare function temporarilyRemoveTrinkets(player: EntityPlayer, trinketType: TrinketType | int): TrinketSituation | undefined;
19
19
  /**
20
20
  * Helper function to restore the player's trinkets back to the way they were before the
21
21
  * `temporarilyRemoveTrinket` function was used. It will re-smelt any smelted trinkets that were
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from "./collectibleNameMap";
4
4
  export * from "./constants";
5
5
  export { disableAllInputs, disableAllInputsExceptFor, disableMovementInputs, disableShootingInputs, enableAllInputs, enableAllInputsExceptFor, } from "./features/disableInputs";
6
6
  export { forgottenSwitch } from "./features/forgottenSwitch";
7
+ export { getCollectibleItemPoolType } from "./features/getCollectibleItemPoolType";
7
8
  export { runInNFrames, runNextFrame } from "./features/runInNFrames";
8
9
  export * from "./features/saveDataManager/exports";
9
10
  export { hasSirenStolenFamiliar, setFamiliarNoSirenSteal, } from "./features/sirenHelpers";
package/dist/index.lua CHANGED
@@ -51,6 +51,11 @@ do
51
51
  local forgottenSwitch = ____forgottenSwitch.forgottenSwitch
52
52
  ____exports.forgottenSwitch = forgottenSwitch
53
53
  end
54
+ do
55
+ local ____getCollectibleItemPoolType = require("features.getCollectibleItemPoolType")
56
+ local getCollectibleItemPoolType = ____getCollectibleItemPoolType.getCollectibleItemPoolType
57
+ ____exports.getCollectibleItemPoolType = getCollectibleItemPoolType
58
+ end
54
59
  do
55
60
  local ____runInNFrames = require("features.runInNFrames")
56
61
  local runInNFrames = ____runInNFrames.runInNFrames
@@ -5,14 +5,14 @@ import { ModUpgraded } from "./types/ModUpgraded";
5
5
  *
6
6
  * Example:
7
7
  * ```
8
- * const mod = RegisterMod("My Mod", 1);
9
- * const modUpgraded = upgradeMod(mod);
8
+ * const modVanilla = RegisterMod("My Mod", 1);
9
+ * const mod = upgradeMod(modVanilla);
10
10
  *
11
11
  * // Subscribe to vanilla callbacks
12
12
  * mod.AddCallback(ModCallbacks.MC_POST_UPDATE, postUpdate);
13
13
  *
14
14
  * // Subscribe to custom callbacks
15
- * modUpgraded.AddCallbackCustom(ModCallbacksCustom.MC_POST_ITEM_PICKUP, postItemPickup);
15
+ * mod.AddCallbackCustom(ModCallbacksCustom.MC_POST_ITEM_PICKUP, postItemPickup);
16
16
  * ```
17
17
  *
18
18
  * For a list of all custom callbacks, check out the
@@ -60,6 +60,8 @@ local ____disableInputs = require("features.disableInputs")
60
60
  local disableInputsInit = ____disableInputs.disableInputsInit
61
61
  local ____forgottenSwitch = require("features.forgottenSwitch")
62
62
  local forgottenSwitchInit = ____forgottenSwitch.forgottenSwitchInit
63
+ local ____getCollectibleItemPoolType = require("features.getCollectibleItemPoolType")
64
+ local getCollectibleItemPoolTypeInit = ____getCollectibleItemPoolType.getCollectibleItemPoolTypeInit
63
65
  local ____runInNFrames = require("features.runInNFrames")
64
66
  local runInNFramesInit = ____runInNFrames.runInNFramesInit
65
67
  local ____main = require("features.saveDataManager.main")
@@ -100,6 +102,7 @@ end
100
102
  function initFeatures(self, mod)
101
103
  disableInputsInit(nil, mod)
102
104
  forgottenSwitchInit(nil, mod)
105
+ getCollectibleItemPoolTypeInit(nil, mod)
103
106
  runInNFramesInit(nil, mod)
104
107
  sirenHelpersInit(nil, mod)
105
108
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.0.459",
3
+ "version": "1.0.463",
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.278",
28
+ "isaac-typescript-definitions": "^1.0.280",
29
29
  "isaacscript-lint": "^1.0.67",
30
30
  "typedoc": "^0.22.9",
31
31
  "typescript": "4.4.4",