isaacscript-common 5.1.3 → 5.1.4
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/features/registerHotkey.d.ts +21 -2
- package/features/registerHotkey.lua +59 -18
- package/index.d.ts +1 -0
- package/index.lua +8 -0
- package/package.json +1 -1
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
import { Keyboard } from "isaac-typescript-definitions";
|
|
2
|
-
|
|
3
|
-
|
|
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), 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)): 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,
|
|
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,79 @@ 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(
|
|
19
|
+
for ____, ____value in __TS__Iterator(staticHotkeyFunctionMap:entries()) do
|
|
18
20
|
local keyboard = ____value[1]
|
|
19
|
-
local
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
checkIfTriggered(nil, keyboard, triggerFunc)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
function checkIfTriggered(self, keyboard, triggerFunc)
|
|
32
|
+
local isPressed = isKeyboardPressed(nil, keyboard)
|
|
33
|
+
local wasPreviouslyPressed = keyPressedMap:getAndSetDefault(keyboard)
|
|
34
|
+
keyPressedMap:set(keyboard, isPressed)
|
|
35
|
+
if isPressed and not wasPreviouslyPressed then
|
|
36
|
+
triggerFunc(nil)
|
|
26
37
|
end
|
|
27
38
|
end
|
|
28
39
|
local FEATURE_NAME = "registerHotkeys"
|
|
29
|
-
|
|
40
|
+
staticHotkeyFunctionMap = __TS__New(Map)
|
|
41
|
+
dynamicHotkeyFunctionMap = __TS__New(Map)
|
|
30
42
|
keyPressedMap = __TS__New(DefaultMap, false)
|
|
31
43
|
---
|
|
32
44
|
-- @internal
|
|
33
45
|
function ____exports.registerHotkeyInit(self, mod)
|
|
34
46
|
mod:AddCallback(ModCallback.POST_RENDER, postRender)
|
|
35
47
|
end
|
|
36
|
-
function
|
|
48
|
+
--- Helper function to run arbitrary code when you press and release a specific keyboard key.
|
|
49
|
+
--
|
|
50
|
+
-- This can be used to easily set up custom hotkeys to facilitate custom game features or to assist
|
|
51
|
+
-- in debugging.
|
|
52
|
+
--
|
|
53
|
+
-- @param keyboardOrFunc Either the key that you want to trigger the hotkey or a function that
|
|
54
|
+
-- returns the key that will trigger the hotkey. Normally, you would just
|
|
55
|
+
-- specify the key directly, but you can use a function for situations where
|
|
56
|
+
-- the key can change (like if end-users can specify a custom hotkey using Mod
|
|
57
|
+
-- Config Menu).
|
|
58
|
+
-- @param triggerFunc A function containing the arbitrary code that you want to execute when the
|
|
59
|
+
-- hotkey is triggered.
|
|
60
|
+
function ____exports.registerHotkey(self, keyboardOrFunc, triggerFunc)
|
|
37
61
|
errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
|
|
38
|
-
if
|
|
39
|
-
|
|
62
|
+
if isFunction(nil, keyboardOrFunc) then
|
|
63
|
+
if dynamicHotkeyFunctionMap:has(keyboardOrFunc) then
|
|
64
|
+
error("Failed to register a hotkey due to a custom hotkey already being defined for the submitted function.")
|
|
65
|
+
end
|
|
66
|
+
dynamicHotkeyFunctionMap:set(keyboardOrFunc, triggerFunc)
|
|
67
|
+
else
|
|
68
|
+
if staticHotkeyFunctionMap:has(keyboardOrFunc) then
|
|
69
|
+
error(((("Failed to register a hotkey due to a hotkey already being defined for key: Keyboard." .. tostring(Keyboard[keyboardOrFunc])) .. " (") .. tostring(keyboardOrFunc)) .. ")")
|
|
70
|
+
end
|
|
71
|
+
staticHotkeyFunctionMap:set(keyboardOrFunc, triggerFunc)
|
|
40
72
|
end
|
|
41
|
-
hotkeyFunctionMap:set(keyboard, func)
|
|
42
73
|
end
|
|
43
|
-
function
|
|
74
|
+
--- Helper function to remove a hotkey created with the `registerHotkey` function.
|
|
75
|
+
--
|
|
76
|
+
-- @param keyboardOrFunc Equal to the value that you passed when initially registering the hotkey.
|
|
77
|
+
function ____exports.unregisterHotkey(self, keyboardOrFunc)
|
|
44
78
|
errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
|
|
45
|
-
if
|
|
46
|
-
|
|
79
|
+
if isFunction(nil, keyboardOrFunc) then
|
|
80
|
+
if not dynamicHotkeyFunctionMap:has(keyboardOrFunc) then
|
|
81
|
+
error("Failed to unregister a hotkey since there is no existing hotkey defined for the submitted function.")
|
|
82
|
+
end
|
|
83
|
+
dynamicHotkeyFunctionMap:delete(keyboardOrFunc)
|
|
84
|
+
else
|
|
85
|
+
if not staticHotkeyFunctionMap:has(keyboardOrFunc) then
|
|
86
|
+
error(((("Failed to unregister a hotkey since there is no existing hotkey defined for key: Keyboard." .. tostring(Keyboard[keyboardOrFunc])) .. " (") .. tostring(keyboardOrFunc)) .. ")")
|
|
87
|
+
end
|
|
88
|
+
staticHotkeyFunctionMap:delete(keyboardOrFunc)
|
|
47
89
|
end
|
|
48
|
-
hotkeyFunctionMap:delete(keyboard)
|
|
49
90
|
end
|
|
50
91
|
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
|