|
@@ -5,6 +5,7 @@
|
|
|
#include "boxes.h"
|
|
|
#include "galaxy.h"
|
|
|
#include "logging.h"
|
|
|
+#include "scripts.h"
|
|
|
#include "utils.h"
|
|
|
|
|
|
Director::Director() {
|
|
@@ -30,7 +31,7 @@ Director::Director() {
|
|
|
SF_sectorline = [this](const std::string &s) { this->SL_sectorline(s); };
|
|
|
SF_portline = [this](const std::string &s) { this->SL_portline(s); };
|
|
|
SF_warpline = [this](const std::string &s) { this->SL_warpline(s); };
|
|
|
-
|
|
|
+ SF_infoline = [this](const std::string &s) { this->SL_infoline(s); };
|
|
|
build_menu();
|
|
|
}
|
|
|
|
|
@@ -197,6 +198,7 @@ void Director::server_line(const std::string &line,
|
|
|
SL_parser = SF_portline;
|
|
|
if (startswith(line, "Sector : ")) SL_parser = SF_sectorline;
|
|
|
if (line == ": ") SL_parser = SF_cimline;
|
|
|
+ if (line == "<Info>") SL_parser = SF_infoline;
|
|
|
}
|
|
|
|
|
|
if (SL_parser) {
|
|
@@ -257,7 +259,7 @@ void Director::build_menu(void) {
|
|
|
"\x1b[32;40mGREEN\x1b[30;42m\xdb\xb2\xb1\xb0 \x1b[0m : ";
|
|
|
md->lazy = true;
|
|
|
md->menu = {{"C", "Configure"},
|
|
|
- {"D", "Display Report"},
|
|
|
+ // {"D", "Display Report"},
|
|
|
{"E", "Export Data/Save"},
|
|
|
{"I", "Information"},
|
|
|
{"P", "Port CIM"},
|
|
@@ -329,7 +331,7 @@ void Director::menu_choice(void) {
|
|
|
config_edit();
|
|
|
return;
|
|
|
break;
|
|
|
- case 'D': // display report
|
|
|
+ case 'T': // display trading report
|
|
|
{
|
|
|
auto pptv = galaxy.find_best_trades();
|
|
|
std::string output;
|
|
@@ -393,10 +395,15 @@ void Director::menu_choice(void) {
|
|
|
chain->activate();
|
|
|
return;
|
|
|
break;
|
|
|
- case 'T': // Trading Report
|
|
|
- break;
|
|
|
+ // case 'T': // Trading Report
|
|
|
+ // break;
|
|
|
case 'S': // Scripts
|
|
|
- break;
|
|
|
+ {
|
|
|
+ init_scripts_menu();
|
|
|
+ chain = scripts_menu;
|
|
|
+ chain->activate();
|
|
|
+ return;
|
|
|
+ } break;
|
|
|
case 'X': // Exit
|
|
|
proxy_deactivate();
|
|
|
return;
|
|
@@ -411,6 +418,71 @@ void Director::menu_choice(void) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+MenuDispatch *Director::init_scripts_menu(void) {
|
|
|
+ MenuDispatch *md;
|
|
|
+ if (scripts_menu) {
|
|
|
+ md = dynamic_cast<MenuDispatch *>(&(*scripts_menu));
|
|
|
+ return md;
|
|
|
+ } else {
|
|
|
+ scripts_menu = std::make_shared<MenuDispatch>(*this);
|
|
|
+ md = static_cast<MenuDispatch *>(&(*scripts_menu));
|
|
|
+ md->menu_box_color = "\x1b[0;32;40m";
|
|
|
+ md->menu_text_color = "\x1b[1;32;40m";
|
|
|
+ md->menu_title = "Scripts Menu";
|
|
|
+ md->menu_options_color = "\x1b[1;32;40m";
|
|
|
+ md->lazy = false;
|
|
|
+ md->menu_prompt = " SCRIPT : ";
|
|
|
+ md->menu = {{"!", "Terror"}, {"T", "Trade"}, {"U", "Upgrade Planet Pants"}};
|
|
|
+ md->setNotify([this]() { this->scripts_done(); });
|
|
|
+ return md;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Director::scripts_done(void) {
|
|
|
+ // Was script selected? If so, run it!
|
|
|
+ // otherwise, back to the menu we go...
|
|
|
+ MenuDispatch *md = dynamic_cast<MenuDispatch *>(&(*scripts_menu));
|
|
|
+ if (md) {
|
|
|
+ if (md->input.empty()) {
|
|
|
+ to_client("Scripts aborted.\n\r");
|
|
|
+ scripts_menu.reset();
|
|
|
+ proxy_deactivate();
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ switch (md->input[0]) {
|
|
|
+ case 'T': // Trade
|
|
|
+ script = std::make_shared<ScriptTrader>(*this);
|
|
|
+ ScriptTrader *ts = static_cast<ScriptTrader *>(&((*script)));
|
|
|
+ chain = script;
|
|
|
+ // Set parameters
|
|
|
+ auto found = galaxy.find_trades(current_sector, false);
|
|
|
+ if (found.empty()) {
|
|
|
+ to_client(
|
|
|
+ "No Trades found. Port burnt (CONFIG: lower burnt_percent?) "
|
|
|
+ "or no ports around.\n\r");
|
|
|
+ proxy_deactivate();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ts->port[0] = found[0].s1;
|
|
|
+ ts->port[1] = found[0].s2;
|
|
|
+ ts->type = found[0].type;
|
|
|
+ chain->activate();
|
|
|
+ return;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ proxy_activate();
|
|
|
+
|
|
|
+ // And to end scripts, we do .. what exactly?
|
|
|
+ // DEBUG: Ok, why does everything work OK if I reset the scripts_menu here??
|
|
|
+ // probably do want to destroy scripts here. ;)
|
|
|
+ // scripts_menu.reset();
|
|
|
+ // proxy_deactivate();
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @brief Setup Config Input
|
|
|
*
|
|
@@ -454,7 +526,7 @@ void Director::config_edit(void) {
|
|
|
to_client(output);
|
|
|
++item;
|
|
|
}
|
|
|
- to_client("Enter number to edit.\n\r");
|
|
|
+ to_client("Enter number to edit, blank to exit.\n\r");
|
|
|
|
|
|
// setup call to config_input:
|
|
|
InputDispatch *id = init_config_input();
|
|
@@ -523,13 +595,11 @@ void Director::config_have_input(void) {
|
|
|
// This is a config item edit
|
|
|
if (id->input.empty()) {
|
|
|
to_client("No change.\n\r");
|
|
|
- // cleared by init config_item.clear();
|
|
|
config_edit();
|
|
|
return;
|
|
|
} else {
|
|
|
BUGZ_LOG(fatal) << "Config EDIT: " << config_item << " = " << id->input;
|
|
|
galaxy.config[config_item] = id->input;
|
|
|
- // cleared by init config_item.clear();
|
|
|
config_edit();
|
|
|
return;
|
|
|
}
|
|
@@ -744,4 +814,32 @@ void Director::SL_warpline(const std::string &line) {
|
|
|
|
|
|
// process warp line
|
|
|
BUGZ_LOG(fatal) << "warpline: [" << line << "]";
|
|
|
+}
|
|
|
+
|
|
|
+void Director::SL_infoline(const std::string &line) {
|
|
|
+ static int state;
|
|
|
+
|
|
|
+ if (line == "<Info>") {
|
|
|
+ state = 0;
|
|
|
+ galaxy.meta["info"] = YAML::Node();
|
|
|
+ }
|
|
|
+ if (line.empty()) {
|
|
|
+ ++state;
|
|
|
+ if (state == 2) {
|
|
|
+ SL_parser = nullptr;
|
|
|
+ // process the parsed information in meta["info"]
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // info to parse:
|
|
|
+ size_t pos = line.find(" : ");
|
|
|
+ if (pos != line.npos) {
|
|
|
+ std::string key = line.substr(0, pos);
|
|
|
+ std::string value = line.substr(pos + 3);
|
|
|
+ trim(key);
|
|
|
+ trim(value);
|
|
|
+ galaxy.meta["info"][key] = value;
|
|
|
+ BUGZ_LOG(fatal) << "Info: " << key << " : " << value;
|
|
|
+ }
|
|
|
}
|