diff --git a/luprex/core/cpp/gui.cpp b/luprex/core/cpp/gui.cpp index 44fb88a4..92ccea56 100644 --- a/luprex/core/cpp/gui.cpp +++ b/luprex/core/cpp/gui.cpp @@ -10,6 +10,15 @@ void Gui::menu_item(const std::string &action, const std::string &label) { elts_.push_back(elt); } +bool Gui::has_action(const std::string &action) const { + for (const GuiElt &elt : elts_) { + if (elt.action_ == action) { + return true; + } + } + return false; +} + LuaDefine(gui_create, "c") { LuaRet lgui; LuaStack LS(L, lgui); diff --git a/luprex/core/cpp/gui.hpp b/luprex/core/cpp/gui.hpp index 1860971c..e1452a80 100644 --- a/luprex/core/cpp/gui.hpp +++ b/luprex/core/cpp/gui.hpp @@ -32,6 +32,7 @@ private: public: const EltVec &elts() const { return elts_; } void clear() { elts_.clear(); } + bool has_action(const std::string &action) const; void menu_item(const std::string &action, const std::string &label); }; diff --git a/luprex/core/cpp/world.cpp b/luprex/core/cpp/world.cpp index 4d9543ac..2de05651 100644 --- a/luprex/core/cpp/world.cpp +++ b/luprex/core/cpp/world.cpp @@ -193,6 +193,13 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) { } void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &action, Gui *gui) { + // Validate that the action is legal. + Gui validation_gui; + update_gui(actor_id, place_id, &validation_gui); + if (!validation_gui.has_action(action)) { + return; + } + lua_State *L = state(); LuaVar actor, place, ugui, func, tangibles, mt, index, actions;