2023-08-23 16:04:58 +08:00
|
|
|
#include "CKObject.hpp"
|
2023-02-28 14:04:38 +08:00
|
|
|
#include "../CKStateChunk.hpp"
|
2023-02-26 21:48:03 +08:00
|
|
|
|
2023-08-26 16:37:26 +08:00
|
|
|
namespace LibCmo::CK2::ObjImpls {
|
2023-02-26 21:48:03 +08:00
|
|
|
|
2023-09-20 10:49:32 +08:00
|
|
|
CKObject::CKObject(CKContext* ctx, CK_ID ckid, CKSTRING name) :
|
|
|
|
m_ID(ckid),
|
2023-11-15 23:05:21 +08:00
|
|
|
m_Name(),
|
2023-09-20 10:49:32 +08:00
|
|
|
m_Context(ctx),
|
2023-11-30 22:48:40 +08:00
|
|
|
m_ObjectFlags(CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE) {
|
2023-11-15 23:05:21 +08:00
|
|
|
// set name with possible nullptr.
|
|
|
|
XContainer::NSXString::FromCKSTRING(m_Name, name);
|
|
|
|
}
|
2023-09-20 10:49:32 +08:00
|
|
|
|
|
|
|
CKObject::~CKObject() {}
|
|
|
|
|
|
|
|
#pragma region Non-virtual Functions
|
|
|
|
|
|
|
|
CK_ID CKObject::GetID(void) const {
|
|
|
|
return m_ID;
|
|
|
|
}
|
|
|
|
CKSTRING CKObject::GetName(void) const {
|
|
|
|
return XContainer::NSXString::ToCKSTRING(m_Name);
|
|
|
|
}
|
|
|
|
void CKObject::SetName(CKSTRING u8_name) {
|
|
|
|
XContainer::NSXString::FromCKSTRING(m_Name, u8_name);
|
|
|
|
}
|
|
|
|
CK_OBJECT_FLAGS CKObject::GetObjectFlags(void) const {
|
|
|
|
return m_ObjectFlags;
|
|
|
|
}
|
|
|
|
void CKObject::SetObjectFlags(CK_OBJECT_FLAGS flags) {
|
|
|
|
m_ObjectFlags = flags;
|
|
|
|
}
|
2023-09-20 15:25:43 +08:00
|
|
|
bool CKObject::IsToBeDeleted() const {
|
2024-11-03 19:05:27 +08:00
|
|
|
return YYCC::EnumHelper::Has(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_TOBEDELETED);
|
2023-09-20 15:25:43 +08:00
|
|
|
}
|
2023-09-20 10:49:32 +08:00
|
|
|
CKContext* CKObject::GetCKContext() const {
|
|
|
|
return m_Context;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
|
2023-09-20 15:25:43 +08:00
|
|
|
void CKObject::PreDelete() {}
|
|
|
|
|
2023-09-17 12:39:21 +08:00
|
|
|
void CKObject::CheckPreDeletion() {}
|
2023-09-20 10:49:32 +08:00
|
|
|
|
2023-09-17 12:39:21 +08:00
|
|
|
void CKObject::CheckPostDeletion() {}
|
2023-02-26 21:48:03 +08:00
|
|
|
|
2023-09-20 10:49:32 +08:00
|
|
|
|
2023-08-25 21:57:22 +08:00
|
|
|
void CKObject::PreSave(CKFileVisitor* file, CKDWORD flags) {}
|
2023-02-26 21:48:03 +08:00
|
|
|
|
2023-08-28 17:04:28 +08:00
|
|
|
bool CKObject::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
|
2024-11-03 19:05:27 +08:00
|
|
|
if (YYCC::EnumHelper::Has(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE)) {
|
2023-10-02 11:04:00 +08:00
|
|
|
// if hierarchy hidden
|
|
|
|
chunk->WriteIdentifier(CK_STATESAVEFLAGS_OBJECT::CK_STATESAVE_OBJECTHIERAHIDDEN);
|
2024-11-03 19:05:27 +08:00
|
|
|
} else if (!YYCC::EnumHelper::Has(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE)) {
|
2023-10-02 11:04:00 +08:00
|
|
|
// if really hidden
|
|
|
|
chunk->WriteIdentifier(CK_STATESAVEFLAGS_OBJECT::CK_STATESAVE_OBJECTHIDDEN);
|
|
|
|
}
|
|
|
|
|
2023-10-02 11:32:18 +08:00
|
|
|
chunk->SetClassId(CK_CLASSID::CKCID_OBJECT);
|
2023-08-28 17:04:28 +08:00
|
|
|
return true;
|
2023-02-26 21:48:03 +08:00
|
|
|
}
|
|
|
|
|
2023-08-25 21:57:22 +08:00
|
|
|
bool CKObject::Load(CKStateChunk* chunk, CKFileVisitor* file) {
|
2023-08-23 16:04:58 +08:00
|
|
|
if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_OBJECT::CK_STATESAVE_OBJECTHIDDEN)) {
|
2024-11-03 19:05:27 +08:00
|
|
|
YYCC::EnumHelper::Remove(this->m_ObjectFlags,
|
|
|
|
CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE,
|
|
|
|
CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE
|
|
|
|
);
|
2023-02-28 14:04:38 +08:00
|
|
|
} else {
|
2023-08-23 16:04:58 +08:00
|
|
|
if (chunk->SeekIdentifier(CK_STATESAVEFLAGS_OBJECT::CK_STATESAVE_OBJECTHIERAHIDDEN)) {
|
2023-02-28 14:04:38 +08:00
|
|
|
// != 0
|
2024-11-03 19:05:27 +08:00
|
|
|
YYCC::EnumHelper::Remove(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
|
|
|
|
YYCC::EnumHelper::Add(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE);
|
2023-02-28 14:04:38 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// == 0
|
2024-11-03 19:05:27 +08:00
|
|
|
YYCC::EnumHelper::Add(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
|
|
|
|
YYCC::EnumHelper::Remove(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE);
|
2023-08-23 16:04:58 +08:00
|
|
|
|
2023-02-28 14:04:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-05 22:31:11 +08:00
|
|
|
return true;
|
2023-02-28 11:35:54 +08:00
|
|
|
}
|
2023-03-08 21:36:13 +08:00
|
|
|
|
2023-08-23 16:04:58 +08:00
|
|
|
void CKObject::PostLoad() {}
|
|
|
|
|
|
|
|
|
2023-09-20 10:49:32 +08:00
|
|
|
void CKObject::Show(CK_OBJECT_SHOWOPTION show) {
|
|
|
|
// clear all visible data of object flags
|
2024-11-03 19:05:27 +08:00
|
|
|
YYCC::EnumHelper::Remove(m_ObjectFlags,
|
2023-09-20 10:49:32 +08:00
|
|
|
CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE,
|
|
|
|
CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE
|
2024-11-03 19:05:27 +08:00
|
|
|
);
|
2023-09-20 10:49:32 +08:00
|
|
|
|
|
|
|
switch (show) {
|
|
|
|
case CK_OBJECT_SHOWOPTION::CKSHOW:
|
2024-11-03 19:05:27 +08:00
|
|
|
YYCC::EnumHelper::Add(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
|
2023-09-20 10:49:32 +08:00
|
|
|
break;
|
|
|
|
case CK_OBJECT_SHOWOPTION::CKHIERARCHICALHIDE:
|
2024-11-03 19:05:27 +08:00
|
|
|
YYCC::EnumHelper::Add(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE);
|
2023-09-20 10:49:32 +08:00
|
|
|
break;
|
|
|
|
case CK_OBJECT_SHOWOPTION::CKHIDE:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CKObject::IsVisible() const {
|
2024-11-03 19:05:27 +08:00
|
|
|
return YYCC::EnumHelper::Has(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
|
2023-09-20 10:49:32 +08:00
|
|
|
}
|
|
|
|
|
2023-03-08 21:36:13 +08:00
|
|
|
|
2023-02-26 21:48:03 +08:00
|
|
|
}
|