Updated script templates to version 3 + added script template writer class

This commit is contained in:
parax0
2015-09-17 23:53:53 -06:00
parent f82b3a20a9
commit 97ef20d0d2
29 changed files with 1914 additions and 1287 deletions

View File

@@ -6,6 +6,7 @@ CMasterTemplate::CMasterTemplate()
{
mVersion = 0;
mFullyLoaded = false;
mHasPropList = false;
}
CMasterTemplate::~CMasterTemplate()
@@ -92,15 +93,17 @@ CPropertyTemplate* CMasterTemplate::GetProperty(u32 PropertyID)
return nullptr;
}
bool CMasterTemplate::HasPropertyList()
{
return mHasPropList;
}
bool CMasterTemplate::IsLoadedSuccessfully()
{
return mFullyLoaded;
}
// ************ STATIC ************
std::unordered_map<EGame, CMasterTemplate*> CMasterTemplate::smMasterMap;
u32 CMasterTemplate::smGameListVersion;
CMasterTemplate* CMasterTemplate::GetMasterForGame(EGame Game)
{
auto it = smMasterMap.find(Game);
@@ -110,3 +113,16 @@ CMasterTemplate* CMasterTemplate::GetMasterForGame(EGame Game)
else
return nullptr;
}
std::list<CMasterTemplate*> CMasterTemplate::GetMasterList()
{
std::list<CMasterTemplate*> list;
for (auto it = smMasterMap.begin(); it != smMasterMap.end(); it++)
list.push_back(it->second);
return list;
}
std::map<EGame, CMasterTemplate*> CMasterTemplate::smMasterMap;
u32 CMasterTemplate::smGameListVersion;

View File

@@ -5,27 +5,29 @@
#include "CTemplateCategory.h"
#include "../EFormatVersion.h"
#include <Common/types.h>
#include <unordered_map>
#include <map>
#include <tinyxml2.h>
class CMasterTemplate
{
friend class CTemplateLoader;
friend class CTemplateWriter;
EGame mGame;
std::string mGameName;
std::string mSourceFile;
u32 mVersion;
bool mFullyLoaded;
std::unordered_map<u32, CScriptTemplate*> mTemplates;
std::unordered_map<u32, std::string> mStates;
std::unordered_map<u32, std::string> mMessages;
std::map<u32, CScriptTemplate*> mTemplates;
std::map<u32, std::string> mStates;
std::map<u32, std::string> mMessages;
std::vector<CTemplateCategory> mCategories;
bool mHasPropList;
std::unordered_map<u32, CPropertyTemplate*> mPropertyList;
std::map<u32, CPropertyTemplate*> mPropertyList;
static std::unordered_map<EGame, CMasterTemplate*> smMasterMap;
static std::map<EGame, CMasterTemplate*> smMasterMap;
static u32 smGameListVersion;
public:
@@ -45,9 +47,11 @@ public:
std::string MessageByID(const CFourCC& MessageID);
std::string MessageByIndex(u32 Index);
CPropertyTemplate* GetProperty(u32 PropertyID);
bool HasPropertyList();
bool IsLoadedSuccessfully();
static CMasterTemplate* GetMasterForGame(EGame Game);
static std::list<CMasterTemplate*> GetMasterList();
};
// ************ INLINE ************

View File

@@ -0,0 +1,121 @@
#include "CProperty.h"
// ************ CPropertyStruct ************
CPropertyStruct::~CPropertyStruct()
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
delete *it;
}
CPropertyBase* CPropertyStruct::PropertyByIndex(u32 index)
{
return mProperties[index];
}
CPropertyBase* CPropertyStruct::PropertyByID(u32 ID)
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
{
if ((*it)->ID() == ID)
return *it;
}
return nullptr;
}
CPropertyBase* CPropertyStruct::PropertyByIDString(const TIDString& str)
{
// Resolve namespace
std::string::size_type nsStart = str.find_first_of(":");
std::string::size_type propStart = nsStart + 1;
// String has namespace; the requested property is within a struct
if (nsStart != std::string::npos)
{
std::string strStructID = str.substr(0, nsStart);
if (!StringUtil::IsHexString(strStructID)) return nullptr;
u32 structID = StringUtil::ToInt32(strStructID);
std::string propName = str.substr(propStart, str.length() - propStart);
CPropertyStruct *pStruct = StructByID(structID);
if (!pStruct) return nullptr;
else return pStruct->PropertyByIDString(propName);
}
// No namespace; fetch the property from this struct
else
{
if (StringUtil::IsHexString(str))
return PropertyByID(StringUtil::ToInt32(str));
else
return nullptr;
}
}
CPropertyStruct* CPropertyStruct::StructByIndex(u32 index)
{
CPropertyBase *pProp = PropertyByIndex(index);
if (pProp->Type() == eStructProperty)
return static_cast<CPropertyStruct*>(pProp);
else
return nullptr;
}
CPropertyStruct* CPropertyStruct::StructByID(u32 ID)
{
CPropertyBase *pProp = PropertyByID(ID);
if (pProp->Type() == eStructProperty)
return static_cast<CPropertyStruct*>(pProp);
else
return nullptr;
}
CPropertyStruct* CPropertyStruct::StructByIDString(const TIDString& str)
{
CPropertyBase *pProp = PropertyByIDString(str);
if (pProp->Type() == eStructProperty)
return static_cast<CPropertyStruct*>(pProp);
else
return nullptr;
}
// ************ STATIC ************
CPropertyStruct* CPropertyStruct::CopyFromTemplate(CStructTemplate *pTemp)
{
CPropertyStruct *pStruct = new CPropertyStruct();
pStruct->mpTemplate = pTemp;
pStruct->Reserve(pTemp->Count());
for (u32 iProp = 0; iProp < pTemp->Count(); iProp++)
{
CPropertyTemplate *pPropTemp = pTemp->PropertyByIndex(iProp);
CPropertyBase *pProp = nullptr;
switch (pPropTemp->Type())
{
case eBoolProperty: pProp = new CBoolProperty(false); break;
case eByteProperty: pProp = new CByteProperty(0); break;
case eShortProperty: pProp = new CShortProperty(0); break;
case eLongProperty: pProp = new CLongProperty(0); break;
case eFloatProperty: pProp = new CFloatProperty(0.f); break;
case eStringProperty: pProp = new CStringProperty(""); break;
case eVector3Property: pProp = new CVector3Property(CVector3f::skZero); break;
case eColorProperty: pProp = new CColorProperty(CColor::skBlack); break;
case eFileProperty: pProp = new CFileProperty(); break;
case eArrayProperty: pProp = new CArrayProperty(); break;
case eUnknownProperty: pProp = new CUnknownProperty(); break;
case eStructProperty: pProp = CPropertyStruct::CopyFromTemplate(static_cast<CStructTemplate*>(pPropTemp)); break;
}
if (pProp)
{
pProp->SetTemplate(pPropTemp);
pStruct->mProperties.push_back(pProp);
}
}
return pStruct;
}

View File

