isaacscript-common 1.2.3 → 1.2.7

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.
@@ -18,7 +18,7 @@ local postPlayerFatalDamageHasSubscriptions = ____postPlayerFatalDamage.postPlay
18
18
  function hasSubscriptions(self)
19
19
  return postPlayerFatalDamageHasSubscriptions(nil)
20
20
  end
21
- function entityTakeDmgPlayer(self, tookDamage, damageAmount, _damageFlags, damageSource, _damageCountdownFrames)
21
+ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damageSource, damageCountdownFrames)
22
22
  if not hasSubscriptions(nil) then
23
23
  return nil
24
24
  end
@@ -46,7 +46,14 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, _damageFlags, damag
46
46
  ) then
47
47
  return nil
48
48
  end
49
- local shouldSustainDeath = postPlayerFatalDamageFire(nil, player)
49
+ local shouldSustainDeath = postPlayerFatalDamageFire(
50
+ nil,
51
+ player,
52
+ damageAmount,
53
+ damageFlags,
54
+ damageSource,
55
+ damageCountdownFrames
56
+ )
50
57
  if shouldSustainDeath ~= nil then
51
58
  return shouldSustainDeath
52
59
  end
@@ -1,4 +1,7 @@
1
1
  /**
2
+ * This is a utility function for users of the `ModCallbacksCustom.POST_NEW_LEVEL_REORDERED` custom
3
+ * callback.
4
+ *
2
5
  * If some specific cases, mods can change the current level during run initialization on the 0th
3
6
  * frame. However, due to how the callback reordering works, the custom PostNewLevel callback will
4
7
  * never fire on the 0th frame. To get around this, call this function before changing levels to
@@ -6,6 +9,9 @@
6
9
  */
7
10
  export declare function forceNewLevelCallback(): void;
