isaacscript-common 1.2.190 → 1.2.193

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,19 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Helper function to manage the stats for a vanilla or custom character. Call this function once at
4
+ * the beginning of your mod to declare the starting stats.
5
+ *
6
+ * You must provide this function with a map of CacheFlag to the default stat amount. For example,
7
+ * the default amount of damage is 3.5. To make a custom character start with 4.5 damage:
8
+ *
9
+ * ```ts
10
+ * const fooDefaultStats = new Map<CacheFlag, number>([
11
+ * [CacheFlag.CACHE_DAMAGE, 4.5],
12
+ * ])
13
+ * registerCharacterStats(PlayerTypeCustom.FOO, fooDefaultStats);
14
+ * ```
15
+ *
16
+ * Note that the format for the `CacheFlag.CACHE_FIREDELAY` value should be in the tears stat
17
+ * format, not the `MaxFireDelay` format.
18
+ */
19
+ export declare function registerCharacterStats(playerType: PlayerType | int, statMap: Map<CacheFlag, number>): void;
@@ -0,0 +1,77 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Map = ____lualib.Map
3
+ local __TS__New = ____lualib.__TS__New
4
+ local ____exports = {}
5
+ local evaluateCache, charactersStatMap
6
+ local ____featuresInitialized = require("featuresInitialized")
7
+ local errorIfFeaturesNotInitialized = ____featuresInitialized.errorIfFeaturesNotInitialized
8
+ local ____cacheFlag = require("functions.cacheFlag")
9
+ local getDefaultPlayerStat = ____cacheFlag.getDefaultPlayerStat
10
+ local ____tears = require("functions.tears")
11
+ local addTearsStat = ____tears.addTearsStat
12
+ function evaluateCache(self, player, cacheFlag)
13
+ local character = player:GetPlayerType()
14
+ local statMap = charactersStatMap:get(character)
15
+ if statMap == nil then
16
+ return
17
+ end
18
+ local stat = statMap:get(cacheFlag)
19
+ local defaultStat = getDefaultPlayerStat(nil, cacheFlag)
20
+ if stat == nil or defaultStat == nil then
21
+ return
22
+ end
23
+ local delta = stat - defaultStat
24
+ repeat
25
+ local ____switch6 = cacheFlag
26
+ local ____cond6 = ____switch6 == CacheFlag.CACHE_DAMAGE
27
+ if ____cond6 then
28
+ do
29
+ player.Damage = player.Damage + delta
30
+ return
31
+ end
32
+ end
33
+ ____cond6 = ____cond6 or ____switch6 == CacheFlag.CACHE_FIREDELAY
34
+ if ____cond6 then
35
+ do
36
+ addTearsStat(nil, player, delta)
37
+ return
38
+ end
39
+ end
40
+ ____cond6 = ____cond6 or ____switch6 == CacheFlag.CACHE_SHOTSPEED
41
+ if ____cond6 then
42
+ do
43
+ player.ShotSpeed = player.ShotSpeed + delta
44
+ break
45
+ end
46
+ end
47
+ ____cond6 = ____cond6 or ____switch6 == CacheFlag.CACHE_RANGE
48
+ if ____cond6 then
49
+ do
50
+ player.TearHeight = player.TearHeight + delta
51
+ break
52
+ end
53
+ end
54
+ ____cond6 = ____cond6 or ____switch6 == CacheFlag.CACHE_SPEED
55
+ if ____cond6 then
56
+ do
57
+ player.MoveSpeed = player.MoveSpeed + delta
58
+ break
59
+ end
60
+ end
61
+ do
62
+ do
63
+ break
64
+ end
65
+ end
66
+ until true
67
+ end
68
+ local FEATURE_NAME = "character stat manager"
69
+ charactersStatMap = __TS__New(Map)
70
+ function ____exports.characterStatsInit(self, mod)
71
+ mod:AddCallback(ModCallbacks.MC_EVALUATE_CACHE, evaluateCache)
72
+ end
73
+ function ____exports.registerCharacterStats(self, playerType, statMap)
74
+ errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
75
+ charactersStatMap:set(playerType, statMap)
76
+ end
77
+ return ____exports
@@ -1,7 +1,8 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /**
3
- * Returns the starting stat that Isaac (the default character) starts with.
3
+ * Returns the starting stat that Isaac (the default character) starts with. For example, if you
4
+ * pass this function `CacheFlag.CACHE_DAMAGE`, it will return 3.5.
4
5
  *
5
- * For example, if you pass this function `CacheFlag.CACHE_DAMAGE`, it will return 3.5.
6
+ * Note that the default fire delay is represented in the tear stat, not the `MaxFireDelay` value.
6
7
  */
