isaacscript-common 5.1.3 → 6.0.0

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.
package/constants.d.ts CHANGED
@@ -34,9 +34,11 @@ export declare const EMPTY_PNG_PATH = "gfx/none.png";
34
34
  * second TMTRAINER item subtracts one from that, and so on.
35
35
  */
36
36
  export declare const FIRST_GLITCHED_COLLECTIBLE_TYPE: CollectibleType;
37
+ /** Game frames are what is returned by the `Game.GetFrameCount` method. */
37
38
  export declare const GAME_FRAMES_PER_SECOND = 30;
39
+ /** Render frames are what is returned by the `Isaac.GetFrameCount` method. */
40
+ export declare const RENDER_FRAMES_PER_SECOND = 60;
38
41
  export declare const GRID_INDEX_CENTER_OF_1X1_ROOM = 67;
39
- export declare const ISAAC_FRAMES_PER_SECOND = 60;
40
42
  /**
41
43
  * The floor is represented by a 13x13 grid. Room indexes start at 0. The first column is
42
44
  * represented by grid indexes 0, 13, 26, and so on.
package/constants.lua CHANGED
@@ -35,9 +35,11 @@ ____exports.EMPTY_PNG_PATH = "gfx/none.png"
35
35
  -- encountered by the player. The first TMTRAINER item takes the final possible 32 bit number. The
36
36
  -- second TMTRAINER item subtracts one from that, and so on.
37
37
  ____exports.FIRST_GLITCHED_COLLECTIBLE_TYPE = (1 << 32) - 1
38
+ --- Game frames are what is returned by the `Game.GetFrameCount` method.
38
39
  ____exports.GAME_FRAMES_PER_SECOND = 30
40
+ --- Render frames are what is returned by the `Isaac.GetFrameCount` method.
41
+ ____exports.RENDER_FRAMES_PER_SECOND = 60
39
42
  ____exports.GRID_INDEX_CENTER_OF_1X1_ROOM = 67
40
- ____exports.ISAAC_FRAMES_PER_SECOND = 60
41
43
  --- The floor is represented by a 13x13 grid. Room indexes start at 0. The first column is
42
44
  -- represented by grid indexes 0, 13, 26, and so on.
43
45
  ____exports.LEVEL_GRID_COLUMN_HEIGHT = 13
@@ -1,3 +1,22 @@
1
1
  import { Keyboard } from "isaac-typescript-definitions";
2
- export declare function registerHotkey(keyboard: Keyboard, func: () => void): void;
3
- export declare function unregisterHotkey(keyboard: Keyboard): void;
2
+ /**
3
+ * Helper function to run arbitrary code when you press and release a specific keyboard key.
4
+ *
5
+ * This can be used to easily set up custom hotkeys to facilitate custom game features or to assist
6
+ * in debugging.
7
+ *
8
+ * @param keyboardOrFunc Either the key that you want to trigger the hotkey or a function that
9
+ * returns the key that will trigger the hotkey. Normally, you would just
10
+ * specify the key directly, but you can use a function for situations where
11
+ * the key can change (like if end-users can specify a custom hotkey using Mod
12
+ * Config Menu).
13
+ * @param triggerFunc A function containing the arbitrary code that you want to execute when the
14
+ * hotkey is triggered.
15
+ */
16
+ export declare function registerHotkey(keyboardOrFunc: Keyboard | (() => Keyboard | undefined), triggerFunc: () => void): void;
17
+ /**
18
+ * Helper function to remove a hotkey created with the `registerHotkey` function.
19
+ *
20
+ * @param keyboardOrFunc Equal to the value that you passed when initially registering the hotkey.
21
+ */
22
+ export declare function unregisterHotkey(keyboardOrFunc: Keyboard | (() => Keyboard | undefined)): void;
@@ -3,7 +3,7 @@ local Map = ____lualib.Map
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local __TS__Iterator = ____lualib.__TS__Iterator
5
5
  local ____exports = {}
