libcmo21/LibCmo/CK2/ObjImpls/CKObject.cpp

116 lines
3.2 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(),
2023-09-20 10:49:32 +08:00
m_Context(ctx),
m_ObjectFlags(CK_OBJECT_FLAGS::CK_OBJECT_VISIBLE) {
// 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;
}
bool CKObject::IsToBeDeleted() const {
return YYCC::EnumHelper::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) {
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);
} 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);
}
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)) {
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
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
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
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
);
2023-09-20 10:49:32 +08:00
switch (show) {
case CK_OBJECT_SHOWOPTION::CKSHOW:
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:
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 {
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
}