diff options
author | rtk0c <[email protected]> | 2022-04-17 20:08:57 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-04-17 20:08:57 -0700 |
commit | 5424a1d5434e3ddd911a504719918c2df027e2fd (patch) | |
tree | 6275aab13140d81dcc46c8290e73ac9a8bbb5605 /source/Ires.hpp | |
parent | afcac59c7d04f4337d6b04ebed8cac7e871ccc50 (diff) |
Changeset: 8 Initial work on sprites and texture system
Diffstat (limited to 'source/Ires.hpp')
-rw-r--r-- | source/Ires.hpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/source/Ires.hpp b/source/Ires.hpp new file mode 100644 index 0000000..66a931e --- /dev/null +++ b/source/Ires.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include "EditorAttachment.hpp" +#include "RcPtr.hpp" +#include "Utils.hpp" + +#include <rapidjson/fwd.h> +#include <robin_hood.h> +#include <filesystem> +#include <memory> +#include <string_view> + +// Forward declarations +class IresObject; +class IresManager; + +class IresObject : public RefCounted { + friend class IresManager; + +public: + enum Kind { + KD_Texture, + KD_SpriteFiles, + KD_Spritesheet, + KD_COUNT, + }; + +private: + std::string mName; + std::unique_ptr<EditorAttachment> mEditorAttachment; + IresManager* mMan = nullptr; + Kind mKind; + +public: + IresObject(Kind kind); + virtual ~IresObject() = default; + + static std::string_view ToString(Kind kind); + static Kind FromString(std::string_view name); + static std::unique_ptr<IresObject> Create(Kind kind); + Kind GetKind() const { return mKind; } + + IresManager* GetAssociatedManager() const { return mMan; } + bool IsAnnoymous() const; + const std::string& GetName() const { return mName; } + + EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); } + void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); } + + static rapidjson::Value WriteFull(const IresObject& ires, rapidjson::Document& root); + static std::unique_ptr<IresObject> ReadFull(const rapidjson::Value& value); + virtual void Write(rapidjson::Value& value, rapidjson::Document& root) const = 0; + virtual void Read(const rapidjson::Value& value) = 0; +}; + +class IresManager { +public: + static inline IresManager* instance = nullptr; + +private: + robin_hood::unordered_map<std::string_view, RcPtr<IresObject>, StringHash, StringEqual> mObjects; + +public: + void DiscoverFilesDesignatedLocation(); + void DiscoverFiles(const std::filesystem::path& dir); + + std::pair<IresObject*, bool> Add(IresObject* mat); + void Delete(IresObject* ires); + bool Rename(IresObject* ires, std::string newName); + + const auto& GetObjects() const { return mObjects; } + IresObject* FindIres(std::string_view path); +}; |