From 5c10727380006d6d8c29e5e394d1d38fe794c3f4 Mon Sep 17 00:00:00 2001 From: Dave Corley Date: Fri, 22 Dec 2023 17:06:16 -0600 Subject: [PATCH] Feat(CS): Add definition files for selection group record type --- components/CMakeLists.txt | 2 +- components/esm3/selectiongroup.cpp | 38 ++++++++++++++++++++++++++++++ components/esm3/selectiongroup.hpp | 34 ++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 components/esm3/selectiongroup.cpp create mode 100644 components/esm3/selectiongroup.hpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index f61a5bd0b2..ca6b644d15 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -166,7 +166,7 @@ add_component_dir (esm3 inventorystate containerstate npcstate creaturestate dialoguestate statstate npcstats creaturestats weatherstate quickkeys fogstate spellstate activespells creaturelevliststate doorstate projectilestate debugprofile aisequence magiceffects custommarkerstate stolenitems transport animationstate controlsstate mappings readerscache - infoorder timestamp formatversion landrecorddata + infoorder timestamp formatversion landrecorddata selectiongroup ) add_component_dir (esmterrain diff --git a/components/esm3/selectiongroup.cpp b/components/esm3/selectiongroup.cpp new file mode 100644 index 0000000000..6b819a4bbc --- /dev/null +++ b/components/esm3/selectiongroup.cpp @@ -0,0 +1,38 @@ +#include "selectiongroup.hpp" + +#include "esmreader.hpp" +#include "esmwriter.hpp" + +namespace ESM +{ + void SelectionGroup::load(ESMReader& esm, bool& isDeleted) + { + + while (esm.hasMoreSubs()) + { + esm.getSubName(); + switch (esm.retSubName().toInt()) + { + case fourCC("SELC"): + mId = esm.getRefId(); + break; + case fourCC("SELI"): + selectedInstances.push_back(esm.getRefId().getRefIdString()); + break; + default: + esm.fail("Unknown subrecord"); + break; + } + } + } + + void SelectionGroup::save(ESMWriter& esm, bool isDeleted) const + { + esm.writeHNCRefId("SELC", mId); + for (std::string id : selectedInstances) + esm.writeHNCString("SELI", id); + } + + void SelectionGroup::blank() {} + +} diff --git a/components/esm3/selectiongroup.hpp b/components/esm3/selectiongroup.hpp new file mode 100644 index 0000000000..021f3c95d5 --- /dev/null +++ b/components/esm3/selectiongroup.hpp @@ -0,0 +1,34 @@ +#ifndef COMPONENTS_ESM_SELECTIONGROUP_H +#define COMPONENTS_ESM_SELECTIONGROUP_H + +#include + +#include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" + +namespace ESM +{ + class ESMReader; + class ESMWriter; + + struct SelectionGroup + { + constexpr static RecNameInts sRecordId = REC_SELG; + + static constexpr std::string_view getRecordType() { return "SelectionGroup"; } + + uint32_t mRecordFlags = 0; + + RefId mId; + + std::vector selectedInstances; + + void load(ESMReader& esm, bool& isDeleted); + void save(ESMWriter& esm, bool isDeleted = false) const; + + /// Set record to default state (does not touch the ID). + void blank(); + }; +} + +#endif