8#include "../Manager/ResMgr.h"
9#include "../Manager/EngineCore.h"
10#include "../Manager/MemoryMgr.h"
11#include "../Util/AssetsDef.h"
12#include "../Util/Loader/XML/XML.h"
17SResource::SResource(std::string classType) :
ReflectionObject(std::move(classType)) {
18 auto resMgr = CORE->GetCore(
ResMgr);
19 resMgr->Register(
this);
20 m_name =
"Resource " + std::to_string(resMgr->GetSize());
23SResource::SResource(
const SResource* resource,
bool isRegister) :
SObject(isRegister),
26 CORE->GetCore(
ResMgr)->Register(
this);
28 m_name = resource->m_name +
" (instance)";
31SResource::~SResource() =
default;
33void SResource::SetName(std::string name) {
34 m_name = std::move(name);
37void SResource::SetAbsoluteID(std::string
id) {
38 m_absoluteId = std::move(
id);
41void SResource::SetResource(std::string name,
bool isInit) {
42 if (m_isInited)
return;
44 auto asset = CORE->GetCore(
ResMgr)->GetAssetReference(std::move(name));
45 SetResource(asset, isInit);
49 if (asset ==
nullptr)
return;
50 if (m_isInited)
return;
52 asset->resource =
this;
54 m_absoluteId = asset->id;
55 if (!asset->hash.empty()) {
56 std::string hash = asset->hash;
59 std::string meta =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
60 "<CSEMETA version=\"1.0.0\">\n"
61 "<hash-data hash=\"" + m_hash +
"\">\n"
62 "\n</hash-data>\n</CSEMETA>";
63 SaveTxtFile(asset->name_path +
".meta", meta);
71SResource* SResource::GetResource(std::string name) {
72 return CORE->GetCore(
ResMgr)->GetSResource(std::move(name));
75void SResource::SetHash(std::string& hash) {
76 std::string srcHash = m_hash;
77 SObject::SetHash(hash);
78 CORE->GetCore(
ResMgr)->ChangeHash(srcHash, hash);
82 if (hash.empty()) hash = m_hash;
83 return CORE->GetCore(
ResMgr)->GetAssetReference(std::move(hash));
86SResource* SResource::Create(
const std::string& name,
const std::string& classType) {
89 if (res !=
nullptr)
return res;
92 res->SetResource(name);
96SResource* SResource::Get(std::string& name) {
98 if (res !=
nullptr)
return res;
103 if (asset ==
nullptr)
return nullptr;
105 SResource* res = GetResource(asset->hash);
106 if (res !=
nullptr)
return res;