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() {
18 auto resMgr = CORE->GetCore(
ResMgr);
19 resMgr->Register(
this);
20 m_name =
"Resource " + std::to_string(resMgr->GetSize());
23SResource::SResource(
bool isRegister) {
24 m_name =
"Unregister Resource";
27SResource::SResource(
const SResource* resource,
bool isRegister) :
SObject(isRegister) {
29 CORE->GetCore(
ResMgr)->Register(
this);
31 m_name = resource->m_name +
" (instance)";
34SResource::~SResource() =
default;
36void SResource::SetName(std::string name) {
37 m_name = std::move(name);
40void SResource::SetAbsoluteID(std::string
id) {
41 m_absoluteId = std::move(
id);
44void SResource::SetResource(std::string name,
bool isInit) {
45 if (m_isInited)
return;
47 auto asset = CORE->GetCore(
ResMgr)->GetAssetReference(std::move(name));
49 SetResource(asset, isInit);
53 if (asset ==
nullptr)
return;
54 if (m_isInited)
return;
57 m_absoluteId = asset->id;
58 if(!asset->hash.empty()) {
59 std::string hash = asset->hash;
63 std::string meta =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
64 "<CSEMETA version=\"1.0.0\">\n"
65 "<hash-data hash=\"" + m_hash +
"\">\n"
66 "\n</hash-data>\n</CSEMETA>";
67 SaveTxtFile(asset->name_path +
".meta", meta);
75SResource* SResource::GetResource(std::string name) {
76 return CORE->GetCore(
ResMgr)->GetSResource(std::move(name));
79void SResource::SetHash(std::string& hash) {
80 std::string srcHash = m_hash;
81 SObject::SetHash(hash);
82 CORE->GetCore(
ResMgr)->ChangeHash(srcHash, hash);
86 if(hash.empty()) hash = m_hash;
87 return CORE->GetCore(
ResMgr)->GetAssetReference(std::move(hash));