8
11
  /**
12
+ * This is a utility function for users of the `ModCallbacksCustom.POST_NEW_ROOM_REORDERED` custom
13
+ * callback.
14
+ *
9
15
  * If some specific cases, mods can change the current room during run initialization on the 0th
10
16
  * frame. However, due to how the callback reordering works, the custom PostNewRoom callback will
11
17
  * never fire on the 0th frame. To get around this, call this function before changing rooms to
@@ -1,2 +1,2 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
- export declare type PostPlayerFatalDamageCallbackType = (player: EntityPlayer) => boolean | void;
2
+ export declare type PostPlayerFatalDamageCallbackType = (player: EntityPlayer, damageAmount: float, damageFlags: int, damageSource: EntityRef, damageCountdownFrames: int) => boolean | void;
@@ -9,7 +9,7 @@ end
9
9
  function ____exports.postPlayerFatalDamageRegister(self, callback, playerVariant)
10
10
  __TS__ArrayPush(subscriptions, {callback, playerVariant})
11
11
  end
12
- function ____exports.postPlayerFatalDamageFire(self, player)
12
+ function ____exports.postPlayerFatalDamageFire(self, player, damageAmount, damageFlags, damageSource, damageCountdownFrames)
13
13
  for ____, ____value in ipairs(subscriptions) do
14
14
  local callback = ____value[1]
15
15
  local playerVariant = ____value[2]
@@ -17,7 +17,14 @@ function ____exports.postPlayerFatalDamageFire(self, player)
17
17
  if playerVariant ~= nil and playerVariant ~= player.Variant then
18
18
  goto __continue5
19
19
  end
20
- local shouldSustainDeath = callback(nil, player)
20
+ local shouldSustainDeath = callback(
21
+ nil,
22
+ player,
23
+ damageAmount,
24
+ damageFlags,
25
+ damageSource,
26
+ damageCountdownFrames
27
+ )
21
28
  if shouldSustainDeath ~= nil then
22
29
  return shouldSustainDeath
23
30
  end
@@ -102,10 +102,14 @@ export declare const MAX_PLAYER_TRINKET_SLOTS = 2;
102
102
  export declare const MAX_ROOM_INDEX = 168;
103
103
  export declare const MAX_VANILLA_CHARACTER = PlayerType.PLAYER_THESOUL_B;
104
104
  export declare const MAX_VANILLA_COLLECTIBLE_TYPE = CollectibleType.COLLECTIBLE_MOMS_RING;
105
- export declare const MOVEMENT_ACTIONS: Set<ButtonAction>;
105
+ export declare const SECOND_IN_MILLISECONDS = 1000;
106
+ export declare const MINUTE_IN_MILLISECONDS: number;
107
+ export declare const MOVEMENT_ACTIONS: ButtonAction[];
108
+ export declare const MOVEMENT_ACTIONS_SET: Set<ButtonAction>;
106
109
  export declare const ONE_BY_ONE_ROOM_GRID_SIZE = 135;
107
110
  export declare const SINGLE_USE_ACTIVE_COLLECTIBLE_TYPES: Set<CollectibleType>;
108
- export declare const SHOOTING_ACTIONS: Set<ButtonAction>;
111
+ export declare const SHOOTING_ACTIONS: ButtonAction[];
112
+ export declare const SHOOTING_ACTIONS_SET: Set<ButtonAction>;
109
113
  export declare const STORY_BOSSES: Set<EntityType>;
110
114
  /**
111
115
  * This is the number of draw coordinates that each heart spans on the UI in the upper left hand
@@ -88,7 +88,10 @@ ____exports.MAX_PLAYER_TRINKET_SLOTS = 2
88
88
  ____exports.MAX_ROOM_INDEX = 168
89
89
  ____exports.MAX_VANILLA_CHARACTER = PlayerType.PLAYER_THESOUL_B
90
90
  ____exports.MAX_VANILLA_COLLECTIBLE_TYPE = CollectibleType.COLLECTIBLE_MOMS_RING
91
- ____exports.MOVEMENT_ACTIONS = __TS__New(Set, {ButtonAction.ACTION_LEFT, ButtonAction.ACTION_RIGHT, ButtonAction.ACTION_UP, ButtonAction.ACTION_DOWN})
91
+ ____exports.SECOND_IN_MILLISECONDS = 1000
92
+ ____exports.MINUTE_IN_MILLISECONDS = 60 * ____exports.SECOND_IN_MILLISECONDS
93
+ ____exports.MOVEMENT_ACTIONS = {ButtonAction.ACTION_LEFT, ButtonAction.ACTION_RIGHT, ButtonAction.ACTION_UP, ButtonAction.ACTION_DOWN}
94
+ ____exports.MOVEMENT_ACTIONS_SET = __TS__New(Set, ____exports.MOVEMENT_ACTIONS)
92
95
  ____exports.ONE_BY_ONE_ROOM_GRID_SIZE = 135
93
96
  ____exports.SINGLE_USE_ACTIVE_COLLECTIBLE_TYPES = __TS__New(Set, {
94
97
  CollectibleType.COLLECTIBLE_FORGET_ME_NOW,
@@ -100,7 +103,8 @@ ____exports.SINGLE_USE_ACTIVE_COLLECTIBLE_TYPES = __TS__New(Set, {
100
103
  CollectibleType.COLLECTIBLE_DEATH_CERTIFICATE,
101
104
  CollectibleType.COLLECTIBLE_R_KEY
102
105
  })
103
- ____exports.SHOOTING_ACTIONS = __TS__New(Set, {ButtonAction.ACTION_SHOOTLEFT, ButtonAction.ACTION_SHOOTRIGHT, ButtonAction.ACTION_SHOOTUP, ButtonAction.ACTION_SHOOTDOWN})
106
+ ____exports.SHOOTING_ACTIONS = {ButtonAction.ACTION_SHOOTLEFT, ButtonAction.ACTION_SHOOTRIGHT, ButtonAction.ACTION_SHOOTUP, ButtonAction.ACTION_SHOOTDOWN}
107
+ ____exports.SHOOTING_ACTIONS_SET = __TS__New(Set, ____exports.SHOOTING_ACTIONS)
104
108
  ____exports.STORY_BOSSES = __TS__New(Set, {
105
109
  EntityType.ENTITY_MOM,
106
110
  EntityType.ENTITY_MOMS_HEART,
@@ -4,8 +4,8 @@ local Set = ____lualib.Set
4
4
  local ____exports = {}
5
5
  local isActionPressed, isActionTriggered, getActionValue, getReturnValue, v
6
6
  local ____constants = require("constants")
7
- local MOVEMENT_ACTIONS = ____constants.MOVEMENT_ACTIONS
8
- local SHOOTING_ACTIONS = ____constants.SHOOTING_ACTIONS
7
+ local MOVEMENT_ACTIONS_SET = ____constants.MOVEMENT_ACTIONS_SET
8
+ local SHOOTING_ACTIONS_SET = ____constants.SHOOTING_ACTIONS_SET
9
9
  local ____errors = require("errors")
10
10
  local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
11
11
  local ____exports = require("features.saveDataManager.exports")
@@ -85,9 +85,9 @@ function ____exports.disableAllInputsExceptFor(self, whitelist)
85
85
  v.run.blacklist = nil
86
86
  end
87
87
  function ____exports.disableMovementInputs(self)
88
- ____exports.enableAllInputsExceptFor(nil, MOVEMENT_ACTIONS)
88
+ ____exports.enableAllInputsExceptFor(nil, MOVEMENT_ACTIONS_SET)
89
89
  end
90
90
  function ____exports.disableShootingInputs(self)
91
- ____exports.enableAllInputsExceptFor(nil, SHOOTING_ACTIONS)
91
+ ____exports.enableAllInputsExceptFor(nil, SHOOTING_ACTIONS_SET)
92
92
  end
93
93
  return ____exports
@@ -61,6 +61,15 @@ export declare function arrayRemoveInPlace<T>(array: T[], ...elements: T[]): boo
61
61
  * @param exceptions Optional. An array of elements to skip over if selected.
62
62
  */
