Added action validation

This commit is contained in:
2021-02-16 14:15:40 -05:00
parent 1a6366e164
commit 210644da57
3 changed files with 17 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);
};

View File

@@ -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;