@@ -7,7 +7,7 @@
* It's a bit hard to read, should be reorganized at some point
*/
#include "../CResource.h"
#include "CScriptTemplate.h"
#include "CPropertyTemplate.h"
#include "EPropertyType.h"
#include <Common/CColor.h>
#include <Common/CVector3f.h>
@@ -15,6 +15,10 @@
#include <string>
#include <list>
class CScriptTemplate;
typedef std::string TIDString;
/*
* CPropertyBase is the base class, containing just some virtual function definitions
* Virtual destructor is mainly there to make cleanup easy; don't need to cast to delete
@@ -23,14 +27,14 @@ class CPropertyBase
{
friend class CScriptLoader;
protected:
CPropertyTemplate *tmp;
CPropertyTemplate *mpTemplate;
public:
virtual ~CPropertyBase() {}
virtual EPropertyType Type() = 0;
CPropertyTemplate *Template() { return tmp; }
void SetTemplate(CPropertyTemplate *_tmp) { tmp = _tmp; }
std::string Name() { return tmp->Name(); }
u32 ID() { return tmp->PropertyID(); }
inline virtual EPropertyType Type() = 0;
inline CPropertyTemplate *Template() { return mpTemplate; }
inline void SetTemplate(CPropertyTemplate *_tmp) { mpTemplate = _tmp; }
inline std::string Name() { return mpTemplate->Name(); }
inline u32 ID() { return mpTemplate->PropertyID(); }
};
/*
@@ -41,14 +45,14 @@ template <typename t, EPropertyType type>
class __CProperty : public CPropertyBase
{
friend class CScriptLoader;
t Value;
t mValue;
public:
__CProperty() {}
__CProperty(t v) { Set(v); }
~__CProperty() {}
EPropertyType Type() { return type; }
t Get() { return Value; }
void Set(t v) { Value = v; }
inline EPropertyType Type() { return type; }
inline t Get() { return mValue; }
inline void Set(t v) { mValue = v; }
};
typedef __CProperty<bool, eBoolProperty> CBoolProperty;
typedef __CProperty<char, eByteProperty> CByteProperty;
@@ -59,6 +63,7 @@ typedef __CProperty<std::string, eStringProperty> CStringProperty;
typedef __CProperty<CVector3f, eVector3Property> CVector3Property;
typedef __CProperty<CColor, eColorProperty> CColorProperty;
typedef __CProperty<CResource*, eFileProperty> CFileProperty;
typedef __CProperty<std::vector<u8>, eArrayProperty> CArrayProperty;
typedef __CProperty<std::vector<u8>, eUnknownProperty> CUnknownProperty;
/*
@@ -67,28 +72,28 @@ typedef __CProperty<std::vector<u8>, eUnknownProperty> CUnknownProperty;
template <>
class __CProperty<CResource*, eFileProperty> : public CPropertyBase
{
CResource *Value;
CResource *mValue;
CToken mToken;
public:
__CProperty<CResource*, eFileProperty>() {
Value = nullptr;
mValue = nullptr;
}
__CProperty<CResource*, eFileProperty>(CResource* v) {
Value = v;
mValue = v;
mToken = CToken(v);
}
~__CProperty<CResource*, eFileProperty>() {}
EPropertyType Type() { return eFileProperty; }
CResource* Get() { return Value; }
void Set(CResource *v)
inline EPropertyType Type() { return eFileProperty; }
inline CResource* Get() { return mValue; }
inline void Set(CResource *v)
{
if (Value != v)
if (mValue != v)
{
Value = v;
mValue = v;
mToken = CToken(v);
}
}
@@ -104,128 +109,27 @@ public:
class CPropertyStruct : public CPropertyBase
{
friend class CScriptLoader;
std::vector<CPropertyBase*> Properties;
std::vector<CPropertyBase*> mProperties;
public:
// Destructor simply iterates through the list and deletes them. Nothing complicated.
~CPropertyStruct()
{
for (auto it = Properties.begin(); it != Properties.end(); it++)
delete *it;
}
~CPropertyStruct();
// Inline
EPropertyType Type() { return eStructProperty; }
u32 Count() { return Properties.size(); }
void Reserve(u32 amount) { Properties.reserve(amount); }
CPropertyBase* PropertyByIndex(u32 index) { return Properties[index]; }
CPropertyBase* PropertyByName(std::string name)
{
// Resolve namespace
std::string::size_type NsStart = name.find_first_of("::");
std::string::size_type PropStart = NsStart + 2;
inline u32 Count() { return mProperties.size(); }
inline void Reserve(u32 amount) { mProperties.reserve(amount); }
inline CPropertyBase* operator[](u32 index) { return mProperties[index]; }
// Namespace; the requested property is within a struct
if (NsStart != std::string::npos)
{
std::string StructName = name.substr(0, NsStart);
std::string PropName = name.substr(PropStart, name.length() - PropStart);
// Functions
CPropertyBase* PropertyByIndex(u32 index);
CPropertyBase* PropertyByID(u32 ID);
CPropertyBase* PropertyByIDString(const TIDString& str);
CPropertyStruct* StructByIndex(u32 index);
CPropertyStruct* StructByID(u32 ID);
CPropertyStruct* StructByIDString(const TIDString& str);
CPropertyStruct *Struct = StructByName(StructName);
if (!Struct) return nullptr;
else return Struct->PropertyByName(PropName);
}
// No namespace; fetch the property from this struct
else
{
// ID string lookup
if (StringUtil::IsHexString(name))
return PropertyByID(std::stoul(name, 0, 16));
// Name lookup
else
{
for (auto it = Properties.begin(); it != Properties.end(); it++)
{
if ((*it)->Name() == name)
return *it;
}
return nullptr;
}
}
}
CPropertyBase* PropertyByID(u32 ID)
{
for (auto it = Properties.begin(); it != Properties.end(); it++)
{
if ((*it)->ID() == ID)
return *it;
}
return nullptr;
}
CPropertyStruct* StructByIndex(u32 index)
{
CPropertyBase *prop = PropertyByIndex(index);
if (prop->Type() == eStructProperty)
return static_cast<CPropertyStruct*>(prop);
else
return nullptr;
}
CPropertyStruct* StructByName(std::string name)
{
CPropertyBase *prop = PropertyByName(name);
if (prop->Type() == eStructProperty)
return static_cast<CPropertyStruct*>(prop);
else
return nullptr;
}
CPropertyStruct* StructByID(u32 ID)
{
CPropertyBase *prop = PropertyByID(ID);
if (prop->Type() == eStructProperty)
return static_cast<CPropertyStruct*>(prop);
else
return nullptr;
}
inline CPropertyBase* operator[](u32 index) { return Properties[index]; }
static CPropertyStruct* CopyFromTemplate(CStructTemplate *pTemp)
{
CPropertyStruct *pStruct = new CPropertyStruct();
pStruct->tmp = pTemp;
pStruct->Reserve(pTemp->Count());
for (u32 iProp = 0; iProp < pTemp->Count(); iProp++)
{
CPropertyTemplate *pPropTemp = pTemp->PropertyByIndex(iProp);
CPropertyBase *pProp = nullptr;
switch (pPropTemp->Type())
{
case eBoolProperty: pProp = new CBoolProperty(false); break;
case eByteProperty: pProp = new CByteProperty(0); break;
case eShortProperty: pProp = new CShortProperty(0); break;
case eLongProperty: pProp = new CLongProperty(0); break;
case eFloatProperty: pProp = new CFloatProperty(0.f); break;
case eStringProperty: pProp = new CStringProperty(""); break;
case eVector3Property: pProp = new CVector3Property(CVector3f::skZero); break;
case eColorProperty: pProp = new CColorProperty(CColor::skBlack); break;
case eFileProperty: pProp = new CFileProperty(); break;
case eUnknownProperty: pProp = new CUnknownProperty(); break;
case eStructProperty: pProp = CPropertyStruct::CopyFromTemplate(static_cast<CStructTemplate*>(pPropTemp)); break;
}
if (pProp)
{
pProp->SetTemplate(pPropTemp);
pStruct->Properties.push_back(pProp);
}
}
return pStruct;
}
// Static
static CPropertyStruct* CopyFromTemplate(CStructTemplate *pTemp);
};
#endif // CPROPERTY

View File

@@ -0,0 +1,169 @@
#include "CPropertyTemplate.h"
#include <iostream>
EPropertyType PropStringToPropEnum(std::string prop)
{
if (prop == "bool") return eBoolProperty;
if (prop == "byte") return eByteProperty;
if (prop == "short") return eShortProperty;
if (prop == "long") return eLongProperty;
if (prop == "float") return eFloatProperty;
if (prop == "string") return eStringProperty;
if (prop == "color") return eColorProperty;
if (prop == "vector3f") return eVector3Property;
if (prop == "file") return eFileProperty;
if (prop == "struct") return eStructProperty;
if (prop == "array") return eArrayProperty;
if (prop == "unknown") return eUnknownProperty;
return eInvalidProperty;
}
std::string PropEnumToPropString(EPropertyType prop)
{
switch (prop)
{
case eBoolProperty: return "bool";
case eByteProperty: return "byte";
case eShortProperty: return "short";
case eLongProperty: return "long";
case eFloatProperty: return "float";
case eStringProperty: return "string";
case eColorProperty: return "color";
case eVector3Property: return "vector3f";
case eFileProperty: return "file";
case eStructProperty: return "struct";
case eArrayProperty: return "array";
case eUnknownProperty: return "unknown";
case eInvalidProperty:
default:
return "invalid";
}
}
/*******************
* CStructTemplate *
*******************/
CStructTemplate::CStructTemplate() : CPropertyTemplate(-1)
{
mIsSingleProperty = false;
mPropType = eStructProperty;
}
CStructTemplate::~CStructTemplate()
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
delete *it;
}
// ************ GETTERS ************
EPropertyType CStructTemplate::Type() const
{
return eStructProperty;
}
bool CStructTemplate::IsSingleProperty() const
{
return mIsSingleProperty;
}
u32 CStructTemplate::Count() const
{
return mProperties.size();
}
CPropertyTemplate* CStructTemplate::PropertyByIndex(u32 index)
{
if (mProperties.size() > index)
return mProperties[index];
else
return nullptr;
}
CPropertyTemplate* CStructTemplate::PropertyByID(u32 ID)
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
{
if ((*it)->PropertyID() == ID)
return *it;
}
return nullptr;
}
CPropertyTemplate* CStructTemplate::PropertyByIDString(const std::string& str)
{
// Resolve namespace
std::string::size_type nsStart = str.find_first_of("::");
std::string::size_type propStart = nsStart + 2;
// String has namespace; the requested property is within a struct
if (nsStart != std::string::npos)
{
std::string strStructID = str.substr(0, nsStart);
if (!StringUtil::IsHexString(strStructID)) return nullptr;
u32 structID = StringUtil::ToInt32(strStructID);
std::string propName = str.substr(propStart, str.length() - propStart);
CStructTemplate *pStruct = StructByID(structID);
if (!pStruct) return nullptr;
else return pStruct->PropertyByIDString(propName);
}
// No namespace; fetch the property from this struct
else
{
// ID string lookup
if (StringUtil::IsHexString(str))
return PropertyByID(std::stoul(str, 0, 16));
else
return nullptr;
}
}
CStructTemplate* CStructTemplate::StructByIndex(u32 index)
{
CPropertyTemplate *pProp = PropertyByIndex(index);
if (pProp->Type() == eStructProperty)
return static_cast<CStructTemplate*>(pProp);
else
return nullptr;
}
CStructTemplate* CStructTemplate::StructByID(u32 ID)
{
CPropertyTemplate *pProp = PropertyByID(ID);
if (pProp && pProp->Type() == eStructProperty)
return static_cast<CStructTemplate*>(pProp);
else
return nullptr;
}
CStructTemplate* CStructTemplate::StructByIDString(const std::string& str)
{
CPropertyTemplate *pProp = PropertyByIDString(str);
if (pProp && pProp->Type() == eStructProperty)
return static_cast<CStructTemplate*>(pProp);
else
return nullptr;
}
// ************ DEBUG ************
void CStructTemplate::DebugPrintProperties(std::string base)
{
base = base + Name() + "::";
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
{
CPropertyTemplate *tmp = *it;
if (tmp->Type() == eStructProperty)
{
CStructTemplate *tmp2 = static_cast<CStructTemplate*>(tmp);
tmp2->DebugPrintProperties(base);
}
else
std::cout << base << tmp->Name() << "\n";
}
}

