Some work to make hotkeys a 'real thing' on the lua side

This commit is contained in:
2025-04-15 18:59:03 -04:00
parent c0160bdd19
commit 11b509cfdf
3 changed files with 105 additions and 10 deletions

View File

@@ -18,22 +18,34 @@ function engio.move(action, xyz, facing)
tangible.animate(actor, nil, {action=action, xyz=xyz, facing=facing})
end
function cube.getlookat()
return { "Hotkeys", "X", "I Am a Cube" }
function cube.lookhotkeys(keys)
keys:add("X", "Cube Hi", function () dprint("Cube Hi") end)
keys:add("A", "Cube Bye", function () dprint("Cube Bye") end)
end
function sphere.getlookat()
return { "Hotkeys", "X", "I Am a Sphere" }
function sphere.lookhotkeys(keys)
keys:add("X", "Sphere Hi", function () dprint("Sphere Hi") end)
keys:add("A", "Sphere Bye", function () dprint("Sphere Bye") end)
end
function engio.getlookat()
local class = tangible.getclass(tangible.place())
if class ~= nil then
local getlookat = class.getlookat
if getlookat ~= nil then
return getlookat()
end
if class == nil then return end
-- if the class has a function 'lookhotkeys', then the correct
-- look-at widget is 'hotkeys'. We're going to automatically
-- generate the correct response.
if class.lookhotkeys ~= nil then
local keys = hotkeylist.create()
class.lookhotkeys(keys)
setmetatable(keys, nil)
return keys
end
-- otherwise, if the class has a function 'getlookat', use that.
if class.getlookat ~= nil then
return class.getlookat()
end
return ""
end