Require cb_ prefix for plans

This commit is contained in:
2021-12-28 14:07:15 -05:00
parent 2e543984e6
commit 3b9dc2c495
4 changed files with 20 additions and 21 deletions

View File

@@ -58,6 +58,9 @@ LuaDefine(gui_menu_item, "action,label", "add a menu item to the current gui") {
LuaStack LS(L, laction, llabel);
std::string action = LS.ckstring(laction);
std::string label = LS.ckstring(llabel);
if (!util::has_prefix(action, "cb_")) {
luaL_error(L, "menuitem callbacks must start with cb_");
}
gui->menu_item(action, label);
return LS.result();
}

View File

@@ -529,6 +529,11 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
return;
}
// Make sure the action starts with "cb_"
if (!util::has_prefix(action, "cb_")) {
return;
}
// Get the actor and place. Make sure both exist.
Tangible *tactor = tangible_get(actor_id);
Tangible *tplace = tangible_get(place_id);

View File

@@ -1,15 +1,15 @@
makeclass('login')
function login.interface(actor, place)
gui.menu_item("becomeplayer", "Become a Player")
gui.menu_item("p123", "Print 1, 2, 3")
gui.menu_item("cb_becomeplayer", "Become a Player")
gui.menu_item("cb_p123", "Print 1, 2, 3")
end
function login.becomeplayer(actor, place, dialog)
function login.cb_becomeplayer(actor, place, dialog)
tangible.setclass(actor, player)
end
function login.p123(actor, place, dialog)
function login.cb_p123(actor, place, dialog)
print(1)
wait(1)
print(2)

View File

@@ -5,10 +5,10 @@ function player.interface(actor, place)
-- print("place=", place)
-- print("t.actor=", tangible.actor())
-- print("t.place=", tangible.place())
gui.menu_item("north", "Go North")
gui.menu_item("south", "Go South")
gui.menu_item("east", "Go East")
gui.menu_item("west", "Go West")
gui.menu_item("cb_north", "Go North")
gui.menu_item("cb_south", "Go South")
gui.menu_item("cb_east", "Go East")
gui.menu_item("cb_west", "Go West")
end
function player:printanimstate()
@@ -16,36 +16,27 @@ function player:printanimstate()
print("Resulting state: ", graphic, plane, x, y, z, facing)
end
function player.north(actor, place, dialog)
function player.cb_north(actor, place, dialog)
print("Moving north")
tangible.animate(place, {action="walk", dy=1})
actor:printanimstate()
end
function player.south(actor, place, dialog)
function player.cb_south(actor, place, dialog)
print("Moving south")
tangible.animate(place, {action="walk", dy=-1})
actor:printanimstate()
end
function player.east(actor, place, dialog)
function player.cb_east(actor, place, dialog)
print("Moving east")
tangible.animate(place, {action="walk", dx=1})
actor:printanimstate()
end
function player.west(actor, place, dialog)
function player.cb_west(actor, place, dialog)
print("Moving west")
tangible.animate(place, {action="walk", dx=-1})
actor:printanimstate()
-- print("actor=", actor)
-- print("place=", place)
-- print("t.actor=", tangible.actor())
-- print("t.place=", tangible.place())
-- wait(1)
-- print("actor=", actor)
-- print("place=", place)
-- print("t.actor=", tangible.actor())
-- print("t.place=", tangible.place())
end