View File

@@ -0,0 +1,72 @@
#ifndef CPROPERTYTEMPLATE
#define CPROPERTYTEMPLATE
#include "EPropertyType.h"
#include <Common/StringUtil.h>
#include <Common/types.h>
#include <string>
#include <vector>
class CPropertyTemplate
{
friend class CTemplateLoader;
friend class CTemplateWriter;
protected:
EPropertyType mPropType;
std::string mPropName;
u32 mPropID;
public:
CPropertyTemplate(u32 ID) { mPropID = ID; }
CPropertyTemplate(EPropertyType type, std::string name, u32 ID) : mPropType(type), mPropName(name), mPropID(ID) {}
virtual EPropertyType Type() const { return mPropType; }
inline std::string Name() const { return mPropName; }
inline u32 PropertyID() const { return mPropID; }
inline void SetName(const std::string& Name) { mPropName = Name; }
};
class CFileTemplate : public CPropertyTemplate
{
friend class CTemplateLoader;
friend class CTemplateWriter;
CStringList mAcceptedExtensions;
public:
CFileTemplate(u32 ID) : CPropertyTemplate(ID) { mPropType = eFileProperty; }
CFileTemplate(std::string name, u32 ID, const CStringList& extensions)
: CPropertyTemplate(ID) {
mPropType = eFileProperty; mPropName = name; mAcceptedExtensions = extensions;
}
EPropertyType Type() const { return eFileProperty; }
const CStringList& Extensions() const { return mAcceptedExtensions; }
};
class CStructTemplate : public CPropertyTemplate
{
friend class CTemplateLoader;
friend class CTemplateWriter;
bool mIsSingleProperty;
std::vector<CPropertyTemplate*> mProperties;
std::string mSourceFile;
public:
CStructTemplate();
~CStructTemplate();
EPropertyType Type() const;
bool IsSingleProperty() const;
u32 Count() const;
CPropertyTemplate* PropertyByIndex(u32 index);
CPropertyTemplate* PropertyByID(u32 ID);
CPropertyTemplate* PropertyByIDString(const std::string& str);
CStructTemplate* StructByIndex(u32 index);
CStructTemplate* StructByID(u32 ID);
CStructTemplate* StructByIDString(const std::string& str);
void DebugPrintProperties(std::string base);
};
#endif // CPROPERTYTEMPLATE