7
8
  export declare function getDefaultPlayerStat(cacheFlag: CacheFlag): number | undefined;
@@ -46,6 +46,11 @@ export declare function characterCanHaveSoulHearts(character: PlayerType | int):
46
46
  * Otherwise, returns false.
47
47
  */
48
48
  export declare function characterGetsBlackHeartFromEternalHeart(character: PlayerType | int): boolean;
49
+ /**
50
+ * Helper function to find the active slot that the player has the corresponding collectible type
51
+ * in. Returns undefined if the player does not have the collectible in any active slot.
52
+ */
53
+ export declare function getActiveItemSlot(player: EntityPlayer, collectibleType: CollectibleType | int): ActiveSlot | undefined;
49
54
  /**
50
55
  * Helper function to get every player with no restrictions, by using `Game.GetNumPlayers` and
51
56
  * `Isaac.GetPlayer`.
@@ -2,9 +2,9 @@ local ____lualib = require("lualib_bundle")
2
2
  local Set = ____lualib.Set
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local __TS__ArraySome = ____lualib.__TS__ArraySome
5
+ local __TS__ArrayFind = ____lualib.__TS__ArrayFind
5
6
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
6
7
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
7
- local __TS__ArrayFind = ____lualib.__TS__ArrayFind
8
8
  local Map = ____lualib.Map
9
9
  local __TS__Iterator = ____lualib.__TS__Iterator
10
10
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
@@ -39,6 +39,7 @@ local ____collectibleSet = require("functions.collectibleSet")
39
39
  local getCollectibleSet = ____collectibleSet.getCollectibleSet
40
40
  local ____utils = require("functions.utils")
41
41
  local ensureAllCases = ____utils.ensureAllCases
42
+ local getEnumValues = ____utils.getEnumValues
42
43
  local ____repeat = ____utils["repeat"]
43
44
  function ____exports.getAllPlayers(self)
44
45
  local numPlayers = game:GetNumPlayers()
@@ -95,15 +96,15 @@ end
95
96
  function getPlayerIndexCollectibleType(self, player, differentiateForgottenAndSoul)
96
97
  local character = player:GetPlayerType()
97
98
  repeat
98
- local ____switch71 = character
99
- local ____cond71 = ____switch71 == PlayerType.PLAYER_THESOUL
100
- if ____cond71 then
99
+ local ____switch73 = character
100
+ local ____cond73 = ____switch73 == PlayerType.PLAYER_THESOUL
101
+ if ____cond73 then
101
102
  do
102
103
  return differentiateForgottenAndSoul and CollectibleType.COLLECTIBLE_SPOON_BENDER or DEFAULT_COLLECTIBLE_TYPE
103
104
  end
104
105
  end
105
- ____cond71 = ____cond71 or ____switch71 == PlayerType.PLAYER_LAZARUS2_B
106
- if ____cond71 then
106
+ ____cond73 = ____cond73 or ____switch73 == PlayerType.PLAYER_LAZARUS2_B
107
+ if ____cond73 then
107
108
  do
108
109
  return CollectibleType.COLLECTIBLE_INNER_EYE
109
110
  end
@@ -240,6 +241,16 @@ end
240
241
  function ____exports.characterGetsBlackHeartFromEternalHeart(self, character)
241
242
  return CHARACTERS_WITH_BLACK_HEART_FROM_ETERNAL_HEART:has(character)
242
243
  end
244
+ function ____exports.getActiveItemSlot(self, player, collectibleType)
245
+ local activeSlots = getEnumValues(nil, ActiveSlot)
246
+ return __TS__ArrayFind(
247
+ activeSlots,
248
+ function(____, activeSlot)
249
+ local activeItem = player:GetActiveItem(activeSlot)
250
+ return activeItem == collectibleType
251
+ end
252
+ )
253
+ end
243
254
  function ____exports.getAzazelBrimstoneDistance(self, playerOrTearHeight)
244
255
  local tearHeight = tonumber(playerOrTearHeight)
245
256
  if tearHeight == nil then
@@ -563,9 +574,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
563
574
  itemPool:RemoveCollectible(collectibleType)
564
575
  end
565
576
  repeat
566
- local ____switch124 = activeSlot
567
- local ____cond124 = ____switch124 == ActiveSlot.SLOT_PRIMARY
568
- if ____cond124 then
577
+ local ____switch126 = activeSlot
578
+ local ____cond126 = ____switch126 == ActiveSlot.SLOT_PRIMARY
579
+ if ____cond126 then
569
580
  do
570
581
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
571
582
  player:RemoveCollectible(primaryCollectibleType)
@@ -574,8 +585,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
574
585
  break
575
586
  end
576
587
  end
577
- ____cond124 = ____cond124 or ____switch124 == ActiveSlot.SLOT_SECONDARY
578
- if ____cond124 then
588
+ ____cond126 = ____cond126 or ____switch126 == ActiveSlot.SLOT_SECONDARY
589
+ if ____cond126 then
579
590
  do
580
591
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
581
592
  player:RemoveCollectible(primaryCollectibleType)
@@ -590,16 +601,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
590
601
  break
591
602
  end
592
603
  end
593
- ____cond124 = ____cond124 or ____switch124 == ActiveSlot.SLOT_POCKET
594
- if ____cond124 then
604
+ ____cond126 = ____cond126 or ____switch126 == ActiveSlot.SLOT_POCKET
605
+ if ____cond126 then
595
606
  do
596
607
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
597
608
  player:SetActiveCharge(charge, activeSlot)
598
609
  break
599
610
  end
600
611
  end
601
- ____cond124 = ____cond124 or ____switch124 == ActiveSlot.SLOT_POCKET2
602
- if ____cond124 then
612
+ ____cond126 = ____cond126 or ____switch126 == ActiveSlot.SLOT_POCKET2
613
+ if ____cond126 then
603
614
  do
604
615
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
605
616
  break
@@ -36,6 +36,21 @@
36
36
  * ```
37
37
  */