6
- local postRender, hotkeyFunctionMap, keyPressedMap
6
+ local postRender, checkIfTriggered, staticHotkeyFunctionMap, dynamicHotkeyFunctionMap, keyPressedMap
7
7
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
8
8
  local Keyboard = ____isaac_2Dtypescript_2Ddefinitions.Keyboard
9
9
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
@@ -13,38 +13,81 @@ local ____featuresInitialized = require("featuresInitialized")
13
13
  local errorIfFeaturesNotInitialized = ____featuresInitialized.errorIfFeaturesNotInitialized
14
14
  local ____input = require("functions.input")
15
15
  local isKeyboardPressed = ____input.isKeyboardPressed
16
+ local ____types = require("functions.types")
17
+ local isFunction = ____types.isFunction
16
18
  function postRender(self)
17
- for ____, ____value in __TS__Iterator(hotkeyFunctionMap:entries()) do
19
+ for ____, ____value in __TS__Iterator(staticHotkeyFunctionMap:entries()) do
18
20
  local keyboard = ____value[1]
19
- local func = ____value[2]
20
- local isPressed = isKeyboardPressed(nil, keyboard)
21
- local wasPreviouslyPressed = keyPressedMap:getAndSetDefault(keyboard)
22
- keyPressedMap:set(keyboard, isPressed)
23
- if isPressed and not wasPreviouslyPressed then
24
- func(nil)
21
+ local triggerFunc = ____value[2]
22
+ checkIfTriggered(nil, keyboard, triggerFunc)
23
+ end
24
+ for ____, ____value in __TS__Iterator(dynamicHotkeyFunctionMap:entries()) do
25
+ local keyboardFunc = ____value[1]
26
+ local triggerFunc = ____value[2]
27
+ local keyboard = keyboardFunc(nil)
28
+ if keyboard ~= nil then
29
+ checkIfTriggered(nil, keyboard, triggerFunc)
25
30
  end
26
31
  end
27
32
  end
33
+ function checkIfTriggered(self, keyboard, triggerFunc)
34
+ local isPressed = isKeyboardPressed(nil, keyboard)
35
+ local wasPreviouslyPressed = keyPressedMap:getAndSetDefault(keyboard)
36
+ keyPressedMap:set(keyboard, isPressed)
37
+ if isPressed and not wasPreviouslyPressed then
38
+ triggerFunc(nil)
39
+ end
40
+ end
28
41
  local FEATURE_NAME = "registerHotkeys"
29
- hotkeyFunctionMap = __TS__New(Map)
42
+ staticHotkeyFunctionMap = __TS__New(Map)
43
+ dynamicHotkeyFunctionMap = __TS__New(Map)
30
44
  keyPressedMap = __TS__New(DefaultMap, false)
31
45
  ---
32
46
  -- @internal
33
47
  function ____exports.registerHotkeyInit(self, mod)
34
48
  mod:AddCallback(ModCallback.POST_RENDER, postRender)
35
49
  end
36
- function ____exports.registerHotkey(self, keyboard, func)
50
+ --- Helper function to run arbitrary code when you press and release a specific keyboard key.
51
+ --
52
+ -- This can be used to easily set up custom hotkeys to facilitate custom game features or to assist
53
+ -- in debugging.
54
+ --
55
+ -- @param keyboardOrFunc Either the key that you want to trigger the hotkey or a function that
56
+ -- returns the key that will trigger the hotkey. Normally, you would just
57
+ -- specify the key directly, but you can use a function for situations where
58
+ -- the key can change (like if end-users can specify a custom hotkey using Mod
59
+ -- Config Menu).
60
+ -- @param triggerFunc A function containing the arbitrary code that you want to execute when the
61
+ -- hotkey is triggered.
62
+ function ____exports.registerHotkey(self, keyboardOrFunc, triggerFunc)
37
63
  errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
