2015-07-26 21:39:49 +00:00
|
|
|
#include "CTemplateLoader.h"
|
|
|
|
#include "CWorldLoader.h"
|
|
|
|
#include <Core/Log.h>
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
void CTemplateLoader::LoadStructProperties(tinyxml2::XMLElement *pElem, CStructTemplate *pTemp, const std::string& 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-09-18 05:53:53 +00:00
|
|
|
CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *pElem, const std::string& 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
|
|
|
|
u32 ID = StringUtil::ToInt32(kpIDStr);
|
|
|
|
CPropertyTemplate *pSource = nullptr;
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
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-09-18 05:53:53 +00:00
|
|
|
name = StringUtil::ToHexString(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-09-18 05:53:53 +00:00
|
|
|
CStringList extensions;
|
|
|
|
if (kpExtensionsStr)
|
|
|
|
extensions = StringUtil::Tokenize(kpExtensionsStr, ",");
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
std::string tempPath = mMasterDir + kpTemplateStr;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLDocument structXML;
|
|
|
|
structXML.LoadFile(tempPath.c_str());
|
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
|
|
|
|
if (!name.empty())
|
|
|
|
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-09-18 05:53:53 +00:00
|
|
|
return nullptr;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ************ SCRIPT OBJECT ************
|
2015-09-18 05:53:53 +00:00
|
|
|
CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc, const std::string& 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;
|
|
|
|
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)
|
|
|
|
asset.ForceNodeIndex = StringUtil::ToInt32(kpForce);
|
|
|
|
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
|
|
|
|
condition.Value = StringUtil::ToInt32(kpConditionValue);
|
|
|
|
|
|
|
|
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");
|
|
|
|
mpMaster->mVersion = StringUtil::ToInt32(pRoot->Attribute("version"));
|
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-09-18 05:53:53 +00:00
|
|
|
std::string propListPath = mMasterDir + pElem->GetText();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLDocument propListXML;
|
|
|
|
propListXML.LoadFile(propListPath.c_str());
|
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
|
|
|
|
std::string strID = pObj->Attribute("ID");
|
|
|
|
u32 ID;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (StringUtil::IsHexString(strID, true))
|
|
|
|
ID = StringUtil::ToInt32(strID);
|
|
|
|
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
|
|
|
|
std::string templateName = pObj->Attribute("template");
|
|
|
|
std::string templatePath = mMasterDir + templateName;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
tinyxml2::XMLDocument scriptXML;
|
|
|
|
scriptXML.LoadFile(templatePath.c_str());
|
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-09-18 05:53:53 +00:00
|
|
|
std::string strID = pState->Attribute("ID");
|
|
|
|
u32 stateID;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (StringUtil::IsHexString(strID, true))
|
|
|
|
stateID = StringUtil::ToInt32(strID);
|
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-09-18 05:53:53 +00:00
|
|
|
std::string stateName = pState->Attribute("name");
|
|
|
|
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-09-18 05:53:53 +00:00
|
|
|
std::string strID = pMessage->Attribute("ID");
|
|
|
|
u32 messageID;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if (StringUtil::IsHexString(strID, true))
|
|
|
|
messageID = StringUtil::ToInt32(strID);
|
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-09-18 05:53:53 +00:00
|
|
|
std::string messageName = pMessage->Attribute("name");
|
|
|
|
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-09-18 05:53:53 +00:00
|
|
|
void CTemplateLoader::LoadPropertyList(tinyxml2::XMLDocument *pDoc, const std::string& 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)
|
|
|
|
{
|
|
|
|
std::string MasterPath = mTemplatesDir + pGameElem->GetText();
|
|
|
|
mMasterDir = StringUtil::GetFileDirectory(MasterPath);
|
|
|
|
|
|
|
|
tinyxml2::XMLDocument MasterXML;
|
|
|
|
MasterXML.LoadFile(MasterPath.c_str());
|
|
|
|
|
|
|
|
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-09-18 05:53:53 +00:00
|
|
|
static const std::string skTemplatesDir = "../templates/";
|
|
|
|
static const std::string 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-09-18 05:53:53 +00:00
|
|
|
GameListXML.LoadFile(skGameListPath.c_str());
|
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();
|
|
|
|
}
|
|
|
|
}
|