Overhaul of command parsing
This commit is contained in:
@@ -29,32 +29,15 @@ private:
|
||||
int64_t gui_place_;
|
||||
int64_t actor_id_;
|
||||
|
||||
|
||||
void do_lua_command(const StringVec &words) {
|
||||
assert(world_->stack_is_clear());
|
||||
if (words.size() != 2) {
|
||||
stdostream() << "lua command (lua) takes a single string" << std::endl;
|
||||
return;
|
||||
}
|
||||
const std::string &exp = words[1];
|
||||
InvocationData dummyresult;
|
||||
Invocation inv(Invocation::KIND_LUA, actor_id_, actor_id_, exp, dummyresult);
|
||||
world_->invoke(inv);
|
||||
world_->invoke(Invocation(Invocation::KIND_LUA, actor_id_, actor_id_, words[1]));
|
||||
}
|
||||
|
||||
void do_syntax_command(const StringVec &words) {
|
||||
stdostream() << "Syntax Error: ";
|
||||
for (int i = 1; i < int(words.size()); i++) {
|
||||
stdostream() << words[i] << " ";
|
||||
}
|
||||
stdostream() << std::endl;
|
||||
stdostream() << "Syntax Error: " << words[1] << std::endl;
|
||||
}
|
||||
|
||||
void do_view_command(const StringVec &cmd) {
|
||||
if (cmd.size() != 1) {
|
||||
stdostream() << "v command (view) takes no arguments" << std::endl;
|
||||
return;
|
||||
}
|
||||
for (int64_t id : world_->get_near(actor_id_, 100, true)) {
|
||||
const Tangible *tan = world_->tangible_get(id);
|
||||
const AnimStep &aqback = tan->anim_queue_.back();
|
||||
@@ -63,17 +46,8 @@ private:
|
||||
}
|
||||
|
||||
void do_menu_command(const StringVec &cmd) {
|
||||
int64_t id;
|
||||
if (cmd.size() == 1) {
|
||||
id = actor_id_;
|
||||
} else if (cmd.size() == 2) {
|
||||
id = util::strtoint(cmd[1], -1);
|
||||
} else {
|
||||
stdostream() << "m command (menu) expects a tangible ID or defaults to actor_id" << std::endl;
|
||||
return;
|
||||
}
|
||||
gui_place_ = id;
|
||||
world_->update_gui(actor_id_, id, &gui_);
|
||||
gui_place_ = util::strtoint(cmd[1], actor_id_);
|
||||
world_->update_gui(actor_id_, gui_place_, &gui_);
|
||||
int index = 0;
|
||||
for (const GuiElt &elt : gui_.elts()) {
|
||||
stdostream() << index << " " << elt.label() << std::endl;
|
||||
@@ -82,60 +56,29 @@ private:
|
||||
}
|
||||
|
||||
void do_choose_command(const StringVec &cmd) {
|
||||
int64_t index;
|
||||
if (cmd.size() == 1) {
|
||||
index = util::strtoint(cmd[0], -1);
|
||||
} else {
|
||||
stdostream() << "c command (choose) expects a menu line number" << std::endl;
|
||||
std::string action = gui_.get_action(util::strtoint(cmd[1], -1));
|
||||
if (action == "") {
|
||||
stdostream() << "Invalid menu item #" << std::endl;
|
||||
return;
|
||||
}
|
||||
const Gui::EltVec &elts = gui_.elts();
|
||||
if ((index < 0) || (index >= int(elts.size()))) {
|
||||
stdostream() << "No menu item #" << index << std::endl;
|
||||
return;
|
||||
}
|
||||
std::string action = elts[index].action();
|
||||
stdostream() << "Invoking plan: " << action << std::endl;
|
||||
InvocationData dummyresult;
|
||||
dummyresult["flavor"] = "chocolate";
|
||||
dummyresult["color"] = "blue";
|
||||
Invocation inv(Invocation::KIND_PLAN, actor_id_, gui_place_, action, dummyresult);
|
||||
Invocation inv(Invocation::KIND_PLAN, actor_id_, gui_place_, action);
|
||||
stdostream() << "Invoking: " << inv.debug_string() << std::endl;
|
||||
world_->invoke(inv);
|
||||
}
|
||||
|
||||
|
||||
void do_snapshot_command(const StringVec &cmd) {
|
||||
if (cmd.size() != 1) {
|
||||
stdostream() << "s command (snapshot) takes no arguments" << std::endl;
|
||||
return;
|
||||
}
|
||||
world_->snapshot();
|
||||
}
|
||||
|
||||
void do_rollback_command(const StringVec &cmd) {
|
||||
if (cmd.size() != 1) {
|
||||
stdostream() << "r command (rollback) takes no arguments" << std::endl;
|
||||
return;
|
||||
}
|
||||
world_->rollback();
|
||||
}
|
||||
|
||||
void do_tick_command(const StringVec &cmd) {
|
||||
int64_t clock;
|
||||
if (cmd.size() == 2) {
|
||||
clock = util::strtoint(cmd[1], -1);
|
||||
} else {
|
||||
stdostream() << "t command (tick) expects a time value" << std::endl;
|
||||
return;
|
||||
}
|
||||
world_->run_scheduled_threads(clock);
|
||||
world_->run_scheduled_threads(util::strtoint(cmd[1], -1));
|
||||
}
|
||||
|
||||
void do_quit_command(const StringVec &cmd) {
|
||||
if (cmd.size() != 1) {
|
||||
stdostream() << "q command (quit) takes no arguments" << std::endl;
|
||||
return;
|
||||
}
|
||||
actor_id_ = 0;
|
||||
}
|
||||
|
||||
@@ -149,9 +92,9 @@ private:
|
||||
else if (words[0] == "snap") do_snapshot_command(words);
|
||||
else if (words[0] == "roll") do_rollback_command(words);
|
||||
else if (words[0] == "tick") do_tick_command(words);
|
||||
else if (util::validinteger(words[0])) do_choose_command(words);
|
||||
else if (words[0] == "choose") do_choose_command(words);
|
||||
else {
|
||||
stdostream() << "Unknown command: " << words[0] << std::endl;
|
||||
stdostream() << "Unsupported command: " << words[0] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user