isaacscript-common 1.2.51 → 1.2.54

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.
@@ -3,7 +3,7 @@ local ____lualib = require("lualib_bundle")
3
3
  local Map = ____lualib.Map
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local ____exports = {}
6
- local hasSubscriptions, postPEffectUpdateReordered, queueEmpty, queueNotEmpty, getPickingUpItemForPlayer, v
6
+ local hasSubscriptions, postPEffectUpdateReordered, queueEmpty, resetPickingUpItem, queueNotEmpty, getPickingUpItemForPlayer, v
7
7
  local ____exports = require("features.saveDataManager.exports")
8
8
  local saveDataManager = ____exports.saveDataManager
9
9
  local ____player = require("functions.player")
@@ -31,20 +31,32 @@ function postPEffectUpdateReordered(self, player)
31
31
  end
32
32
  end
33
33
  function queueEmpty(self, player, pickingUpItem)
34
- if pickingUpItem.id ~= CollectibleType.COLLECTIBLE_NULL then
35
- postItemPickupFire(nil, player, pickingUpItem)
36
- pickingUpItem.id = CollectibleType.COLLECTIBLE_NULL
37
- pickingUpItem.type = ItemType.ITEM_NULL
34
+ if pickingUpItem.subType == CollectibleType.COLLECTIBLE_NULL then
35
+ return
36
+ end
37
+ postItemPickupFire(nil, player, pickingUpItem)
38
+ resetPickingUpItem(nil, pickingUpItem)
39
+ local character = player:GetPlayerType()
40
+ if character == PlayerType.PLAYER_THEFORGOTTEN then
41
+ local theSoul = player:GetSubPlayer()
42
+ if theSoul ~= nil then
43
+ local theSoulPickingUpItem = getPickingUpItemForPlayer(nil, theSoul)
44
+ resetPickingUpItem(nil, theSoulPickingUpItem)
45
+ end
38
46
  end
39
47
  end
48
+ function resetPickingUpItem(self, pickingUpItem)
49
+ pickingUpItem.itemType = ItemType.ITEM_NULL
50
+ pickingUpItem.subType = CollectibleType.COLLECTIBLE_NULL
51
+ end
40
52
  function queueNotEmpty(self, player, pickingUpItem)
41
53
  local queuedItem = player.QueuedItem.Item
42
54
  if queuedItem == nil then
43
55
  return
44
56
  end
45
- if queuedItem.Type ~= pickingUpItem.type or queuedItem.ID ~= pickingUpItem.id then
46
- pickingUpItem.type = queuedItem.Type
47
- pickingUpItem.id = queuedItem.ID
57
+ if queuedItem.Type ~= pickingUpItem.itemType or queuedItem.ID ~= pickingUpItem.subType then
58
+ pickingUpItem.itemType = queuedItem.Type
59
+ pickingUpItem.subType = queuedItem.ID
48
60
  preItemPickupFire(nil, player, pickingUpItem)
49
61
  end
50
62
  end
@@ -52,7 +64,7 @@ function getPickingUpItemForPlayer(self, player)
52
64
  local index = getPlayerIndex(nil, player)
53
65
  local pickingUpItem = v.run.pickingUpItem:get(index)
54
66
  if pickingUpItem == nil then
55
- pickingUpItem = {id = CollectibleType.COLLECTIBLE_NULL, type = ItemType.ITEM_NULL}
67
+ pickingUpItem = {itemType = ItemType.ITEM_NULL, subType = CollectibleType.COLLECTIBLE_NULL}
56
68
  v.run.pickingUpItem:set(index, pickingUpItem)
57
69
  end
58
70
  return pickingUpItem
@@ -15,10 +15,10 @@ function ____exports.postItemPickupFire(self, player, pickingUpItem)
15
15
  local itemType = ____value[2]
16
16
  local itemID = ____value[3]
17
17
  do
18
- if itemType ~= nil and itemType ~= pickingUpItem.type then
18
+ if itemType ~= nil and itemType ~= pickingUpItem.itemType then
19
19
  goto __continue5
20
20
  end
21
- if itemID ~= nil and itemID ~= pickingUpItem.id then
21
+ if itemID ~= nil and itemID ~= pickingUpItem.subType then
22
22
  goto __continue5
23
23
  end
24
24
  callback(nil, player, pickingUpItem)
@@ -15,10 +15,10 @@ function ____exports.preItemPickupFire(self, player, pickingUpItem)
15
15
  local itemType = ____value[2]
16
16
  local itemID = ____value[3]
17
17
  do
18
- if itemType ~= nil and itemType ~= pickingUpItem.type then
18
+ if itemType ~= nil and itemType ~= pickingUpItem.itemType then
19
19
  goto __continue5
20
20
  end
21
- if itemID ~= nil and itemID ~= pickingUpItem.id then
21
+ if itemID ~= nil and itemID ~= pickingUpItem.subType then
22
22
  goto __continue5
23
23
  end
24
24
  callback(nil, player, pickingUpItem)
package/dist/index.d.ts CHANGED
@@ -73,6 +73,7 @@ export * from "./maps/trinketNameMap";
73
73
  export * from "./sets/cards";
74
74
  export * from "./types/AnyEntity";
75
75
  export * from "./types/CallbackParametersCustom";
76
+ export * from "./types/DefaultMap";
76
77
  export * from "./types/HealthType";
77
78
  export * from "./types/JSONDoor";
78
79
  export * from "./types/JSONEntity";
package/dist/index.lua CHANGED
@@ -578,6 +578,14 @@ do
578
578
  end
579
579
  end
580
580
  end
581
+ do
582
+ local ____export = require("types.DefaultMap")
583
+ for ____exportKey, ____exportValue in pairs(____export) do
584
+ if ____exportKey ~= "default" then
585
+ ____exports[____exportKey] = ____exportValue
586
+ end
587
+ end
588
+ end
581
589
  do
582
590
  local ____export = require("types.HealthType")
583
591
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -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
@@ -1,6 +1,7 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  export interface PickingUpItem {
3
3
  /** Needed so that we can distinguish between picking up a collectible and a trinket. */
4
- type: ItemType;
5
- id: int;
4
+ itemType: ItemType;
5
+ /** Equal to either the collectible type or the trinket type. */
6
+ subType: CollectibleType | TrinketType | int;
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.51",
3
+ "version": "1.2.54",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",