Files
OpenSpace/data/assets/util/scene_helper.asset
T
2019-06-04 17:11:53 +02:00

69 lines
2.3 KiB
Plaintext

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
openspace.bindKeyLocal(k.Key, k.Command, k.Documentation, k.Name, k.GuiPath)
else
openspace.bindKey(k.Key, k.Command, k.Documentation, k.Name, k.GuiPath)
end
end
end
asset.export("bindKeys", bindKeys)
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 _, k in ipairs(keys) do
openspace.clearKey(k.Key or k)
end
end
asset.export("unbindKeys", unbindKeys)
local deltaTimeKeys = {}
local setDeltaTimeKeys = function(t)
local Keys = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'Shift+1', 'Shift+2', 'Shift+3', 'Shift+4', 'Shift+5', 'Shift+6', 'Shift+7', 'Shift+8', 'Shift+9', 'Shift+0',
'Ctrl+1', 'Ctrl+2', 'Ctrl+3', 'Ctrl+4', 'Ctrl+5', 'Ctrl+6', 'Ctrl+7', 'Ctrl+8', 'Ctrl+9', 'Ctrl+0',
'Alt+1', 'Alt+2', 'Alt+3', 'Alt+4', 'Alt+5', 'Alt+6', 'Alt+7', 'Alt+8', 'Alt+9', 'Alt+0'
}
if #t > #Keys then
openspace.printError("Error settings delta time keys: Too many delta times (" .. #t .. ")")
return
end
unbindKeys(deltaTimeKeys)
result = {}
for i, v in ipairs(t) do
openspace.bindKeyLocal(
Keys[i],
'openspace.time.interpolateDeltaTime(' .. v .. ")",
'Setting the simulation speed to ' .. v .. ' seconds per realtime second',
'Set sim speed ' .. v,
'/Simulation Speed'
)
table.insert(result, Keys[i])
end
deltaTimeKeys = result
return result
end
asset.export("setDeltaTimeKeys", setDeltaTimeKeys)