38
38
  export declare const ensureAllCases: (obj: never) => never;
39
+ /**
40
+ * TypeScriptToLua will transpile TypeScript enums to Lua tables that have a double mapping. Thus,
41
+ * when you iterate over them, you will get both the names of the enums and the values of the enums,
42
+ * in a random order. If all you need are the keys of an enum, use this helper function.
43
+ *
44
+ * This function will return the enum keys in a sorted order, which may not necessarily be the same
45
+ * order as which they were declared in.
46
+ *
47
+ * This function will work properly for both number enums and string enums. (Reverse mappings are
48
+ * not created for string enums.)
49
+ *
50
+ * For a more in depth explanation, see:
51
+ * https://isaacscript.github.io/docs/gotchas#iterating-over-enums
52
+ */
53
+ export declare function getEnumKeys<T>(transpiledEnum: T): string[];
39
54
  /**
40
55
  * TypeScriptToLua will transpile TypeScript enums to Lua tables that have a double mapping. Thus,
41
56
  * when you iterate over them, you will get both the names of the enums and the values of the enums,
@@ -6,6 +6,16 @@ local __TS__StringSubstr = ____lualib.__TS__StringSubstr
6
6
  local ____exports = {}
7
7
  local HEX_STRING_LENGTH = 6
8
8
  ____exports.ensureAllCases = function(____, obj) return obj end
9
+ function ____exports.getEnumKeys(self, transpiledEnum)
10
+ local enumKeys = {}
11
+ for key in pairs(transpiledEnum) do
12
+ if type(key) == "string" then
13
+ __TS__ArrayPush(enumKeys, key)
14
+ end
15
+ end
16
+ __TS__ArraySort(enumKeys)
17
+ return enumKeys
18
+ end
9
19
  function ____exports.getEnumValues(self, transpiledEnum)
10
20
  local enumValues = {}
11
21
  for key, value in pairs(transpiledEnum) do
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from "./enums/PillEffectClass";
12
12
  export * from "./enums/PillEffectType";
13
13
  export * from "./enums/PocketItemType";
14
14
  export * from "./enums/SerializationType";
15
+ export * from "./features/characterStats";
15
16
  export { deployJSONRoom, deployRandomJSONRoom, emptyRoom, } from "./features/deployJSONRoom";
16
17
  export { disableAllInputs, disableAllInputsExceptFor, disableMovementInputs, disableShootingInputs, enableAllInputs, enableAllInputsExceptFor, } from "./features/disableInputs";
17
18
  export { disableAllSound, enableAllSound } from "./features/disableSound";
package/dist/index.lua CHANGED
@@ -110,6 +110,14 @@ do
110
110
  end
111
111
  end
112
112
  end
113
+ do
114
+ local ____export = require("features.characterStats")
115
+ for ____exportKey, ____exportValue in pairs(____export) do
116
+ if ____exportKey ~= "default" then
117
+ ____exports[____exportKey] = ____exportValue
118
+ end
119
+ end
120
+ end
113
121
  do
114
122
  local ____deployJSONRoom = require("features.deployJSONRoom")
115
123
  local deployJSONRoom = ____deployJSONRoom.deployJSONRoom
@@ -1,2 +1,3 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /** The default fire delay is represented in the tear stat, not the `MaxFireDelay` value. */
2
3
  export declare const DEFAULT_PLAYER_STAT_MAP: ReadonlyMap<CacheFlag, number>;
