isaacscript-common 1.2.35 → 1.2.38

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,18 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Helper function to add and remove familiars based on the amount of associated collectibles that a
4
+ * player has. Use this instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of
5
+ * the spawned familiar will be set properly and Box of Friends functions correctly.
6
+ *
7
+ * This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
8
+ * to `CacheFlag.CACHE_FAMILIARS`).
9
+ *
10
+ * @param player The player that has the collectibles for this familiar.
11
+ * @param collectibleType The collectible type of the collectible associated with this familiar.
12
+ * @param familiarVariant The variant of the familiar to spawn or remove.
13
+ * @param familiarSubType The sub-type of the familiar to spawn
14
+ * @returns The amount of familiars that were added or removed. For example, the player has 0
15
+ * collectibles and there were 2 familiars, this function would remove the 2 familiars and return
16
+ * -2.
17
+ */
18
+ export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int): int;
@@ -0,0 +1,78 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____lualib = require("lualib_bundle")
3
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
4
+ local ____exports = {}
5
+ local useItemBoxOfFriends, v
6
+ local ____errors = require("errors")
7
+ local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
8
+ local ____familiars = require("functions.familiars")
9
+ local getFamiliars = ____familiars.getFamiliars
10
+ local ____exports = require("features.saveDataManager.exports")
11
+ local saveDataManager = ____exports.saveDataManager
12
+ function useItemBoxOfFriends(self)
13
+ local ____v_room_0, ____numBoxOfFriendsUses_1 = v.room, "numBoxOfFriendsUses"
14
+ ____v_room_0[____numBoxOfFriendsUses_1] = ____v_room_0[____numBoxOfFriendsUses_1] + 1
15
+ end
16
+ local FEATURE_NAME = "check familiar"
17
+ local initialized = false
18
+ v = {room = {numBoxOfFriendsUses = 0}}
19
+ function ____exports.checkFamiliarInit(self, mod)
20
+ initialized = true
21
+ saveDataManager(nil, "checkFamiliar", v)
22
+ mod:AddCallback(ModCallbacks.MC_USE_ITEM, useItemBoxOfFriends, CollectibleType.COLLECTIBLE_BOX_OF_FRIENDS)
23
+ end
24
+ function ____exports.checkFamiliar(self, player, collectibleType, familiarVariant, familiarSubType)
25
+ if not initialized then
26
+ local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
27
+ error(msg)
28
+ end
29
+ local game = Game()
30
+ local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
31
+ local playerPtrHash = GetPtrHash(player)
32
+ local familiars = getFamiliars(nil, familiarVariant, familiarSubTypeToSearchFor)
33
+ local familiarsForThisPlayer = __TS__ArrayFilter(
34
+ familiars,
35
+ function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
36
+ )
37
+ local numCollectibles = player:GetCollectibleNum(collectibleType)
38
+ local numFamiliarsThatShouldExist = numCollectibles * (v.room.numBoxOfFriendsUses + 1)
39
+ if #familiarsForThisPlayer == numFamiliarsThatShouldExist then
40
+ return 0
41
+ end
42
+ if #familiarsForThisPlayer > numFamiliarsThatShouldExist then
43
+ local numFamiliarsToRemove = #familiarsForThisPlayer - numFamiliarsThatShouldExist
44
+ do
45
+ local i = 0
46
+ while i < numFamiliarsToRemove do
47
+ local familiar = familiarsForThisPlayer[i + 1]
48
+ familiar:Remove()
49
+ i = i + 1
50
+ end
51
+ end
52
+ return numFamiliarsToRemove * -1
53
+ end
54
+ local numFamiliarsToSpawn = numFamiliarsThatShouldExist - #familiarsForThisPlayer
55
+ local collectibleRNG = player:GetCollectibleRNG(collectibleType)
56
+ local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
57
+ do
58
+ local i = 0
59
+ while i < numFamiliarsToSpawn do
60
+ collectibleRNG:Next()
61
+ local familiar = game:Spawn(
62
+ EntityType.ENTITY_FAMILIAR,
63
+ familiarVariant,
64
+ player.Position,
65
+ Vector.Zero,
66
+ player,
67
+ familiarSubTypeToUse,
68
+ collectibleRNG:GetSeed()
69
+ ):ToFamiliar()
70
+ if familiar ~= nil then
71
+ familiar.Player = player
72
+ end
73
+ i = i + 1
74
+ end
75
+ end
76
+ return numFamiliarsToSpawn
77
+ end
78
+ return ____exports
@@ -1,21 +1,4 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
- /**
3
- * Helper function to add and remove familiars based on the amount of associated collectibles that a
4
- * player has. Use this instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of
5
- * the spawned familiar will be set properly.
6
- *
7
- * This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
8
- * to `CacheFlag.CACHE_FAMILIARS`).
9
- *
10
- * @param player The player that has the collectibles for this familiar.
11
- * @param collectibleType The collectible type of the collectible associated with this familiar.
12
- * @param familiarVariant The variant of the familiar to spawn or remove.
13
- * @param familiarSubType The sub-type of the familiar to spawn
14
- * @returns The amount of familiars that were added or removed. For example, the player has 0
15
- * collectibles and there were 2 familiars, this function would remove the 2 familiars and return
16
- * -2.
17
- */
18
- export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int): int;
19
2
  /**
20
3
  * Helper function to get all of the familiars in the room.
21
4
  *
@@ -1,7 +1,6 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
- local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
5
4
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
6
5
  local ____exports = {}
7
6
  local ____constants = require("constants")
@@ -26,55 +25,6 @@ function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
26
25
  end
27
26
  return familiars
28
27
  end
29
- function ____exports.checkFamiliar(self, player, collectibleType, familiarVariant, familiarSubType)
30
- local game = Game()
31
- local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
32
- local playerPtrHash = GetPtrHash(player)
33
- local familiars = ____exports.getFamiliars(nil, familiarVariant, familiarSubTypeToSearchFor)
34
- local familiarsForThisPlayer = __TS__ArrayFilter(
35
- familiars,
36
- function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
37
- )
38
- local numCollectibles = player:GetCollectibleNum(collectibleType)
39
- if #familiarsForThisPlayer == numCollectibles then
40
- return 0
41
- end
42
- if #familiarsForThisPlayer > numCollectibles then
43
- local numFamiliarsToRemove = #familiarsForThisPlayer - numCollectibles
44
- do
45
- local i = 0
46
- while i < numFamiliarsToRemove do
47
- local familiar = familiarsForThisPlayer[i + 1]
48
- familiar:Remove()
49
- i = i + 1
50
- end
51
- end
52
- return numFamiliarsToRemove * -1
53
- end
54
- local numFamiliarsToSpawn = numCollectibles - #familiarsForThisPlayer
55
- local collectibleRNG = player:GetCollectibleRNG(collectibleType)
56
- local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
57
- do
58
- local i = 0
59
- while i < numFamiliarsToSpawn do
60
- collectibleRNG:Next()
61
- local familiar = game:Spawn(
62
- EntityType.ENTITY_FAMILIAR,
63
- familiarVariant,
64
- player.Position,
65
- Vector.Zero,
66
- player,
67
- familiarSubTypeToUse,
68
- collectibleRNG:GetSeed()
69
- ):ToFamiliar()
70
- if familiar ~= nil then
71
- familiar.Player = player
72
- end
73
- i = i + 1
74
- end
75
- end
76
- return numFamiliarsToSpawn
77
- end
78
28
  function ____exports.isFamiliarThatShootsPlayerTears(self, familiar)
79
29
  return FAMILIARS_THAT_SHOOT_PLAYER_TEARS:has(familiar.Type)
80
30
  end
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { forceNewLevelCallback, forceNewRoomCallback, } from "./callbacks/reorderedCallbacks";
2
2
  export * from "./constants";
3
+ export * from "./features/checkFamiliar";
3
4
  export { deployJSONRoom, deployRandomJSONRoom, emptyRoom, } from "./features/deployJSONRoom";
4
5
  export { disableAllInputs, disableAllInputsExceptFor, disableMovementInputs, disableShootingInputs, enableAllInputs, enableAllInputsExceptFor, } from "./features/disableInputs";
5
6
  export { forgottenSwitch } from "./features/forgottenSwitch";
package/dist/index.lua CHANGED
@@ -15,6 +15,14 @@ do
15
15
  end
16
16
  end
17
17
  end
18
+ do
19
+ local ____export = require("features.checkFamiliar")
20
+ for ____exportKey, ____exportValue in pairs(____export) do
21
+ if ____exportKey ~= "default" then
22
+ ____exports[____exportKey] = ____exportValue
23
+ end
24
+ end
25
+ end
18
26
  do
19
27
  local ____deployJSONRoom = require("features.deployJSONRoom")
20
28
  local deployJSONRoom = ____deployJSONRoom.deployJSONRoom
@@ -69,6 +69,8 @@ local ____preNewLevel = require("callbacks.preNewLevel")
69
69
  local preNewLevelCallbackInit = ____preNewLevel.preNewLevelCallbackInit
70
70
  local ____reorderedCallbacks = require("callbacks.reorderedCallbacks")
71
71
  local reorderedCallbacksInit = ____reorderedCallbacks.reorderedCallbacksInit
72
+ local ____checkFamiliar = require("features.checkFamiliar")
73
+ local checkFamiliarInit = ____checkFamiliar.checkFamiliarInit
72
74
  local ____deployJSONRoom = require("features.deployJSONRoom")
73
75
  local deployJSONRoomInit = ____deployJSONRoom.deployJSONRoomInit
74
76
  local ____disableInputs = require("features.disableInputs")
@@ -127,6 +129,7 @@ function initCustomCallbacks(self, mod)
127
129
  postGridEntityCollisionInit(nil, mod)
128
130
  end
129
131
  function initFeatures(self, mod)
132
+ checkFamiliarInit(nil, mod)
130
133
  deployJSONRoomInit(nil, mod)
131
134
  disableInputsInit(nil, mod)
132
135
  forgottenSwitchInit(nil, mod)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.35",
3
+ "version": "1.2.38",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",