Parse Rooms and added proper room JSON

This commit is contained in:
Timothy O'Barr
2026-08-18 11:59:09 -05:00
parent 455e54b557
commit db2cb3aeea
6 changed files with 63 additions and 79 deletions
-1
View File
@@ -24,7 +24,6 @@ private:
std::string name;
std::string description;
std::vector<Exit> exits;
std::vector<std::unique_ptr<Object>> objects;
public:
Room();
+1 -8
View File
@@ -20,14 +20,7 @@ bool Game::Init() {
stream.open(absolute(filePath));
json = nlohmann::json::parse(stream);
// rooms = json.get<std::vector<std::vector<Room>>>();
auto &roomData = json["rooms"];
for (const auto &roomCol: rooms) {
for (const auto &roomRow: roomCol) {
// rooms.push_back(roomRow.get<Room>());
}
}
rooms = json.get<std::vector<std::vector<Room>>>();
player.Init();
parser = CommandParser();
+3 -5
View File
@@ -34,18 +34,16 @@ void Room::Print() const {
}
inline void from_json(const json &j, Exit &e) {
void from_json(const json &j, Exit &e) {
j.at("exitID").get_to(e.exitID);
j.at("dir").get_to(e.dir);
j.at("isLocked").get_to(e.isLocked);
}
inline void to_json(json &j, const Exit &e) {
j = json{{"exitID", e.exitID}, {"dir", e.dir}, {"isLocked", e.isLocked}};
}
void to_json(json &j, const Exit &e) { j = json{{"exitID", e.exitID}, {"dir", e.dir}, {"isLocked", e.isLocked}}; }
inline void from_json(const json &j, Room &r) {
void from_json(const json &j, Room &r) {
j.at("id").get_to(r.id);
j.at("name").get_to(r.name);
j.at("description").get_to(r.description);