View File

@@ -4,11 +4,10 @@
CScriptObject::CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate)
{
mpTemplate = pTemplate;
mpArea = pArea;
mpLayer = pLayer;
mpTemplate = pTemplate;
mpProperties = nullptr;
mAttribFlags = 0;
mpTemplate->AddObject(this);
}
@@ -19,186 +18,72 @@ CScriptObject::~CScriptObject()
}
// ************ DATA MANIPULATION ************
void CScriptObject::EvalutateXForm()
void CScriptObject::CopyFromTemplate(CScriptTemplate *pTemp, u32 propCount)
{
// Reset XForm values to defaults
mPosition = CVector3f(0);
mRotation = CVector3f(0);
mScale = CVector3f(1);
mVolumeSize = CVector3f(0);
mVolumeShape = -1;
// Look for PRS attribs
for (u32 a = 0; a < mAttribs.size(); a++)
{
if ((mAttribs[a].Type == ePositionAttrib) ||
(mAttribs[a].Type == eRotationAttrib) ||
(mAttribs[a].Type == eScaleAttrib) ||
(mAttribs[a].Type == eVolumeAttrib))
{
CVector3Property *attrib = static_cast<CVector3Property*>(mAttribs[a].Prop);
if (mAttribs[a].Type == ePositionAttrib)
mPosition = attrib->Get();
else if (mAttribs[a].Type == eRotationAttrib)
mRotation = attrib->Get();
else if (mAttribs[a].Type == eScaleAttrib)
mScale = attrib->Get();
else if (mAttribs[a].Type == eVolumeAttrib) {
mVolumeSize = attrib->Get();
mVolumeShape = mAttribs[a].Settings;
}
}
}
CStructTemplate *pBaseStruct = pTemp->BaseStructByCount(propCount);
delete mpProperties;
mpProperties = CPropertyStruct::CopyFromTemplate(pBaseStruct);
}
void CScriptObject::EvaluateInstanceName()
void CScriptObject::EvaluateProperties()
{
// Reset instance name to default
mInstanceName = mpTemplate->TemplateName();
// Simply look for an instance name - set if we find it
for (u32 a = 0; a < mAttribs.size(); a++)
{
if (mAttribs[a].Type == eNameAttrib)
{
CStringProperty *str = static_cast<CStringProperty*>(mAttribs[a].Prop);
mInstanceName = str->Get();
return;
}
}
}
void CScriptObject::EvaluateTevColor()
{
// Evaluate the TEV color initializer - this is used for beam troopers
mTevColor = CColor::skWhite; // Initialize to white in case there's no vulnerability attrib
for (u32 a = 0; a < mAttribs.size(); a++)
{
if (mAttribs[a].Type == eVulnerabilityAttrib)
{
CPropertyStruct* vuln = static_cast<CPropertyStruct*>(mAttribs[a].Prop);
u32 Power = static_cast<CLongProperty*>(vuln->PropertyByIndex(0))->Get();
u32 Ice = static_cast<CLongProperty*>(vuln->PropertyByIndex(1))->Get();
u32 Wave = static_cast<CLongProperty*>(vuln->PropertyByIndex(2))->Get();
u32 Plasma = static_cast<CLongProperty*>(vuln->PropertyByIndex(3))->Get();
if (Plasma != 2) mTevColor = CColor::skRed;
else if (Ice != 2) mTevColor = CColor::skWhite;
else if (Power != 2) mTevColor = CColor::skYellow;
else if (Wave != 2) mTevColor = CColor::skPurple;
else mTevColor = CColor::skWhite;
break;
}
}
mpInstanceName = mpTemplate->FindInstanceName(mpProperties);
mpPosition = mpTemplate->FindPosition(mpProperties);
mpRotation = mpTemplate->FindRotation(mpProperties);
mpScale = mpTemplate->FindScale(mpProperties);
mpActive = mpTemplate->FindActive(mpProperties);
mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
mVolumeShape = mpTemplate->VolumeShape(this);
EvaluateDisplayModel();
}
void CScriptObject::EvaluateDisplayModel()
{
// Look for animset or model
for (u32 a = 0; a < mAttribs.size(); a++)
{
// Evaluate AnimSet attrib
if (mAttribs[a].Type == eAnimSetAttrib)
{
// Get the AnimationParameters struct so we can fetch relevant values from it...
SAttrib *Attrib = &mAttribs[a];
CPropertyStruct *AnimParams = static_cast<CPropertyStruct*>(Attrib->Prop);
EGame game = mpTemplate->MasterTemplate()->GetGame();
CResource *ANCS;
if (Attrib->Res)
ANCS = Attrib->Res;
else if (game <= eCorruption)
ANCS = static_cast<CFileProperty*>( (*AnimParams)[0] )->Get();
else
ANCS = static_cast<CFileProperty*>( (*AnimParams)[1] )->Get();
if ((ANCS) && (ANCS->Type() == eCharacter))
{
// Get animset + node index and return the relevant model
CAnimSet *set = static_cast<CAnimSet*>(ANCS);
u32 node;
if (mpTemplate->MasterTemplate()->GetGame() >= eCorruptionProto)
node = 0;
else if (Attrib->Settings == -1)
node = static_cast<CLongProperty*>( (*AnimParams)[1] )->Get();
else
node = Attrib->Settings;
CModel *model = set->getNodeModel(node);
if (model && (model->Type() == eModel))
{
mpDisplayModel = model;
return;
}
}
}
// Evaluate Model attrib
else if (mAttribs[a].Type == eModelAttrib)
{
SAttrib *Attrib = &mAttribs[a];
CResource *CMDL;
if (Attrib->Res)
CMDL = Attrib->Res;
else
CMDL = static_cast<CFileProperty*>(Attrib->Prop)->Get();
if (CMDL && (CMDL->Type() == eModel))
{
mpDisplayModel = static_cast<CModel*>(CMDL);
return;
}
}
}
// No valid display asset
mpDisplayModel = nullptr;
return;
mpDisplayModel = mpTemplate->FindDisplayModel(mpProperties);
mModelToken = CToken(mpDisplayModel);
}
// ************ GETTERS ************
CPropertyBase* CScriptObject::PropertyByIndex(u32 index)
CPropertyBase* CScriptObject::PropertyByIndex(u32 index) const
{
return mpProperties->PropertyByIndex(index);
}
CPropertyBase* CScriptObject::PropertyByName(std::string name)
CPropertyBase* CScriptObject::PropertyByIDString(std::string str) const
{
return mpProperties->PropertyByName(name);
return mpProperties->PropertyByIDString(str);
}
CScriptTemplate* CScriptObject::Template()
CScriptTemplate* CScriptObject::Template() const
{
return mpTemplate;
}
CMasterTemplate* CScriptObject::MasterTemplate()
CMasterTemplate* CScriptObject::MasterTemplate() const
{
return mpTemplate->MasterTemplate();
}
CGameArea* CScriptObject::Area()
CGameArea* CScriptObject::Area() const
{
return mpArea;
}
CScriptLayer* CScriptObject::Layer()
CScriptLayer* CScriptObject::Layer() const
{
return mpLayer;
}
CPropertyStruct* CScriptObject::Properties()
CPropertyStruct* CScriptObject::Properties() const
{
return mpProperties;
}
u32 CScriptObject::NumProperties() const
{
return mpProperties->Count();
}
u32 CScriptObject::ObjectTypeID() const
{
return mpTemplate->ObjectID();
@@ -229,40 +114,74 @@ const SLink& CScriptObject::OutLink(u32 index) const
return mOutConnections[index];
}
// Attribs
CVector3f CScriptObject::GetPosition() const
std::string CScriptObject::InstanceName() const
{
return mPosition;
if (mpInstanceName)
return mpInstanceName->Get();
else
return "";
}
CVector3f CScriptObject::GetRotation() const
CVector3f CScriptObject::Position() const
{
return mRotation;
if (mpPosition)
return mpPosition->Get();
else
return CVector3f::skZero;
}
CVector3f CScriptObject::GetScale() const
CVector3f CScriptObject::Rotation() const
{
return mScale;
if (mpRotation)
return mpRotation->Get();
else
return CVector3f::skZero;
}
CVector3f CScriptObject::GetVolume() const
CVector3f CScriptObject::Scale() const
{
return mVolumeSize;
if (mpScale)
return mpScale->Get();
else
return CVector3f::skOne;
}
u32 CScriptObject::GetVolumeShape() const
bool CScriptObject::IsActive() const
{
return mVolumeShape;
if (mpActive)
return mpActive->Get();
else
return true;
}
std::string CScriptObject::GetInstanceName() const
void CScriptObject::SetPosition(const CVector3f& newPos)
{
return mInstanceName;
if (mpPosition) mpPosition->Set(newPos);
}
CColor CScriptObject::GetTevColor() const
void CScriptObject::SetRotation(const CVector3f& newRot)
{
return mTevColor;
if (mpRotation) mpRotation->Set(newRot);
}
void CScriptObject::SetScale(const CVector3f& newScale)
{
if (mpScale) mpScale->Set(newScale);
}
void CScriptObject::SetName(const std::string& newName)
{
if (mpInstanceName) mpInstanceName->Set(newName);
}
void CScriptObject::SetActive(bool isActive)
{
if (mpActive) mpActive->Set(isActive);
}
CPropertyStruct* CScriptObject::LightParameters() const
{
return mpLightParameters;
}
CModel* CScriptObject::GetDisplayModel() const
@@ -270,18 +189,7 @@ CModel* CScriptObject::GetDisplayModel() const
return mpDisplayModel;
}
int CScriptObject::GetAttribFlags() const
EVolumeShape CScriptObject::VolumeShape() const
{
return mAttribFlags;
}
// ************ STATIC ************
CScriptObject* CScriptObject::CopyFromTemplate(CScriptTemplate *pTemp, CGameArea *pArea, CScriptLayer *pLayer)
{
CScriptObject *pObj = new CScriptObject(pArea, pLayer, pTemp);
CStructTemplate *pBaseStruct = pTemp->BaseStruct();
pObj->mpProperties = CPropertyStruct::CopyFromTemplate(pBaseStruct);
return pObj;
return mVolumeShape;
}

