From 33ca5d3a22f3738f2eb808553d73eacc5675fa70 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 4 Jun 2019 17:11:53 +0200 Subject: [PATCH] Warn if keybinds are defined twice (closes #899) Update Ghoul --- data/assets/util/scene_helper.asset | 37 ++++++++++++++------------- ext/ghoul | 2 +- src/interaction/keybindingmanager.cpp | 5 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/data/assets/util/scene_helper.asset b/data/assets/util/scene_helper.asset index 4144ec2b8e..3bf977dc1b 100644 --- a/data/assets/util/scene_helper.asset +++ b/data/assets/util/scene_helper.asset @@ -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) diff --git a/ext/ghoul b/ext/ghoul index 810483aa96..629a0c09be 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 810483aa965195e72fc127fbc5763912938da42c +Subproject commit 629a0c09be20431077c365f6fa3ae4c21d7c1f85 diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 4b02056f76..595967a244 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -186,7 +186,7 @@ scripting::LuaLibrary KeybindingManager::luaLibrary() { "bindKey", &luascriptfunctions::bindKey, {}, - "string, string [,string]", + "string, string [, string]", "Binds a key by name to a lua string command to execute both locally " "and to broadcast to clients if this is the host of a parallel session. " "The first argument is the key, the second argument is the Lua command " @@ -197,7 +197,7 @@ scripting::LuaLibrary KeybindingManager::luaLibrary() { "bindKeyLocal", &luascriptfunctions::bindKeyLocal, {}, - "string, string [,string]", + "string, string [, string]", "Binds a key by name to a lua string command to execute only locally. " "The first argument is the key, the second argument is the Lua command " "that is to be executed, and the optional third argument is a human " @@ -211,7 +211,6 @@ scripting::LuaLibrary KeybindingManager::luaLibrary() { "Returns a list of information about the keybindings for the provided " "key. Each element in the list is a table describing the 'Command' that " "was bound and whether it was a 'Remote' script or not." - } } };