mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-13 07:06:19 +00:00
Added support for enum properties
This commit is contained in:
@@ -58,6 +58,13 @@ CPropertyStruct* CScriptLoader::LoadStructMP1(CInputStream& SCLY, CStructTemplat
|
||||
pProp = new CLongProperty(v);
|
||||
break;
|
||||
}
|
||||
case eEnumProperty: {
|
||||
CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pPropTmp);
|
||||
long ID = SCLY.ReadLong();
|
||||
long index = pTemp->EnumeratorIndex(ID);
|
||||
pProp = new CEnumProperty(index);
|
||||
break;
|
||||
}
|
||||
case eFloatProperty: {
|
||||
float v = SCLY.ReadFloat();
|
||||
pProp = new CFloatProperty(v);
|
||||
@@ -265,6 +272,15 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct,
|
||||
break;
|
||||
}
|
||||
|
||||
case eEnumProperty: {
|
||||
CEnumProperty *pEnumCast = static_cast<CEnumProperty*>(pProp);
|
||||
CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pPropTemp);
|
||||
long ID = SCLY.ReadLong();
|
||||
long index = pTemp->EnumeratorIndex(ID);
|
||||
pEnumCast->Set(index);
|
||||
break;
|
||||
}
|
||||
|
||||
case eFloatProperty: {
|
||||
CFloatProperty *pFloatCast = static_cast<CFloatProperty*>(pProp);
|
||||
pFloatCast->Set(SCLY.ReadFloat());
|
||||
|
||||
@@ -2,6 +2,31 @@
|
||||
#include "CWorldLoader.h"
|
||||
#include <Core/Log.h>
|
||||
|
||||
void CTemplateLoader::LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate *pTemp, const std::string& templateName)
|
||||
{
|
||||
tinyxml2::XMLElement *pChild = pElem->FirstChildElement("enumerator");
|
||||
|
||||
while (pChild)
|
||||
{
|
||||
const char *kpID = pChild->Attribute("value");
|
||||
const char *kpName = pChild->Attribute("name");
|
||||
|
||||
if (kpID && kpName)
|
||||
pTemp->mEnumerators.push_back(CEnumTemplate::SEnumerator(kpName, StringUtil::ToInt32(kpID)));
|
||||
|
||||
else
|
||||
{
|
||||
std::string LogErrorBase = "Couldn't parse enumerator in " + templateName + "; ";
|
||||
|
||||
if (!kpID && kpName) Log::Error(LogErrorBase + "no valid ID (" + kpName + ")");
|
||||
if (kpID && !kpName) Log::Error(LogErrorBase + "no valid name (ID " + kpID + ")");
|
||||
else Log::Error(LogErrorBase + "no valid ID or name");
|
||||
}
|
||||
|
||||
pChild = pChild->NextSiblingElement("enumerator");
|
||||
}
|
||||
}
|
||||
|
||||
void CTemplateLoader::LoadStructProperties(tinyxml2::XMLElement *pElem, CStructTemplate *pTemp, const std::string& templateName)
|
||||
{
|
||||
tinyxml2::XMLElement *pChild = pElem->FirstChildElement();
|
||||
@@ -135,6 +160,48 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p
|
||||
return pStruct;
|
||||
}
|
||||
|
||||
// Load Enum
|
||||
else if (strcmp(pElem->Name(), "enum") == 0)
|
||||
{
|
||||
CEnumTemplate *pEnum = new CEnumTemplate(ID);
|
||||
|
||||
// Read children enumerators
|
||||
// Priority: [Embedded] -> [Template]
|
||||
|
||||
// Embedded
|
||||
if (!pElem->NoChildren())
|
||||
LoadEnumerators(pElem, pEnum, templateName);
|
||||
|
||||
// Template
|
||||
else if (kpTemplateStr)
|
||||
{
|
||||
std::string tempPath = mMasterDir + kpTemplateStr;
|
||||
|
||||
tinyxml2::XMLDocument enumXML;
|
||||
enumXML.LoadFile(tempPath.c_str());
|
||||
|
||||
if (enumXML.Error())
|
||||
Log::Error("Couldn't open enum XML: " + mMasterDir + kpTemplateStr);
|
||||
|
||||
else
|
||||
{
|
||||
tinyxml2::XMLElement *pRoot = enumXML.FirstChildElement("enum");
|
||||
pEnum->mSourceFile = kpTemplateStr;
|
||||
|
||||
if (pRoot->Attribute("name"))
|
||||
pEnum->mPropName = pRoot->Attribute("name");
|
||||
|
||||
LoadEnumerators(pRoot, pEnum, kpTemplateStr );
|
||||
}
|
||||
|
||||
// Name
|
||||
if (!name.empty())
|
||||
pEnum->mPropName = name;
|
||||
|
||||
return pEnum;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ class CTemplateLoader
|
||||
CTemplateLoader(const std::string& templatesDir) : mTemplatesDir(templatesDir) {}
|
||||
|
||||
// Load Property
|
||||
void LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate *pTemp, const std::string& templateName);
|
||||
void LoadStructProperties(tinyxml2::XMLElement *pElem, CStructTemplate *pTemp, const std::string& templateName);
|
||||
CPropertyTemplate* LoadPropertyTemplate(tinyxml2::XMLElement *pElem, const std::string& templateName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user