@@ -2,12 +2,21 @@ local ____lualib = require("lualib_bundle")
2
2
  local Map = ____lualib.Map
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local ____exports = {}
5
- ____exports.DEFAULT_PLAYER_STAT_MAP = __TS__New(Map, {
6
- {CacheFlag.CACHE_DAMAGE, 3.5},
7
- {CacheFlag.CACHE_FIREDELAY, 10},
8
- {CacheFlag.CACHE_SHOTSPEED, 1},
9
- {CacheFlag.CACHE_RANGE, 6.5},
10
- {CacheFlag.CACHE_SPEED, 1},
11
- {CacheFlag.CACHE_LUCK, 0}
12
- })
5
+ local ____tears = require("functions.tears")
6
+ local getTearsStat = ____tears.getTearsStat
7
+ local DEFAULT_MAX_FIRE_DELAY = 10
8
+ ____exports.DEFAULT_PLAYER_STAT_MAP = __TS__New(
9
+ Map,
10
+ {
11
+ {CacheFlag.CACHE_DAMAGE, 3.5},
12
+ {
13
+ CacheFlag.CACHE_FIREDELAY,
14
+ getTearsStat(nil, DEFAULT_MAX_FIRE_DELAY)
15
+ },
16
+ {CacheFlag.CACHE_SHOTSPEED, 1},
17
+ {CacheFlag.CACHE_RANGE, 6.5},
18
+ {CacheFlag.CACHE_SPEED, 1},
19
+ {CacheFlag.CACHE_LUCK, 0}
20
+ }
21
+ )
13
22
  return ____exports
@@ -78,6 +78,8 @@ local ____roomClearChange = require("callbacks.roomClearChange")
78
78
  local roomClearChangeCallbackInit = ____roomClearChange.roomClearChangeCallbackInit
79
79
  local ____ModUpgraded = require("classes.ModUpgraded")
80
80
  local ModUpgraded = ____ModUpgraded.ModUpgraded
81
+ local ____characterStats = require("features.characterStats")
82
+ local characterStatsInit = ____characterStats.characterStatsInit
81
83
  local ____deployJSONRoom = require("features.deployJSONRoom")
82
84
  local deployJSONRoomInit = ____deployJSONRoom.deployJSONRoomInit
83
85
  local ____disableInputs = require("features.disableInputs")
@@ -163,6 +165,7 @@ function initFeatures(self, mod)
163
165
  taintedLazarusPlayersInit(nil, mod)
164
166
  fastResetInit(nil, mod)
165
167
  fadeInRemoverInit(nil, mod)
168
+ characterStatsInit(nil, mod)
166
169
  end
167
170
  function ____exports.upgradeMod(self, modVanilla, verbose)
168
171
  if verbose == nil then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.190",
3
+ "version": "1.2.193",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,11 +25,11 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "isaac-typescript-definitions": "^1.0.372",
28
+ "isaac-typescript-definitions": "^1.0.373",
29
29
  "isaacscript-lint": "^1.0.93",
30
30
  "isaacscript-tsconfig": "^1.1.8",
31
31
  "typedoc": "^0.22.13",
32
32
  "typescript": "4.6.2",
33
- "typescript-to-lua": "^1.4.1"
33
+ "typescript-to-lua": "^1.4.2"
34
34
  }
35
35
  }