isaacscript-common 1.2.49 → 1.2.52

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.
@@ -34,8 +34,8 @@ function setDamageFrame(self, tookDamage, damageFlags)
34
34
  local playerIndex = getPlayerIndex(nil, player)
35
35
  local trackingArray = v.run.damageFrameMap:get(playerIndex)
36
36
  if trackingArray ~= nil then
37
- local lastDamageFrame, callbackActivatedOnThisFrame = table.unpack(trackingArray)
38
- if lastDamageFrame == gameFrameCount and callbackActivatedOnThisFrame then
37
+ local lastDamageFrame, callbackFiredOnThisFrame = table.unpack(trackingArray)
38
+ if lastDamageFrame == gameFrameCount and callbackFiredOnThisFrame then
39
39
  return
40
40
  end
41
41
  end
@@ -26,14 +26,16 @@ function postPEffectUpdateReordered(self, player)
26
26
  return
27
27
  end
28
28
  local playerIndex = getPlayerIndex(nil, player)
29
- local storedHealth = v.run.healthMap:get(playerIndex)
30
- if storedHealth == nil then
31
- storedHealth = __TS__New(Map)
29
+ local playerHealthMap = v.run.playersHealthMap:get(playerIndex)
30
+ if playerHealthMap == nil then
31
+ playerHealthMap = __TS__New(Map)
32
+ v.run.playersHealthMap:set(playerIndex, playerHealthMap)
32
33
  end
33
34
  local healthTypes = getEnumValues(nil, HealthType)
34
35
  for ____, healthType in ipairs(healthTypes) do
35
- local storedHealthValue = storedHealth:get(healthType)
36
+ local storedHealthValue = playerHealthMap:get(healthType)
36
37
  local currentHealthValue = getCurrentHealthValue(nil, player, healthType)
38
+ playerHealthMap:set(healthType, currentHealthValue)
37
39
  if storedHealthValue ~= nil and storedHealthValue ~= currentHealthValue then
38
40
  local amount = currentHealthValue - storedHealthValue
39
41
  postPlayerChangeHealthFire(nil, player, healthType, amount)
@@ -98,7 +100,7 @@ function getCurrentHealthValue(self, player, healthType)
98
100
  end
99
101
  until true
100
102
  end
101
- v = {run = {healthMap = __TS__New(Map)}}
103
+ v = {run = {playersHealthMap = __TS__New(Map)}}
102
104
  function ____exports.postPlayerChangeHealthCallbackInit(self, mod)
103
105
  saveDataManager(nil, "postPlayerChangeHealth", v, hasSubscriptions)
104
106
  mod:AddCallbackCustom(ModCallbacksCustom.MC_POST_PEFFECT_UPDATE_REORDERED, postPEffectUpdateReordered)
