Require cb_ prefix for plans
This commit is contained in:
@@ -58,6 +58,9 @@ LuaDefine(gui_menu_item, "action,label", "add a menu item to the current gui") {
|
|||||||
LuaStack LS(L, laction, llabel);
|
LuaStack LS(L, laction, llabel);
|
||||||
std::string action = LS.ckstring(laction);
|
std::string action = LS.ckstring(laction);
|
||||||
std::string label = LS.ckstring(llabel);
|
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);
|
gui->menu_item(action, label);
|
||||||
return LS.result();
|
return LS.result();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -529,6 +529,11 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the action starts with "cb_"
|
||||||
|
if (!util::has_prefix(action, "cb_")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the actor and place. Make sure both exist.
|
// Get the actor and place. Make sure both exist.
|
||||||
Tangible *tactor = tangible_get(actor_id);
|
Tangible *tactor = tangible_get(actor_id);
|
||||||
Tangible *tplace = tangible_get(place_id);
|
Tangible *tplace = tangible_get(place_id);
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
makeclass('login')
|
makeclass('login')
|
||||||
|
|
||||||
function login.interface(actor, place)
|
function login.interface(actor, place)
|
||||||
gui.menu_item("becomeplayer", "Become a Player")
|
gui.menu_item("cb_becomeplayer", "Become a Player")
|
||||||
gui.menu_item("p123", "Print 1, 2, 3")
|
gui.menu_item("cb_p123", "Print 1, 2, 3")
|
||||||
end
|
end
|
||||||
|
|
||||||
function login.becomeplayer(actor, place, dialog)
|
function login.cb_becomeplayer(actor, place, dialog)
|
||||||
tangible.setclass(actor, player)
|
tangible.setclass(actor, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
function login.p123(actor, place, dialog)
|
function login.cb_p123(actor, place, dialog)
|
||||||
print(1)
|
print(1)
|
||||||
wait(1)
|
wait(1)
|
||||||
print(2)
|
print(2)
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ function player.interface(actor, place)
|
|||||||
-- print("place=", place)
|
-- print("place=", place)
|
||||||
-- print("t.actor=", tangible.actor())
|
-- print("t.actor=", tangible.actor())
|
||||||
-- print("t.place=", tangible.place())
|
-- print("t.place=", tangible.place())
|
||||||
gui.menu_item("north", "Go North")
|
gui.menu_item("cb_north", "Go North")
|
||||||
gui.menu_item("south", "Go South")
|
gui.menu_item("cb_south", "Go South")
|
||||||
gui.menu_item("east", "Go East")
|
gui.menu_item("cb_east", "Go East")
|
||||||
gui.menu_item("west", "Go West")
|
gui.menu_item("cb_west", "Go West")
|
||||||
end
|
end
|
||||||
|
|
||||||
function player:printanimstate()
|
function player:printanimstate()
|
||||||
@@ -16,36 +16,27 @@ function player:printanimstate()
|
|||||||
print("Resulting state: ", graphic, plane, x, y, z, facing)
|
print("Resulting state: ", graphic, plane, x, y, z, facing)
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.north(actor, place, dialog)
|
function player.cb_north(actor, place, dialog)
|
||||||
print("Moving north")
|
print("Moving north")
|
||||||
tangible.animate(place, {action="walk", dy=1})
|
tangible.animate(place, {action="walk", dy=1})
|
||||||
actor:printanimstate()
|
actor:printanimstate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.south(actor, place, dialog)
|
function player.cb_south(actor, place, dialog)
|
||||||
print("Moving south")
|
print("Moving south")
|
||||||
tangible.animate(place, {action="walk", dy=-1})
|
tangible.animate(place, {action="walk", dy=-1})
|
||||||
actor:printanimstate()
|
actor:printanimstate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.east(actor, place, dialog)
|
function player.cb_east(actor, place, dialog)
|
||||||
print("Moving east")
|
print("Moving east")
|
||||||
tangible.animate(place, {action="walk", dx=1})
|
tangible.animate(place, {action="walk", dx=1})
|
||||||
actor:printanimstate()
|
actor:printanimstate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.west(actor, place, dialog)
|
function player.cb_west(actor, place, dialog)
|
||||||
print("Moving west")
|
print("Moving west")
|
||||||
tangible.animate(place, {action="walk", dx=-1})
|
tangible.animate(place, {action="walk", dx=-1})
|
||||||
actor:printanimstate()
|
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
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user