isaacscript-common 7.1.0 → 7.1.1

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 +1 @@
1
- {"version":3,"file":"postPlayerChangeStat.d.ts","sourceRoot":"","sources":["../../src/callbacks/postPlayerChangeStat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAsBrD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAO/D"}
1
+ {"version":3,"file":"postPlayerChangeStat.d.ts","sourceRoot":"","sources":["../../src/callbacks/postPlayerChangeStat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AA+BrD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAO/D"}
@@ -2,7 +2,7 @@ local ____lualib = require("lualib_bundle")
2
2
  local Map = ____lualib.Map
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local ____exports = {}
5
- local hasSubscriptions, postPEffectUpdateReordered, v
5
+ local hasSubscriptions, postPEffectUpdateReordered, statEquals, v
6
6
  local ____DefaultMap = require("classes.DefaultMap")
7
7
  local DefaultMap = ____DefaultMap.DefaultMap
8
8
  local ____enums = require("enums.index")
@@ -12,7 +12,11 @@ local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
12
12
  local ____exports = require("features.saveDataManager.exports")
13
13
  local saveDataManager = ____exports.saveDataManager
14
14
  local ____functions = require("functions.index")
15
+ local colorEquals = ____functions.colorEquals
15
16
  local getPlayerStat = ____functions.getPlayerStat
17
+ local isBitSet128 = ____functions.isBitSet128
18
+ local isBoolean = ____functions.isBoolean
19
+ local isColor = ____functions.isColor
16
20
  local isNumber = ____functions.isNumber
17
21
  local ____enums = require("functions.enums")
18
22
  local getEnumValues = ____enums.getEnumValues
@@ -31,23 +35,48 @@ function postPEffectUpdateReordered(self, player)
31
35
  local playerIndex = getPlayerIndex(nil, player, true)
32
36
  local playerStatMap = v.run.playersStatMap:getAndSetDefault(playerIndex)
33
37
  for ____, statType in ipairs(getEnumValues(nil, StatType)) do
34
- local storedStatValue = playerStatMap:get(statType)
35
- local currentStatValue = getPlayerStat(nil, player, statType)
36
- playerStatMap:set(statType, currentStatValue)
37
- if storedStatValue ~= nil and storedStatValue ~= currentStatValue then
38
- local isNumberStat = isNumber(nil, storedStatValue) and isNumber(nil, currentStatValue)
39
- local difference = isNumberStat and currentStatValue - storedStatValue or 0
40
- postPlayerChangeStatFire(
41
- nil,
42
- player,
43
- statType,
44
- difference,
45
- storedStatValue,
46
- currentStatValue
47
- )
38
+ do
39
+ local storedStatValue = playerStatMap:get(statType)
40
+ local currentStatValue = getPlayerStat(nil, player, statType)
41
+ playerStatMap:set(statType, currentStatValue)
42
+ if storedStatValue == nil then
43
+ goto __continue7
44
+ end
45
+ if not statEquals(nil, storedStatValue, currentStatValue) then
46
+ local isNumberStat = isNumber(nil, storedStatValue) and isNumber(nil, currentStatValue)
47
+ local difference = isNumberStat and currentStatValue - storedStatValue or 0
48
+ postPlayerChangeStatFire(
49
+ nil,
50
+ player,
51
+ statType,
52
+ difference,
53
+ storedStatValue,
54
+ currentStatValue
55
+ )
56
+ end
48
57
  end
58
+ ::__continue7::
49
59
  end
50
60
  end
61
+ function statEquals(self, oldValue, newValue)
62
+ local isNumberStat = isNumber(nil, oldValue) and isNumber(nil, newValue)
63
+ if isNumberStat then
64
+ return oldValue == newValue
65
+ end
66
+ local isBooleanStat = isBoolean(nil, oldValue) and isBoolean(nil, newValue)
67
+ if isBooleanStat then
68
+ return oldValue == newValue
69
+ end
70
+ local isBitSet128Stat = isBitSet128(nil, oldValue) and isBitSet128(nil, newValue)
71
+ if isBitSet128Stat then
72
+ return oldValue == newValue
73
+ end
74
+ local isColorStat = isColor(nil, oldValue) and isColor(nil, newValue)
75
+ if isColorStat then
76
+ return colorEquals(nil, oldValue, newValue)
77
+ end
78
+ error("Failed to determine the type of a stat in the \"POST_PLAYER_CHANGE_STAT\" callback.")
79
+ end
51
80
  v = {run = {playersStatMap = __TS__New(
52
81
  DefaultMap,
53
82
  function() return __TS__New(Map) end
@@ -23,8 +23,6 @@ export declare enum StatType {
23
23
  /** Corresponds to `CacheFlag.FLYING` (1 << 7) and `EntityPlayer.CanFly`. */
24
24
  FLYING = 10,
25
25
  /** Corresponds to `CacheFlag.LUCK` (1 << 10) and `EntityPlayer.Luck`. */
26
- LUCK = 11,
27
- /** Corresponds to `CacheFlag.SIZE` (1 << 11) and `EntityPlayer.SizeMulti`. */
28
- SIZE = 12
26
+ LUCK = 11
29
27
  }
30
28
  //# sourceMappingURL=StatType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StatType.d.ts","sourceRoot":"","sources":["../../src/enums/StatType.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,oBAAY,QAAQ;IAClB,4EAA4E;IAC5E,MAAM,IAAA;IAEN,sFAAsF;IACtF,UAAU,IAAA;IAEV,mFAAmF;IACnF,UAAU,IAAA;IAEV,+EAA+E;IAC/E,WAAW,IAAA;IAEX,8EAA8E;IAC9E,UAAU,IAAA;IAEV,4FAA4F;IAC5F,yBAAyB,IAAA;IAEzB,qFAAqF;IACrF,kBAAkB,IAAA;IAElB,8EAA8E;IAC9E,UAAU,IAAA;IAEV,kFAAkF;IAClF,SAAS,IAAA;IAET,mFAAmF;IACnF,UAAU,IAAA;IAEV,4EAA4E;IAC5E,MAAM,KAAA;IAKN,yEAAyE;IACzE,IAAI,KAAA;IAEJ,8EAA8E;IAC9E,IAAI,KAAA;CAIL"}
1
+ {"version":3,"file":"StatType.d.ts","sourceRoot":"","sources":["../../src/enums/StatType.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,oBAAY,QAAQ;IAClB,4EAA4E;IAC5E,MAAM,IAAA;IAEN,sFAAsF;IACtF,UAAU,IAAA;IAEV,mFAAmF;IACnF,UAAU,IAAA;IAEV,+EAA+E;IAC/E,WAAW,IAAA;IAEX,8EAA8E;IAC9E,UAAU,IAAA;IAEV,4FAA4F;IAC5F,yBAAyB,IAAA;IAEzB,qFAAqF;IACrF,kBAAkB,IAAA;IAElB,8EAA8E;IAC9E,UAAU,IAAA;IAEV,kFAAkF;IAClF,SAAS,IAAA;IAET,mFAAmF;IACnF,UAAU,IAAA;IAEV,4EAA4E;IAC5E,MAAM,KAAA;IAKN,yEAAyE;IACzE,IAAI,KAAA;CAOL"}
@@ -25,6 +25,4 @@ ____exports.StatType.FLYING = 10
25
25
  ____exports.StatType[____exports.StatType.FLYING] = "FLYING"
26
26
  ____exports.StatType.LUCK = 11
27
27
  ____exports.StatType[____exports.StatType.LUCK] = "LUCK"
28
- ____exports.StatType.SIZE = 12
29
- ____exports.StatType[____exports.StatType.SIZE] = "SIZE"
30
28
  return ____exports
@@ -1 +1 @@
1
- {"version":3,"file":"playerStats.d.ts","sourceRoot":"","sources":["../../src/functions/playerStats.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,CAAC,SAAS,QAAQ,EAC9C,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,CAAC,GACV,YAAY,CAAC,CAAC,CAAC,CAkBjB"}
1
+ {"version":3,"file":"playerStats.d.ts","sourceRoot":"","sources":["../../src/functions/playerStats.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,CAAC,SAAS,QAAQ,EAC9C,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,CAAC,GACV,YAAY,CAAC,CAAC,CAAC,CAiBjB"}
@@ -15,8 +15,7 @@ function ____exports.getPlayerStat(self, player, statType)
15
15
  [StatType.TEAR_FLAG] = player.TearFlags,
16
16
  [StatType.TEAR_COLOR] = player.TearColor,
17
17
  [StatType.FLYING] = player.CanFly,
18
- [StatType.LUCK] = player.Luck,
19
- [StatType.SIZE] = player.SizeMulti
18
+ [StatType.LUCK] = player.Luck
20
19
  })[statType]
21
20
  end
22
21
  return ____exports
@@ -13,6 +13,5 @@ export interface StatTypeType {
13
13
  [StatType.TEAR_COLOR]: Color;
14
14
  [StatType.FLYING]: boolean;
15
15
  [StatType.LUCK]: float;
16
- [StatType.SIZE]: Vector;
17
16
  }
18
17
  //# sourceMappingURL=StatTypeType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StatTypeType.d.ts","sourceRoot":"","sources":["../../src/interfaces/StatTypeType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;IACzB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;IAC9B,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,KAAK,CAAC;IAC5C,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC;IACrC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC3B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IACvB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACzB"}
1
+ {"version":3,"file":"StatTypeType.d.ts","sourceRoot":"","sources":["../../src/interfaces/StatTypeType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;IACzB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;IAC9B,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,KAAK,CAAC;IAC5C,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC;IACrC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC3B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;CACxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "7.1.0",
3
+ "version": "7.1.1",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -4,7 +4,14 @@ import { ModUpgraded } from "../classes/ModUpgraded";
4
4
  import { StatType } from "../enums";
5
5
  import { ModCallbackCustom } from "../enums/ModCallbackCustom";
6
6
  import { saveDataManager } from "../features/saveDataManager/exports";
7
- import { getPlayerStat, isNumber } from "../functions";
7
+ import {
8
+ colorEquals,
9
+ getPlayerStat,
10
+ isBitSet128,
11
+ isBoolean,
12
+ isColor,
13
+ isNumber,
14
+ } from "../functions";
8
15
  import { getEnumValues } from "../functions/enums";
9
16
  import { getPlayerIndex } from "../functions/playerIndex";
10
17
  import { PlayerIndex } from "../types/PlayerIndex";
@@ -13,11 +20,13 @@ import {
13
20
  postPlayerChangeStatHasSubscriptions,
14
21
  } from "./subscriptions/postPlayerChangeStat";
15
22
 
23
+ type PossibleStatType = number | boolean | BitFlags<TearFlag> | Color;
24
+
16
25
  const v = {
17
26
  run: {
18
27
  playersStatMap: new DefaultMap<
19
28
  PlayerIndex,
20
- Map<StatType, number | boolean | BitFlags<TearFlag> | Color | Vector>
29
+ Map<StatType, PossibleStatType>
21
30
  >(() => new Map()),
22
31
  },
23
32
  };
@@ -52,7 +61,11 @@ function postPEffectUpdateReordered(player: EntityPlayer) {
52
61
  const currentStatValue = getPlayerStat(player, statType);
53
62
  playerStatMap.set(statType, currentStatValue);
54
63
 
55
- if (storedStatValue !== undefined && storedStatValue !== currentStatValue) {
64
+ if (storedStatValue === undefined) {
65
+ continue;
66
+ }
67
+
68
+ if (!statEquals(storedStatValue, currentStatValue)) {
56
69
  const isNumberStat =
57
70
  isNumber(storedStatValue) && isNumber(currentStatValue);
58
71
  const difference = isNumberStat ? currentStatValue - storedStatValue : 0;
@@ -66,3 +79,32 @@ function postPEffectUpdateReordered(player: EntityPlayer) {
66
79
  }
67
80
  }
68
81
  }
82
+
83
+ function statEquals(
84
+ oldValue: PossibleStatType,
85
+ newValue: PossibleStatType,
86
+ ): boolean {
87
+ const isNumberStat = isNumber(oldValue) && isNumber(newValue);
88
+ if (isNumberStat) {
89
+ return oldValue === newValue;
90
+ }
91
+
92
+ const isBooleanStat = isBoolean(oldValue) && isBoolean(newValue);
93
+ if (isBooleanStat) {
94
+ return oldValue === newValue;
95
+ }
96
+
97
+ const isBitSet128Stat = isBitSet128(oldValue) && isBitSet128(newValue);
98
+ if (isBitSet128Stat) {
99
+ return oldValue === newValue; // The class has the "__eq" meta-method.
100
+ }
101
+
102
+ const isColorStat = isColor(oldValue) && isColor(newValue);
103
+ if (isColorStat) {
104
+ return colorEquals(oldValue, newValue);
105
+ }
106
+
107
+ error(
108
+ 'Failed to determine the type of a stat in the "POST_PLAYER_CHANGE_STAT" callback.',
109
+ );
110
+ }
@@ -33,15 +33,15 @@ export enum StatType {
33
33
  /** Corresponds to `CacheFlag.FLYING` (1 << 7) and `EntityPlayer.CanFly`. */
34
34
  FLYING,
35
35
 
36
- // `CacheFlag.WEAPON` (1 << 8) does not have a corresponding `EntityPlayer` field.
37
- // `CacheFlag.FAMILIARS` (1 << 9) does not have a corresponding `EntityPlayer` field.
36
+ // - `CacheFlag.WEAPON` (1 << 8) does not have a corresponding `EntityPlayer` field.
37
+ // - `CacheFlag.FAMILIARS` (1 << 9) does not have a corresponding `EntityPlayer` field.
38
38
 
39
39
  /** Corresponds to `CacheFlag.LUCK` (1 << 10) and `EntityPlayer.Luck`. */
40
40
  LUCK,
41
41
 
42
- /** Corresponds to `CacheFlag.SIZE` (1 << 11) and `EntityPlayer.SizeMulti`. */
43
- SIZE,
44
-
45
- // `CacheFlag.COLOR` (1 << 12) does not have a corresponding `EntityPlayer` field.
46
- // `CacheFlag.PICKUP_VISION` (1 << 13) does not have a corresponding `EntityPlayer` field.
42
+ // - `CacheFlag.SIZE` (1 << 12) does not have a corresponding `EntityPlayer` field. (After picking
43
+ // up Magic Mushroom, the values of `EntityPlayer.Size` and `EntityPlayer.SizeMulti` do not
44
+ // change.)
45
+ // - `CacheFlag.COLOR` (1 << 12) does not have a corresponding `EntityPlayer` field.
46
+ // - `CacheFlag.PICKUP_VISION` (1 << 13) does not have a corresponding `EntityPlayer` field.
47
47
  }
@@ -21,6 +21,5 @@ export function getPlayerStat<T extends StatType>(
21
21
  [StatType.TEAR_COLOR]: player.TearColor, // 1 << 6
22
22
  [StatType.FLYING]: player.CanFly, // 1 << 7
23
23
  [StatType.LUCK]: player.Luck, // 1 << 10
24
- [StatType.SIZE]: player.SizeMulti, // 1 << 11
25
24
  }[statType];
26
25
  }
@@ -14,5 +14,4 @@ export interface StatTypeType {
14
14
  [StatType.TEAR_COLOR]: Color;
15
15
  [StatType.FLYING]: boolean;
16
16
  [StatType.LUCK]: float;
17
- [StatType.SIZE]: Vector;
18
17
  }