38
- if hotkeyFunctionMap:has(keyboard) then
39
- error(((("Failed to register a hotkey for key Keyboard." .. tostring(Keyboard[keyboard])) .. " (") .. tostring(keyboard)) .. ") due to a custom hotkey already being defined for that key.")
64
+ if isFunction(nil, keyboardOrFunc) then
65
+ if dynamicHotkeyFunctionMap:has(keyboardOrFunc) then
66
+ error("Failed to register a hotkey due to a custom hotkey already being defined for the submitted function.")
67
+ end
68
+ dynamicHotkeyFunctionMap:set(keyboardOrFunc, triggerFunc)
69
+ else
70
+ if staticHotkeyFunctionMap:has(keyboardOrFunc) then
71
+ error(((("Failed to register a hotkey due to a hotkey already being defined for key: Keyboard." .. tostring(Keyboard[keyboardOrFunc])) .. " (") .. tostring(keyboardOrFunc)) .. ")")
72
+ end
73
+ staticHotkeyFunctionMap:set(keyboardOrFunc, triggerFunc)
40
74
  end
41
- hotkeyFunctionMap:set(keyboard, func)
42
75
  end
43
- function ____exports.unregisterHotkey(self, keyboard)
76
+ --- Helper function to remove a hotkey created with the `registerHotkey` function.
77
+ --
78
+ -- @param keyboardOrFunc Equal to the value that you passed when initially registering the hotkey.
79
+ function ____exports.unregisterHotkey(self, keyboardOrFunc)
44
80
  errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
45
- if not hotkeyFunctionMap:has(keyboard) then
46
- error(((("Failed to unregister a hotkey for key Keyboard." .. tostring(Keyboard[keyboard])) .. " (") .. tostring(keyboard)) .. ") due to no function being defined for that key.")
81
+ if isFunction(nil, keyboardOrFunc) then
82
+ if not dynamicHotkeyFunctionMap:has(keyboardOrFunc) then
83
+ error("Failed to unregister a hotkey since there is no existing hotkey defined for the submitted function.")
84
+ end
85
+ dynamicHotkeyFunctionMap:delete(keyboardOrFunc)
86
+ else
87
+ if not staticHotkeyFunctionMap:has(keyboardOrFunc) then
88
+ error(((("Failed to unregister a hotkey since there is no existing hotkey defined for key: Keyboard." .. tostring(Keyboard[keyboardOrFunc])) .. " (") .. tostring(keyboardOrFunc)) .. ")")
89
+ end
90
+ staticHotkeyFunctionMap:delete(keyboardOrFunc)
47
91
  end
48
- hotkeyFunctionMap:delete(keyboard)
49
92
  end
50
93
  return ____exports
package/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export { ConversionHeartSubType, registerCharacterHealthConversion, } from "./fe
13
13
  export { registerCharacterStats } from "./features/characterStats";
14
14
  export { getCollectibleItemPoolType } from "./features/collectibleItemPoolType";
15
15
  export { removeCustomGrid, spawnCustomGrid } from "./features/customGridEntity";
16
+ export * from "./features/customStage/exports";
16
17
  export * from "./features/debugDisplay/exports";
17
18
  export { deployJSONRoom, deployRandomJSONRoom, emptyRoom, } from "./features/deployJSONRoom";
18
19
  export { disableAllSound, enableAllSound } from "./features/disableAllSound";
package/index.lua CHANGED
@@ -107,6 +107,14 @@ do
107
107
  ____exports.removeCustomGrid = removeCustomGrid
108
108
  ____exports.spawnCustomGrid = spawnCustomGrid
109
109
  end
110
+ do
111
+ local ____export = require("features.customStage.exports")
112
+ for ____exportKey, ____exportValue in pairs(____export) do
113
+ if ____exportKey ~= "default" then
114
+ ____exports[____exportKey] = ____exportValue
115
+ end
116
+ end
117
+ end
110
118
  do
111
119
  local ____export = require("features.debugDisplay.exports")
112
120
  for ____exportKey, ____exportValue in pairs(____export) do
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "5.1.3",
3
+ "version": "6.0.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",