Wip: working on add scenery

This commit is contained in:
Timothy O'Barr
2026-09-01 16:27:01 -05:00
parent 15f0e369b2
commit 668d416256
7 changed files with 138 additions and 71 deletions
+18 -7
View File
@@ -24,15 +24,26 @@ protected:
int roomIdItBelongsTo; int roomIdItBelongsTo;
public: public:
Object() = default;
Object(const int i, std::string n, std::string desc, std::vector<std::string> 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; virtual void Interact() = 0;
std::string const GetName() { return name; } std::string GetName() const { return name; }
std::string const GetDescription() { return description; } std::string GetDescription() const { return description; }
ObjectType const GetObjectType() { return type; } ObjectType GetObjectType() const { return type; }
std::vector<std::string> const GetKeywords() { return keywords; } std::vector<std::string> GetKeywords() const { return keywords; }
int GetId() { return id; } int GetId() const { return id; }
int GetRoomId() { return roomIdItBelongsTo; } int GetRoomId() const { return roomIdItBelongsTo; }
bool CanTake() { return canTake; } bool CanTake() const { return canTake; }
virtual ~Object() = default; virtual ~Object() = default;
}; };
+3 -2
View File
@@ -4,7 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "json.hpp" #include "json.hpp"
#include "object.h" #include "scenery.h"
using json = nlohmann::json; using json = nlohmann::json;
@@ -27,10 +27,11 @@ private:
std::string name; std::string name;
std::string description; std::string description;
std::vector<Exit> exits; std::vector<Exit> exits;
std::vector<Scenery> scenery;
public: public:
Room(); Room();
Room(int id, std::string name, std::string desc, std::vector<Exit> e); Room(int id, std::string name, std::string desc, std::vector<Exit> e, std::vector<Scenery> s);
Room(const Room &r); Room(const Room &r);
void PrintAvalibleExits(); void PrintAvalibleExits();
+9 -8
View File
@@ -1,16 +1,17 @@
#pragma once #pragma once
#include <iostream>
#include <iomanip> #include <iomanip>
#include <iostream>
#include "object.h" #include "object.h"
class Scenery : Object class Scenery : public Object {
{ public:
private:
bool containsItem;
public:
Scenery(); Scenery();
Scenery(int i, std::string n, std::string desc, std::vector<std::string> k, ObjectType t, bool cT, int rID);
void Examine(); void Examine();
void Interact(); void Interact() override;
~Scenery();
friend void from_json(const nlohmann::json &j, Scenery &s);
friend void to_json(json &j, const Scenery &s);
}; };
+6 -3
View File
@@ -10,11 +10,12 @@ Room::Room() {
exits.clear(); exits.clear();
} }
Room::Room(int id, std::string n, std::string desc, std::vector<Exit> e) { Room::Room(int id, std::string n, std::string desc, std::vector<Exit> e, std::vector<Scenery> s) {
id = id; id = id;
name = n; name = n;
description = desc; description = desc;
exits = e; exits = e;
scenery = s;
} }
Room::Room(const Room &r) { 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("name").get_to(r.name);
j.at("description").get_to(r.description); j.at("description").get_to(r.description);
j.at("exits").get_to(r.exits); j.at("exits").get_to(r.exits);
j.at("scenery").get_to(r.scenery);
} }
void to_json(nlohmann::json &j, const Room &r) { void to_json(json &j, const Room &r) {
j = json{{"id", r.id}, {"name", r.name}, {"description", r.description}, {"exits", r.exits}}; j = json{
{"id", r.id}, {"name", r.name}, {"description", r.description}, {"exits", r.exits}, {"scenery", r.scenery}};
} }
+29 -18
View File
@@ -1,29 +1,40 @@
#include "scenery.h" #include "scenery.h"
Scenery::Scenery() Scenery::Scenery() {
{
type = ObjectType::SCENERY; type = ObjectType::SCENERY;
name = "Scenery"; name = "Scenery";
containsItem = false;
} }
void Scenery::Interact() Scenery::Scenery(int i, std::string n, std::string desc, std::vector<std::string> k, ObjectType t, bool cT, int rID) {
{ id = i;
if (containsItem) name = std::move(n);
{ description = std::move(desc);
// Give Item keywords = std::move(k);
} type = t;
Examine(); canTake = cT;
roomIdItBelongsTo = rID;
} }
void Scenery::Examine() void Scenery::Interact() { Examine(); }
{
printf("%s\n", GetDescription().data()); 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() void to_json(json &j, const Scenery &s) {
{ j = json{{"id", s.id},
type = ObjectType::NONE; {"name", s.name},
name = ""; {"description", s.description},
keywords.clear(); {"keywords", s.keywords},
{"type", s.type},
{"canTake", s.canTake},
{"roomIdItBelongsTo", s.roomIdItBelongsTo}};
} }
+4
View File
@@ -14,6 +14,10 @@
"isLocked": false "isLocked": false
} }
], ],
"scenery": [
{
}
],
"id": -8528, "id": -8528,
"name": "Test Room 1" "name": "Test Room 1"
}, },
+38 -2
View File
@@ -3,13 +3,49 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Game game; // Calls default constructor which Initializes GAME Game game; // Calls default constructor which Initializes GAME
if (!game) { fs::path path("Resources/rooms.json");
std::vector<std::vector<Room>> 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.Init();
Game::SetGameInstance(&game); Game::SetGameInstance(&game);
} }
while (game.GetIsActive()) { while (game.GetIsActive()) {
game.Run(); game.Run();
} }*/
return 0; return 0;
} }