diff --git a/Engine/headers/object.h b/Engine/headers/object.h index 0df414f..0e05fd5 100644 --- a/Engine/headers/object.h +++ b/Engine/headers/object.h @@ -24,15 +24,26 @@ protected: int roomIdItBelongsTo; public: + Object() = default; + Object(const int i, std::string n, std::string desc, std::vector k, const ObjectType o, const bool ct, + const int rID) { + id = i; + name = std::move(n); + description = std::move(desc); + keywords = std::move(k); + type = o; + canTake = ct; + roomIdItBelongsTo = rID; + } virtual void Interact() = 0; - std::string const GetName() { return name; } - std::string const GetDescription() { return description; } + std::string GetName() const { return name; } + std::string GetDescription() const { return description; } - ObjectType const GetObjectType() { return type; } - std::vector const GetKeywords() { return keywords; } - int GetId() { return id; } - int GetRoomId() { return roomIdItBelongsTo; } - bool CanTake() { return canTake; } + ObjectType GetObjectType() const { return type; } + std::vector GetKeywords() const { return keywords; } + int GetId() const { return id; } + int GetRoomId() const { return roomIdItBelongsTo; } + bool CanTake() const { return canTake; } virtual ~Object() = default; }; diff --git a/Engine/headers/room.h b/Engine/headers/room.h index 165bd2d..2c573e6 100644 --- a/Engine/headers/room.h +++ b/Engine/headers/room.h @@ -4,7 +4,7 @@ #include #include #include "json.hpp" -#include "object.h" +#include "scenery.h" using json = nlohmann::json; @@ -27,10 +27,11 @@ private: std::string name; std::string description; std::vector exits; + std::vector scenery; public: Room(); - Room(int id, std::string name, std::string desc, std::vector e); + Room(int id, std::string name, std::string desc, std::vector e, std::vector s); Room(const Room &r); void PrintAvalibleExits(); diff --git a/Engine/headers/scenery.h b/Engine/headers/scenery.h index eb2536e..07dde2c 100644 --- a/Engine/headers/scenery.h +++ b/Engine/headers/scenery.h @@ -1,16 +1,17 @@ #pragma once -#include #include +#include #include "object.h" -class Scenery : Object -{ - private: - bool containsItem; - public: - Scenery(); - void Examine(); - void Interact(); - ~Scenery(); +class Scenery : public Object { +public: + Scenery(); + Scenery(int i, std::string n, std::string desc, std::vector k, ObjectType t, bool cT, int rID); + void Examine(); + void Interact() override; + + + friend void from_json(const nlohmann::json &j, Scenery &s); + friend void to_json(json &j, const Scenery &s); }; diff --git a/Engine/src/room.cpp b/Engine/src/room.cpp index 3846304..2cbef0e 100644 --- a/Engine/src/room.cpp +++ b/Engine/src/room.cpp @@ -10,11 +10,12 @@ Room::Room() { exits.clear(); } -Room::Room(int id, std::string n, std::string desc, std::vector e) { +Room::Room(int id, std::string n, std::string desc, std::vector e, std::vector s) { id = id; name = n; description = desc; exits = e; + scenery = s; } Room::Room(const Room &r) { @@ -67,8 +68,10 @@ void from_json(const json &j, Room &r) { j.at("name").get_to(r.name); j.at("description").get_to(r.description); j.at("exits").get_to(r.exits); + j.at("scenery").get_to(r.scenery); } -void to_json(nlohmann::json &j, const Room &r) { - j = json{{"id", r.id}, {"name", r.name}, {"description", r.description}, {"exits", r.exits}}; +void to_json(json &j, const Room &r) { + j = json{ + {"id", r.id}, {"name", r.name}, {"description", r.description}, {"exits", r.exits}, {"scenery", r.scenery}}; } diff --git a/Engine/src/scenery.cpp b/Engine/src/scenery.cpp index abd716f..53f0ec0 100644 --- a/Engine/src/scenery.cpp +++ b/Engine/src/scenery.cpp @@ -1,29 +1,40 @@ #include "scenery.h" -Scenery::Scenery() -{ - type = ObjectType::SCENERY; - name = "Scenery"; - containsItem = false; +Scenery::Scenery() { + type = ObjectType::SCENERY; + name = "Scenery"; } -void Scenery::Interact() -{ - if (containsItem) - { - // Give Item - } - Examine(); +Scenery::Scenery(int i, std::string n, std::string desc, std::vector k, ObjectType t, bool cT, int rID) { + id = i; + name = std::move(n); + description = std::move(desc); + keywords = std::move(k); + type = t; + canTake = cT; + roomIdItBelongsTo = rID; } -void Scenery::Examine() -{ - printf("%s\n", GetDescription().data()); +void Scenery::Interact() { Examine(); } + +void Scenery::Examine() { printf("%s\n", GetDescription().data()); } + +void from_json(const json &j, Scenery &s) { + j.at("id").get_to(s.id); + j.at("name").get_to(s.name); + j.at("description").get_to(s.description); + j.at("keywords").get_to(s.keywords); + j.at("type").get_to(s.type); + j.at("canTake").get_to(s.canTake); + j.at("roomIdItBelongsTo").get_to(s.roomIdItBelongsTo); } -Scenery::~Scenery() -{ - type = ObjectType::NONE; - name = ""; - keywords.clear(); +void to_json(json &j, const Scenery &s) { + j = json{{"id", s.id}, + {"name", s.name}, + {"description", s.description}, + {"keywords", s.keywords}, + {"type", s.type}, + {"canTake", s.canTake}, + {"roomIdItBelongsTo", s.roomIdItBelongsTo}}; } diff --git a/Resources/Rooms.json b/Resources/Rooms.json index 26979c1..c8a6e75 100644 --- a/Resources/Rooms.json +++ b/Resources/Rooms.json @@ -1,35 +1,39 @@ [ - [ + [ + { + "description": "A fascinating Room. There's ... nothing in it, neat.", + "exits": [ { - "description": "A fascinating Room. There's ... nothing in it, neat.", - "exits": [ - { - "dir": 2, - "exitID": 1, - "isLocked": false - }, - { - "dir": 1, - "exitID": 2, - "isLocked": false - } - ], - "id": -8528, - "name": "Test Room 1" + "dir": 2, + "exitID": 1, + "isLocked": false }, { - "description": "Another test room. What a shocker", - "exits": [], - "id": -8608, - "name": "Test Room 2" + "dir": 1, + "exitID": 2, + "isLocked": false } - ], - [ + ], + "scenery": [ { - "description": "Testing another column", - "exits": [], - "id": -8656, - "name": "Test Room 3" } - ] + ], + "id": -8528, + "name": "Test Room 1" + }, + { + "description": "Another test room. What a shocker", + "exits": [], + "id": -8608, + "name": "Test Room 2" + } + ], + [ + { + "description": "Testing another column", + "exits": [], + "id": -8656, + "name": "Test Room 3" + } + ] ] diff --git a/main.cpp b/main.cpp index e075dd2..e00c98c 100644 --- a/main.cpp +++ b/main.cpp @@ -3,13 +3,49 @@ int main(int argc, char *argv[]) { Game game; // Calls default constructor which Initializes GAME - if (!game) { + fs::path path("Resources/rooms.json"); + + std::vector> rooms = { + { + { + 0, + "Test Room 1", + "First Test Room", + {{0, S, false}, {1, E, false}}, + {{0, "Rock", "A Grey Rock", {"Rock"}, ObjectType::SCENERY, false, 0}}, + }, + {1, + "Test Room 2", + "A court yard", + {{2, W, false}, {3, E, false}, {4, S, false}}, + {{1, + "Tree", + "A fine looking Tree stands in the courtyard", + {"Tree"}, + ObjectType::SCENERY, + false, + 1}}}, + + }, + {{3, + "Test Room 3", + "You can hear the sound of a waterfall nearby", + {{5, N, false}, {6, E, false}}, + {{3, "Waterfall", "A fine waterfall on a cliff", {"Waterfall"}, ObjectType::SCENERY, false, 3}}}}}; + + nlohmann::json j(rooms); + + std::fstream outFile(absolute(path), std::fstream::in | std::fstream::out | std::fstream::app); + outFile << std::setw(4) << j << std::endl; + + outFile.close(); + /*if (!game) { game.Init(); Game::SetGameInstance(&game); } while (game.GetIsActive()) { game.Run(); - } + }*/ return 0; }