aboutsummaryrefslogtreecommitdiff
path: root/source/30-game/Ires.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/30-game/Ires.cpp')
-rw-r--r--source/30-game/Ires.cpp48
1 files changed, 16 insertions, 32 deletions
diff --git a/source/30-game/Ires.cpp b/source/30-game/Ires.cpp
index 10a6867..bfa4cdf 100644
--- a/source/30-game/Ires.cpp
+++ b/source/30-game/Ires.cpp
@@ -3,14 +3,16 @@
#include "AppConfig.hpp"
#include "EditorCore.hpp"
#include "EditorUtils.hpp"
-#include "Macros.hpp"
#include "Material.hpp"
-#include "RapidJsonHelper.hpp"
-#include "ScopeGuard.hpp"
#include "Shader.hpp"
#include "Sprite.hpp"
#include "Texture.hpp"
-#include "Utils.hpp"
+
+#include <Macros.hpp>
+#include <Metadata.hpp>
+#include <RapidJsonHelper.hpp>
+#include <ScopeGuard.hpp>
+#include <Utils.hpp>
#include <imgui.h>
#include <misc/cpp/imgui_stdlib.h>
@@ -29,27 +31,6 @@ IresObject::IresObject(Kind kind)
: mKind{ kind } {
}
-std::string_view IresObject::ToString(Kind kind) {
- switch (kind) {
- case KD_Texture: return BRUSSEL_TAG_PREFIX_Ires "Texture"sv;
- case KD_Shader: return BRUSSEL_TAG_PREFIX_Ires "Shader"sv;
- case KD_Material: return BRUSSEL_TAG_PREFIX_Ires "Material"sv;
- case KD_SpriteFiles: return BRUSSEL_TAG_PREFIX_Ires "SpriteFiles"sv;
- case KD_Spritesheet: return BRUSSEL_TAG_PREFIX_Ires "Spritesheet"sv;
- case KD_COUNT: break;
- }
- return std::string_view();
-}
-
-IresObject::Kind IresObject::FromString(std::string_view name) {
- if (name == BRUSSEL_TAG_PREFIX_Ires "Texture"sv) return KD_Texture;
- if (name == BRUSSEL_TAG_PREFIX_Ires "Shader"sv) return KD_Shader;
- if (name == BRUSSEL_TAG_PREFIX_Ires "Material"sv) return KD_Material;
- if (name == BRUSSEL_TAG_PREFIX_Ires "SpriteFiles"sv) return KD_SpriteFiles;
- if (name == BRUSSEL_TAG_PREFIX_Ires "Spritesheet"sv) return KD_Spritesheet;
- return KD_COUNT;
-}
-
std::unique_ptr<IresObject> IresObject::Create(Kind kind) {
switch (kind) {
case KD_Texture: return std::make_unique<IresTexture>();
@@ -128,7 +109,7 @@ void IresObject::ShowReference(IEditor& editor) {
}
void IresObject::ShowEditor(IEditor& editor) {
- ImGui::Text("%s", ToString(mKind).data());
+ ImGui::Text("%.*s", PRINTF_STRING_VIEW(Metadata::EnumToString(mKind)));
bool isAnnoymous = mName.empty();
if (isAnnoymous) {
@@ -148,7 +129,7 @@ void IresObject::WriteFull(IresWritingContext& ctx, IresObject* ires, rapidjson:
rapidjson::Value rvIres(rapidjson::kObjectType);
ires->Write(ctx, rvIres, root);
- value.AddMember("Type", rapidjson::StringRef(ToString(ires->GetKind())), root.GetAllocator());
+ value.AddMember("Type", rapidjson::StringRef(Metadata::EnumToString(ires->GetKind())), root.GetAllocator());
value.AddMember("Uid", ires->mUid.Write(root), root.GetAllocator());
value.AddMember("Value", rvIres, root.GetAllocator());
}
@@ -169,8 +150,9 @@ std::unique_ptr<IresObject> IresObject::ReadFull(IresLoadingContext& ctx, const
std::unique_ptr<IresObject> IresObject::ReadBasic(const rapidjson::Value& value) {
auto rvType = rapidjson::GetProperty(value, rapidjson::kStringType, "Type"sv);
if (!rvType) return nullptr;
- auto kind = FromString(rapidjson::AsStringView(*rvType));
- auto ires = Create(kind);
+ auto kind = Metadata::EnumFromString<Kind>(rapidjson::AsStringView(*rvType));
+ assert(kind.has_value());
+ auto ires = Create(kind.value());
if (!ires) return nullptr;
auto rvUid = rapidjson::GetProperty(value, rapidjson::kArrayType, "Uid"sv);
@@ -212,7 +194,7 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
std::vector<std::vector<LoadCandidate*>> candidatesByKind;
IresLoadTimeContext() {
- candidatesByKind.resize(IresObject::KD_COUNT);
+ candidatesByKind.resize((int)IresObject::KD_COUNT);
}
std::vector<LoadCandidate*>& GetByKind(IresObject::Kind kind) {
@@ -282,7 +264,7 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
// Load Ires in order by type, there are dependencies between them
// TODO full arbitary dependency between Ires
- for (int i = 0; i < IresObject::KD_COUNT; ++i) {
+ for (int i = 0; i < (int)IresObject::KD_COUNT; ++i) {
auto kind = static_cast<IresObject::Kind>(i);
auto& list = ctx.GetByKind(kind);
for (auto cand : list) {
@@ -302,7 +284,7 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
std::pair<IresObject*, bool> IresManager::Add(IresObject* ires) {
auto& name = ires->mName;
if (name.empty()) {
- name = Utils::MakeRandomNumberedName(IresObject::ToString(ires->GetKind()).data());
+ name = Utils::MakeRandomNumberedName(Metadata::EnumToString(ires->GetKind()).data());
}
auto& uid = ires->mUid;
@@ -423,3 +405,5 @@ IresObject* IresManager::FindIres(const Uid& uid) const {
return nullptr;
}
}
+
+#include <generated/Ires.gs.inl>