63
63
  export declare function getRandomArrayElement<T>(array: T[], seed?: number, exceptions?: T[]): T;
64
+ /**
65
+ * Helper function to get a random element from the provided array. Once the random element is
66
+ * decided, it is then removed from the array (in-place).
67
+ *
68
+ * @param array The array to get an element from.
69
+ * @param seed Optional. The seed used to select the random element. `Random()` by default.
70
+ * @param exceptions Optional. An array of elements to skip over if selected.
71
+ */
72
+ export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?: number, exceptions?: T[]): T;
64
73
  export declare function getRandomArrayIndex<T>(array: T[], seed?: number): int;
65
74
  /**
66
75
  * Since Lua uses tables for every non-primitive data structure, it is non-trivial to determine if a
@@ -145,6 +145,17 @@ function ____exports.getRandomArrayElement(self, array, seed, exceptions)
145
145
  local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions, seed)
146
146
  return arrayWithoutExceptions[randomIndex + 1]
147
147
  end
148
+ function ____exports.getRandomArrayElementAndRemove(self, array, seed, exceptions)
149
+ if seed == nil then
150
+ seed = Random()
151
+ end
152
+ if exceptions == nil then
153
+ exceptions = {}
154
+ end
155
+ local randomArrayElement = ____exports.getRandomArrayElement(nil, array, seed, exceptions)
156
+ ____exports.arrayRemoveInPlace(nil, array, randomArrayElement)
157
+ return randomArrayElement
158
+ end
148
159
  function ____exports.isArray(self, ____table)
149
160
  local metatable = getmetatable(____table)
150
161
  if metatable ~= nil then
@@ -89,6 +89,11 @@ export declare function removeCollectiblePickupDelay(collectible: EntityPickup):
89
89
  * Python program located at: https://github.com/Rchardon/RebirthItemTracker
90
90
  */
91
91
  export declare function removeCollectibleFromItemTracker(collectibleType: CollectibleType | int): void;
92
+ /**
93
+ * Helper function to put a message in the log.txt file to let the Rebirth Item Tracker know that
94
+ * the build has been rerolled.
95
+ */
96
+ export declare function setCollectiblesRerolledForItemTracker(): void;
92
97
  export declare function setCollectibleBlind(collectible: EntityPickup): void;