View File

@@ -3,6 +3,7 @@
#include "SConnection.h"
#include "CProperty.h"
#include "CPropertyTemplate.h"
#include "CScriptTemplate.h"
#include "EAttribType.h"
#include "../model/CModel.h"
@@ -24,48 +25,32 @@ class CScriptObject
std::vector<SLink> mInConnections;
CPropertyStruct *mpProperties;
CVector3f mPosition, mRotation, mScale;
CVector3f mVolumeSize;
u32 mVolumeShape;
std::string mInstanceName;
CColor mTevColor;
CModel* mpDisplayModel;
struct SAttrib
{
EAttribType Type;
u32 Settings;
CResource *Res;
CToken ResToken;
CPropertyBase *Prop;
// Convenience constructor
SAttrib(EAttribType type, CResource *res, u32 settings, CPropertyBase *prop) {
Type = type;
Res = res;
ResToken = CToken(res);
Settings = settings;
Prop = prop;
}
};
std::vector<SAttrib> mAttribs;
int mAttribFlags; // int container for EAttribType flags
CStringProperty *mpInstanceName;
CVector3Property *mpPosition;
CVector3Property *mpRotation;
CVector3Property *mpScale;
CBoolProperty *mpActive;
CPropertyStruct *mpLightParameters;
CModel *mpDisplayModel;
CToken mModelToken;
EVolumeShape mVolumeShape;
public:
CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate);
~CScriptObject();
void CopyFromTemplate(CScriptTemplate *pTemp, u32 propCount);
void EvaluateProperties();
void EvaluateDisplayModel();
void EvaluateInstanceName();
void EvaluateTevColor();
void EvalutateXForm();
CScriptTemplate* Template();
CMasterTemplate* MasterTemplate();
CGameArea* Area();
CScriptLayer* Layer();
CPropertyStruct* Properties();
CScriptTemplate* Template() const;
CMasterTemplate* MasterTemplate() const;
CGameArea* Area() const;
CScriptLayer* Layer() const;
CPropertyStruct* Properties() const;
u32 NumProperties() const;
CPropertyBase* PropertyByIndex(u32 index) const;
CPropertyBase* PropertyByIDString(std::string str) const;
u32 ObjectTypeID() const;
u32 InstanceID() const;
u32 NumInLinks() const;
@@ -73,21 +58,19 @@ public:
const SLink& InLink(u32 index) const;
const SLink& OutLink(u32 index) const;
CPropertyBase* PropertyByIndex(u32 index);
CPropertyBase* PropertyByName(std::string name);
CVector3f GetPosition() const;
CVector3f GetRotation() const;
CVector3f GetScale() const;
CVector3f GetVolume() const;
u32 GetVolumeShape() const;
std::string GetInstanceName() const;
CColor GetTevColor() const;
CVector3f Position() const;
CVector3f Rotation() const;
CVector3f Scale() const;
std::string InstanceName() const;
bool IsActive() const;
void SetPosition(const CVector3f& newPos);
void SetRotation(const CVector3f& newRot);
void SetScale(const CVector3f& newScale);
void SetName(const std::string& newName);
void SetActive(bool isActive);
CPropertyStruct* LightParameters() const;
CModel* GetDisplayModel() const;
int GetAttribFlags() const;
// Static
static CScriptObject* CopyFromTemplate(CScriptTemplate *pTemp, CGameArea *pArea, CScriptLayer *pLayer);
EVolumeShape VolumeShape() const;
};
#endif // CSCRIPTOBJECT_H

View File

