Files
integration/luprex/lua/login.lua

87 lines
2.6 KiB
Lua

makeclass("world")
makeclass('login')
makeclass("engio")
makeclass('cube')
makeclass('sphere')
-- This gets called on every login except the admin user.
function login.init()
local player = global.get("nextplayer")
global.set("nextplayer", player + 1)
dprint("login.init initializing player ", player)
actor.player = player
tangible.animinit(actor, {bp="character", plane="earth", xyz={player * 100, 0, 90}})
end
-- This gets called on the admin user. You can call login.init in here if you want.
function world.init()
dprint("world.init")
global.set("nextplayer", 0)
tangible.build{class=cube, plane="earth", xyz={500,-100,0}}
tangible.build{class=sphere, plane="earth", xyz={500,100,0}}
login.init()
end
function engio.move(action, xyz, facing)
-- todo: sanity check the parameters.
dprint("engio.move ", action, " ", xyz[1], " ", xyz[2], " ", xyz[3])
tangible.animate(actor, nil, {action=action, xyz=xyz, facing=facing})
end
function cube.lookhotkeys(keys)
keys:add("Z", "Cube Hi", function () dprint("Doing Cube Hi") end)
keys:add("X", "Cube Bye", function () dprint("Doing Cube Bye") end)
keys:add("C", "Cube Yo", function () dprint("Doing Cube Yo") end)
end
function sphere.lookhotkeys(keys)
keys:add("Z", "Sphere Hi", function () dprint("Doing Sphere Hi") end)
keys:add("X", "Sphere Bye", function () dprint("Doing Sphere Bye") end)
keys:add("C", "Sphere Yo", function () dprint("Doing Sphere Yo") end)
end
function engio.getlookat()
local class = tangible.getclass(place)
-- if the tangible is not of any class, return empty string.
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
-- by default, return the empty string.
return ""
end
function engio.presshotkey(action)
local class = tangible.getclass(place)
-- if the tangible doesn't have a 'lookhotkeys' function, do nothing
if class == nil or class.lookhotkeys == nil then
return
end
local press = hotkeypress.create(action)
class.lookhotkeys(press)
local closure = press.closure
if closure ~= nil then
closure()
end
end