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

50 lines
1.2 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:
virtual void Interact() = 0;
std::string const GetName() { return name; }
std::string const GetDescription() { return description; }
ObjectType const GetObjectType() { return type; }
std::vector<std::string> const GetKeywords() { return keywords; }
int GetId() { return id; }
int GetRoomId() { return roomIdItBelongsTo; }
bool CanTake() { return canTake; }
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()}};
}