mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-10 14:07:56 +00:00
Initial commit of current work on Prime World Editor
This commit is contained in:
112
Resource/script/CMasterTemplate.cpp
Normal file
112
Resource/script/CMasterTemplate.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#include "CMasterTemplate.h"
|
||||
#include "../factory/CWorldLoader.h"
|
||||
#include <Core/Log.h>
|
||||
|
||||
CMasterTemplate::CMasterTemplate()
|
||||
{
|
||||
mVersion = 0;
|
||||
mFullyLoaded = false;
|
||||
}
|
||||
|
||||
CMasterTemplate::~CMasterTemplate()
|
||||
{
|
||||
for (auto it = mTemplates.begin(); it != mTemplates.end(); it++)
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
EGame CMasterTemplate::GetGame()
|
||||
{
|
||||
return mGame;
|
||||
}
|
||||
|
||||
CScriptTemplate* CMasterTemplate::TemplateByID(u32 ObjectID)
|
||||
{
|
||||
auto it = mTemplates.find(ObjectID);
|
||||
|
||||
if (it != mTemplates.end())
|
||||
return it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CScriptTemplate* CMasterTemplate::TemplateByID(const CFourCC& ObjectID)
|
||||
{
|
||||
return TemplateByID(ObjectID.ToLong());
|
||||
}
|
||||
|
||||
CScriptTemplate* CMasterTemplate::TemplateByIndex(u32 Index)
|
||||
{
|
||||
auto it = mTemplates.begin();
|
||||
return (std::next(it, Index))->second;
|
||||
}
|
||||
|
||||
std::string CMasterTemplate::StateByID(u32 StateID)
|
||||
{
|
||||
auto it = mStates.find(StateID);
|
||||
|
||||
if (it != mStates.end())
|
||||
return it->second;
|
||||
else
|
||||
return "Invalid";
|
||||
}
|
||||
|
||||
std::string CMasterTemplate::StateByID(const CFourCC& State)
|
||||
{
|
||||
return StateByID(State.ToLong());
|
||||
}
|
||||
|
||||
std::string CMasterTemplate::StateByIndex(u32 Index)
|
||||
{
|
||||
auto it = mStates.begin();
|
||||
return (std::next(it, Index))->second;
|
||||
}
|
||||
|
||||
std::string CMasterTemplate::MessageByID(u32 MessageID)
|
||||
{
|
||||
auto it = mMessages.find(MessageID);
|
||||
|
||||
if (it != mMessages.end())
|
||||
return it->second;
|
||||
else
|
||||
return "Invalid";
|
||||
}
|
||||
|
||||
std::string CMasterTemplate::MessageByID(const CFourCC& MessageID)
|
||||
{
|
||||
return MessageByID(MessageID.ToLong());
|
||||
}
|
||||
|
||||
std::string CMasterTemplate::MessageByIndex(u32 Index)
|
||||
{
|
||||
auto it = mMessages.begin();
|
||||
return (std::next(it, Index))->second;
|
||||
}
|
||||
|
||||
CPropertyTemplate* CMasterTemplate::GetProperty(u32 PropertyID)
|
||||
{
|
||||
auto it = mPropertyList.find(PropertyID);
|
||||
|
||||
if (it != mPropertyList.end())
|
||||
return it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (it != smMasterMap.end())
|
||||
return it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
66
Resource/script/CMasterTemplate.h
Normal file
66
Resource/script/CMasterTemplate.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef CMASTERTEMPLATE_H
|
||||
#define CMASTERTEMPLATE_H
|
||||
|
||||
#include "CScriptTemplate.h"
|
||||
#include "CTemplateCategory.h"
|
||||
#include "../EFormatVersion.h"
|
||||
#include <Common/types.h>
|
||||
#include <unordered_map>
|
||||
#include <tinyxml2.h>
|
||||
|
||||
class CMasterTemplate
|
||||
{
|
||||
friend class CTemplateLoader;
|
||||
|
||||
EGame mGame;
|
||||
std::string mGameName;
|
||||
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::vector<CTemplateCategory> mCategories;
|
||||
|
||||
bool mHasPropList;
|
||||
std::unordered_map<u32, CPropertyTemplate*> mPropertyList;
|
||||
|
||||
static std::unordered_map<EGame, CMasterTemplate*> smMasterMap;
|
||||
static u32 smGameListVersion;
|
||||
|
||||
public:
|
||||
CMasterTemplate();
|
||||
~CMasterTemplate();
|
||||
EGame GetGame();
|
||||
u32 NumScriptTemplates();
|
||||
u32 NumStates();
|
||||
u32 NumMessages();
|
||||
CScriptTemplate* TemplateByID(u32 ObjectID);
|
||||
CScriptTemplate* TemplateByID(const CFourCC& ObjectID);
|
||||
CScriptTemplate* TemplateByIndex(u32 Index);
|
||||
std::string StateByID(u32 StateID);
|
||||
std::string StateByID(const CFourCC& StateID);
|
||||
std::string StateByIndex(u32 Index);
|
||||
std::string MessageByID(u32 MessageID);
|
||||
std::string MessageByID(const CFourCC& MessageID);
|
||||
std::string MessageByIndex(u32 Index);
|
||||
CPropertyTemplate* GetProperty(u32 PropertyID);
|
||||
bool IsLoadedSuccessfully();
|
||||
|
||||
static CMasterTemplate* GetMasterForGame(EGame Game);
|
||||
};
|
||||
|
||||
// ************ INLINE ************
|
||||
inline u32 CMasterTemplate::NumScriptTemplates() {
|
||||
return mTemplates.size();
|
||||
}
|
||||
|
||||
inline u32 CMasterTemplate::NumStates() {
|
||||
return mStates.size();
|
||||
}
|
||||
|
||||
inline u32 CMasterTemplate::NumMessages() {
|
||||
return mMessages.size();
|
||||
}
|
||||
|
||||
#endif // CMASTERTEMPLATE_H
|
||||
227
Resource/script/CProperty.h
Normal file
227
Resource/script/CProperty.h
Normal file
@@ -0,0 +1,227 @@
|
||||
#ifndef CPROPERTY
|
||||
#define CPROPERTY
|
||||
|
||||
/*
|
||||
* This header file declares some classes used to track script object properties
|
||||
* CPropertyBase, __CProperty (and typedefs), CPropertyStruct
|
||||
*/
|
||||
#include "../CResource.h"
|
||||
#include "CScriptTemplate.h"
|
||||
#include "EPropertyType.h"
|
||||
#include <Common/CColor.h>
|
||||
#include <Common/CVector3f.h>
|
||||
#include <Core/CToken.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
class CPropertyBase
|
||||
{
|
||||
friend class CScriptLoader;
|
||||
protected:
|
||||
CPropertyTemplate *tmp;
|
||||
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(); }
|
||||
};
|
||||
|
||||
/*
|
||||
* __CProperty is a template subclass for actual properties.
|
||||
* Don't use this class directly. Typedefs are provided for every possible property type.
|
||||
*/
|
||||
template <typename t, EPropertyType type>
|
||||
class __CProperty : public CPropertyBase
|
||||
{
|
||||
friend class CScriptLoader;
|
||||
t Value;
|
||||
public:
|
||||
__CProperty() {}
|
||||
__CProperty(t v) { Set(v); }
|
||||
~__CProperty() {}
|
||||
EPropertyType Type() { return type; }
|
||||
t Get() { return Value; }
|
||||
void Set(t v) { Value = v; }
|
||||
};
|
||||
typedef __CProperty<bool, eBoolProperty> CBoolProperty;
|
||||
typedef __CProperty<char, eByteProperty> CByteProperty;
|
||||
typedef __CProperty<short, eShortProperty> CShortProperty;
|
||||
typedef __CProperty<long, eLongProperty> CLongProperty;
|
||||
typedef __CProperty<float, eFloatProperty> CFloatProperty;
|
||||
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>, eUnknownProperty> CUnknownProperty;
|
||||
|
||||
/*
|
||||
* Template specialization for CFileProperty to allow a token for resources
|
||||
*/
|
||||
template <>
|
||||
class __CProperty<CResource*, eFileProperty> : public CPropertyBase
|
||||
{
|
||||
CResource *Value;
|
||||
CToken mToken;
|
||||
|
||||
public:
|
||||
__CProperty<CResource*, eFileProperty>() {
|
||||
Value = nullptr;
|
||||
}
|
||||
|
||||
__CProperty<CResource*, eFileProperty>(CResource* v) {
|
||||
Value = v;
|
||||
mToken = CToken(v);
|
||||
}
|
||||
|
||||
~__CProperty<CResource*, eFileProperty>() {}
|
||||
|
||||
EPropertyType Type() { return eFileProperty; }
|
||||
CResource* Get() { return Value; }
|
||||
void Set(CResource *v)
|
||||
{
|
||||
if (Value != v)
|
||||
{
|
||||
Value = v;
|
||||
mToken = CToken(v);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* CPropertyStruct is for defining structs of properties.
|
||||
*/
|
||||
class CPropertyStruct : public CPropertyBase
|
||||
{
|
||||
friend class CScriptLoader;
|
||||
std::vector<CPropertyBase*> Properties;
|
||||
public:
|
||||
// Destructor simply iterates through the list and deletes them. Nothing complicated.
|
||||
~CPropertyStruct()
|
||||
{
|
||||
for (auto it = Properties.begin(); it != Properties.end(); it++)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// 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);
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CPROPERTY
|
||||
|
||||
95
Resource/script/CScriptLayer.cpp
Normal file
95
Resource/script/CScriptLayer.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "CScriptLayer.h"
|
||||
|
||||
CScriptLayer::CScriptLayer()
|
||||
{
|
||||
mLayerName = "New Layer";
|
||||
mActive = true;
|
||||
mVisible = true;
|
||||
}
|
||||
|
||||
CScriptLayer::~CScriptLayer()
|
||||
{
|
||||
for (auto it = mObjects.begin(); it != mObjects.end(); it++)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
// ************* DATA MANIPULATION *************
|
||||
void CScriptLayer::AddObject(CScriptObject* object)
|
||||
{
|
||||
mObjects.push_back(object);
|
||||
}
|
||||
|
||||
void CScriptLayer::DeleteObjectByIndex(u32 index)
|
||||
{
|
||||
delete mObjects[index];
|
||||
mObjects.erase(mObjects.begin() + index, mObjects.begin() + index);
|
||||
}
|
||||
|
||||
void CScriptLayer::DeleteObjectByID(u32 ID)
|
||||
{
|
||||
for (auto it = mObjects.begin(); it != mObjects.end(); it++)
|
||||
{
|
||||
if ((*it)->InstanceID() == ID)
|
||||
{
|
||||
delete *it;
|
||||
mObjects.erase(it, it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptLayer::Reserve(u32 amount)
|
||||
{
|
||||
mObjects.reserve(amount);
|
||||
}
|
||||
|
||||
// ************* GETTERS *************
|
||||
std::string CScriptLayer::Name()
|
||||
{
|
||||
return mLayerName;
|
||||
}
|
||||
|
||||
bool CScriptLayer::IsActive()
|
||||
{
|
||||
return mActive;
|
||||
}
|
||||
|
||||
bool CScriptLayer::IsVisible()
|
||||
{
|
||||
return mVisible;
|
||||
}
|
||||
|
||||
u32 CScriptLayer::GetNumObjects()
|
||||
{
|
||||
return mObjects.size();
|
||||
}
|
||||
|
||||
CScriptObject* CScriptLayer::ObjectByIndex(u32 index)
|
||||
{
|
||||
return mObjects[index];
|
||||
}
|
||||
|
||||
CScriptObject* CScriptLayer::ObjectByID(u32 ID)
|
||||
{
|
||||
for (auto it = mObjects.begin(); it != mObjects.end(); it++)
|
||||
if ((*it)->InstanceID() == ID)
|
||||
return *it;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ************* SETTERS *************
|
||||
void CScriptLayer::SetName(std::string name)
|
||||
{
|
||||
mLayerName = name;
|
||||
}
|
||||
|
||||
void CScriptLayer::SetActive(bool active)
|
||||
{
|
||||
mActive = active;
|
||||
}
|
||||
|
||||
void CScriptLayer::SetVisible(bool visible)
|
||||
{
|
||||
mVisible = visible;
|
||||
}
|
||||
48
Resource/script/CScriptLayer.h
Normal file
48
Resource/script/CScriptLayer.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef SSCRIPTLAYER_H
|
||||
#define SSCRIPTLAYER_H
|
||||
|
||||
#include "CScriptObject.h"
|
||||
#include <Common/types.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class CScriptLayer
|
||||
{
|
||||
std::string mLayerName;
|
||||
bool mActive;
|
||||
bool mVisible;
|
||||
std::vector<CScriptObject*> mObjects;
|
||||
public:
|
||||
CScriptLayer();
|
||||
~CScriptLayer();
|
||||
|
||||
// Data Manipulation
|
||||
void AddObject(CScriptObject* object);
|
||||
void DeleteObjectByIndex(u32 index);
|
||||
void DeleteObjectByID(u32 ID);
|
||||
void Reserve(u32 amount);
|
||||
|
||||
// Getters and Setters
|
||||
std::string Name();
|
||||
bool IsActive();
|
||||
bool IsVisible();
|
||||
u32 GetNumObjects();
|
||||
CScriptObject* ObjectByIndex(u32 index);
|
||||
CScriptObject* ObjectByID(u32 ID);
|
||||
|
||||
void SetName(std::string name);
|
||||
void SetActive(bool active);
|
||||
void SetVisible(bool visible);
|
||||
|
||||
// Operators
|
||||
CScriptObject* operator[](u32 index);
|
||||
};
|
||||
|
||||
// ************* INLINE FUNCTIONS *************
|
||||
inline CScriptObject* CScriptLayer::operator[](u32 index)
|
||||
{
|
||||
return mObjects[index];
|
||||
}
|
||||
|
||||
|
||||
#endif // SSCRIPTLAYER_H
|
||||
287
Resource/script/CScriptObject.cpp
Normal file
287
Resource/script/CScriptObject.cpp
Normal file
@@ -0,0 +1,287 @@
|
||||
#include "CScriptObject.h"
|
||||
#include "../CAnimSet.h"
|
||||
#include "CMasterTemplate.h"
|
||||
|
||||
CScriptObject::CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate)
|
||||
{
|
||||
mpArea = pArea;
|
||||
mpLayer = pLayer;
|
||||
mpTemplate = pTemplate;
|
||||
mpProperties = nullptr;
|
||||
mAttribFlags = 0;
|
||||
mpTemplate->AddObject(this);
|
||||
}
|
||||
|
||||
CScriptObject::~CScriptObject()
|
||||
{
|
||||
if (mpProperties) delete mpProperties;
|
||||
mpTemplate->RemoveObject(this);
|
||||
}
|
||||
|
||||
// ************ DATA MANIPULATION ************
|
||||
void CScriptObject::EvalutateXForm()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptObject::EvaluateInstanceName()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// ************ GETTERS ************
|
||||
CPropertyBase* CScriptObject::PropertyByIndex(u32 index)
|
||||
{
|
||||
return mpProperties->PropertyByIndex(index);
|
||||
}
|
||||
|
||||
CPropertyBase* CScriptObject::PropertyByName(std::string name)
|
||||
{
|
||||
return mpProperties->PropertyByName(name);
|
||||
}
|
||||
|
||||
CScriptTemplate* CScriptObject::Template()
|
||||
{
|
||||
return mpTemplate;
|
||||
}
|
||||
|
||||
CMasterTemplate* CScriptObject::MasterTemplate()
|
||||
{
|
||||
return mpTemplate->MasterTemplate();
|
||||
}
|
||||
|
||||
CGameArea* CScriptObject::Area()
|
||||
{
|
||||
return mpArea;
|
||||
}
|
||||
|
||||
CScriptLayer* CScriptObject::Layer()
|
||||
{
|
||||
return mpLayer;
|
||||
}
|
||||
|
||||
CPropertyStruct* CScriptObject::Properties()
|
||||
{
|
||||
return mpProperties;
|
||||
}
|
||||
|
||||
u32 CScriptObject::ObjectTypeID() const
|
||||
{
|
||||
return mpTemplate->ObjectID();
|
||||
}
|
||||
|
||||
u32 CScriptObject::InstanceID() const
|
||||
{
|
||||
return mInstanceID;
|
||||
}
|
||||
|
||||
u32 CScriptObject::NumInLinks() const
|
||||
{
|
||||
return mInConnections.size();
|
||||
}
|
||||
|
||||
u32 CScriptObject::NumOutLinks() const
|
||||
{
|
||||
return mOutConnections.size();
|
||||
}
|
||||
|
||||
const SLink& CScriptObject::InLink(u32 index) const
|
||||
{
|
||||
return mInConnections[index];
|
||||
}
|
||||
|
||||
const SLink& CScriptObject::OutLink(u32 index) const
|
||||
{
|
||||
return mOutConnections[index];
|
||||
}
|
||||
|
||||
// Attribs
|
||||
CVector3f CScriptObject::GetPosition() const
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
CVector3f CScriptObject::GetRotation() const
|
||||
{
|
||||
return mRotation;
|
||||
}
|
||||
|
||||
CVector3f CScriptObject::GetScale() const
|
||||
{
|
||||
return mScale;
|
||||
}
|
||||
|
||||
CVector3f CScriptObject::GetVolume() const
|
||||
{
|
||||
return mVolumeSize;
|
||||
}
|
||||
|
||||
u32 CScriptObject::GetVolumeShape() const
|
||||
{
|
||||
return mVolumeShape;
|
||||
}
|
||||
|
||||
std::string CScriptObject::GetInstanceName() const
|
||||
{
|
||||
return mInstanceName;
|
||||
}
|
||||
|
||||
CColor CScriptObject::GetTevColor() const
|
||||
{
|
||||
return mTevColor;
|
||||
}
|
||||
|
||||
CModel* CScriptObject::GetDisplayModel() const
|
||||
{
|
||||
return mpDisplayModel;
|
||||
}
|
||||
|
||||
int CScriptObject::GetAttribFlags() 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;
|
||||
}
|
||||
93
Resource/script/CScriptObject.h
Normal file
93
Resource/script/CScriptObject.h
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef CSCRIPTOBJECT_H
|
||||
#define CSCRIPTOBJECT_H
|
||||
|
||||
#include "SConnection.h"
|
||||
#include "CProperty.h"
|
||||
#include "CScriptTemplate.h"
|
||||
#include "EAttribType.h"
|
||||
#include "../model/CModel.h"
|
||||
|
||||
class CGameArea;
|
||||
class CScriptLayer;
|
||||
|
||||
class CScriptObject
|
||||
{
|
||||
friend class CScriptLoader;
|
||||
friend class CAreaLoader;
|
||||
|
||||
CScriptTemplate *mpTemplate;
|
||||
CGameArea *mpArea;
|
||||
CScriptLayer *mpLayer;
|
||||
|
||||
u32 mInstanceID;
|
||||
std::vector<SLink> mOutConnections;
|
||||
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
|
||||
|
||||
public:
|
||||
CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate);
|
||||
~CScriptObject();
|
||||
|
||||
void EvaluateDisplayModel();
|
||||
void EvaluateInstanceName();
|
||||
void EvaluateTevColor();
|
||||
void EvalutateXForm();
|
||||
|
||||
CScriptTemplate* Template();
|
||||
CMasterTemplate* MasterTemplate();
|
||||
CGameArea* Area();
|
||||
CScriptLayer* Layer();
|
||||
CPropertyStruct* Properties();
|
||||
u32 ObjectTypeID() const;
|
||||
u32 InstanceID() const;
|
||||
u32 NumInLinks() const;
|
||||
u32 NumOutLinks() const;
|
||||
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;
|
||||
CModel* GetDisplayModel() const;
|
||||
int GetAttribFlags() const;
|
||||
|
||||
// Static
|
||||
static CScriptObject* CopyFromTemplate(CScriptTemplate *pTemp, CGameArea *pArea, CScriptLayer *pLayer);
|
||||
};
|
||||
|
||||
#endif // CSCRIPTOBJECT_H
|
||||
316
Resource/script/CScriptTemplate.cpp
Normal file
316
Resource/script/CScriptTemplate.cpp
Normal file
@@ -0,0 +1,316 @@
|
||||
#include "CScriptTemplate.h"
|
||||
#include "CScriptObject.h"
|
||||
#include "CMasterTemplate.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <Core/Log.h>
|
||||
#include <Core/CResCache.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;
|
||||
}
|
||||
|
||||
CScriptTemplate::~CScriptTemplate()
|
||||
{
|
||||
if (mpBaseStruct)
|
||||
delete mpBaseStruct;
|
||||
}
|
||||
|
||||
CMasterTemplate* CScriptTemplate::MasterTemplate()
|
||||
{
|
||||
return mpMaster;
|
||||
}
|
||||
|
||||
std::string CScriptTemplate::TemplateName() const
|
||||
{
|
||||
return mTemplateName;
|
||||
}
|
||||
|
||||
CStructTemplate* CScriptTemplate::BaseStruct()
|
||||
{
|
||||
return mpBaseStruct;
|
||||
}
|
||||
|
||||
u32 CScriptTemplate::AttribCount() const
|
||||
{
|
||||
return mAttribs.size();
|
||||
}
|
||||
|
||||
CAttribTemplate* CScriptTemplate::Attrib(u32 index)
|
||||
{
|
||||
if (mAttribs.size() > index)
|
||||
return &mAttribs[index];
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
u32 CScriptTemplate::ObjectID() const
|
||||
{
|
||||
return mObjectID;
|
||||
}
|
||||
|
||||
u32 CScriptTemplate::NumObjects() const
|
||||
{
|
||||
return mObjectList.size();
|
||||
}
|
||||
|
||||
const std::list<CScriptObject*>& CScriptTemplate::ObjectList() const
|
||||
{
|
||||
return mObjectList;
|
||||
}
|
||||
|
||||
void CScriptTemplate::AddObject(CScriptObject *pObject)
|
||||
{
|
||||
mObjectList.push_back(pObject);
|
||||
}
|
||||
|
||||
void CScriptTemplate::RemoveObject(CScriptObject *pObject)
|
||||
{
|
||||
for (auto it = mObjectList.begin(); it != mObjectList.end(); it++)
|
||||
{
|
||||
if (*it == pObject)
|
||||
{
|
||||
mObjectList.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptTemplate::SortObjects()
|
||||
{
|
||||
// todo: make this function take layer names into account
|
||||
mObjectList.sort([](CScriptObject *pA, CScriptObject *pB) -> bool {
|
||||
return (pA->InstanceID() < pB->InstanceID());
|
||||
});
|
||||
}
|
||||
|
||||
void CScriptTemplate::SetVisible(bool Visible)
|
||||
{
|
||||
mVisible = Visible;
|
||||
}
|
||||
|
||||
bool CScriptTemplate::IsVisible()
|
||||
{
|
||||
return mVisible;
|
||||
}
|
||||
|
||||
// Debug function
|
||||
void CScriptTemplate::DebugPrintProperties()
|
||||
{
|
||||
mpBaseStruct->DebugPrintProperties("");
|
||||
}
|
||||
141
Resource/script/CScriptTemplate.h
Normal file
141
Resource/script/CScriptTemplate.h
Normal file
@@ -0,0 +1,141 @@
|
||||
#ifndef CSCRIPTTEMPLATE_H
|
||||
#define CSCRIPTTEMPLATE_H
|
||||
|
||||
#include "EPropertyType.h"
|
||||
#include "EAttribType.h"
|
||||
#include <Common/CFourCC.h>
|
||||
#include <Common/types.h>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <tinyxml2.h>
|
||||
#include <Resource/CResource.h>
|
||||
|
||||
class CMasterTemplate;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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.
|
||||
*/
|
||||
class CScriptObject;
|
||||
|
||||
class CScriptTemplate
|
||||
{
|
||||
friend class CTemplateLoader;
|
||||
|
||||
CMasterTemplate *mpMaster;
|
||||
CStructTemplate *mpBaseStruct;
|
||||
std::list<CScriptObject*> mObjectList;
|
||||
std::string mTemplateName;
|
||||
std::vector<CAttribTemplate> mAttribs;
|
||||
u32 mObjectID;
|
||||
bool mVisible;
|
||||
|
||||
public:
|
||||
CScriptTemplate(CMasterTemplate *pMaster);
|
||||
~CScriptTemplate();
|
||||
|
||||
CMasterTemplate* MasterTemplate();
|
||||
std::string TemplateName() const;
|
||||
CStructTemplate* BaseStruct();
|
||||
u32 AttribCount() const;
|
||||
CAttribTemplate* Attrib(u32 index);
|
||||
u32 ObjectID() const;
|
||||
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
|
||||
46
Resource/script/CTemplateCategory.h
Normal file
46
Resource/script/CTemplateCategory.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef CTEMPLATECATEGORY_H
|
||||
#define CTEMPLATECATEGORY_H
|
||||
|
||||
#include "CScriptTemplate.h"
|
||||
#include <algorithm>
|
||||
|
||||
class CTemplateCategory
|
||||
{
|
||||
std::string mCategoryName;
|
||||
std::vector<CScriptTemplate*> mTemplates;
|
||||
|
||||
public:
|
||||
CTemplateCategory() {}
|
||||
|
||||
inline CTemplateCategory(const std::string& Name) {
|
||||
SetName(Name);
|
||||
}
|
||||
|
||||
inline void SetName(const std::string& Name) {
|
||||
mCategoryName = Name;
|
||||
}
|
||||
|
||||
inline void AddTemplate(CScriptTemplate *pTmp) {
|
||||
mTemplates.push_back(pTmp);
|
||||
}
|
||||
|
||||
inline void Sort() {
|
||||
std::sort(mTemplates.begin(), mTemplates.end(), [](CScriptTemplate* pA, CScriptTemplate* pB) -> bool {
|
||||
return (pA->TemplateName() < pB->TemplateName());
|
||||
});
|
||||
}
|
||||
|
||||
inline u32 NumTemplates() {
|
||||
return mTemplates.size();
|
||||
}
|
||||
|
||||
inline CScriptTemplate* GetTemplate(u32 index) {
|
||||
return mTemplates[index];
|
||||
}
|
||||
|
||||
inline CScriptTemplate* operator[](u32 index) {
|
||||
return mTemplates[index];
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CTEMPLATECATEGORY_H
|
||||
26
Resource/script/EAttribType.h
Normal file
26
Resource/script/EAttribType.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef EATTRIBTYPE
|
||||
#define EATTRIBTYPE
|
||||
|
||||
#include <Common/EnumUtil.h>
|
||||
#include <string>
|
||||
|
||||
enum EAttribType
|
||||
{
|
||||
eNameAttrib = 0x1,
|
||||
ePositionAttrib = 0x2,
|
||||
eRotationAttrib = 0x4,
|
||||
eScaleAttrib = 0x8,
|
||||
eModelAttrib = 0x10,
|
||||
eAnimSetAttrib = 0x20,
|
||||
eVolumeAttrib = 0x40,
|
||||
eVulnerabilityAttrib = 0x80,
|
||||
eInvalidAttrib = 0x80000000
|
||||
};
|
||||
DEFINE_ENUM_FLAGS(EAttribType)
|
||||
|
||||
// functions defined in CScriptTemplate.cpp
|
||||
EAttribType AttribStringToAttribEnum(const std::string& Attrib);
|
||||
std::string AttribEnumToAttribString(EAttribType Attrib);
|
||||
|
||||
#endif // EATTRIBTYPE
|
||||
|
||||
130
Resource/script/EObjectType.h
Normal file
130
Resource/script/EObjectType.h
Normal file
@@ -0,0 +1,130 @@
|
||||
#ifndef EOBJECTTYPE_H
|
||||
#define EOBJECTTYPE_H
|
||||
|
||||
// dunno if this is actually needed, but here it is.
|
||||
enum EObjectType
|
||||
{
|
||||
Actor = 0x0,
|
||||
Waypoint = 0x2,
|
||||
DoorArea = 0x3,
|
||||
Trigger = 0x4,
|
||||
Timer = 0x5,
|
||||
Counter = 0x6,
|
||||
Effect = 0x7,
|
||||
Platform = 0x8,
|
||||
Sound = 0x9,
|
||||
Generator = 0xA,
|
||||
Dock = 0xB,
|
||||
Camera = 0xC,
|
||||
CameraWaypoint = 0xD,
|
||||
NewIntroBoss = 0xE,
|
||||
SpawnPoint = 0xF,
|
||||
CameraHint = 0x10,
|
||||
Pickup = 0x11,
|
||||
MemoryRelay = 0x13,
|
||||
RandomRelay = 0x14,
|
||||
Relay = 0x15,
|
||||
Beetle = 0x16,
|
||||
HUDMemo = 0x17,
|
||||
CameraFilterKeyframe = 0x18,
|
||||
CameraBlurKeyframe = 0x19,
|
||||
DamageableTrigger = 0x1A,
|
||||
Debris = 0x1B,
|
||||
CameraShaker = 0x1C,
|
||||
ActorKeyFrame = 0x1D,
|
||||
Water = 0x20,
|
||||
Warwasp = 0x21,
|
||||
SpacePirate = 0x24,
|
||||
FlyingPirate = 0x25,
|
||||
ElitePirate = 0x26,
|
||||
MetroidBeta = 0x27,
|
||||
ChozoGhost = 0x28,
|
||||
CoverPoint = 0x2A,
|
||||
SpiderBallWaypoint = 0x2C,
|
||||
BloodFlower = 0x2D,
|
||||
FlickerBat = 0x2E,
|
||||
PathCamera = 0x2F,
|
||||
GrapplePoint = 0x30,
|
||||
PuddleSpore = 0x31,
|
||||
SpiderBallAttractionSurface = 0x33,
|
||||
PuddleToadGamma = 0x34,
|
||||
Fog = 0x35,
|
||||
FireFlea = 0x36,
|
||||
MetareeAlpha = 0x37,
|
||||
ActorRotate = 0x39,
|
||||
SpecialFunction = 0x3A,
|
||||
SpankWeed = 0x3B,
|
||||
Zoomer = 0x3D,
|
||||
PlayerHint = 0x3E,
|
||||
Ripper = 0x3F,
|
||||
PickupGenerator = 0x40,
|
||||
PointOfInterest = 0x42,
|
||||
Drone = 0x43,
|
||||
MetroidAlpha = 0x44,
|
||||
DebrisExtended = 0x45,
|
||||
Steam = 0x46,
|
||||
Ripple = 0x47,
|
||||
BallTrigger = 0x48,
|
||||
TargetingPoint = 0x49,
|
||||
ElectroMagneticPulse = 0x4A,
|
||||
IceSheegoth = 0x4B,
|
||||
PlayerActor = 0x4C,
|
||||
Flaahgra = 0x4D,
|
||||
AreaAttributes = 0x4E,
|
||||
FishCloud = 0x4F,
|
||||
FishCloudModifier = 0x50,
|
||||
VisorFlare = 0x51,
|
||||
VisorGoo = 0x53,
|
||||
JellyZap = 0x54,
|
||||
ControllerAction = 0x55,
|
||||
Switch = 0x56,
|
||||
PlayerStateChange = 0x57,
|
||||
Thardus = 0x58,
|
||||
WallCrawlerSwarm = 0x5A,
|
||||
AIJumpPoint = 0x5B,
|
||||
FlaahgraTentacle = 0x5C,
|
||||
RoomAcoustics = 0x5D,
|
||||
ColorModulate = 0x5E,
|
||||
ThardusRockProjectile = 0x5F,
|
||||
Midi = 0x60,
|
||||
StreamedAudio = 0x61,
|
||||
WorldTeleporter = 0x62,
|
||||
Repulsor = 0x63,
|
||||
GunTurret = 0x64,
|
||||
Babygoth = 0x66,
|
||||
Eyeball = 0x67,
|
||||
RadialKnockback = 0x68,
|
||||
CameraPitchVolume = 0x69,
|
||||
EnvFxDensityController = 0x6A,
|
||||
Magdolite = 0x6B,
|
||||
TeamAIMgr = 0x6C,
|
||||
SnakeWeedSwarm = 0x6D,
|
||||
ActorContraption = 0x6E,
|
||||
Oculus = 0x6F,
|
||||
Geemer = 0x70,
|
||||
SpindleCamera = 0x71,
|
||||
AtomicAlpha = 0x72,
|
||||
CameraHintTrigger = 0x73,
|
||||
RumbleEffect = 0x74,
|
||||
AmbientAI = 0x75,
|
||||
AtomicBeta = 0x77,
|
||||
Puffer = 0x79,
|
||||
Tryclops = 0x7A,
|
||||
Ridley = 0x7B,
|
||||
Seedling = 0x7C,
|
||||
ThermalHeatFader = 0x7D,
|
||||
Burrower = 0x7F,
|
||||
ScriptBeam = 0x81,
|
||||
WorldLightFader = 0x82,
|
||||
MetroidPrimeStage2 = 0x83,
|
||||
MetroidPrimeRelay = 0x84,
|
||||
MazeNode = 0x85,
|
||||
OmegaPirate = 0x86,
|
||||
PhazonPool = 0x87,
|
||||
PhazonHealingNodule = 0x88,
|
||||
NewCameraShaker = 0x89,
|
||||
ShadowProjector = 0x8A,
|
||||
BeamEnergyBall = 0x8B
|
||||
};
|
||||
|
||||
#endif // EOBJECTTYPE_H
|
||||
28
Resource/script/EPropertyType.h
Normal file
28
Resource/script/EPropertyType.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef EPROPERTYTYPE
|
||||
#define EPROPERTYTYPE
|
||||
|
||||
#include <string>
|
||||
|
||||
enum EPropertyType
|
||||
{
|
||||
eBoolProperty,
|
||||
eByteProperty,
|
||||
eShortProperty,
|
||||
eLongProperty,
|
||||
eFloatProperty,
|
||||
eStringProperty,
|
||||
eVector3Property,
|
||||
eColorProperty,
|
||||
eEnumProperty,
|
||||
eFileProperty,
|
||||
eStructProperty,
|
||||
eUnknownProperty,
|
||||
eInvalidProperty
|
||||
};
|
||||
|
||||
// functions defined in CScriptTemplate.cpp
|
||||
EPropertyType PropStringToPropEnum(std::string prop);
|
||||
std::string PropEnumToPropString(EPropertyType prop);
|
||||
|
||||
#endif // EPROPERTYTYPE
|
||||
|
||||
13
Resource/script/SConnection.h
Normal file
13
Resource/script/SConnection.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef SCONNECTION_H
|
||||
#define SCONNECTION_H
|
||||
|
||||
#include <Common/types.h>
|
||||
|
||||
struct SLink
|
||||
{
|
||||
u32 State;
|
||||
u32 Message;
|
||||
u32 ObjectID; // not a pointer because it can refer to objects outside the current area
|
||||
};
|
||||
|
||||
#endif // SCONNECTION_H
|
||||
Reference in New Issue
Block a user