Added action validation
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user