mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-16 00:17:14 +00:00
Added support for script instance cloning
This commit is contained in:
@@ -113,15 +113,16 @@ public:
|
||||
}
|
||||
|
||||
// Accessors
|
||||
u32 State() const { return mStateID; }
|
||||
u32 Message() const { return mMessageID; }
|
||||
u32 SenderID() const { return mSenderID; }
|
||||
u32 ReceiverID() const { return mReceiverID; }
|
||||
CScriptObject* Sender() const { return mpArea->InstanceByID(mSenderID); }
|
||||
CScriptObject* Receiver() const { return mpArea->InstanceByID(mReceiverID); }
|
||||
inline CGameArea* Area() const { return mpArea; }
|
||||
inline u32 State() const { return mStateID; }
|
||||
inline u32 Message() const { return mMessageID; }
|
||||
inline u32 SenderID() const { return mSenderID; }
|
||||
inline u32 ReceiverID() const { return mReceiverID; }
|
||||
inline CScriptObject* Sender() const { return mpArea->InstanceByID(mSenderID); }
|
||||
inline CScriptObject* Receiver() const { return mpArea->InstanceByID(mReceiverID); }
|
||||
|
||||
void SetState(u32 StateID) { mStateID = StateID; }
|
||||
void SetMessage(u32 MessageID) { mMessageID = MessageID; }
|
||||
inline void SetState(u32 StateID) { mStateID = StateID; }
|
||||
inline void SetMessage(u32 MessageID) { mMessageID = MessageID; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -99,13 +99,8 @@ void CPropertyStruct::Copy(const IProperty *pkProp)
|
||||
{
|
||||
const CPropertyStruct *pkSource = static_cast<const CPropertyStruct*>(pkProp);
|
||||
|
||||
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
|
||||
delete *it;
|
||||
|
||||
mProperties.resize(pkSource->mProperties.size());
|
||||
|
||||
for (u32 iSub = 0; iSub < mProperties.size(); iSub++)
|
||||
mProperties[iSub] = pkSource->mProperties[iSub]->Clone(Instance(), this);
|
||||
mProperties[iSub]->Copy(pkSource->mProperties[iSub]);
|
||||
}
|
||||
|
||||
bool CPropertyStruct::ShouldCook()
|
||||
@@ -196,6 +191,15 @@ CPropertyStruct* CPropertyStruct::StructByIDString(const TIDString& rkStr) const
|
||||
}
|
||||
|
||||
// ************ CArrayProperty ************
|
||||
void CArrayProperty::Copy(const IProperty *pkProp)
|
||||
{
|
||||
const CArrayProperty *pkSource = static_cast<const CArrayProperty*>(pkProp);
|
||||
Resize(pkSource->Count());
|
||||
|
||||
for (u32 iSub = 0; iSub < mProperties.size(); iSub++)
|
||||
mProperties[iSub]->Copy(pkSource->mProperties[iSub]);
|
||||
}
|
||||
|
||||
bool CArrayProperty::ShouldCook()
|
||||
{
|
||||
return (mpTemplate->CookPreference() == eNeverCook ? false : true);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef IPROPERTY
|
||||
#define IPROPERTY
|
||||
|
||||
/* This header file declares some classes used to track script object properties
|
||||
* IProperty, TTypedProperty (and typedefs), CPropertyStruct, and CArrayProperty */
|
||||
#include "EPropertyType.h"
|
||||
#include "IPropertyValue.h"
|
||||
#include "Core/Resource/CResource.h"
|
||||
@@ -21,7 +19,6 @@ typedef TString TIDString;
|
||||
|
||||
/*
|
||||
* IProperty 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 IProperty
|
||||
{
|
||||
@@ -69,6 +66,15 @@ public:
|
||||
/*
|
||||
* TTypedProperty is a template subclass for actual properties.
|
||||
*/
|
||||
#define IMPLEMENT_PROPERTY_CLONE(ClassName) \
|
||||
virtual IProperty* Clone(CScriptObject *pInstance, CPropertyStruct *pParent) const \
|
||||
{ \
|
||||
if (!pParent) pParent = mpParent; \
|
||||
ClassName *pOut = new ClassName(mpTemplate, pInstance, pParent); \
|
||||
pOut->Copy(this); \
|
||||
return pOut; \
|
||||
}
|
||||
|
||||
template <typename ValueType, EPropertyType TypeEnum, class ValueClass>
|
||||
class TTypedProperty : public IProperty
|
||||
{
|
||||
@@ -94,14 +100,7 @@ public:
|
||||
mValue.Set(pkCast->mValue.Get());
|
||||
}
|
||||
|
||||
virtual TTypedProperty* Clone(class CScriptObject *pInstance, CPropertyStruct *pParent) const
|
||||
{
|
||||
if (!pParent) pParent = mpParent;
|
||||
|
||||
TTypedProperty *pOut = new TTypedProperty(mpTemplate, pInstance, pParent);
|
||||
pOut->Copy(this);
|
||||
return pOut;
|
||||
}
|
||||
IMPLEMENT_PROPERTY_CLONE(TTypedProperty)
|
||||
|
||||
virtual bool Matches(const IProperty *pkProp) const
|
||||
{
|
||||
@@ -138,6 +137,7 @@ class TStringProperty : public TTypedProperty<TString, eStringProperty, CStringV
|
||||
{
|
||||
public:
|
||||
IMPLEMENT_PROPERTY_CTORS(TStringProperty, TString)
|
||||
IMPLEMENT_PROPERTY_CLONE(TStringProperty)
|
||||
virtual bool MatchesDefault() { return Get().IsEmpty(); }
|
||||
virtual bool ShouldCook() { return true; }
|
||||
};
|
||||
@@ -146,6 +146,7 @@ class TFileProperty : public TTypedProperty<CResourceInfo, eFileProperty, CFileV
|
||||
{
|
||||
public:
|
||||
IMPLEMENT_PROPERTY_CTORS(TFileProperty, CResourceInfo)
|
||||
IMPLEMENT_PROPERTY_CLONE(TFileProperty)
|
||||
virtual bool MatchesDefault() { return !Get().IsValid(); }
|
||||
virtual bool ShouldCook() { return true; }
|
||||
};
|
||||
@@ -154,6 +155,7 @@ class TCharacterProperty : public TTypedProperty<CAnimationParameters, eCharacte
|
||||
{
|
||||
public:
|
||||
IMPLEMENT_PROPERTY_CTORS(TCharacterProperty, CAnimationParameters)
|
||||
IMPLEMENT_PROPERTY_CLONE(TCharacterProperty)
|
||||
virtual bool MatchesDefault() { return Get().AnimSet() == nullptr; }
|
||||
virtual bool ShouldCook() { return true; }
|
||||
};
|
||||
@@ -162,6 +164,7 @@ class TMayaSplineProperty : public TTypedProperty<std::vector<u8>, eMayaSplinePr
|
||||
{
|
||||
public:
|
||||
IMPLEMENT_PROPERTY_CTORS(TMayaSplineProperty, std::vector<u8>)
|
||||
IMPLEMENT_PROPERTY_CLONE(TMayaSplineProperty)
|
||||
virtual bool MatchesDefault() { return Get().empty(); }
|
||||
};
|
||||
|
||||
@@ -256,6 +259,8 @@ public:
|
||||
EPropertyType Type() const { return eArrayProperty; }
|
||||
static inline EPropertyType StaticType() { return eArrayProperty; }
|
||||
|
||||
virtual void Copy(const IProperty *pkProp);
|
||||
|
||||
virtual IProperty* Clone(CScriptObject *pInstance, CPropertyStruct *pParent) const
|
||||
{
|
||||
if (!pParent) pParent = mpParent;
|
||||
|
||||
Reference in New Issue
Block a user