mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-14 10:46:10 +00:00
Add ability to reference resources by name
This commit is contained in:
@@ -17,31 +17,26 @@ ProjectResourceFactory::ProjectResourceFactory()
|
||||
m_factoryMgr.AddFactory(HECL::FOURCC('PART'), pshag::FParticleFactory);
|
||||
}
|
||||
|
||||
void ProjectResourceFactory::RecursiveAddDirObjects(const HECL::ProjectPath& path)
|
||||
{
|
||||
HECL::DirectoryEnumerator de = path.enumerateDir();
|
||||
for (const HECL::DirectoryEnumerator::Entry& ent : de)
|
||||
{
|
||||
if (ent.m_isDir)
|
||||
RecursiveAddDirObjects(HECL::ProjectPath(path, ent.m_name));
|
||||
if (ent.m_name.size() == 13 && ent.m_name[4] == _S('_'))
|
||||
{
|
||||
HECL::SystemUTF8View entu8(ent.m_name);
|
||||
u32 id = strtoul(entu8.c_str() + 5, nullptr, 16);
|
||||
if (id)
|
||||
{
|
||||
pshag::SObjectTag objTag = {HECL::FourCC(entu8.c_str()), id};
|
||||
if (m_resPaths.find(objTag) == m_resPaths.end())
|
||||
m_resPaths[objTag] = HECL::ProjectPath(path, ent.m_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectResourceFactory::BuildObjectMap(const HECL::Database::Project::ProjectDataSpec& spec)
|
||||
void ProjectResourceFactory::BuildObjectMap(const HECL::Database::Project::ProjectDataSpec &spec)
|
||||
{
|
||||
m_resPaths.clear();
|
||||
RecursiveAddDirObjects(spec.cookedPath);
|
||||
m_namedResources.clear();
|
||||
HECL::SystemString catalogPath = HECL::ProjectPath(spec.cookedPath, std::string(spec.spec.m_name) + "/catalog.yaml").getAbsolutePath();
|
||||
FILE* catalogFile = HECL::Fopen(catalogPath.c_str(), _S("r"));
|
||||
if (!HECL::StrCmp(spec.spec.m_name, "MP3"))
|
||||
{
|
||||
DataSpec::NamedResourceCatalog<DataSpec::UniqueID64> catalog;
|
||||
if (catalogFile)
|
||||
catalog.fromYAMLFile(catalogFile);
|
||||
RecursiveAddDirObjects(spec.cookedPath, catalog);
|
||||
}
|
||||
else
|
||||
{
|
||||
DataSpec::NamedResourceCatalog<DataSpec::UniqueID32> catalog;
|
||||
if (catalogFile)
|
||||
catalog.fromYAMLFile(catalogFile);
|
||||
RecursiveAddDirObjects(spec.cookedPath, catalog);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<pshag::IObj> ProjectResourceFactory::Build(const pshag::SObjectTag& tag,
|
||||
@@ -83,9 +78,12 @@ bool ProjectResourceFactory::CanBuild(const pshag::SObjectTag& tag)
|
||||
return true;
|
||||
}
|
||||
|
||||
const pshag::SObjectTag* ProjectResourceFactory::GetResourceIdByName(const char*) const
|
||||
const pshag::SObjectTag* ProjectResourceFactory::GetResourceIdByName(const char* name) const
|
||||
{
|
||||
return nullptr;
|
||||
if (m_namedResources.find(name) == m_namedResources.end())
|
||||
return nullptr;
|
||||
const pshag::SObjectTag& tag = m_namedResources.at(name);
|
||||
return &tag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user