2015-07-26 21:39:49 +00:00
|
|
|
#include "CTemplateLoader.h"
|
|
|
|
#include "CWorldLoader.h"
|
|
|
|
#include <Core/Log.h>
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void CTemplateLoader::LoadBitFlags(tinyxml2::XMLElement *pElem, CBitfieldTemplate *pTemp, const TString& templateName)
|
2015-10-25 23:43:11 +00:00
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pChild = pElem->FirstChildElement("bitflag");
|
|
|
|
|
|
|
|
while (pChild)
|
|
|
|
{
|
|
|
|
const char *kpMask = pChild->Attribute("mask");
|
|
|
|
const char *kpName = pChild->Attribute("name");
|
|
|
|
|
|
|
|
if (kpMask && kpName)
|
2015-11-24 06:08:31 +00:00
|
|
|
pTemp->mBitFlags.push_back(CBitfieldTemplate::SBitFlag(kpName, TString(kpMask).ToInt32()));
|
2015-10-25 23:43:11 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString LogErrorBase = "Couldn't parse bit flag in " + templateName + "; ";
|
2015-10-25 23:43:11 +00:00
|
|
|
|
|
|
|
if (!kpMask && kpName) Log::Error(LogErrorBase + "no mask (" + kpName + ")");
|
|
|
|
else if (kpMask && !kpName) Log::Error(LogErrorBase + "no name (mask " + kpMask + ")");
|
|
|
|
else Log::Error(LogErrorBase + "no valid ID or name");
|
|
|
|
}
|
|
|
|
|
|
|
|
pChild = pChild->NextSiblingElement("bitflag");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void CTemplateLoader::LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate *pTemp, const TString& templateName)
|
2015-10-19 10:35:05 +00:00
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pChild = pElem->FirstChildElement("enumerator");
|
|
|
|
|
|
|
|
while (pChild)
|
|
|
|
{
|
|
|
|
const char *kpID = pChild->Attribute("value");
|
|
|
|
const char *kpName = pChild->Attribute("name");
|
|
|
|
|
|
|
|
if (kpID && kpName)
|
2015-11-24 06:08:31 +00:00
|
|
|
pTemp->mEnumerators.push_back(CEnumTemplate::SEnumerator(kpName, TString(kpID).ToInt32()));
|
2015-10-19 10:35:05 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString LogErrorBase = "Couldn't parse enumerator in " + templateName + "; ";
|
2015-10-19 10:35:05 +00:00
|
|
|
|
2015-10-25 23:43:11 +00:00
|
|
|
if (!kpID && kpName) Log::Error(LogErrorBase + "no valid ID (" + kpName + ")");
|
|
|
|
else if (kpID && !kpName) Log::Error(LogErrorBase + "no valid name (ID " + kpID + ")");
|
2015-10-19 10:35:05 +00:00
|
|
|
else Log::Error(LogErrorBase + "no valid ID or name");
|
|
|
|
}
|
|
|
|
|
|
|
|
pChild = pChild->NextSiblingElement("enumerator");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void CTemplateLoader::LoadStructProperties(tinyxml2::XMLElement *pElem, CStructTemplate *pTemp, const TString& templateName)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLElement *pChild = pElem->FirstChildElement();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
while (pChild)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
CPropertyTemplate *pProp = LoadPropertyTemplate(pChild, templateName);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (pProp)
|
|
|
|
pTemp->mProperties.push_back(pProp);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
pChild = pChild->NextSiblingElement();
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *pElem, const TString& templateName)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
const char *kpIDStr = pElem->Attribute("ID");
|
|
|
|
const char *kpNameStr = pElem->Attribute("name");
|
|
|
|
const char *kpTypeStr = pElem->Attribute("type");
|
|
|
|
const char *kpExtensionsStr = pElem->Attribute("ext");
|
|
|
|
const char *kpTemplateStr = pElem->Attribute("template");
|
|
|
|
|
|
|
|
// Get ID + name, find source template if it exists
|
2015-11-24 06:08:31 +00:00
|
|
|
u32 ID = TString(kpIDStr).ToInt32();
|
2015-09-18 05:53:53 +00:00
|
|
|
CPropertyTemplate *pSource = nullptr;
|
2015-11-24 06:08:31 +00:00
|
|
|
TString name;
|
2015-09-18 05:53:53 +00:00
|
|
|
|
|
|
|
if (mpMaster->HasPropertyList())
|
|
|
|
pSource = mpMaster->GetProperty(ID);
|
|
|
|
|
|
|
|
if (kpNameStr)
|
|
|
|
name = kpNameStr;
|
|
|
|
else if (pSource)
|
|
|
|
name = pSource->Name();
|
2015-07-26 21:39:49 +00:00
|
|
|
else
|
2015-11-24 06:08:31 +00:00
|
|
|
name = TString::HexString(ID);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Load Property
|
|
|
|
if (strcmp(pElem->Name(), "property") == 0)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
CPropertyTemplate *pProp;
|
|
|
|
EPropertyType type = eInvalidProperty;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Type
|
|
|
|
if (kpTypeStr)
|
|
|
|
type = PropStringToPropEnum(kpTypeStr);
|
|
|
|
else if (pSource)
|
|
|
|
type = pSource->Type();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// File property
|
|
|
|
if (type == eFileProperty)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TStringList extensions;
|
2015-09-18 05:53:53 +00:00
|
|
|
if (kpExtensionsStr)
|
2015-11-24 06:08:31 +00:00
|
|
|
extensions = TString(kpExtensionsStr).Split(",");
|
2015-09-18 05:53:53 +00:00
|
|
|
else if (pSource)
|
|
|
|
extensions = static_cast<CFileTemplate*>(pSource)->Extensions();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
pProp = new CFileTemplate(name, ID, extensions);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Regular property
|
|
|
|
else
|
|
|
|
pProp = new CPropertyTemplate(type, name, ID);
|
|
|
|
|
|
|
|
return pProp;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Load Struct
|
|
|
|
else if (strcmp(pElem->Name(), "struct") == 0)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
CStructTemplate *pStruct = new CStructTemplate();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
pStruct->mPropID = ID;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Read children properties
|
|
|
|
// Priority: [Embedded] -> [Template] -> [Master]
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Embedded
|
|
|
|
if (!pElem->NoChildren())
|
|
|
|
LoadStructProperties(pElem, pStruct, templateName);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Template
|
|
|
|
else if (kpTemplateStr)
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString tempPath = mMasterDir + kpTemplateStr;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLDocument structXML;
|
2015-11-24 06:08:31 +00:00
|
|
|
structXML.LoadFile(*tempPath);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (structXML.Error())
|
|
|
|
Log::Error("Couldn't open struct XML: " + mMasterDir + kpTemplateStr);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pRoot = structXML.FirstChildElement("struct");
|
|
|
|
pStruct->mSourceFile = kpTemplateStr;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (pRoot->Attribute("type"))
|
|
|
|
pStruct->mIsSingleProperty = (strcmp(pRoot->Attribute("type"), "single") == 0);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (pRoot->Attribute("name"))
|
|
|
|
pStruct->mPropName = pRoot->Attribute("name");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
LoadStructProperties(pRoot, pStruct, templateName);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Master
|
|
|
|
else if (pSource)
|
|
|
|
{
|
|
|
|
CStructTemplate *pSourceStruct = static_cast<CStructTemplate*>(pSource);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
for (u32 iProp = 0; iProp < pSourceStruct->Count(); iProp++)
|
|
|
|
pStruct->mProperties.push_back(pSourceStruct->PropertyByIndex(iProp));
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// If it's none of these, then it probably has no children because it's a property list entry.
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Single property?
|
|
|
|
if (kpTypeStr)
|
|
|
|
pStruct->mIsSingleProperty = (strcmp(kpTypeStr, "single") == 0);
|
|
|
|
else if (pSource)
|
|
|
|
pStruct->mIsSingleProperty = static_cast<CStructTemplate*>(pSource)->IsSingleProperty();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Name
|
2015-11-24 06:08:31 +00:00
|
|
|
if (!name.IsEmpty())
|
2015-09-18 05:53:53 +00:00
|
|
|
pStruct->mPropName = name;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
return pStruct;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 10:35:05 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString tempPath = mMasterDir + kpTemplateStr;
|
2015-10-19 10:35:05 +00:00
|
|
|
|
|
|
|
tinyxml2::XMLDocument enumXML;
|
2015-11-24 06:08:31 +00:00
|
|
|
enumXML.LoadFile(*tempPath);
|
2015-10-19 10:35:05 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
2015-10-25 23:43:11 +00:00
|
|
|
}
|
2015-10-19 10:35:05 +00:00
|
|
|
|
2015-10-25 23:43:11 +00:00
|
|
|
// Name
|
2015-11-24 06:08:31 +00:00
|
|
|
if (!name.IsEmpty())
|
2015-10-25 23:43:11 +00:00
|
|
|
pEnum->mPropName = name;
|
2015-10-19 10:35:05 +00:00
|
|
|
|
2015-10-25 23:43:11 +00:00
|
|
|
return pEnum;
|
2015-10-19 10:35:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-25 23:43:11 +00:00
|
|
|
|
|
|
|
// Load Bitfield
|
|
|
|
else if (strcmp(pElem->Name(), "bitfield") == 0)
|
|
|
|
{
|
|
|
|
CBitfieldTemplate *pBitfield = new CBitfieldTemplate(ID);
|
|
|
|
|
|
|
|
// Embedded
|
|
|
|
if (!pElem->NoChildren())
|
|
|
|
LoadBitFlags(pElem, pBitfield, templateName);
|
|
|
|
|
|
|
|
// Template
|
|
|
|
else if (kpTemplateStr)
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString tempPath = mMasterDir + kpTemplateStr;
|
2015-10-25 23:43:11 +00:00
|
|
|
|
|
|
|
tinyxml2::XMLDocument bitfieldXML;
|
2015-11-24 06:08:31 +00:00
|
|
|
bitfieldXML.LoadFile(*tempPath);
|
2015-10-25 23:43:11 +00:00
|
|
|
|
|
|
|
if (bitfieldXML.Error())
|
|
|
|
Log::Error("Couldn't open bitfield XML: " + mMasterDir + kpTemplateStr);
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pRoot = bitfieldXML.FirstChildElement("bitfield");
|
|
|
|
pBitfield->mSourceFile = kpTemplateStr;
|
|
|
|
|
|
|
|
if (pRoot->Attribute("name"))
|
|
|
|
pBitfield->mPropName = pRoot->Attribute("name");
|
|
|
|
|
|
|
|
LoadBitFlags(pRoot, pBitfield, kpTemplateStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name
|
2015-11-24 06:08:31 +00:00
|
|
|
if (!name.IsEmpty())
|
2015-10-25 23:43:11 +00:00
|
|
|
pBitfield->mPropName = name;
|
|
|
|
|
|
|
|
return pBitfield;
|
|
|
|
}
|
2015-09-18 05:53:53 +00:00
|
|
|
return nullptr;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ************ SCRIPT OBJECT ************
|
2015-11-24 10:22:37 +00:00
|
|
|
CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc, const TString& /*templateName*/, u32 objectID)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
CScriptTemplate *pScript = new CScriptTemplate(mpMaster);
|
2015-09-18 05:53:53 +00:00
|
|
|
pScript->mObjectID = objectID;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLElement *pRoot = pDoc->FirstChildElement("ScriptTemplate");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Name
|
|
|
|
tinyxml2::XMLElement *pNameElem = pRoot->FirstChildElement("name");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (pNameElem)
|
|
|
|
pScript->mTemplateName = pNameElem->GetText();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Properties
|
|
|
|
tinyxml2::XMLElement *pPropsElem = pRoot->FirstChildElement("properties");
|
|
|
|
|
|
|
|
while (pPropsElem)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
CScriptTemplate::SPropertySet set;
|
|
|
|
|
|
|
|
const char *kpVersion = pPropsElem->Attribute("version");
|
|
|
|
set.SetName = (kpVersion ? kpVersion : "");
|
|
|
|
set.pBaseStruct = new CStructTemplate();
|
|
|
|
set.pBaseStruct->mIsSingleProperty = false;
|
|
|
|
set.pBaseStruct->mPropID = -1;
|
|
|
|
set.pBaseStruct->mPropName = pScript->mTemplateName;
|
|
|
|
LoadStructProperties(pPropsElem, set.pBaseStruct, pScript->mTemplateName);
|
|
|
|
pScript->mPropertySets.push_back(set);
|
|
|
|
|
|
|
|
pPropsElem = pPropsElem->NextSiblingElement("properties");
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Editor Parameters
|
|
|
|
tinyxml2::XMLElement *pEditor = pRoot->FirstChildElement("editor");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (pEditor)
|
|
|
|
{
|
|
|
|
// Editor Properties
|
|
|
|
tinyxml2::XMLElement *pEdProperties = pEditor->FirstChildElement("properties");
|
|
|
|
tinyxml2::XMLElement *pEdProp = pEdProperties->FirstChildElement("property");
|
|
|
|
|
|
|
|
while (pEdProp)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
const char *kpName = pEdProp->Attribute("name");
|
|
|
|
const char *kpID = pEdProp->Attribute("ID");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (kpName && kpID)
|
|
|
|
{
|
|
|
|
if (strcmp(kpName, "InstanceName") == 0)
|
|
|
|
pScript->mNameIDString = kpID;
|
|
|
|
else if (strcmp(kpName, "Position") == 0)
|
|
|
|
pScript->mPositionIDString = kpID;
|
|
|
|
else if (strcmp(kpName, "Rotation") == 0)
|
|
|
|
pScript->mRotationIDString = kpID;
|
|
|
|
else if (strcmp(kpName, "Scale") == 0)
|
|
|
|
pScript->mScaleIDString = kpID;
|
|
|
|
else if (strcmp(kpName, "Active") == 0)
|
|
|
|
pScript->mActiveIDString = kpID;
|
|
|
|
else if (strcmp(kpName, "LightParameters") == 0)
|
|
|
|
pScript->mLightParametersIDString = kpID;
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
pEdProp = pEdProp->NextSiblingElement("property");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Editor Assets
|
|
|
|
tinyxml2::XMLElement *pEdAssets = pEditor->FirstChildElement("assets");
|
|
|
|
tinyxml2::XMLElement *pAsset = pEdAssets->FirstChildElement();
|
|
|
|
|
|
|
|
while (pAsset)
|
|
|
|
{
|
|
|
|
const char *kpSource = pAsset->Attribute("source");
|
|
|
|
const char *kpID = pAsset->GetText();
|
|
|
|
|
|
|
|
if (kpSource && kpID)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
CScriptTemplate::SEditorAsset asset;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (strcmp(pAsset->Name(), "animparams") == 0)
|
|
|
|
asset.AssetType = CScriptTemplate::SEditorAsset::eAnimParams;
|
|
|
|
else if (strcmp(pAsset->Name(), "model") == 0)
|
|
|
|
asset.AssetType = CScriptTemplate::SEditorAsset::eModel;
|
2015-09-26 22:55:14 +00:00
|
|
|
else if (strcmp(pAsset->Name(), "collision") == 0)
|
|
|
|
asset.AssetType = CScriptTemplate::SEditorAsset::eCollision;
|
2015-09-18 05:53:53 +00:00
|
|
|
else
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
pAsset = pAsset->NextSiblingElement();
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (strcmp(kpSource, "property") == 0)
|
|
|
|
asset.AssetSource = CScriptTemplate::SEditorAsset::eProperty;
|
|
|
|
else if (strcmp(kpSource, "file") == 0)
|
|
|
|
asset.AssetSource = CScriptTemplate::SEditorAsset::eFile;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pAsset = pAsset->NextSiblingElement();
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
const char *kpForce = pAsset->Attribute("force");
|
|
|
|
if (kpForce)
|
2015-11-24 06:08:31 +00:00
|
|
|
asset.ForceNodeIndex = TString(kpForce).ToInt32();
|
2015-09-18 05:53:53 +00:00
|
|
|
else
|
|
|
|
asset.ForceNodeIndex = -1;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
asset.AssetLocation = kpID;
|
|
|
|
pScript->mAssets.push_back(asset);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
pAsset = pAsset->NextSiblingElement();
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Rotation
|
|
|
|
tinyxml2::XMLElement *pRotType = pEditor->FirstChildElement("rotation_type");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (pRotType)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
const char *kpType = pRotType->GetText();
|
|
|
|
|
|
|
|
if (kpType)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (strcmp(kpType, "disabled") == 0) pScript->mRotationType = CScriptTemplate::eRotationDisabled;
|
|
|
|
else pScript->mRotationType = CScriptTemplate::eRotationEnabled;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Scale
|
|
|
|
tinyxml2::XMLElement *pScaleType = pEditor->FirstChildElement("scale_type");
|
|
|
|
|
|
|
|
if (pScaleType)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
const char *kpType = pScaleType->GetText();
|
|
|
|
|
|
|
|
if (kpType)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (strcmp(kpType, "disabled") == 0) pScript->mScaleType = CScriptTemplate::eScaleDisabled;
|
|
|
|
else if (strcmp(kpType, "volume") == 0) pScript->mScaleType = CScriptTemplate::eScaleVolume;
|
|
|
|
else pScript->mScaleType = CScriptTemplate::eScaleEnabled;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Preview Volume
|
|
|
|
if (pScript->mScaleType == CScriptTemplate::eScaleVolume)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLElement *pVolume = pEditor->FirstChildElement("preview_volume");
|
|
|
|
|
|
|
|
// Lambda to avoid duplicating volume shape code
|
|
|
|
auto GetVolumeType = [](const char *kpType) -> EVolumeShape {
|
|
|
|
if (strcmp(kpType, "none") == 0) return eNoShape;
|
|
|
|
if (strcmp(kpType, "Box") == 0) return eBoxShape;
|
|
|
|
if (strcmp(kpType, "AxisAlignedBox") == 0) return eAxisAlignedBoxShape;
|
|
|
|
if (strcmp(kpType, "Ellipsoid") == 0) return eEllipsoidShape;
|
|
|
|
if (strcmp(kpType, "Cylinder") == 0) return eCylinderShape;
|
|
|
|
if (strcmp(kpType, "CylinderLarge") == 0) return eCylinderLargeShape;
|
|
|
|
if (strcmp(kpType, "Conditional") == 0) return eConditionalShape;
|
|
|
|
return eInvalidShape;
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *kpShape = pVolume->Attribute("shape");
|
|
|
|
|
|
|
|
if (kpShape)
|
|
|
|
pScript->mVolumeShape = GetVolumeType(kpShape);
|
|
|
|
|
|
|
|
// Conditional
|
|
|
|
if (pScript->mVolumeShape == eConditionalShape)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
const char *kpID = pVolume->Attribute("propertyID");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (kpID)
|
|
|
|
{
|
|
|
|
pScript->mVolumeConditionIDString = kpID;
|
|
|
|
tinyxml2::XMLElement *pCondition = pVolume->FirstChildElement("condition");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
while (pCondition)
|
|
|
|
{
|
|
|
|
const char *kpConditionValue = pCondition->Attribute("value");
|
|
|
|
const char *kpConditionShape = pCondition->Attribute("shape");
|
|
|
|
|
|
|
|
if (kpConditionValue && kpConditionShape)
|
|
|
|
{
|
|
|
|
CScriptTemplate::SVolumeCondition condition;
|
|
|
|
condition.Shape = GetVolumeType(kpConditionShape);
|
|
|
|
|
|
|
|
if (strcmp(kpConditionValue, "true") == 0)
|
|
|
|
condition.Value = 1;
|
|
|
|
else if (strcmp(kpConditionValue, "false") == 0)
|
|
|
|
condition.Value = 0;
|
|
|
|
else
|
2015-11-24 06:08:31 +00:00
|
|
|
condition.Value = TString(kpConditionValue).ToInt32();
|
2015-09-18 05:53:53 +00:00
|
|
|
|
|
|
|
pScript->mVolumeConditions.push_back(condition);
|
|
|
|
}
|
|
|
|
|
|
|
|
pCondition = pCondition->NextSiblingElement("condition");
|
|
|
|
}
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
return pScript;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ************ MASTER ************
|
|
|
|
void CTemplateLoader::LoadMasterTemplate(tinyxml2::XMLDocument *pDoc)
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLElement *pRoot = pDoc->FirstChildElement("MasterTemplate");
|
2015-11-24 06:08:31 +00:00
|
|
|
mpMaster->mVersion = TString(pRoot->Attribute("version")).ToInt32();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLElement *pElem = pRoot->FirstChildElement();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
while (pElem)
|
|
|
|
{
|
2015-07-26 21:39:49 +00:00
|
|
|
// Properties
|
2015-09-18 05:53:53 +00:00
|
|
|
if (strcmp(pElem->Name(), "properties") == 0)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString propListPath = mMasterDir + pElem->GetText();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLDocument propListXML;
|
2015-11-24 06:08:31 +00:00
|
|
|
propListXML.LoadFile(*propListPath);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (propListXML.Error())
|
|
|
|
Log::Error("Couldn't open property list: " + propListPath);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
else
|
2015-09-18 05:53:53 +00:00
|
|
|
LoadPropertyList(&propListXML, propListPath);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Objects
|
|
|
|
else if (strcmp(pElem->Name(), "objects") == 0)
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLElement *pObj = pElem->FirstChildElement("object");
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
while (pObj)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
// ID can either be a hex number or an ASCII fourCC
|
2015-11-24 06:08:31 +00:00
|
|
|
TString strID = pObj->Attribute("ID");
|
2015-09-18 05:53:53 +00:00
|
|
|
u32 ID;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
if (strID.IsHexString(true))
|
|
|
|
ID = strID.ToInt32();
|
2015-09-18 05:53:53 +00:00
|
|
|
else
|
|
|
|
ID = CFourCC(strID).ToLong();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
// Load up the object
|
2015-11-24 06:08:31 +00:00
|
|
|
TString templateName = pObj->Attribute("template");
|
|
|
|
TString templatePath = mMasterDir + templateName;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLDocument scriptXML;
|
2015-11-24 06:08:31 +00:00
|
|
|
scriptXML.LoadFile(*templatePath);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (scriptXML.Error())
|
|
|
|
Log::Error("Couldn't open script template: " + templatePath);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CScriptTemplate *pTemp = LoadScriptTemplate(&scriptXML, templateName, ID);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (pTemp)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
pTemp->mSourceFile = templateName;
|
|
|
|
mpMaster->mTemplates[ID] = pTemp;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
pObj = pObj->NextSiblingElement("object");
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// States
|
|
|
|
else if (strcmp(pElem->Name(), "states") == 0)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pState = pElem->FirstChildElement("state");
|
|
|
|
|
|
|
|
while (pState)
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString strID = pState->Attribute("ID");
|
2015-09-18 05:53:53 +00:00
|
|
|
u32 stateID;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
if (strID.IsHexString(true))
|
|
|
|
stateID = strID.ToInt32();
|
2015-07-26 21:39:49 +00:00
|
|
|
else
|
2015-09-18 05:53:53 +00:00
|
|
|
stateID = CFourCC(strID).ToLong();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
TString stateName = pState->Attribute("name");
|
2015-09-18 05:53:53 +00:00
|
|
|
mpMaster->mStates[stateID] = stateName;
|
2015-07-26 21:39:49 +00:00
|
|
|
pState = pState->NextSiblingElement("state");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Messages
|
|
|
|
else if (strcmp(pElem->Name(), "messages") == 0)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pMessage = pElem->FirstChildElement("message");
|
|
|
|
|
|
|
|
while (pMessage)
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString strID = pMessage->Attribute("ID");
|
2015-09-18 05:53:53 +00:00
|
|
|
u32 messageID;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
if (strID.IsHexString(true))
|
|
|
|
messageID = strID.ToInt32();
|
2015-07-26 21:39:49 +00:00
|
|
|
else
|
2015-09-18 05:53:53 +00:00
|
|
|
messageID = CFourCC(strID).ToLong();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
TString messageName = pMessage->Attribute("name");
|
2015-09-18 05:53:53 +00:00
|
|
|
mpMaster->mMessages[messageID] = messageName;
|
2015-07-26 21:39:49 +00:00
|
|
|
pMessage = pMessage->NextSiblingElement("message");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
pElem = pElem->NextSiblingElement();
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void CTemplateLoader::LoadPropertyList(tinyxml2::XMLDocument *pDoc, const TString& listName)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pElem = pDoc->FirstChildElement()->FirstChildElement();
|
|
|
|
|
|
|
|
while (pElem)
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
CPropertyTemplate *pProp = LoadPropertyTemplate(pElem, listName);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
if (pProp)
|
|
|
|
mpMaster->mPropertyList[pProp->PropertyID()] = pProp;
|
|
|
|
|
|
|
|
pElem = pElem->NextSiblingElement();
|
|
|
|
}
|
2015-09-18 05:53:53 +00:00
|
|
|
|
|
|
|
mpMaster->mHasPropList = true;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CMasterTemplate* CTemplateLoader::LoadGame(tinyxml2::XMLNode *pNode)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pGameElem = pNode->FirstChildElement();
|
|
|
|
mpMaster = new CMasterTemplate();
|
|
|
|
|
|
|
|
// Parse game parameters
|
|
|
|
while (pGameElem)
|
|
|
|
{
|
|
|
|
if (strcmp(pGameElem->Name(), "name") == 0)
|
|
|
|
mpMaster->mGameName = pGameElem->GetText();
|
|
|
|
|
|
|
|
else if (strcmp(pGameElem->Name(), "mlvl") == 0)
|
|
|
|
{
|
|
|
|
u32 VersionNum = std::stoul(pGameElem->GetText(), 0, 16);
|
|
|
|
mpMaster->mGame = CWorldLoader::GetFormatVersion(VersionNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp(pGameElem->Name(), "master") == 0)
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
TString MasterPath = mTemplatesDir + pGameElem->GetText();
|
|
|
|
mMasterDir = MasterPath.GetFileDirectory();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
tinyxml2::XMLDocument MasterXML;
|
2015-11-24 06:08:31 +00:00
|
|
|
MasterXML.LoadFile(*MasterPath);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
if (MasterXML.Error())
|
2015-09-18 05:53:53 +00:00
|
|
|
{
|
2015-07-26 21:39:49 +00:00
|
|
|
Log::Error("Couldn't open master template at " + MasterPath + " - error " + std::to_string(MasterXML.ErrorID()));
|
2015-09-18 05:53:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
else
|
2015-09-18 05:53:53 +00:00
|
|
|
{
|
2015-07-26 21:39:49 +00:00
|
|
|
LoadMasterTemplate(&MasterXML);
|
2015-09-18 05:53:53 +00:00
|
|
|
mpMaster->mSourceFile = pGameElem->GetText();
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
pGameElem = pGameElem->NextSiblingElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
mpMaster->mFullyLoaded = true;
|
|
|
|
return mpMaster;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ************ PUBLIC ************
|
|
|
|
void CTemplateLoader::LoadGameList()
|
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
static const TString skTemplatesDir = "../templates/";
|
|
|
|
static const TString skGameListPath = skTemplatesDir + "GameList.xml";
|
2015-07-26 21:39:49 +00:00
|
|
|
Log::Write("Loading game list");
|
|
|
|
|
|
|
|
// Load Game List XML
|
|
|
|
tinyxml2::XMLDocument GameListXML;
|
2015-11-24 06:08:31 +00:00
|
|
|
GameListXML.LoadFile(*skGameListPath);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
if (GameListXML.Error())
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
Log::Error("Couldn't open game list at " + skGameListPath + " - error " + std::to_string(GameListXML.ErrorID()));
|
2015-07-26 21:39:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse
|
|
|
|
tinyxml2::XMLNode *pNode = GameListXML.FirstChild()->NextSibling()->FirstChild();
|
|
|
|
|
|
|
|
while (pNode)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLElement *pElement = pNode->ToElement();
|
|
|
|
|
|
|
|
// Game List version number
|
|
|
|
if (strcmp(pElement->Name(), "version") == 0)
|
|
|
|
{
|
|
|
|
u32 VersionNum = std::stoul(pElement->GetText());
|
|
|
|
CMasterTemplate::smGameListVersion = VersionNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Games
|
|
|
|
else if (strcmp(pElement->Name(), "game") == 0)
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
CTemplateLoader Loader(skTemplatesDir);
|
2015-07-26 21:39:49 +00:00
|
|
|
CMasterTemplate *pMaster = Loader.LoadGame(pNode);
|
|
|
|
|
|
|
|
if (!pMaster->IsLoadedSuccessfully())
|
|
|
|
{
|
|
|
|
Log::Error("Master template for " + pMaster->mGameName + " couldn't be loaded");
|
|
|
|
delete pMaster;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
CMasterTemplate::smMasterMap[pMaster->mGame] = pMaster;
|
|
|
|
}
|
|
|
|
|
|
|
|
pNode = pNode->NextSibling();
|
|
|
|
}
|
|
|
|
}
|