@@ -5,230 +5,19 @@
#include <string>
#include <Core/Log.h>
#include <Core/CResCache.h>
#include <Resource/CAnimSet.h>
EPropertyType PropStringToPropEnum(std::string prop)
{
if (prop == "bool") return eBoolProperty;
if (prop == "byte") return eByteProperty;
if (prop == "short") return eShortProperty;
if (prop == "long") return eLongProperty;
if (prop == "float") return eFloatProperty;
if (prop == "string") return eStringProperty;
if (prop == "color") return eColorProperty;
if (prop == "vector3f") return eVector3Property;
if (prop == "file") return eFileProperty;
if (prop == "struct") return eStructProperty;
if (prop == "unknown") return eUnknownProperty;
return eInvalidProperty;
}
std::string PropEnumToPropString(EPropertyType prop)
{
switch (prop)
{
case eBoolProperty: return "bool";
case eByteProperty: return "byte";
case eShortProperty: return "short";
case eLongProperty: return "long";
case eFloatProperty: return "float";
case eStringProperty: return "string";
case eColorProperty: return "color";
case eVector3Property: return "vector3f";
case eFileProperty: return "file";
case eStructProperty: return "struct";
case eUnknownProperty: return "unknown";
case eInvalidProperty:
default:
return "invalid";
}
}
EAttribType AttribStringToAttribEnum(const std::string& Attrib)
{
if (Attrib == "name") return eNameAttrib;
if (Attrib == "position") return ePositionAttrib;
if (Attrib == "rotation") return eRotationAttrib;
if (Attrib == "scale") return eScaleAttrib;
if (Attrib == "model") return eModelAttrib;
if (Attrib == "animset") return eAnimSetAttrib;
if (Attrib == "volume") return eVolumeAttrib;
if (Attrib == "vulnerability") return eVulnerabilityAttrib;
return eInvalidAttrib;
}
std::string AttribEnumToAttribString(EAttribType Attrib)
{
switch (Attrib)
{
case eNameAttrib: return "name";
case ePositionAttrib: return "position";
case eRotationAttrib: return "rotation";
case eScaleAttrib: return "scale";
case eModelAttrib: return "model";
case eAnimSetAttrib: return "animset";
case eVolumeAttrib: return "volume";
case eVulnerabilityAttrib: return "vulnerability";
case eInvalidAttrib:
default:
return "invalid";
}
}
/*******************
* CStructTemplate *
*******************/
CStructTemplate::CStructTemplate() : CPropertyTemplate(-1)
{
mIsSingleProperty = false;
mPropertyCount = -1;
mPropType = eStructProperty;
}
CStructTemplate::~CStructTemplate()
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
delete *it;
}
// ************ GETTERS ************
EPropertyType CStructTemplate::Type() const
{
return eStructProperty;
}
bool CStructTemplate::IsSingleProperty() const
{
return mIsSingleProperty;
}
s32 CStructTemplate::TemplateCount() const
{
return mPropertyCount;
}
u32 CStructTemplate::Count() const
{
return mProperties.size();
}
CPropertyTemplate* CStructTemplate::PropertyByIndex(u32 index)
{
if (mProperties.size() > index)
return mProperties[index];
else
return nullptr;
}
CPropertyTemplate* CStructTemplate::PropertyByName(std::string name)
{
// Resolve namespace
std::string::size_type NsStart = name.find_first_of("::");
std::string::size_type PropStart = NsStart + 2;
// Namespace; the requested property is within a struct
if (NsStart != std::string::npos)
{
std::string StructName = name.substr(0, NsStart);
std::string PropName = name.substr(PropStart, name.length() - PropStart);
CStructTemplate *tmp = StructByName(StructName);
if (!tmp) return nullptr;
else return tmp->PropertyByName(PropName);
}
// No namespace; fetch the property from this struct
else
{
// ID string lookup
if (StringUtil::IsHexString(name))
return PropertyByID(std::stoul(name, 0, 16));
// Name lookup
else
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
{
if ((*it)->Name() == name)
return *it;
}
return nullptr;
}
}
}
CPropertyTemplate* CStructTemplate::PropertyByID(u32 ID)
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
{
if ((*it)->PropertyID() == ID)
return *it;
}
return nullptr;
}
CStructTemplate* CStructTemplate::StructByIndex(u32 index)
{
CPropertyTemplate *prop = PropertyByIndex(index);
if (prop->Type() == eStructProperty)
return static_cast<CStructTemplate*>(prop);
else
return nullptr;
}
CStructTemplate* CStructTemplate::StructByName(std::string name)
{
CPropertyTemplate *prop = PropertyByName(name);
if (prop && prop->Type() == eStructProperty)
return static_cast<CStructTemplate*>(prop);
else
return nullptr;
}
CStructTemplate* CStructTemplate::StructByID(u32 ID)
{
CPropertyTemplate *prop = PropertyByID(ID);
if (prop && prop->Type() == eStructProperty)
return static_cast<CStructTemplate*>(prop);
else
return nullptr;
}
// ************ DEBUG ************
void CStructTemplate::DebugPrintProperties(std::string base)
{
base = base + Name() + "::";
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
{
CPropertyTemplate *tmp = *it;
if (tmp->Type() == eStructProperty)
{
CStructTemplate *tmp2 = static_cast<CStructTemplate*>(tmp);
tmp2->DebugPrintProperties(base);
}
else
std::cout << base << tmp->Name() << "\n";
}
}
/*******************
* CScriptTemplate *
*******************/
CScriptTemplate::CScriptTemplate(CMasterTemplate *pMaster)
{
mpBaseStruct = nullptr;
mpMaster = pMaster;
mVisible = true;
mVolumeShape = eNoShape;
}
CScriptTemplate::~CScriptTemplate()
{
if (mpBaseStruct)
delete mpBaseStruct;
for (u32 iSet = 0; iSet < mPropertySets.size(); iSet++)
delete mPropertySets[iSet].pBaseStruct;
}
CMasterTemplate* CScriptTemplate::MasterTemplate()
@@ -236,27 +25,51 @@ CMasterTemplate* CScriptTemplate::MasterTemplate()
return mpMaster;
}
std::string CScriptTemplate::TemplateName() const
std::string CScriptTemplate::TemplateName(s32 propCount) const
{
return mTemplateName;
// Return original name if there is only one property set
// or if caller doesn't want to distinguish between sets
if ((NumPropertySets() == 1) || (propCount == -1))
return mTemplateName;
// Otherwise we return the template name with the set name appended
for (auto it = mPropertySets.begin(); it != mPropertySets.end(); it++)
if (it->pBaseStruct->Count() == propCount)
return mTemplateName + " (" + it->SetName + ")";
return mTemplateName + " (Invalid)";
}
CStructTemplate* CScriptTemplate::BaseStruct()
std::string CScriptTemplate::PropertySetNameByCount(s32 propCount) const
{
return mpBaseStruct;
for (auto it = mPropertySets.begin(); it != mPropertySets.end(); it++)
if (it->pBaseStruct->Count() == propCount)
return it->SetName;
return "";
}
u32 CScriptTemplate::AttribCount() const
std::string CScriptTemplate::PropertySetNameByIndex(u32 index) const
{
return mAttribs.size();
}
CAttribTemplate* CScriptTemplate::Attrib(u32 index)
{
if (mAttribs.size() > index)
return &mAttribs[index];
if (index < NumPropertySets())
return mPropertySets[index].SetName;
else
return nullptr;
return "";
}
u32 CScriptTemplate::NumPropertySets() const
{
return mPropertySets.size();
}
CScriptTemplate::ERotationType CScriptTemplate::RotationType() const
{
return mRotationType;
}
CScriptTemplate::EScaleType CScriptTemplate::ScaleType() const
{
return mScaleType;
}
u32 CScriptTemplate::ObjectID() const
@@ -264,6 +77,206 @@ u32 CScriptTemplate::ObjectID() const
return mObjectID;
}
void CScriptTemplate::SetVisible(bool visible)
{
mVisible = visible;
}
bool CScriptTemplate::IsVisible() const
{
return mVisible;
}
void CScriptTemplate::DebugPrintProperties(int propCount)
{
CStructTemplate *pTemp = BaseStructByCount(propCount);
if (pTemp) pTemp->DebugPrintProperties("");
}
// ************ PROPERTY FETCHING ************
template<typename t, EPropertyType propType>
t TFetchProperty(CPropertyStruct *pProperties, const TIDString& ID)
{
if (ID.empty()) return nullptr;
CPropertyBase *pProp = pProperties->PropertyByIDString(ID);
if (pProp && (pProp->Type() == propType))
return static_cast<t>(pProp);
else
return nullptr;
}
CStructTemplate* CScriptTemplate::BaseStructByCount(s32 propCount)
{
for (u32 iSet = 0; iSet < mPropertySets.size(); iSet++)
if (mPropertySets[iSet].pBaseStruct->Count() == propCount)
return mPropertySets[iSet].pBaseStruct;
return nullptr;
}
CStructTemplate* CScriptTemplate::BaseStructByIndex(u32 index)
{
if (index < NumPropertySets())
return mPropertySets[index].pBaseStruct;
else
return nullptr;
}
EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
{
if (pObj->Template() != this)
{
Log::Error(pObj->Template()->TemplateName() + " instance somehow called VolumeShape() on " + TemplateName() + " template");
return eInvalidShape;
}
if (mVolumeShape == eConditionalShape)
{
CPropertyBase *pProp = pObj->Properties()->PropertyByIDString(mVolumeConditionIDString);
// Get value of the condition test property (only boolean, integral, and enum types supported)
int v;
switch (pProp->Type())
{
case eBoolProperty:
v = (static_cast<CBoolProperty*>(pProp)->Get() ? 1 : 0);
break;
case eByteProperty:
v = (int) static_cast<CByteProperty*>(pProp)->Get();
break;
case eShortProperty:
v = (int) static_cast<CShortProperty*>(pProp)->Get();
break;
case eLongProperty:
case eEnumProperty:
v = (int) static_cast<CLongProperty*>(pProp)->Get();
break;
}
// Test and check whether any of the conditions are true
for (auto it = mVolumeConditions.begin(); it != mVolumeConditions.end(); it++)
{
if (it->Value == v)
return it->Shape;
}
Log::Error(TemplateName() + " instance " + StringUtil::ToHexString(pObj->InstanceID(), true, true, 8) + " has unexpected volume shape value of " + StringUtil::ToHexString((u32) v, true, true));
return eInvalidShape;
}
else return mVolumeShape;
}
CStringProperty* CScriptTemplate::FindInstanceName(CPropertyStruct *pProperties)
{
return TFetchProperty<CStringProperty*, eStringProperty>(pProperties, mNameIDString);
}
CVector3Property* CScriptTemplate::FindPosition(CPropertyStruct *pProperties)
{
return TFetchProperty<CVector3Property*, eVector3Property>(pProperties, mPositionIDString);
}
CVector3Property* CScriptTemplate::FindRotation(CPropertyStruct *pProperties)
{
return TFetchProperty<CVector3Property*, eVector3Property>(pProperties, mRotationIDString);
}
CVector3Property* CScriptTemplate::FindScale(CPropertyStruct *pProperties)
{
return TFetchProperty<CVector3Property*, eVector3Property>(pProperties, mScaleIDString);
}
CBoolProperty* CScriptTemplate::FindActive(CPropertyStruct *pProperties)
{
return TFetchProperty<CBoolProperty*, eBoolProperty>(pProperties, mActiveIDString);
}
CPropertyStruct* CScriptTemplate::FindLightParameters(CPropertyStruct *pProperties)
{
return TFetchProperty<CPropertyStruct*, eStructProperty>(pProperties, mLightParametersIDString);
}
CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties)
{
for (auto it = mAssets.begin(); it != mAssets.end(); it++)
{
CResource *pRes = nullptr;
int animSetIndex = -1;
// File
if (it->AssetSource == SEditorAsset::eFile)
{
std::string path = "../resources/" + it->AssetLocation;
pRes = gResCache.GetResource(path);
}
// Property
else
{
CPropertyBase *pProp = pProperties->PropertyByIDString(it->AssetLocation);
if (pProp->Type() == eFileProperty)
{
CFileProperty *pFile = static_cast<CFileProperty*>(pProp);
pRes = pFile->Get();
}
else if (pProp->Type() == eStructProperty)
{
CPropertyStruct *pStruct = static_cast<CPropertyStruct*>(pProp);
// Slightly hacky code to fetch the correct parameters for each game
EGame game = mpMaster->GetGame();
if (game <= eCorruption)
pRes = static_cast<CFileProperty*>(pStruct->PropertyByIndex(0))->Get();
else
pRes = static_cast<CFileProperty*>(pStruct->PropertyByIndex(1))->Get();
if (it->ForceNodeIndex >= 0)
animSetIndex = it->ForceNodeIndex;
else if (game >= eCorruptionProto)
animSetIndex = 0;
else
animSetIndex = static_cast<CLongProperty*>(pStruct->PropertyByIndex(1))->Get();
}
}
// Verify resource exists + is correct type
if (pRes)
{
if ((it->AssetType == SEditorAsset::eModel) && (pRes->Type() == eModel))
return static_cast<CModel*>(pRes);
if ((it->AssetType == SEditorAsset::eAnimParams) && ((pRes->Type() == eAnimSet)))
{
CAnimSet *pSet = static_cast<CAnimSet*>(pRes);
if (animSetIndex < pSet->getNodeCount())
{
CModel *pModel = pSet->getNodeModel(animSetIndex);
if (pModel && (pModel->Type() == eModel))
return pModel;
}
}
}
}
return nullptr;
}
bool CScriptTemplate::HasPosition()
{
return (!mPositionIDString.empty());
}
// ************ OBJECT TRACKING ************
u32 CScriptTemplate::NumObjects() const
{
return mObjectList.size();
@@ -298,19 +311,3 @@ void CScriptTemplate::SortObjects()
return (pA->InstanceID() < pB->InstanceID());
});
}
void CScriptTemplate::SetVisible(bool Visible)
{
mVisible = Visible;
}
bool CScriptTemplate::IsVisible()
{
return mVisible;
}
// Debug function
void CScriptTemplate::DebugPrintProperties()
{
mpBaseStruct->DebugPrintProperties("");
}

