246 lines
7.5 KiB
C++
246 lines
7.5 KiB
C++
/*
|
|
speciesgen
|
|
Copyright (C) 2022-2023 prisixia
|
|
|
|
This file is part of speciesgen.
|
|
|
|
speciesgen is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
speciesgen is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with speciesgen. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// Name: weightstage.cpp
|
|
// Purpose: Implementation of WeightStage and related
|
|
// Author: prisixia
|
|
// Created: 2022-10-03
|
|
// Copyright: (C) 2022-2023 prisixia
|
|
// Licence: GNU General Public License version 3
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef SPECIESGEN_STARPOUNDS_WEIGHTSTAGE_H
|
|
#define SPECIESGEN_STARPOUNDS_WEIGHTSTAGE_H
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "starpounds/types.h"
|
|
|
|
#include "cereal/types/string.hpp"
|
|
#include "cereal/types/vector.hpp"
|
|
|
|
namespace Starpounds {
|
|
class WeightStageSub {
|
|
public:
|
|
WeightStageSub() = default;
|
|
WeightStageSub(const std::string &, const std::string &,
|
|
const std::string &, const Types::Chests);
|
|
WeightStageSub(const std::string &);
|
|
WeightStageSub(const Types::Subs, const std::string &);
|
|
|
|
[[nodiscard]] std::string GetName() const;
|
|
[[nodiscard]] std::string GetFriendlyName() const;
|
|
[[nodiscard]] std::string GetChestDescription() const;
|
|
[[nodiscard]] Types::Chests GetChestType() const;
|
|
|
|
void SetName(const std::string &);
|
|
void SetFriendlyName(const std::string &);
|
|
void SetChestDescription(const std::string &);
|
|
void SetChestType(const Types::Chests);
|
|
|
|
protected:
|
|
std::string m_name;
|
|
std::string m_friendlyName;
|
|
std::string m_descriptionChest;
|
|
Types::Chests m_typeChest;
|
|
};
|
|
|
|
class WeightStage : public WeightStageSub {
|
|
public:
|
|
WeightStage() = default;
|
|
WeightStage(const std::string &, const std::string &, const std::string &,
|
|
const Types::Chests, const std::string &, const Types::Legs,
|
|
const bool, const bool,
|
|
const std::vector<WeightStageSub> & = {});
|
|
WeightStage(const std::string &, const bool, const bool,
|
|
const std::vector<WeightStageSub> & = {});
|
|
|
|
[[nodiscard]] std::string GetLegDescription() const;
|
|
[[nodiscard]] Types::Legs GetLegType() const;
|
|
[[nodiscard]] bool HasFrames() const;
|
|
[[nodiscard]] bool HasID() const;
|
|
[[nodiscard]] std::vector<WeightStageSub> GetSubs() const;
|
|
|
|
void SetLegDescription(const std::string &);
|
|
void SetLegType(const Types::Legs);
|
|
void SetFrames(const bool);
|
|
void SetID(const bool);
|
|
void SetSubs(const std::vector<WeightStageSub> &);
|
|
|
|
private:
|
|
std::string m_descriptionLeg;
|
|
Types::Legs m_typeLeg;
|
|
bool m_frames;
|
|
bool m_id;
|
|
std::vector<WeightStageSub> m_subs;
|
|
};
|
|
} // namespace Starpounds
|
|
|
|
//----------------------------------------------------------------------
|
|
// Serialisation
|
|
//----------------------------------------------------------------------
|
|
|
|
namespace cereal {
|
|
template <class Archive>
|
|
void Load(Archive &archive, Starpounds::WeightStageSub &m) {
|
|
std::string name;
|
|
std::string friendlyName;
|
|
std::string descriptionChest;
|
|
std::string typeChest;
|
|
|
|
archive(CEREAL_NVP(name), CEREAL_NVP_("friendly_name", friendlyName),
|
|
CEREAL_NVP_("desc_chest", descriptionChest),
|
|
CEREAL_NVP_("type_chest", typeChest));
|
|
|
|
m.SetName(name);
|
|
m.SetFriendlyName(friendlyName);
|
|
m.SetChestDescription(descriptionChest);
|
|
m.SetChestType(
|
|
magic_enum::enum_cast<Starpounds::Types::Chests>(typeChest).value_or(
|
|
Starpounds::Types::Chests::Chest));
|
|
}
|
|
|
|
template <class Archive>
|
|
void Save(Archive &archive, Starpounds::WeightStageSub const &m) {
|
|
const std::string name = m.GetName();
|
|
const std::string friendlyName = m.GetFriendlyName();
|
|
const std::string descriptionChest = m.GetChestDescription();
|
|
const std::string typeChest =
|
|
static_cast<std::string>(magic_enum::enum_name(m.GetChestType()));
|
|
|
|
archive(CEREAL_NVP(name), CEREAL_NVP_("friendly_name", friendlyName),
|
|
CEREAL_NVP_("desc_chest", descriptionChest),
|
|
CEREAL_NVP_("type_chest", typeChest));
|
|
|
|
/*
|
|
* At the moment, cereal doesn't really support optional values
|
|
* for deserialisation, meaning that we have to serialise all fields
|
|
* even if they're eventually unneeded.
|
|
*/
|
|
|
|
/*
|
|
archive(CEREAL_NVP(name));
|
|
|
|
if (!friendlyName.empty()) {
|
|
archive(CEREAL_NVP_("friendly_name", friendlyName));
|
|
}
|
|
|
|
if (!descriptionChest.empty()) {
|
|
archive(CEREAL_NVP_("desc_chest", descriptionChest));
|
|
}
|
|
|
|
archive(CEREAL_NVP_("type_chest", typeChest));
|
|
*/
|
|
}
|
|
|
|
template <class Archive>
|
|
void Load(Archive &archive, Starpounds::WeightStage &m) {
|
|
std::string name;
|
|
std::string friendlyName;
|
|
std::string descriptionChest;
|
|
std::string descriptionLeg;
|
|
std::string typeChest;
|
|
std::string typeLeg;
|
|
bool frames;
|
|
bool id;
|
|
std::vector<Starpounds::WeightStageSub> subs;
|
|
|
|
archive(CEREAL_NVP(name), CEREAL_NVP_("friendly_name", friendlyName),
|
|
CEREAL_NVP_("desc_chest", descriptionChest),
|
|
CEREAL_NVP_("desc_leg", descriptionLeg),
|
|
CEREAL_NVP_("type_chest", typeChest),
|
|
CEREAL_NVP_("type_leg", typeLeg),
|
|
CEREAL_NVP_("need_frames", frames), CEREAL_NVP_("need_id", id),
|
|
CEREAL_NVP(subs));
|
|
|
|
m.SetName(name);
|
|
m.SetFriendlyName(friendlyName);
|
|
m.SetChestDescription(descriptionChest);
|
|
m.SetLegDescription(descriptionLeg);
|
|
m.SetChestType(
|
|
magic_enum::enum_cast<Starpounds::Types::Chests>(typeChest).value_or(
|
|
Starpounds::Types::Chests::Chest));
|
|
m.SetLegType(
|
|
magic_enum::enum_cast<Starpounds::Types::Legs>(typeLeg).value_or(
|
|
Starpounds::Types::Legs::Legs));
|
|
m.SetFrames(frames);
|
|
m.SetID(id);
|
|
m.SetSubs(subs);
|
|
}
|
|
|
|
template <class Archive>
|
|
void Save(Archive &archive, Starpounds::WeightStage const &m) {
|
|
const std::string name = m.GetName();
|
|
const std::string friendlyName = m.GetFriendlyName();
|
|
const std::string descriptionChest = m.GetChestDescription();
|
|
const std::string descriptionLeg = m.GetLegDescription();
|
|
const std::string typeChest =
|
|
static_cast<std::string>(magic_enum::enum_name(m.GetChestType()));
|
|
const std::string typeLeg =
|
|
static_cast<std::string>(magic_enum::enum_name(m.GetLegType()));
|
|
const bool frames = m.HasFrames();
|
|
const bool id = m.HasID();
|
|
const std::vector<Starpounds::WeightStageSub> subs = m.GetSubs();
|
|
|
|
archive(CEREAL_NVP(name), CEREAL_NVP_("friendly_name", friendlyName),
|
|
CEREAL_NVP_("desc_chest", descriptionChest),
|
|
CEREAL_NVP_("desc_leg", descriptionLeg),
|
|
CEREAL_NVP_("type_chest", typeChest),
|
|
CEREAL_NVP_("type_leg", typeLeg),
|
|
CEREAL_NVP_("need_frames", frames), CEREAL_NVP_("need_id", id),
|
|
CEREAL_NVP(subs));
|
|
|
|
/*
|
|
* At the moment, cereal doesn't really support optional values
|
|
* for deserialisation, meaning that we have to serialise all fields
|
|
* even if they're eventually unneeded.
|
|
*/
|
|
|
|
/*
|
|
archive(CEREAL_NVP(name));
|
|
|
|
if (!friendlyName.empty()) {
|
|
archive(CEREAL_NVP_("friendly_name", friendlyName));
|
|
}
|
|
|
|
if (!descriptionChest.empty()) {
|
|
archive(CEREAL_NVP_("desc_chest", descriptionChest));
|
|
}
|
|
|
|
if (!descriptionLeg.empty()) {
|
|
archive(CEREAL_NVP_("desc_leg", descriptionLeg));
|
|
}
|
|
|
|
archive(CEREAL_NVP_("type_chest", typeChest),
|
|
CEREAL_NVP_("type_leg", typeLeg),
|
|
CEREAL_NVP_("need_frames", frames), CEREAL_NVP_("need_id", id));
|
|
|
|
if (!subs.empty()) {
|
|
archive(CEREAL_NVP(subs));
|
|
}
|
|
*/
|
|
}
|
|
} // namespace cereal
|
|
|
|
#endif // SPECIESGEN_STARPOUNDS_WEIGHTSTAGE_H
|