diff --git a/source/Misc/Skin.cpp b/source/Misc/Skin.cpp index 920f547f..3fe6f310 100644 --- a/source/Misc/Skin.cpp +++ b/source/Misc/Skin.cpp @@ -10,27 +10,29 @@ const CSkin CSkin::NIL = CSkin(); // ------------------------------------------------------------------------------------------------ CSkin::CSkin() noexcept - : m_ID(SQMOD_UNKNOWN), m_Name() + : m_ID(SQMOD_UNKNOWN) { } CSkin::CSkin(SQInt32 id) noexcept - : m_ID(VALID_ENTITYGETEX(id, Max)), m_Name(GetSkinName(id)) + : m_ID(VALID_ENTITYGETEX(id, Max)) { } CSkin::CSkin(const SQChar * name, SQInt32 id) noexcept - : CSkin(IsSkinValid(GetSkinID(name)) ? GetSkinID(name) : id) + : m_ID(GetSkinID(name)) { - + if (VALID_ENTITYEX(m_ID, Max)) + { + m_ID = id; + } } // ------------------------------------------------------------------------------------------------ CSkin::CSkin(const CSkin & s) noexcept : m_ID(s.m_ID) - , m_Name(s.m_Name) , m_Tag(s.m_Tag) , m_Data(s.m_Data) { @@ -39,7 +41,6 @@ CSkin::CSkin(const CSkin & s) noexcept CSkin::CSkin(CSkin && s) noexcept : m_ID(s.m_ID) - , m_Name(s.m_Name) , m_Tag(s.m_Tag) , m_Data(s.m_Data) { @@ -56,7 +57,6 @@ CSkin::~CSkin() CSkin & CSkin::operator = (const CSkin & s) noexcept { m_ID = s.m_ID; - m_Name = s.m_Name; m_Tag = s.m_Tag; m_Data = s.m_Data; @@ -66,7 +66,6 @@ CSkin & CSkin::operator = (const CSkin & s) noexcept CSkin & CSkin::operator = (CSkin && s) noexcept { m_ID = s.m_ID; - m_Name = s.m_Name; m_Tag = s.m_Tag; m_Data = s.m_Data; @@ -76,11 +75,7 @@ CSkin & CSkin::operator = (CSkin && s) noexcept // ------------------------------------------------------------------------------------------------ CSkin & CSkin::operator = (SQInt32 id) noexcept { - if (m_ID != id) - { - m_Name = GetSkinName(id); - m_ID = id; - } + m_ID = VALID_ENTITYGETEX(id, Max); return *this; } @@ -119,7 +114,24 @@ bool CSkin::operator >= (const CSkin & s) const noexcept // ------------------------------------------------------------------------------------------------ SQInteger CSkin::Cmp(const CSkin & s) const noexcept { - return m_ID == s.m_ID ? 0 : (m_ID > s.m_ID ? 1 : -1); + if (m_ID == s.m_ID) + { + return 0; + } + else if (m_ID > s.m_ID) + { + return 1; + } + else + { + return -1; + } +} + +// ------------------------------------------------------------------------------------------------ +const SQChar * CSkin::ToString() const noexcept +{ + return GetSkinName(m_ID); } // ------------------------------------------------------------------------------------------------ @@ -130,21 +142,13 @@ SQInteger CSkin::GetID() const noexcept void CSkin::SetID(SQInt32 id) noexcept { - if (m_ID != id) - { - m_Name = GetSkinName(id); - m_ID = id; - } + m_ID = VALID_ENTITYGETEX(id, Max); } // ------------------------------------------------------------------------------------------------ CSkin & CSkin::SetnGet(SQInt32 id) noexcept { - if (m_ID != id) - { - m_Name = GetSkinName(id); - m_ID = id; - } + m_ID = VALID_ENTITYGETEX(id, Max); return *this; } @@ -202,14 +206,14 @@ bool CSkin::IsValid() const noexcept // ------------------------------------------------------------------------------------------------ const SQChar * CSkin::GetName() const noexcept { - return m_Name.c_str(); + return GetSkinName(m_ID); } // ------------------------------------------------------------------------------------------------ void CSkin::SetName(const SQChar * name) noexcept { m_ID = GetSkinID(name); - m_Name = GetSkinName(m_ID); + m_ID = VALID_ENTITYGETEX(m_ID, Max); } // ------------------------------------------------------------------------------------------------ @@ -236,12 +240,14 @@ bool Register_CSkin(HSQUIRRELVM vm) LogDbg("Beginning registration of type"); // Attempt to register the specified type Sqrat::RootTable(vm).Bind(_SC("CSkin"), Sqrat::Class< CSkin >(vm, _SC("CSkin")) + /* Constructors */ .Ctor() .Ctor< SQInt32 >() .Ctor< const SQChar *, SQInt32 >() - + /* Metamethods */ .Func(_SC("_cmp"), &CSkin::Cmp) - + .Func(_SC("_tostring"), &CSkin::ToString) + /* Properties */ .Prop(_SC("id"), &CSkin::GetID, &CSkin::SetID) .Prop(_SC("gtag"), &CSkin::GetGlobalTag, &CSkin::SetGlobalTag) .Prop(_SC("gdata"), &CSkin::GetGlobalData, &CSkin::SetGlobalData) @@ -249,9 +255,8 @@ bool Register_CSkin(HSQUIRRELVM vm) .Prop(_SC("ldata"), &CSkin::GetLocalData, &CSkin::SetLocalData) .Prop(_SC("valid"), &CSkin::IsValid) .Prop(_SC("name"), &CSkin::GetName, &CSkin::SetName) - + /* Functions */ .Func(_SC("setng"), &CSkin::SetnGet) - .Func(_SC("apply"), &CSkin::Apply) ); // Output debugging information diff --git a/source/Misc/Skin.hpp b/source/Misc/Skin.hpp index 1f758b5a..5d09decb 100644 --- a/source/Misc/Skin.hpp +++ b/source/Misc/Skin.hpp @@ -7,73 +7,209 @@ // ------------------------------------------------------------------------------------------------ namespace SqMod { -// ------------------------------------------------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------ + * Class responsible for managing and interacting with skin models. +*/ class CSkin : public IdentifierStorage< CSkin, SQMOD_SKINID_CAP > { public: - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Helper member for times when a null reference to an instance of this type is needed. + */ static const CSkin NIL; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Default constructor. + */ CSkin() noexcept; + + /* -------------------------------------------------------------------------------------------- + * Construct an instance of this type and reference the specified skin. + */ CSkin(SQInt32 id) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Construct an instance of this type and reference the skin extracted from the specified name. + */ CSkin(const SQChar * name, SQInt32 id) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Copy constructor. + */ CSkin(const CSkin & s) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Move constructor. + */ CSkin(CSkin && s) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Destructor. + */ ~CSkin() noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Copy assignment operator. + */ CSkin & operator = (const CSkin & s) noexcept; + + /* -------------------------------------------------------------------------------------------- + * Move assignment operator. + */ CSkin & operator = (CSkin && s) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Skin identifier assignment operator. + */ CSkin & operator = (SQInt32 id) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Equality comparison operator. + */ bool operator == (const CSkin & s) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Inequality comparison operator. + */ bool operator != (const CSkin & s) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Less than comparison operator. + */ bool operator < (const CSkin & s) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Greater than comparison operator. + */ bool operator > (const CSkin & s) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Less than or equal comparison operator. + */ bool operator <= (const CSkin & s) const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Greater than or equal comparison operator. + */ bool operator >= (const CSkin & s) const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Implicit conversion to skin identifier. + */ operator SQInt32 () const noexcept { return m_ID; } + + /* -------------------------------------------------------------------------------------------- + * Implicit conversion to boolean. + */ operator bool () const noexcept { return IsSkinValid(m_ID); } - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Negation operator. + */ bool operator ! () const noexcept { return !IsSkinValid(m_ID); } - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Used by the script to compare two instances of this type. + */ SQInteger Cmp(const CSkin & s) const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Convert this type to a string. + */ const SQChar * ToString() const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the identifier referenced by this instance. + */ SQInteger GetID() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the identifier referenced by this instance. + */ void SetID(SQInt32 id) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Set the identifier that this insance should reference and + * get a reference to the instance to chain operations. + */ CSkin & SetnGet(SQInt32 id) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the global tag. + */ const SQChar * GetGlobalTag() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the global tag. + */ void SetGlobalTag(const SQChar * tag) const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the global data. + */ SqObj & GetGlobalData() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the global data. + */ void SetGlobalData(SqObj & data) const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the local tag. + */ const SQChar * GetLocalTag() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the local tag. + */ void SetLocalTag(const SQChar * tag) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the local data. + */ SqObj & GetLocalData() noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the local data. + */ void SetLocalData(SqObj & data) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * See whether the referenced skin identifier is valid. + */ bool IsValid() const noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Retrieve the name of the referenced skin. + */ const SQChar * GetName() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * Change the identifier of the referenced skin. + */ void SetName(const SQChar * name) noexcept; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * Apply the referenced skin identifier to the specified player instance. + */ void Apply(const Reference< CPlayer > & player) const noexcept; + private: - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * The identifier of the referenced skin. + */ SQInt32 m_ID; - // -------------------------------------------------------------------------------------------- - String m_Name; - // -------------------------------------------------------------------------------------------- + + /* -------------------------------------------------------------------------------------------- + * The local tag associated with this instance. + */ SqTag m_Tag; + + /* -------------------------------------------------------------------------------------------- + * The local data associated with this instance. + */ SqObj m_Data; };