libcmo21/LibCmo/CK2/ObjImpls/CKObject.cpp

102 lines
2.7 KiB
C++
Raw Normal View History

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
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),
m_Name(name),
m_Context(ctx),
m_ObjectFlags(CK_OBJECT_FLAGS::CK_PARAMETERIN_DISABLED) {}
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;
}
bool CKObject::IsToBeDeleted() const {
return EnumsHelper::Has(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_TOBEDELETED);
}
2023-09-20 10:49:32 +08:00
CKContext* CKObject::GetCKContext() const {
return m_Context;
}
#pragma endregion
void CKObject::PreDelete() {}
void CKObject::CheckPreDeletion() {}
2023-09-20 10:49:32 +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) {
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)) {
EnumsHelper::Rm(this->m_ObjectFlags,
EnumsHelper::Merge({ 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
2023-08-23 16:04:58 +08:00
EnumsHelper::Rm(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
EnumsHelper::Add(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE);
2023-02-28 14:04:38 +08:00
} else {
// == 0
2023-08-23 16:04:58 +08:00
EnumsHelper::Add(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
EnumsHelper::Rm(this->m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE);
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
EnumsHelper::Rm(m_ObjectFlags, EnumsHelper::Merge({
CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE,
CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE
}));
switch (show) {
case CK_OBJECT_SHOWOPTION::CKSHOW:
EnumsHelper::Add(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
break;
case CK_OBJECT_SHOWOPTION::CKHIERARCHICALHIDE:
EnumsHelper::Add(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_HIERACHICALHIDE);
break;
case CK_OBJECT_SHOWOPTION::CKHIDE:
return;
}
}
bool CKObject::IsVisible() const {
return EnumsHelper::Has(m_ObjectFlags, CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE);
}
2023-03-08 21:36:13 +08:00
2023-02-26 21:48:03 +08:00
}