mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-16 08:27:01 +00:00
Finished the template writer and regenerated templates (most of the template changes are just automated formatting changes)
This commit is contained in:
@@ -99,6 +99,11 @@ TString CMasterTemplate::MessageByIndex(u32 Index)
|
||||
return (std::next(it, Index))->second;
|
||||
}
|
||||
|
||||
TString CMasterTemplate::GetDirectory() const
|
||||
{
|
||||
return mSourceFile.GetFileDirectory();
|
||||
}
|
||||
|
||||
bool CMasterTemplate::IsLoadedSuccessfully()
|
||||
{
|
||||
return mFullyLoaded;
|
||||
@@ -135,6 +140,79 @@ TString CMasterTemplate::GetPropertyName(u32 PropertyID)
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
void CMasterTemplate::AddProperty(IPropertyTemplate *pTemp, const TString& rkTemplateName)
|
||||
{
|
||||
auto it = smIDMap.find(pTemp->PropertyID());
|
||||
|
||||
// Add this property/template to existing ID info
|
||||
if (it != smIDMap.end())
|
||||
{
|
||||
SPropIDInfo& rInfo = it->second;
|
||||
bool NewTemplate = true;
|
||||
|
||||
for (u32 iTemp = 0; iTemp < rInfo.XMLList.size(); iTemp++)
|
||||
{
|
||||
if (rInfo.XMLList[iTemp] == rkTemplateName)
|
||||
{
|
||||
NewTemplate = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NewTemplate)
|
||||
rInfo.XMLList.push_back(rkTemplateName);
|
||||
|
||||
it->second.PropertyList.push_back(pTemp);
|
||||
}
|
||||
|
||||
// Create new ID info
|
||||
else
|
||||
{
|
||||
SPropIDInfo Info;
|
||||
Info.XMLList.push_back(rkTemplateName);
|
||||
Info.PropertyList.push_back(pTemp);
|
||||
smIDMap[pTemp->PropertyID()] = Info;
|
||||
}
|
||||
}
|
||||
|
||||
void CMasterTemplate::RenameProperty(u32 ID, const TString& rkNewName)
|
||||
{
|
||||
auto NameIt = smPropertyNames.find(ID);
|
||||
TString CurName = (NameIt == smPropertyNames.end() ? "" : NameIt->second);
|
||||
|
||||
auto InfoIt = smIDMap.find(ID);
|
||||
|
||||
if (InfoIt != smIDMap.end())
|
||||
{
|
||||
const SPropIDInfo& rkInfo = InfoIt->second;
|
||||
|
||||
for (u32 iTemp = 0; iTemp < rkInfo.PropertyList.size(); iTemp++)
|
||||
{
|
||||
IPropertyTemplate *pTemp = rkInfo.PropertyList[iTemp];
|
||||
|
||||
if (pTemp->Name() == CurName)
|
||||
pTemp->SetName(rkNewName);
|
||||
}
|
||||
}
|
||||
|
||||
if (NameIt != smPropertyNames.end())
|
||||
smPropertyNames[ID] = rkNewName;
|
||||
}
|
||||
|
||||
std::vector<TString> CMasterTemplate::GetTemplatesUsingID(u32 ID)
|
||||
{
|
||||
auto InfoIt = smIDMap.find(ID);
|
||||
|
||||
if (InfoIt != smIDMap.end())
|
||||
{
|
||||
const SPropIDInfo& rkInfo = InfoIt->second;
|
||||
return rkInfo.XMLList;
|
||||
}
|
||||
else
|
||||
return std::vector<TString>();
|
||||
}
|
||||
|
||||
std::map<u32, CMasterTemplate::SPropIDInfo> CMasterTemplate::smIDMap;
|
||||
std::map<EGame, CMasterTemplate*> CMasterTemplate::smMasterMap;
|
||||
std::map<u32, TString> CMasterTemplate::smPropertyNames;
|
||||
u32 CMasterTemplate::smGameListVersion;
|
||||
|
||||
@@ -18,11 +18,18 @@ class CMasterTemplate
|
||||
bool mFullyLoaded;
|
||||
|
||||
std::vector<TString> mGameVersions;
|
||||
std::map<TString, CStructTemplate*> mStructTemplates;
|
||||
|
||||
std::map<u32, CScriptTemplate*> mTemplates;
|
||||
std::map<u32, TString> mStates;
|
||||
std::map<u32, TString> mMessages;
|
||||
|
||||
|
||||
struct SPropIDInfo
|
||||
{
|
||||
std::vector<TString> XMLList; // List of script/struct templates that use this ID
|
||||
std::vector<IPropertyTemplate*> PropertyList; // List of all properties that use this ID
|
||||
};
|
||||
static std::map<u32, SPropIDInfo> smIDMap;
|
||||
static std::map<EGame, CMasterTemplate*> smMasterMap;
|
||||
static std::map<u32, TString> smPropertyNames;
|
||||
static u32 smGameListVersion;
|
||||
@@ -45,11 +52,15 @@ public:
|
||||
TString MessageByID(u32 MessageID);
|
||||
TString MessageByID(const CFourCC& MessageID);
|
||||
TString MessageByIndex(u32 Index);
|
||||
TString GetDirectory() const;
|
||||
bool IsLoadedSuccessfully();
|
||||
|
||||
static CMasterTemplate* GetMasterForGame(EGame Game);
|
||||
static std::list<CMasterTemplate*> GetMasterList();
|
||||
static TString GetPropertyName(u32 PropertyID);
|
||||
static void AddProperty(IPropertyTemplate *pTemp, const TString& rkTemplateName);
|
||||
static void RenameProperty(u32 ID, const TString& rkNewName);
|
||||
static std::vector<TString> GetTemplatesUsingID(u32 ID);
|
||||
};
|
||||
|
||||
// ************ INLINE ************
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
IPropertyTemplate(u32 ID, CStructTemplate *pParent = 0)
|
||||
: mID(ID)
|
||||
, mpParent(pParent)
|
||||
, mName("Unknown")
|
||||
, mName("UNSET PROPERTY NAME")
|
||||
, mCookPreference(eNoCookPreference)
|
||||
{
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
|
||||
// TTypedPropertyTemplate - Template property class that allows for tracking
|
||||
// a default value. Typedefs are set up for a bunch of property types.
|
||||
template<typename PropType, EPropertyType PropTypeEnum, class ValueClass>
|
||||
template<typename PropType, EPropertyType PropTypeEnum, class ValueClass, bool CanHaveDefaultValue>
|
||||
class TTypedPropertyTemplate : public IPropertyTemplate
|
||||
{
|
||||
friend class CTemplateLoader;
|
||||
@@ -146,9 +146,9 @@ public:
|
||||
TTypedPropertyTemplate(u32 ID, const TString& rkName, ECookPreference CookPreference, CStructTemplate *pParent = 0)
|
||||
: IPropertyTemplate(ID, rkName, CookPreference, pParent) {}
|
||||
|
||||
virtual EPropertyType Type() const { return PropTypeEnum; }
|
||||
virtual bool CanHaveDefault() const { return true; }
|
||||
virtual bool IsNumerical() const { return false; }
|
||||
virtual EPropertyType Type() const { return PropTypeEnum; }
|
||||
virtual bool CanHaveDefault() const { return CanHaveDefaultValue; }
|
||||
virtual bool IsNumerical() const { return false; }
|
||||
|
||||
virtual IProperty* InstantiateProperty(CPropertyStruct *pParent)
|
||||
{
|
||||
@@ -200,7 +200,7 @@ public:
|
||||
// TNumericalPropertyTemplate - Subclass of TTypedPropertyTemplate for numerical
|
||||
// property types, and allows a min/max value and a suffix to be tracked.
|
||||
template<typename PropType, EPropertyType PropTypeEnum, class ValueClass>
|
||||
class TNumericalPropertyTemplate : public TTypedPropertyTemplate<PropType,PropTypeEnum,ValueClass>
|
||||
class TNumericalPropertyTemplate : public TTypedPropertyTemplate<PropType,PropTypeEnum,ValueClass,true>
|
||||
{
|
||||
friend class CTemplateLoader;
|
||||
friend class CTemplateWriter;
|
||||
@@ -252,7 +252,7 @@ public:
|
||||
|
||||
virtual void SetParam(const TString& rkParamName, const TString& rkValue)
|
||||
{
|
||||
TTypedPropertyTemplate<PropType,PropTypeEnum,ValueClass>::SetParam(rkParamName, rkValue);
|
||||
TTypedPropertyTemplate::SetParam(rkParamName, rkValue);
|
||||
|
||||
if (rkParamName == "range")
|
||||
{
|
||||
@@ -288,14 +288,15 @@ public:
|
||||
};
|
||||
|
||||
// Typedefs for all property types that don't need further functionality.
|
||||
typedef TTypedPropertyTemplate<bool, eBoolProperty, CBoolValue> TBoolTemplate;
|
||||
typedef TNumericalPropertyTemplate<s8, eByteProperty, CByteValue> TByteTemplate;
|
||||
typedef TNumericalPropertyTemplate<s16, eShortProperty, CShortValue> TShortTemplate;
|
||||
typedef TNumericalPropertyTemplate<s32, eLongProperty, CLongValue> TLongTemplate;
|
||||
typedef TNumericalPropertyTemplate<float, eFloatProperty, CFloatValue> TFloatTemplate;
|
||||
typedef TTypedPropertyTemplate<TString, eStringProperty, CStringValue> TStringTemplate;
|
||||
typedef TTypedPropertyTemplate<CVector3f, eVector3Property, CVector3Value> TVector3Template;
|
||||
typedef TTypedPropertyTemplate<CColor, eColorProperty, CColorValue> TColorTemplate;
|
||||
typedef TTypedPropertyTemplate<bool, eBoolProperty, CBoolValue, true> TBoolTemplate;
|
||||
typedef TNumericalPropertyTemplate<s8, eByteProperty, CByteValue> TByteTemplate;
|
||||
typedef TNumericalPropertyTemplate<s16, eShortProperty, CShortValue> TShortTemplate;
|
||||
typedef TNumericalPropertyTemplate<s32, eLongProperty, CLongValue> TLongTemplate;
|
||||
typedef TNumericalPropertyTemplate<float, eFloatProperty, CFloatValue> TFloatTemplate;
|
||||
typedef TTypedPropertyTemplate<TString, eStringProperty, CStringValue, false> TStringTemplate;
|
||||
typedef TTypedPropertyTemplate<CVector3f, eVector3Property, CVector3Value, true> TVector3Template;
|
||||
typedef TTypedPropertyTemplate<CColor, eColorProperty, CColorValue, true> TColorTemplate;
|
||||
typedef TTypedPropertyTemplate<CAnimationParameters, eCharacterProperty, CCharacterValue, false> TCharacterTemplate;
|
||||
|
||||
// CFileTemplate - Property template for files. Tracks a list of file types that
|
||||
// the property is allowed to accept.
|
||||
@@ -348,36 +349,8 @@ public:
|
||||
const TStringList& Extensions() const { return mAcceptedExtensions; }
|
||||
};
|
||||
|
||||
// CCharacterTemplate - Typed property that doesn't allow default values.
|
||||
class CCharacterTemplate : public TTypedPropertyTemplate<CAnimationParameters,
|
||||
eCharacterProperty,
|
||||
CCharacterValue>
|
||||
{
|
||||
friend class CTemplateLoader;
|
||||
friend class CTemplateWriter;
|
||||
|
||||
public:
|
||||
CCharacterTemplate(u32 ID, CStructTemplate *pParent = 0)
|
||||
: TTypedPropertyTemplate(ID, pParent) { }
|
||||
|
||||
CCharacterTemplate(u32 ID, const TString& rkName, ECookPreference CookPreference, CStructTemplate *pParent = 0)
|
||||
: TTypedPropertyTemplate(ID, rkName, CookPreference, pParent) { }
|
||||
|
||||
virtual bool CanHaveDefault() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IProperty* InstantiateProperty(CPropertyStruct *pParent)
|
||||
{
|
||||
return new TCharacterProperty(this, pParent);
|
||||
}
|
||||
|
||||
DEFINE_TEMPLATE_CLONE(CCharacterTemplate)
|
||||
};
|
||||
|
||||
// CEnumTemplate - Property template for enums. Tracks a list of possible values (enumerators).
|
||||
class CEnumTemplate : public TLongTemplate
|
||||
class CEnumTemplate : public TTypedPropertyTemplate<s32, eEnumProperty, CHexLongValue, true>
|
||||
{
|
||||
friend class CTemplateLoader;
|
||||
friend class CTemplateWriter;
|
||||
@@ -400,12 +373,12 @@ class CEnumTemplate : public TLongTemplate
|
||||
|
||||
public:
|
||||
CEnumTemplate(u32 ID, CStructTemplate *pParent = 0)
|
||||
: TLongTemplate(ID, pParent)
|
||||
: TTypedPropertyTemplate(ID, pParent)
|
||||
{
|
||||
}
|
||||
|
||||
CEnumTemplate(u32 ID, const TString& rkName, ECookPreference CookPreference, CStructTemplate *pParent = 0)
|
||||
: TLongTemplate(ID, rkName, CookPreference, pParent)
|
||||
: TTypedPropertyTemplate(ID, rkName, CookPreference, pParent)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -424,7 +397,7 @@ public:
|
||||
|
||||
virtual void Copy(const IPropertyTemplate *pkTemp)
|
||||
{
|
||||
TLongTemplate::Copy(pkTemp);
|
||||
TTypedPropertyTemplate::Copy(pkTemp);
|
||||
|
||||
const CEnumTemplate *pkEnum = static_cast<const CEnumTemplate*>(pkTemp);
|
||||
mEnumerators = pkEnum->mEnumerators;
|
||||
@@ -435,7 +408,7 @@ public:
|
||||
{
|
||||
const CEnumTemplate *pkEnum = static_cast<const CEnumTemplate*>(pkTemp);
|
||||
|
||||
return ( (TLongTemplate::Matches(pkTemp)) &&
|
||||
return ( (TTypedPropertyTemplate::Matches(pkTemp)) &&
|
||||
(mEnumerators == pkEnum->mEnumerators) &&
|
||||
(mSourceFile == pkEnum->mSourceFile) );
|
||||
}
|
||||
@@ -474,7 +447,7 @@ public:
|
||||
|
||||
// CBitfieldTemplate - Property template for bitfields, which can have multiple
|
||||
// distinct boolean parameters packed into one property.
|
||||
class CBitfieldTemplate : public TTypedPropertyTemplate<u32, eBitfieldProperty, CHexLongValue>
|
||||
class CBitfieldTemplate : public TTypedPropertyTemplate<u32, eBitfieldProperty, CHexLongValue, true>
|
||||
{
|
||||
friend class CTemplateLoader;
|
||||
friend class CTemplateWriter;
|
||||
@@ -594,6 +567,11 @@ public:
|
||||
IPropertyTemplate::Copy(pkTemp);
|
||||
|
||||
const CStructTemplate *pkStruct = static_cast<const CStructTemplate*>(pkTemp);
|
||||
CopyStructData(pkStruct);
|
||||
}
|
||||
|
||||
void CopyStructData(const CStructTemplate *pkStruct)
|
||||
{
|
||||
mVersionPropertyCounts = pkStruct->mVersionPropertyCounts;
|
||||
mIsSingleProperty = pkStruct->mIsSingleProperty;
|
||||
mSourceFile = pkStruct->mSourceFile;
|
||||
@@ -611,7 +589,17 @@ public:
|
||||
if ( (IPropertyTemplate::Matches(pkTemp)) &&
|
||||
(mVersionPropertyCounts == pkStruct->mVersionPropertyCounts) &&
|
||||
(mIsSingleProperty == pkStruct->mIsSingleProperty) &&
|
||||
(mSourceFile == pkStruct->mSourceFile) &&
|
||||
(mSourceFile == pkStruct->mSourceFile) )
|
||||
{
|
||||
return StructDataMatches(pkStruct);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StructDataMatches(const CStructTemplate *pkStruct) const
|
||||
{
|
||||
if ( (mIsSingleProperty == pkStruct->mIsSingleProperty) &&
|
||||
(mSubProperties.size() == pkStruct->mSubProperties.size()) )
|
||||
{
|
||||
for (u32 iSub = 0; iSub < mSubProperties.size(); iSub++)
|
||||
@@ -673,6 +661,8 @@ public:
|
||||
|
||||
virtual void Copy(const IPropertyTemplate *pkTemp)
|
||||
{
|
||||
IPropertyTemplate::Copy(pkTemp);
|
||||
|
||||
CStructTemplate::Copy(pkTemp);
|
||||
mElementName = static_cast<const CArrayTemplate*>(pkTemp)->mElementName;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
|
||||
TString ToString() const
|
||||
{
|
||||
return TString::HexString(mValue, true, true, 8);
|
||||
return TString::HexString(mValue, true, true, mValue > 0xFF ? 8 : 2);
|
||||
}
|
||||
|
||||
void FromString(const TString& rkString)
|
||||
|
||||
Reference in New Issue
Block a user