diff options
author | rtk0c <[email protected]> | 2022-05-30 17:03:20 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-05-30 17:03:20 -0700 |
commit | e66286ebe30afc9acc4531fc2bea29b7fb924f93 (patch) | |
tree | fa6b76554c3eb88bc8f088fbab68e20c40118ca7 /source/Ires.hpp | |
parent | 366ef5a5450c6e0e680c924c3454943a9ae9814d (diff) |
Changeset: 56 Buildsystem cleanup: change to layered structure for different targets
Diffstat (limited to 'source/Ires.hpp')
-rw-r--r-- | source/Ires.hpp | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/source/Ires.hpp b/source/Ires.hpp deleted file mode 100644 index 83ca175..0000000 --- a/source/Ires.hpp +++ /dev/null @@ -1,117 +0,0 @@ -#pragma once - -#include "EditorAttachment.hpp" -#include "EditorCore.hpp" -#include "RcPtr.hpp" -#include "Uid.hpp" -#include "Utils.hpp" - -#include <rapidjson/fwd.h> -#include <robin_hood.h> -#include <filesystem> -#include <memory> -#include <string_view> - -// Forward declarations -class IresManager; -class IresWritingContext; -class IresLoadingContext; - -class IresObject : public RefCounted { - friend class IresManager; - -public: - enum Kind { - KD_Texture, - KD_Shader, - KD_Material, - KD_SpriteFiles, - KD_Spritesheet, - KD_COUNT, - }; - -private: - std::string mName; // Serialized as filename - Uid mUid; // Serialized in full mode - std::unique_ptr<EditorAttachment> mEditorAttachment; // Transient - IresManager* mMan = nullptr; // Transient - Kind mKind; // Serialized in full mode - -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; } - void SetName(std::string name); - const Uid& GetUid() const { return mUid; } - - static void ShowNameSafe(IresObject* ires); - static void ShowNameNull(); - void ShowName() const; - - static void ShowReferenceSafe(IEditor& editor, IresObject* ires); - static void ShowReferenceNull(IEditor& editor); - void ShowReference(IEditor& editor); - - virtual void ShowEditor(IEditor& editor); - - EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); } - void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); } - - static void WriteFull(IresWritingContext& ctx, IresObject* ires, rapidjson::Value& value, rapidjson::Document& root); - - /// Sequentially call ReadBasic() and then ReadPartial() - static std::unique_ptr<IresObject> ReadFull(IresLoadingContext& ctx, const rapidjson::Value& value); - /// Reads the type and UID of the object from data, and return a newly constructed Ires object. - static std::unique_ptr<IresObject> ReadBasic(const rapidjson::Value& value); - /// Reads all object-speific data from the root-level data object into the given Ires object. - static bool ReadPartial(IresLoadingContext& ctx, IresObject* ires, const rapidjson::Value& value); - - virtual void Write(IresWritingContext& ctx, rapidjson::Value& value, rapidjson::Document& root) const; - virtual void Read(IresLoadingContext& ctx, const rapidjson::Value& value); - -protected: - rapidjson::Value WriteIresRef(IresObject* object); -}; - -class IresWritingContext { -public: - virtual ~IresWritingContext() = default; -}; - -class IresLoadingContext { -public: - virtual ~IresLoadingContext() = default; - virtual IresObject* FindIres(const Uid& uid) const = 0; -}; - -class IresManager final : public IresWritingContext, public IresLoadingContext { -public: - static inline IresManager* instance = nullptr; - -private: - robin_hood::unordered_map<Uid, RcPtr<IresObject>> mObjByUid; - -public: - void DiscoverFilesDesignatedLocation(); - void DiscoverFiles(const std::filesystem::path& dir); - - std::pair<IresObject*, bool> Add(IresObject* mat); - IresObject* Load(const std::filesystem::path& filePath); - void Delete(IresObject* ires); - bool Rename(IresObject* ires, std::string newName); - - void Reload(IresObject* ires); - void Save(IresObject* ires); - void Save(IresObject* ires, const std::filesystem::path& filePath); - - const auto& GetObjects() const { return mObjByUid; } - virtual IresObject* FindIres(const Uid& uid) const override; -}; |