diff --git a/src/Core/Resource/Script/CScriptTemplate.h b/src/Core/Resource/Script/CScriptTemplate.h index 28076d18..364be38b 100644 --- a/src/Core/Resource/Script/CScriptTemplate.h +++ b/src/Core/Resource/Script/CScriptTemplate.h @@ -109,6 +109,7 @@ private: public: CScriptTemplate(CMasterTemplate *pMaster); ~CScriptTemplate(); + void Serialize(IArchive& rArc); void PostLoad(); EGame Game() const; diff --git a/src/Core/Resource/Script/IPropertyNew.cpp b/src/Core/Resource/Script/IPropertyNew.cpp index be439dbb..6c3f6f3f 100644 --- a/src/Core/Resource/Script/IPropertyNew.cpp +++ b/src/Core/Resource/Script/IPropertyNew.cpp @@ -91,7 +91,6 @@ void* IPropertyNew::GetChildDataPointer(void* pPropertyData) const return pPropertyData; } -#if 0 void IPropertyNew::Serialize(IArchive& rArc) { if (rArc.Game() <= ePrime) @@ -101,13 +100,12 @@ void IPropertyNew::Serialize(IArchive& rArc) rArc << SERIAL_HEX("ID", mID) << SERIAL("Description", mDescription) - << SERIAL("CookPref", mCookPref) + << SERIAL("CookPref", mCookPreference) << SERIAL("MinVersion", mMinVersion) << SERIAL("MaxVersion", mMaxVersion); // Children don't get serialized for most property types } -#endif void IPropertyNew::InitFromArchetype(IPropertyNew* pOther) { diff --git a/src/Core/Resource/Script/IPropertyNew.h b/src/Core/Resource/Script/IPropertyNew.h index ea86a8ff..abd5f960 100644 --- a/src/Core/Resource/Script/IPropertyNew.h +++ b/src/Core/Resource/Script/IPropertyNew.h @@ -20,20 +20,20 @@ typedef TString TIDString; enum class EPropertyFlag : u32 { /** Property is an archetype (a template for other properties to copy from) */ - IsArchetype = 0x1, + IsArchetype = 0x1, /** Property is an array archetype (a template for elements of an array property) */ - IsArrayArchetype = 0x2, + IsArrayArchetype = 0x2, /** This property and all its children are a single unit and do not have individual property IDs, sizes, etc. */ - IsAtomic = 0x4, + IsAtomic = 0x4, /** We have cached whether the property name is correct */ - HasCachedNameCheck = 0x40000000, + HasCachedNameCheck = 0x40000000, /** The name of the property is a match for the property ID hash */ - HasCorrectPropertyName = 0x80000000, + HasCorrectPropertyName = 0x80000000, /** Flags that are left intact when copying from an archetype */ - ArchetypeCopyFlags = EPropertyFlag::IsAtomic, + ArchetypeCopyFlags = EPropertyFlag::IsAtomic, /** Flags that are inheritable from parent */ - InheritableFlags = EPropertyFlag::IsArchetype | EPropertyFlag::IsArrayArchetype | EPropertyFlag::IsAtomic, + InheritableFlags = EPropertyFlag::IsArchetype | EPropertyFlag::IsArrayArchetype | EPropertyFlag::IsAtomic, }; DECLARE_FLAGS_ENUMCLASS(EPropertyFlag, FPropertyFlags) @@ -190,9 +190,7 @@ public: virtual const char* HashableTypeName() const; virtual void* GetChildDataPointer(void* pPropertyData) const; -#if 0 virtual void Serialize(IArchive& rArc); -#endif virtual void InitFromArchetype(IPropertyNew* pOther); virtual TString GetTemplateFileName(); @@ -215,7 +213,6 @@ public: inline IPropertyNew* RootParent(); inline IPropertyNew* Archetype() const; inline CScriptTemplate* ScriptTemplate() const; - inline CMasterTemplate* MasterTemplate() const; inline TString Name() const; inline TString Description() const; inline TString Suffix() const; @@ -349,14 +346,6 @@ public: virtual bool CanHaveDefault() const { return true; } -#if 0 - virtual void Serialize(IArchive& rArc) - { - IPropertyNew::Serialize(rArc); - rArc << SERIAL("DefaultValue", mDefaultValue); - } -#endif - virtual void InitFromArchetype(IPropertyNew* pOther) { IPropertyNew::InitFromArchetype(pOther); @@ -382,7 +371,23 @@ public: }; template -class TNumericalPropertyNew : public TTypedPropertyNew +class TSerializeableTypedProperty : public TTypedPropertyNew +{ +protected: + TSerializeableTypedProperty() + : TTypedPropertyNew() + {} + +public: + virtual void Serialize(IArchive& rArc) + { + IPropertyNew::Serialize(rArc); + rArc << SERIAL("DefaultValue", mDefaultValue); + } +}; + +template +class TNumericalPropertyNew : public TSerializeableTypedProperty { friend class IPropertyNew; friend class CTemplateLoader; @@ -392,20 +397,18 @@ protected: PropType mMaxValue; TNumericalPropertyNew() - : TTypedPropertyNew() + : TSerializeableTypedProperty() , mMinValue( -1 ) , mMaxValue( -1 ) {} public: -#if 0 virtual void Serialize(IArchive& rArc) { TTypedPropertyNew::Serialize(rArc); - rArc << SERIAL("Min", mMin) - << SERIAL("Max", mMax); + rArc << SERIAL("Min", mMinValue) + << SERIAL("Max", mMaxValue); } -#endif virtual void InitFromArchetype(IPropertyNew* pOther) { diff --git a/src/Core/Resource/Script/Property/CAnimationProperty.h b/src/Core/Resource/Script/Property/CAnimationProperty.h index 7d13c230..2acf9d29 100644 --- a/src/Core/Resource/Script/Property/CAnimationProperty.h +++ b/src/Core/Resource/Script/Property/CAnimationProperty.h @@ -3,13 +3,13 @@ #include "../IPropertyNew.h" -class CAnimationProperty : public TTypedPropertyNew< int, EPropertyTypeNew::Animation > +class CAnimationProperty : public TSerializeableTypedProperty< u32, EPropertyTypeNew::Animation > { friend class IPropertyNew; protected: CAnimationProperty() - : TTypedPropertyNew() + : TSerializeableTypedProperty() {} public: diff --git a/src/Core/Resource/Script/Property/CAnimationSetProperty.h b/src/Core/Resource/Script/Property/CAnimationSetProperty.h index 30c786d9..5d9c0589 100644 --- a/src/Core/Resource/Script/Property/CAnimationSetProperty.h +++ b/src/Core/Resource/Script/Property/CAnimationSetProperty.h @@ -3,13 +3,13 @@ #include "../IPropertyNew.h" -class CAnimationSetProperty : public TTypedPropertyNew< CAnimationParameters, EPropertyTypeNew::AnimationSet > +class CAnimationSetProperty : public TSerializeableTypedProperty< CAnimationParameters, EPropertyTypeNew::AnimationSet > { friend class IPropertyNew; protected: CAnimationSetProperty() - : TTypedPropertyNew() + : TSerializeableTypedProperty() {} public: diff --git a/src/Core/Resource/Script/Property/CArrayProperty.h b/src/Core/Resource/Script/Property/CArrayProperty.h index d0fda7c8..6928dfed 100644 --- a/src/Core/Resource/Script/Property/CArrayProperty.h +++ b/src/Core/Resource/Script/Property/CArrayProperty.h @@ -20,7 +20,7 @@ struct SScriptArray /** You probably shouldn't use this on intrinsic classes; script only */ /** @todo proper support of default values for arrays (this would be used for prefabs) */ -class CArrayProperty : public TTypedPropertyNew +class CArrayProperty : public TTypedPropertyNew { friend class IPropertyNew; friend class CTemplateLoader; @@ -105,6 +105,12 @@ public: Resize(pPropertyData, rArray.Count); } + virtual void Serialize(IArchive& rArc) + { + TTypedPropertyNew::Serialize(rArc); + //rArc << SERIAL("ItemArchetype", mpItemArchetype); + } + virtual void SerializeValue(void* pData, IArchive& Arc) const { u32 Count = ArrayCount(pData); diff --git a/src/Core/Resource/Script/Property/CAssetProperty.h b/src/Core/Resource/Script/Property/CAssetProperty.h index 6e1a4960..ed60de45 100644 --- a/src/Core/Resource/Script/Property/CAssetProperty.h +++ b/src/Core/Resource/Script/Property/CAssetProperty.h @@ -4,19 +4,17 @@ #include "../IPropertyNew.h" #include "Core/Resource/CResTypeFilter.h" -class CAssetProperty : public TTypedPropertyNew +class CAssetProperty : public TSerializeableTypedProperty { friend class CTemplateLoader; CResTypeFilter mTypeFilter; public: -#if 0 virtual void Serialize(IArchive& rArc) { - TTypedPropertyNew::Serialize(rArc); + TSerializeableTypedProperty::Serialize(rArc); rArc << SERIAL("AcceptedTypes", mTypeFilter); } -#endif virtual void InitFromArchetype(IPropertyNew* pOther) { diff --git a/src/Core/Resource/Script/Property/CBoolProperty.h b/src/Core/Resource/Script/Property/CBoolProperty.h index 98dd2379..bd384c26 100644 --- a/src/Core/Resource/Script/Property/CBoolProperty.h +++ b/src/Core/Resource/Script/Property/CBoolProperty.h @@ -3,13 +3,13 @@ #include "../IPropertyNew.h" -class CBoolProperty : public TTypedPropertyNew< bool, EPropertyTypeNew::Bool > +class CBoolProperty : public TSerializeableTypedProperty< bool, EPropertyTypeNew::Bool > { friend class IPropertyNew; protected: CBoolProperty() - : TTypedPropertyNew() + : TSerializeableTypedProperty() {} public: diff --git a/src/Core/Resource/Script/Property/CByteProperty.h b/src/Core/Resource/Script/Property/CByteProperty.h index a0dbbe74..e458242e 100644 --- a/src/Core/Resource/Script/Property/CByteProperty.h +++ b/src/Core/Resource/Script/Property/CByteProperty.h @@ -3,7 +3,7 @@ #include "../IPropertyNew.h" -class CByteProperty : public TNumericalPropertyNew< char, EPropertyTypeNew::Byte > +class CByteProperty : public TNumericalPropertyNew< s8, EPropertyTypeNew::Byte > { friend class IPropertyNew; diff --git a/src/Core/Resource/Script/Property/CColorProperty.h b/src/Core/Resource/Script/Property/CColorProperty.h index e8adb09b..ea6ff90d 100644 --- a/src/Core/Resource/Script/Property/CColorProperty.h +++ b/src/Core/Resource/Script/Property/CColorProperty.h @@ -3,13 +3,13 @@ #include "../IPropertyNew.h" -class CColorProperty : public TTypedPropertyNew< CColor, EPropertyTypeNew::Color > +class CColorProperty : public TSerializeableTypedProperty< CColor, EPropertyTypeNew::Color > { friend class IPropertyNew; protected: CColorProperty() - : TTypedPropertyNew() + : TSerializeableTypedProperty() {} public: diff --git a/src/Core/Resource/Script/Property/CEnumProperty.h b/src/Core/Resource/Script/Property/CEnumProperty.h index 2fff8240..ada67dd9 100644 --- a/src/Core/Resource/Script/Property/CEnumProperty.h +++ b/src/Core/Resource/Script/Property/CEnumProperty.h @@ -11,7 +11,7 @@ * In PWE, however, they are both implemented the same way under the hood. */ template -class TEnumPropertyBase : public TTypedPropertyNew +class TEnumPropertyBase : public TSerializeableTypedProperty { friend class CTemplateLoader; struct SEnumValue @@ -19,13 +19,24 @@ class TEnumPropertyBase : public TTypedPropertyNew TString Name; u32 ID; + SEnumValue() + : ID(0) + {} + SEnumValue(const TString& rkInName, u32 InID) : Name(rkInName), ID(InID) {} + inline bool operator==(const SEnumValue& rkOther) const { return( Name == rkOther.Name && ID == rkOther.ID ); } + + void Serialize(IArchive& rArc) + { + rArc << SERIAL_AUTO(Name) + << SERIAL_HEX_AUTO(ID); + } }; std::vector mValues; @@ -41,6 +52,12 @@ public: return "choice"; } + virtual void Serialize(IArchive& rArc) + { + TSerializeableTypedProperty::Serialize(rArc); + rArc << SERIAL_CONTAINER("Values", mValues, "Values"); + } + virtual void SerializeValue(void* pData, IArchive& Arc) const { Arc.SerializePrimitive( (u32&) ValueRef(pData) ); diff --git a/src/Core/Resource/Script/Property/CFlagsProperty.h b/src/Core/Resource/Script/Property/CFlagsProperty.h index 71ae6613..4abf3449 100644 --- a/src/Core/Resource/Script/Property/CFlagsProperty.h +++ b/src/Core/Resource/Script/Property/CFlagsProperty.h @@ -3,7 +3,7 @@ #include "../IPropertyNew.h" -class CFlagsProperty : public TTypedPropertyNew +class CFlagsProperty : public TSerializeableTypedProperty { friend class CTemplateLoader; friend class IPropertyNew; @@ -13,6 +13,10 @@ class CFlagsProperty : public TTypedPropertyNew TString Name; u32 Mask; + SBitFlag() + : Mask(0) + {} + SBitFlag(const TString& rkInName, u32 InMask) : Name(rkInName), Mask(InMask) {} @@ -22,13 +26,11 @@ class CFlagsProperty : public TTypedPropertyNew return( Name == rkOther.Name && Mask == rkOther.Mask ); } -#if 0 void Serialize(IArchive& rArc) { rArc << SERIAL("FlagName", Name) << SERIAL_HEX("FlagMask", Mask); } -#endif }; std::vector mBitFlags; u32 mAllFlags; @@ -37,7 +39,7 @@ class CFlagsProperty : public TTypedPropertyNew TString mSourceFile; CFlagsProperty() - : TTypedPropertyNew() + : TSerializeableTypedProperty() , mAllFlags(0) {} @@ -59,21 +61,11 @@ public: return mBitFlags[Idx].Mask; } -#if 0 virtual void Serialize(IArchive& rArc) { - TTypedPropertyNew::Serialize(rArc); - rArc << SERIAL_CONTAINER("Flags", mFlags, "Flag"); - - // Initialize the "all flags" cache - if (rArc.IsReader()) - { - mAllFlags = 0; - for (u32 FlagIdx = 0; FlagIdx < mFlags.size(); FlagIdx++) - mAllFlags |= mFlags[FlagIdx].Mask; - } + TSerializeableTypedProperty::Serialize(rArc); + rArc << SERIAL_CONTAINER("Flags", mBitFlags, "Flag"); } -#endif virtual void PostInitialize() { diff --git a/src/Core/Resource/Script/Property/CIntProperty.h b/src/Core/Resource/Script/Property/CIntProperty.h index 68effd44..4e6ea93a 100644 --- a/src/Core/Resource/Script/Property/CIntProperty.h +++ b/src/Core/Resource/Script/Property/CIntProperty.h @@ -3,7 +3,7 @@ #include "../IPropertyNew.h" -class CIntProperty : public TNumericalPropertyNew< int, EPropertyTypeNew::Int > +class CIntProperty : public TNumericalPropertyNew< s32, EPropertyTypeNew::Int > { friend class IPropertyNew; diff --git a/src/Core/Resource/Script/Property/CSequenceProperty.h b/src/Core/Resource/Script/Property/CSequenceProperty.h index 1377d4fc..f4edcac3 100644 --- a/src/Core/Resource/Script/Property/CSequenceProperty.h +++ b/src/Core/Resource/Script/Property/CSequenceProperty.h @@ -3,7 +3,7 @@ #include "../IPropertyNew.h" -class CSequenceProperty : public TTypedPropertyNew< int, EPropertyTypeNew::Sequence > +class CSequenceProperty : public TTypedPropertyNew< s32, EPropertyTypeNew::Sequence > { friend class IPropertyNew; diff --git a/src/Core/Resource/Script/Property/CShortProperty.h b/src/Core/Resource/Script/Property/CShortProperty.h index f1e1c8c6..427ccdbb 100644 --- a/src/Core/Resource/Script/Property/CShortProperty.h +++ b/src/Core/Resource/Script/Property/CShortProperty.h @@ -3,7 +3,7 @@ #include "../IPropertyNew.h" -class CShortProperty : public TNumericalPropertyNew< short, EPropertyTypeNew::Short > +class CShortProperty : public TNumericalPropertyNew< s16, EPropertyTypeNew::Short > { friend class IPropertyNew; diff --git a/src/Core/Resource/Script/Property/CSoundProperty.h b/src/Core/Resource/Script/Property/CSoundProperty.h index 9c7aac53..8b7ed779 100644 --- a/src/Core/Resource/Script/Property/CSoundProperty.h +++ b/src/Core/Resource/Script/Property/CSoundProperty.h @@ -3,13 +3,13 @@ #include "../IPropertyNew.h" -class CSoundProperty : public TTypedPropertyNew< int, EPropertyTypeNew::Sound > +class CSoundProperty : public TSerializeableTypedProperty< s32, EPropertyTypeNew::Sound > { friend class IPropertyNew; protected: CSoundProperty() - : TTypedPropertyNew() + : TSerializeableTypedProperty() {} public: diff --git a/src/Core/Resource/Script/Property/CStringProperty.h b/src/Core/Resource/Script/Property/CStringProperty.h index d1a0f763..e33b9f15 100644 --- a/src/Core/Resource/Script/Property/CStringProperty.h +++ b/src/Core/Resource/Script/Property/CStringProperty.h @@ -3,13 +3,13 @@ #include "../IPropertyNew.h" -class CStringProperty : public TTypedPropertyNew< TString, EPropertyTypeNew::String > +class CStringProperty : public TSerializeableTypedProperty< TString, EPropertyTypeNew::String > { friend class IPropertyNew; protected: CStringProperty() - : TTypedPropertyNew() + : TSerializeableTypedProperty() {} public: diff --git a/src/Core/Resource/Script/Property/CStructProperty.h b/src/Core/Resource/Script/Property/CStructProperty.h index 831d131c..3bf0aef9 100644 --- a/src/Core/Resource/Script/Property/CStructProperty.h +++ b/src/Core/Resource/Script/Property/CStructProperty.h @@ -87,14 +87,13 @@ public: return mpArchetype->HashableTypeName(); } -#if 0 virtual void Serialize(IArchive& rArc) { IPropertyNew::Serialize(rArc); if (rArc.ParamBegin("SubProperties")) { - u32 NumChildren; + u32 NumChildren = mChildren.size(); rArc.SerializeContainerSize(NumChildren, "Property"); if (rArc.IsReader()) @@ -111,7 +110,7 @@ public: if (rArc.IsReader()) { - mChildren[ChildIdx] = Create(Type, this, mpMasterTemplate, mpScriptTemplate); + mChildren[ChildIdx] = Create(Type, this, mGame, mpScriptTemplate); } mChildren[ChildIdx]->Serialize(rArc); @@ -122,7 +121,6 @@ public: rArc.ParamEnd(); } } -#endif virtual void SerializeValue(void* pData, IArchive& Arc) const { diff --git a/src/Core/Resource/Script/Property/CVectorProperty.h b/src/Core/Resource/Script/Property/CVectorProperty.h index f7811970..6a3fc968 100644 --- a/src/Core/Resource/Script/Property/CVectorProperty.h +++ b/src/Core/Resource/Script/Property/CVectorProperty.h @@ -3,13 +3,13 @@ #include "../IPropertyNew.h" -class CVectorProperty : public TTypedPropertyNew< CVector3f, EPropertyTypeNew::Vector > +class CVectorProperty : public TSerializeableTypedProperty< CVector3f, EPropertyTypeNew::Vector > { friend class IPropertyNew; protected: CVectorProperty() - : TTypedPropertyNew() + : TSerializeableTypedProperty() {} public: diff --git a/src/Editor/WorldEditor/CTemplateEditDialog.cpp b/src/Editor/WorldEditor/CTemplateEditDialog.cpp index 599162e0..24d7bdd0 100644 --- a/src/Editor/WorldEditor/CTemplateEditDialog.cpp +++ b/src/Editor/WorldEditor/CTemplateEditDialog.cpp @@ -132,7 +132,7 @@ void CTemplateEditDialog::AddTemplate(IPropertyNew* pProp) if (!Source.IsEmpty()) { - CStructPropertyNew* pStruct = pProp->MasterTemplate()->StructAtSource(Source); + CStructPropertyNew* pStruct = CMasterTemplate::MasterForGame(pProp->Game())->StructAtSource(Source); if (!mStructTemplatesToResave.contains(pStruct)) mStructTemplatesToResave << pStruct; @@ -161,7 +161,7 @@ void CTemplateEditDialog::UpdateDescription(const TString& rkNewDesc) AddTemplate(mpProperty); // Update all copies of this property in memory with the new description - TString SourceFile = mpProperty->FindStructSource(); + TString SourceFile = mpProperty->GetTemplateFileName(); if (!SourceFile.IsEmpty()) { @@ -171,10 +171,10 @@ void CTemplateEditDialog::UpdateDescription(const TString& rkNewDesc) { for (u32 TemplateIdx = 0; TemplateIdx < pkTemplates->size(); TemplateIdx++) { - IPropertyNew* pTemp = pkTemplates->at(TemplateIdx); + IPropertyNew* pProp = pkTemplates->at(TemplateIdx); - if (pTemp->FindStructSource() == SourceFile && pTemp->Description() == mOriginalDescription) - pTemp->SetDescription(rkNewDesc); + if (pProp->GetTemplateFileName() == SourceFile && pProp->Description() == mOriginalDescription) + pProp->SetDescription(rkNewDesc); } } }