View File

@@ -1,141 +1,128 @@
#ifndef CSCRIPTTEMPLATE_H
#define CSCRIPTTEMPLATE_H
#include "CPropertyTemplate.h"
#include "CProperty.h"
#include "EPropertyType.h"
#include "EVolumeShape.h"
#include "EAttribType.h"
#include <Common/CFourCC.h>
#include <Common/types.h>
#include <list>
#include <vector>
#include <tinyxml2.h>
#include <Resource/CResource.h>
#include <Resource/model/CModel.h>
class CMasterTemplate;
class CScriptObject;
/**
* CPropertyTemplate and CStructTemplate each define the layout of a single property/struct.
* The reason they're classes instead of structs is so their internal values can't be externally modified.
* CFileTemplate is a very simple subclass with one extra value - a file extension fourCC
*/
class CPropertyTemplate
{
friend class CTemplateLoader;
typedef std::string TIDString;
protected:
EPropertyType mPropType;
std::string mPropName;
u32 mPropID;
public:
CPropertyTemplate(u32 ID) { mPropID = ID; }
CPropertyTemplate(EPropertyType type, std::string name, u32 ID) : mPropType(type), mPropName(name), mPropID(ID) {}
virtual EPropertyType Type() const { return mPropType; }
inline std::string Name() const { return mPropName; }
inline u32 PropertyID() const { return mPropID; }
inline void SetName(const std::string& Name) { mPropName = Name; }
};
class CFileTemplate : public CPropertyTemplate
{
friend class CTemplateLoader;
CStringList mAcceptedExtensions;
public:
CFileTemplate(u32 ID) : CPropertyTemplate(ID) { mPropType = eFileProperty; }
CFileTemplate(std::string name, u32 ID, const CStringList& extensions)
: CPropertyTemplate(ID) {
mPropType = eFileProperty; mPropName = name; mAcceptedExtensions = extensions;
}
EPropertyType Type() const { return eFileProperty; }
const CStringList& Extensions() const { return mAcceptedExtensions; }
};
class CStructTemplate : public CPropertyTemplate
{
friend class CTemplateLoader;
bool mIsSingleProperty;
s32 mPropertyCount;
std::vector<CPropertyTemplate*> mProperties;
public:
CStructTemplate();
~CStructTemplate();
EPropertyType Type() const;
bool IsSingleProperty() const;
s32 TemplateCount() const;
u32 Count() const;
CPropertyTemplate* PropertyByIndex(u32 index);
CPropertyTemplate* PropertyByName(std::string name);
CPropertyTemplate* PropertyByID(u32 ID);
CStructTemplate* StructByIndex(u32 index);
CStructTemplate* StructByName(std::string name);
CStructTemplate* StructByID(u32 ID);
void DebugPrintProperties(std::string base);
};
/**
* CAttribTemplate defines editor attributes.
* They enable PWE to access and use object properties for use in the world editor.
*/
class CAttribTemplate
{
friend class CTemplateLoader;
EAttribType AttribType;
std::string AttribTarget;
std::string ResFile;
u32 ExtraSettings;
public:
CAttribTemplate() {}
EAttribType Type() const { return AttribType; }
std::string Target() const { return AttribTarget; }
std::string Resource() const { return ResFile; }
u32 Settings() const { return ExtraSettings; }
};
/**
/*
* CScriptTemplate is a class that encases the data contained in one of the XML templates.
* It essentially sets the layout of any given script object.
*
* It contains any data that applies globally to every instance of the object, such as
* property names, editor attribute properties, etc.
* property names, editor attribute properties, etc.
*/
class CScriptObject;
class CScriptTemplate
{
friend class CTemplateLoader;
friend class CTemplateWriter;
public:
enum ERotationType {
eRotationEnabled, eRotationDisabled
};
enum EScaleType {
eScaleEnabled, eScaleDisabled, eScaleVolume
};
private:
struct SPropertySet {
std::string SetName;
CStructTemplate *pBaseStruct;
};
struct SEditorAsset
{
enum {
eModel, eAnimParams
} AssetType;
enum {
eProperty, eFile
} AssetSource;
TIDString AssetLocation;
s32 ForceNodeIndex; // Force animsets to use specific node instead of one from property
};
CMasterTemplate *mpMaster;
CStructTemplate *mpBaseStruct;
std::vector<SPropertySet> mPropertySets;
std::list<CScriptObject*> mObjectList;
ERotationType mRotationType;
EScaleType mScaleType;
std::string mTemplateName;
std::vector<CAttribTemplate> mAttribs;
std::string mSourceFile;
u32 mObjectID;
bool mVisible;
// Editor Properties
TIDString mNameIDString;
TIDString mPositionIDString;
TIDString mRotationIDString;
TIDString mScaleIDString;
TIDString mActiveIDString;
TIDString mLightParametersIDString;
std::vector<SEditorAsset> mAssets;
// Preview Volume
EVolumeShape mVolumeShape;
TIDString mVolumeConditionIDString;
struct SVolumeCondition {
int Value;
EVolumeShape Shape;
};
std::vector<SVolumeCondition> mVolumeConditions;
public:
CScriptTemplate(CMasterTemplate *pMaster);
~CScriptTemplate();
CMasterTemplate* MasterTemplate();
std::string TemplateName() const;
CStructTemplate* BaseStruct();
u32 AttribCount() const;
CAttribTemplate* Attrib(u32 index);
std::string TemplateName(s32 propCount = -1) const;
std::string PropertySetNameByCount(s32 propCount) const;
std::string PropertySetNameByIndex(u32 index) const;
u32 NumPropertySets() const;
ERotationType RotationType() const;
EScaleType ScaleType() const;
u32 ObjectID() const;
void SetVisible(bool visible);
bool IsVisible() const;
void DebugPrintProperties(int propCount = -1);
// Property Fetching
CStructTemplate* BaseStructByCount(s32 propCount);
CStructTemplate* BaseStructByIndex(u32 index);
EVolumeShape VolumeShape(CScriptObject *pObj);
CStringProperty* FindInstanceName(CPropertyStruct *pProperties);
CVector3Property* FindPosition(CPropertyStruct *pProperties);
CVector3Property* FindRotation(CPropertyStruct *pProperties);
CVector3Property* FindScale(CPropertyStruct *pProperties);
CBoolProperty* FindActive(CPropertyStruct *pProperties);
CPropertyStruct* FindLightParameters(CPropertyStruct *pProperties);
CModel* FindDisplayModel(CPropertyStruct *pProperties);
bool HasPosition();
// Object Tracking
u32 NumObjects() const;
const std::list<CScriptObject*>& ObjectList() const;
void AddObject(CScriptObject *pObject);
void RemoveObject(CScriptObject *pObject);
void SortObjects();
void SetVisible(bool Visible);
bool IsVisible();
void DebugPrintProperties();
};
#endif // CSCRIPTTEMPLATE_H

View File

@@ -16,6 +16,7 @@ enum EPropertyType
eEnumProperty,
eFileProperty,
eStructProperty,
eArrayProperty,
eUnknownProperty,
eInvalidProperty
};

View File

@@ -0,0 +1,17 @@
#ifndef EVOLUMESHAPE
#define EVOLUMESHAPE
enum EVolumeShape
{
eNoShape,
eAxisAlignedBoxShape,
eBoxShape,
eEllipsoidShape,
eCylinderShape,
eCylinderLargeShape,
eConditionalShape,
eInvalidShape
};
#endif // EVOLUMESHAPE