isaacscript-common 1.2.190 → 1.2.191

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;
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.191",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",