Files
Text-Adventure/Engine/headers/object.h
T

61 lines
1.6 KiB
C++
Raw Normal View History

2026-08-07 13:10:07 -05:00
#pragma once
#include <iomanip>
#include <iostream>
#include <vector>
#include "json.hpp"
using json = nlohmann::json;
enum class ObjectType { ITEM, SCENERY, NONE };
class Object {
protected:
int id;
std::string name;
std::string description;
std::vector<std::string> keywords;
ObjectType type;
bool canTake;
int roomIdItBelongsTo;
public:
2026-09-01 16:27:01 -05:00
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;
}
2026-08-07 13:10:07 -05:00
virtual void Interact() = 0;
2026-09-01 16:27:01 -05:00
std::string GetName() const { return name; }
std::string GetDescription() const { return description; }
2026-08-07 13:10:07 -05:00
2026-09-01 16:27:01 -05:00
ObjectType GetObjectType() const { return type; }
std::vector<std::string> GetKeywords() const { return keywords; }
int GetId() const { return id; }
int GetRoomId() const { return roomIdItBelongsTo; }
bool CanTake() const { return canTake; }
2026-08-07 13:10:07 -05:00
virtual ~Object() = default;
};
// Global/Namespace scope serialization functions
inline void to_json(json &j, Object &obj) {
j = json{{"id", obj.GetId()},
{"name", obj.GetName()},
{"description", obj.GetDescription()},
{"keywords", obj.GetKeywords()},
{"type", obj.GetObjectType()},
{"canTake", obj.CanTake()},
{"roomIdItBelongsTo", obj.GetRoomId()}};
}