@@ -0,0 +1,26 @@
1
+ declare type FirstArg<K, V> = Iterable<[K, V]> | V | ((k: K) => V);
2
+ declare type SecondArg<K, V> = V | ((k: K) => V);
3
+ /**
4
+ * An extended Map with a new method of `getAndSetDefault`.
5
+ *
6
+ * When instantiating the object, you must specify either a default value or a function that returns
7
+ * a default value.
8
+ *
9
+ * Example:
10
+ * ```ts
11
+ * const defaultMap1 = new DefaultMap<string, string>("foo");
12
+ * const defaultMap2 = new DefaultMap<string, string>(["a", "b", "c"], "bar");
13
+ * ```
14
+ */
15
+ export declare class DefaultMap<K, V> extends Map<K, V> {
16
+ private defaultValue;
17
+ private defaultValueFactory;
18
+ constructor(iterableOrDefaultValueOrDefaultValueFactory: FirstArg<K, V>, defaultValueOrDefaultValueFactory?: SecondArg<K, V>);
19
+ /**
20
+ * Almost the same as `Map.prototype.get`. However, if the key does not exist in the map, then
21
+ * this method will set the default value for the key and return the default value.
22
+ */
23
+ getAndSetDefault(key: K): V | undefined;
24
+ getDefaultValue(key: K): V;
25
+ }
26
+ export {};
@@ -0,0 +1,67 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____lualib = require("lualib_bundle")
3
+ local __TS__Class = ____lualib.__TS__Class
4
+ local Map = ____lualib.Map
5
+ local __TS__ClassExtends = ____lualib.__TS__ClassExtends
6
+ local ____exports = {}
7
+ local parseArguments, parseArgumentsOne, parseArgumentsTwo, parseDefaultValueOrDefaultValueFactory
8
+ function parseArguments(self, firstArg, secondArg)
9
+ return secondArg == nil and parseArgumentsOne(nil, firstArg) or parseArgumentsTwo(nil, firstArg, secondArg)
10
+ end
11
+ function parseArgumentsOne(self, firstArg)
12
+ local defaultValue, defaultValueFactory = table.unpack(parseDefaultValueOrDefaultValueFactory(nil, firstArg))
13
+ return {nil, defaultValue, defaultValueFactory}
14
+ end
15
+ function parseArgumentsTwo(self, firstArg, secondArg)
16
+ local firstArgType = type(firstArg)
17
+ if firstArgType ~= "table" then
18
+ error("A DefaultMap constructor with two arguments must have the first argument be an array.")
19
+ end
20
+ local defaultValue, defaultValueFactory = table.unpack(parseDefaultValueOrDefaultValueFactory(nil, secondArg))
21
+ return {firstArg, defaultValue, defaultValueFactory}
22
+ end
23
+ function parseDefaultValueOrDefaultValueFactory(self, arg)
24
+ local argType = type(arg)
25
+ if argType == "function" then
26
+ return {nil, arg}
27
+ end
28
+ if argType == "boolean" or argType == "number" or argType == "string" then
29
+ return {arg, nil}
30
+ end
31
+ return error("A DefaultMap must be initialized with a default value that is either a primitive or a function that returns a default value.")
32
+ end
33
+ ____exports.DefaultMap = __TS__Class()
34
+ local DefaultMap = ____exports.DefaultMap
35
+ DefaultMap.name = "DefaultMap"
36
+ __TS__ClassExtends(DefaultMap, Map)
37
+ function DefaultMap.prototype.____constructor(self, iterableOrDefaultValueOrDefaultValueFactory, defaultValueOrDefaultValueFactory)
38
+ local iterable, defaultValue, defaultValueFactory = table.unpack(parseArguments(nil, iterableOrDefaultValueOrDefaultValueFactory, defaultValueOrDefaultValueFactory))
39
+ if defaultValue == nil and defaultValueFactory == nil then
40
+ error("A DefaultMap must be instantiated with either a default value or a function that returns a default value.")
41
+ end
42
+ if iterable == nil then
43
+ Map.prototype.____constructor(self)
44
+ else
45
+ Map.prototype.____constructor(self, iterable)
46
+ end
47
+ self.defaultValue = defaultValue
48
+ self.defaultValueFactory = defaultValueFactory
49
+ end
50
+ function DefaultMap.prototype.getAndSetDefault(self, key)
51
+ if self:has(key) then
52
+ return self:get(key)
53
+ end
54
+ local defaultValue = self:getDefaultValue(key)
55
+ self:set(key, defaultValue)
56
+ return defaultValue
57
+ end
58
+ function DefaultMap.prototype.getDefaultValue(self, key)
59
+ if self.defaultValue ~= nil then
60
+ return self.defaultValue
61
+ end
62
+ if self.defaultValueFactory ~= nil then
63
+ return self:defaultValueFactory(key)
64
+ end
65
+ return error("A DefaultMap was incorrectly instantiated.")
66
+ end
67
+ return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.49",
3
+ "version": "1.2.52",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",