git repos / saland

commit 6166342f

Poul Sander · 2021-06-20 09:38
6166342f75912f2a8672da16a28a7d43afff745d patch · browse files
parent 2a628a116cfc0a799c85977a5735cc119a376c79

Can now list iventory content in console

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 39a84f3..01f85e6 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -183,6 +183,7 @@ struct ConcoleCommandTiled : public ConsoleCommand {
}
};
+
static GotoConsoleCommand gcc;
static ResetRegionConsoleCommand rrcc;
static ShopCommand sc;
diff --git a/src/saland/GameConsoleCommand.cpp b/src/saland/GameConsoleCommand.cpp index 8360b5b..f912343 100644 --- a/src/saland/GameConsoleCommand.cpp +++ b/src/saland/GameConsoleCommand.cpp
@@ -66,6 +66,33 @@ struct ConsoleCommandGiveItem : public ConsoleCommand {
};
+struct ConsoleCommandItem : public ConsoleCommand {
+ virtual std::string getCommand() const override {
+ return "item";
+ }
+
+ virtual std::string run(const std::vector<std::string>& args) override {
+ if (args.size() < 2) {
+ throw std::runtime_error("Must be called like: item list");
+ }
+ if (args.at(1) == "list") {
+ std::string message = "";
+ for (const auto& item : globalData.player.item_inventory) {
+ message += item.first + ":" + std::to_string(item.second) + ", ";
+ }
+ return message;
+ }
+ else {
+ throw std::runtime_error(args.at(2)+" not recognized");
+ }
+ }
+
+ virtual std::string helpMessage() const override {
+ return "Handles item functionality. Example: item list";
+ }
+};
+
+
struct ConsoleCommandQuit : public ConsoleCommand {
virtual std::string getCommand() const override {
return "quit";
@@ -125,11 +152,13 @@ struct ConsoleCommandConfig : public ConsoleCommand {
};
static ConsoleCommandGiveItem cc_give_item;
+static ConsoleCommandItem cc_item;
static ConsoleCommandQuit cc_quit;
static ConsoleCommandConfig cc_config;
void GameConsoleCommandRegister() {
RegisterCommand(&cc_give_item);
+ RegisterCommand(&cc_item);
RegisterCommand(&cc_quit);
RegisterCommand(&cc_config);
}
\ No newline at end of file