aboutsummaryrefslogtreecommitdiff
path: root/source/Game/Ires.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-03 23:30:01 -0700
committerrtk0c <[email protected]>2022-06-03 23:30:01 -0700
commit791b3f354b378769bffe623b05f1305c91b77101 (patch)
tree5409b311e6232eb4a6d3f8259b780d76b8ee1c59 /source/Game/Ires.hpp
parent60ccc62f4934e44ad5b905fdbcf458302b8d8a09 (diff)
Changeset: 64 [WIP] Rename directoriesmaster-switch-to-build2
Diffstat (limited to 'source/Game/Ires.hpp')
-rw-r--r--source/Game/Ires.hpp125
1 files changed, 0 insertions, 125 deletions
diff --git a/source/Game/Ires.hpp b/source/Game/Ires.hpp
deleted file mode 100644
index b6420f3..0000000
--- a/source/Game/Ires.hpp
+++ /dev/null
@@ -1,125 +0,0 @@
-#pragma once
-
-#include "EditorAttachment.hpp"
-#include "EditorCore.hpp"
-
-#include <MacrosCodegen.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;
-
-namespace Tags {
-enum class IresObjectKind {
- KD_Texture,
- KD_Shader,
- KD_Material,
- KD_SpriteFiles,
- KD_Spritesheet,
- KD_COUNT,
-};
-BRUSSEL_ENUM(IresObjectKind, ToString FromString ExcludeHeuristics);
-} // namespace Tags
-
-class IresObject : public RefCounted {
- friend class IresManager;
-
-public:
- using Kind = Tags::IresObjectKind;
- using enum Tags::IresObjectKind;
-
-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::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;
-};
-
-#include <generated/Ires.gh.inl>