git repos / saland

commit a2be71d7

Poul Sander · 2021-08-10 20:45
a2be71d75f05ad7369432cb147f908285d9172ff patch · browse files
parent 32ae8f61a347722193ac6b24f5e47562729b8cf9

Move draw overlay to GameConsoleCommand and fix the help message

Changed files

M src/saland/Game.cpp before
M src/saland/GameConsoleCommand.cpp before
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index fef7ae4..10ee143 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -125,33 +125,6 @@ struct ResetRegionConsoleCommand : public ConsoleCommand {
};
-struct DrawOverlayConsoleCommand : public ConsoleCommand {
- virtual std::string getCommand() const override {
- return "draw_overlay";
- }
-
- virtual std::string run(const std::vector<std::string>& args) override {
- if (args.size() != 3) {
- return "Must be ran like \"goto X Y\"";
- }
- int turn_on = string2int_trows(args[2]);
- if (turn_on) {
- globalData.debugDrawCollision = true;
- globalData.debugDrawProtectedAreas = true;
- return "Overlay enabled!";
- }
- else {
- globalData.debugDrawCollision = false;
- globalData.debugDrawProtectedAreas = false;
- return "Overlay disabled";
- }
- }
-
- virtual std::string helpMessage() const override {
- return "Call like \"draw_overlay TYPE 0/1\". Example: \"draw_overlay main 1\"";
- }
-};
-
void RunGameState(sago::GameStateInterface& state );
struct ShopCommand : public ConsoleCommand {
@@ -188,7 +161,6 @@ static GotoConsoleCommand gcc;
static ResetRegionConsoleCommand rrcc;
static ShopCommand sc;
static ConcoleCommandTiled cct;
-static DrawOverlayConsoleCommand docc;
struct Game::GameImpl {
GameRegion gameRegion;
@@ -257,7 +229,6 @@ Game::Game() {
RegisterCommand(&rrcc);
RegisterCommand(&sc);
RegisterCommand(&cct);
- RegisterCommand(&docc);
GameConsoleCommandRegister();
data.reset(new Game::GameImpl());
data->human.reset(new Human());
diff --git a/src/saland/GameConsoleCommand.cpp b/src/saland/GameConsoleCommand.cpp index f912343..79147d0 100644 --- a/src/saland/GameConsoleCommand.cpp +++ b/src/saland/GameConsoleCommand.cpp
@@ -24,6 +24,7 @@ https://github.com/sago007/saland
#include "../global.hpp"
#include "console/Console.hpp"
#include "../common.h"
+#include <sstream>
struct ConsoleCommandGiveItem : public ConsoleCommand {
virtual std::string getCommand() const override {
@@ -151,14 +152,55 @@ struct ConsoleCommandConfig : public ConsoleCommand {
}
};
+static int string2int_trows(const std::string& s) {
+ try {
+ return std::stoi(s);
+ }
+ catch (std::exception&) {
+ std::stringstream ss;
+ ss << "Failed to convert \"" << s << "\" to an integer";
+ throw std::runtime_error(ss.str());
+ }
+}
+
+
+struct DrawOverlayConsoleCommand : public ConsoleCommand {
+ virtual std::string getCommand() const override {
+ return "draw_overlay";
+ }
+
+ virtual std::string run(const std::vector<std::string>& args) override {
+ if (args.size() != 3) {
+ return "Must be ran like \"draw_overlay <TYPE>(Ignored) 0|1\"";
+ }
+ int turn_on = string2int_trows(args[2]);
+ if (turn_on) {
+ globalData.debugDrawCollision = true;
+ globalData.debugDrawProtectedAreas = true;
+ return "Overlay enabled!";
+ }
+ else {
+ globalData.debugDrawCollision = false;
+ globalData.debugDrawProtectedAreas = false;
+ return "Overlay disabled";
+ }
+ }
+
+ virtual std::string helpMessage() const override {
+ return "Call like \"draw_overlay TYPE 0/1\". Example: \"draw_overlay main 1\"";
+ }
+};
+
static ConsoleCommandGiveItem cc_give_item;
static ConsoleCommandItem cc_item;
static ConsoleCommandQuit cc_quit;
static ConsoleCommandConfig cc_config;
+static DrawOverlayConsoleCommand docc;
void GameConsoleCommandRegister() {
RegisterCommand(&cc_give_item);
RegisterCommand(&cc_item);
RegisterCommand(&cc_quit);
RegisterCommand(&cc_config);
+ RegisterCommand(&docc);
}
\ No newline at end of file