mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-13 08:58:54 -05:00
@@ -1,18 +1,23 @@
|
||||
local bindKeys = function(t)
|
||||
for i, k in ipairs(t) do
|
||||
local bindFunction
|
||||
local bindKeys = function(t, ignoreWarning)
|
||||
ignoreWarning = ignoreWarning or false
|
||||
for _, k in ipairs(t) do
|
||||
assert(k.Key, 'No key provided')
|
||||
assert(k.Command, 'No command provided for key ' .. k.Key)
|
||||
|
||||
k.Name = k.Name or k.Key
|
||||
k.GuiPath = k.GuiPath or ''
|
||||
|
||||
local currentKey = openspace.getKeyBinding(k.Key)
|
||||
if (next(currentKey) ~= nil) and (not ignoreWarning) then
|
||||
|
||||
openspace.printWarning('New keybind for "' .. k.Key .. '" is added, but a previous keybind already existed. If you want to silence this warning, pass "true", to this call to bindKeys')
|
||||
end
|
||||
|
||||
if k.Local then
|
||||
bindFunction = openspace.bindKeyLocal
|
||||
openspace.bindKeyLocal(k.Key, k.Command, k.Documentation, k.Name, k.GuiPath)
|
||||
else
|
||||
bindFunction = openspace.bindKey
|
||||
openspace.bindKey(k.Key, k.Command, k.Documentation, k.Name, k.GuiPath)
|
||||
end
|
||||
if k.Name == nil then
|
||||
k.Name = k.Key
|
||||
end
|
||||
if k.GuiPath == nil then
|
||||
k.GuiPath = ""
|
||||
end
|
||||
bindFunction(k.Key, k.Command, k.Documentation, k.Name, k.GuiPath)
|
||||
end
|
||||
end
|
||||
asset.export("bindKeys", bindKeys)
|
||||
@@ -21,12 +26,8 @@ local unbindKeys = function(keys)
|
||||
-- We check against k and k.Key to provide compatability
|
||||
-- for both calls with the same table that goes to bindKeys
|
||||
-- as well as the return values from setDeltaTimeKeys
|
||||
for i, k in ipairs(keys) do
|
||||
if k.Key then
|
||||
openspace.clearKey(k.Key)
|
||||
else
|
||||
openspace.clearKey(k)
|
||||
end
|
||||
for _, k in ipairs(keys) do
|
||||
openspace.clearKey(k.Key or k)
|
||||
end
|
||||
end
|
||||
asset.export("unbindKeys", unbindKeys)
|
||||
|
||||
Reference in New Issue
Block a user