93
98
  /**
94
99
  * Helper function to remove the collectible from a collectible pedestal and make it appear as if a
@@ -164,6 +164,9 @@ function ____exports.removeCollectibleFromItemTracker(self, collectibleType)
164
164
  local collectibleName = ____exports.getCollectibleName(nil, collectibleType)
165
165
  Isaac.DebugString(((("Removing collectible " .. tostring(collectibleType)) .. " (") .. collectibleName) .. ") on player 0 (Player)")
166
166
  end
167
+ function ____exports.setCollectiblesRerolledForItemTracker(self)
168
+ Isaac.DebugString("Added 3 Collectibles")
169
+ end
167
170
  function ____exports.setCollectibleBlind(self, collectible)
168
171
  if collectible.Variant ~= PickupVariant.PICKUP_COLLECTIBLE then
169
172
  error("You cannot set a collectible to be blind for pickups of variant: " .. tostring(collectible.Variant))
@@ -1,15 +1,16 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
- local Set = ____lualib.Set
4
3
  local __TS__StringReplace = ____lualib.__TS__StringReplace
5
4
  local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
6
- local __TS__Iterator = ____lualib.__TS__Iterator
5
+ local __TS__ArraySome = ____lualib.__TS__ArraySome
7
6
  local __TS__StringSlice = ____lualib.__TS__StringSlice
8
7
  local ____exports = {}
9
8
  local ____constants = require("constants")
10
9
  local MAX_NUM_INPUTS = ____constants.MAX_NUM_INPUTS
11
10
  local MOVEMENT_ACTIONS = ____constants.MOVEMENT_ACTIONS
12
11
  local SHOOTING_ACTIONS = ____constants.SHOOTING_ACTIONS
12
+ local ____math = require("functions.math")
13
+ local range = ____math.range
13
14
  local ControllerLiteral = ControllerLiteral or ({})
14
15
  ControllerLiteral.DPAD_LEFT = 0
15
16
  ControllerLiteral[ControllerLiteral.DPAD_LEFT] = "DPAD_LEFT"
@@ -72,63 +73,45 @@ function ____exports.controllerToString(self, controller)
72
73
  return "unknown"
73
74
  end
74
75
  function ____exports.isActionPressedOnAnyInput(self, buttonAction)
75
- do
76
- local i = 0
77
- while i < MAX_NUM_INPUTS do
78
- if Input.IsActionPressed(buttonAction, i) then
79
- return true
80
- end
81
- i = i + 1
82
- end
83
- end
84
- return false
76
+ local validInputs = range(nil, 0, MAX_NUM_INPUTS - 1)
77
+ return __TS__ArraySome(
78
+ validInputs,
79
+ function(____, input) return Input.IsActionPressed(buttonAction, input) end
80
+ )
85
81
  end
86
82
  function ____exports.isActionTriggeredOnAnyInput(self, buttonAction)
87
- do
88
- local i = 0
89
- while i < MAX_NUM_INPUTS do
90
- if Input.IsActionTriggered(buttonAction, i) then
91
- return true
92
- end
93
- i = i + 1
94
- end
95
- end
96
- return false
83
+ local validInputs = range(nil, 0, MAX_NUM_INPUTS - 1)
84
+ return __TS__ArraySome(
85
+ validInputs,
86
+ function(____, input) return Input.IsActionTriggered(buttonAction, input) end
87
+ )
97
88
  end
98
89
  function ____exports.isKeyboardPressed(self, key)
99
90
  return Input.IsButtonPressed(key, 0)
100
91
  end
101
92
  function ____exports.isMoveActionPressedOnAnyInput(self)
102
- for ____, buttonAction in __TS__Iterator(MOVEMENT_ACTIONS:values()) do
103
- if ____exports.isActionPressedOnAnyInput(nil, buttonAction) then
104
- return true
105
- end
106
- end
107
- return false
93
+ return __TS__ArraySome(
94
+ MOVEMENT_ACTIONS,
95
+ function(____, moveAction) return ____exports.isActionPressedOnAnyInput(nil, moveAction) end
96
+ )
108
97
  end
109
98
  function ____exports.isMoveActionTriggeredOnAnyInput(self)
110
- for ____, buttonAction in __TS__Iterator(MOVEMENT_ACTIONS:values()) do
111
- if ____exports.isActionTriggeredOnAnyInput(nil, buttonAction) then
112
- return true
113
- end
114
- end
115
- return false
99
+ return __TS__ArraySome(
100
+ MOVEMENT_ACTIONS,
101
+ function(____, moveAction) return ____exports.isActionTriggeredOnAnyInput(nil, moveAction) end
102
+ )
116
103
  end
117
104
  function ____exports.isShootActionPressedOnAnyInput(self)
118
- for ____, buttonAction in __TS__Iterator(SHOOTING_ACTIONS:values()) do
119
- if ____exports.isActionPressedOnAnyInput(nil, buttonAction) then
120
- return true
121
- end
122
- end
123
- return false
105
+ return __TS__ArraySome(
106
+ SHOOTING_ACTIONS,
107
+ function(____, shootAction) return ____exports.isActionPressedOnAnyInput(nil, shootAction) end
108
+ )
124
109
  end
125
110
  function ____exports.isShootActionTriggeredOnAnyInput(self)
126
- for ____, buttonAction in __TS__Iterator(SHOOTING_ACTIONS:values()) do
127
- if ____exports.isActionTriggeredOnAnyInput(nil, buttonAction) then
128
- return true
129
- end
130
- end
131
- return false
111
+ return __TS__ArraySome(
112
+ SHOOTING_ACTIONS,
113
+ function(____, shootAction) return ____exports.isActionTriggeredOnAnyInput(nil, shootAction) end
114
+ )
132
115
  end
133
116
  function ____exports.keyboardToString(self, keyboard)
134
117
  for ____, ____value in ipairs(__TS__ObjectEntries(Keyboard)) do
@@ -17,6 +17,8 @@ export declare function isEven(num: int): boolean;
17
17
  export declare function isOdd(num: int): boolean;
18
18
  export declare function lerp(a: number, b: number, pos: float): number;
19
19
  export declare function lerpAngleDegrees(aStart: number, aEnd: number, percent: float): number;
20
+ /** Helper function to return an array with the elements from start to end, inclusive. */
21
+ export declare function range(start: int, end: int): int[];
20
22
  /**
21
23
  * If rounding fails, this function returns 0.
22
24
  * From: http://lua-users.org/wiki/SimpleRound
@@ -87,6 +87,17 @@ end
87
87
  function ____exports.lerpAngleDegrees(self, aStart, aEnd, percent)
88
88
  return aStart + ____exports.getAngleDifference(nil, aStart, aEnd) * percent
89
89
  end
90
+ function ____exports.range(self, start, ____end)
91
+ local array = {}
92
+ do
93
+ local i = start
94
+ while i <= ____end do
95
+ __TS__ArrayPush(array, i)
96
+ i = i + 1
97
+ end
98
+ end
99
+ return array
100
+ end
90
101
  function ____exports.round(self, num, numDecimalPlaces)
91
102
  if numDecimalPlaces == nil then
92
103
  numDecimalPlaces = 0
@@ -1,3 +1,7 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Only used for special room shapes where the top left wall grid index is not equal to
4
+ * `DEFAULT_TOP_LEFT_WALL_GRID_INDEX`.
5
+ */
2
6
  export declare const ROOM_SHAPE_TO_TOP_LEFT_WALL_GRID_INDEX_MAP: Map<RoomShape, number>;
3
7
  export declare const DEFAULT_TOP_LEFT_WALL_GRID_INDEX = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.3",
3
+ "version": "1.2.7",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@zamiell/typescript-to-lua": "^1.4.0",
29
- "isaac-typescript-definitions": "^1.0.334",
29
+ "isaac-typescript-definitions": "^1.0.335",
30
30
  "isaacscript-lint": "^1.0.79",
31
31
  "isaacscript-tsconfig": "^1.1.8",
32
32
  "typedoc": "^0.22.11",