200 lines
5.9 KiB
C++
200 lines
5.9 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: metadata.cpp
|
|
// Purpose: Implementation of Metadata
|
|
// Author: prisixia
|
|
// Created: 2022-10-02
|
|
// Copyright: (C) 2022-2023 prisixia
|
|
// Licence: GNU General Public License version 3
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef SPECIESGEN_STARBOUND_METADATA_H
|
|
#define SPECIESGEN_STARBOUND_METADATA_H
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "cereal/types/string.hpp"
|
|
#include "cereal/types/vector.hpp"
|
|
|
|
namespace Starbound {
|
|
class Metadata {
|
|
public:
|
|
Metadata() = default;
|
|
Metadata(const std::string &, const std::string &, const std::string &,
|
|
const std::string & =
|
|
"This mod has been generated via speciesgen made by prisixia.",
|
|
const std::string & = "1.0.0_gen" SPECIESGEN_VERSION,
|
|
const std::string & = "http://git.vern.cc/prisixia/speciesgen",
|
|
const std::vector<std::string> & = {"starpounds"});
|
|
|
|
[[nodiscard]] std::string GetName() const;
|
|
[[nodiscard]] std::string GetFriendlyName() const;
|
|
[[nodiscard]] std::string GetDescription() const;
|
|
[[nodiscard]] std::string GetAuthor() const;
|
|
[[nodiscard]] std::string GetVersion() const;
|
|
[[nodiscard]] std::string GetLink() const;
|
|
[[nodiscard]] std::string GetSteamContentID() const;
|
|
[[nodiscard]] std::string GetTags() const;
|
|
[[nodiscard]] std::vector<std::string> GetIncludes() const;
|
|
[[nodiscard]] std::vector<std::string> GetRequires() const;
|
|
[[nodiscard]] uint32_t GetPriority() const;
|
|
|
|
void SetName(const std::string &);
|
|
void SetFriendlyName(const std::string &);
|
|
void SetDescription(const std::string &);
|
|
void SetAuthor(const std::string &);
|
|
void SetVersion(const std::string &);
|
|
void SetLink(const std::string &);
|
|
void SetSteamContentID(const std::string &);
|
|
void SetTags(const std::string &);
|
|
void SetIncludes(const std::vector<std::string> &);
|
|
void SetRequires(const std::vector<std::string> &);
|
|
void SetPriority(const uint32_t);
|
|
|
|
private:
|
|
std::string m_name;
|
|
std::string m_friendlyName;
|
|
std::string m_description;
|
|
std::string m_author;
|
|
std::string m_version;
|
|
std::string m_link;
|
|
std::string m_steamContentId;
|
|
std::string m_tags;
|
|
std::vector<std::string> m_includes;
|
|
std::vector<std::string> m_requires;
|
|
uint32_t m_priority;
|
|
};
|
|
} // namespace Starbound
|
|
|
|
//----------------------------------------------------------------------
|
|
// Serialisation
|
|
//----------------------------------------------------------------------
|
|
|
|
namespace cereal {
|
|
template <class Archive> void Load(Archive &archive, Starbound::Metadata &m) {
|
|
std::string name;
|
|
std::string friendlyName;
|
|
std::string description;
|
|
std::string author;
|
|
std::string version;
|
|
std::string link;
|
|
std::string steamContentId;
|
|
std::string tags;
|
|
std::vector<std::string> includes;
|
|
std::vector<std::string> _requires;
|
|
uint32_t priority;
|
|
|
|
archive(CEREAL_NVP(name), CEREAL_NVP(friendlyName), CEREAL_NVP(description),
|
|
CEREAL_NVP(author), CEREAL_NVP(version), CEREAL_NVP(link),
|
|
CEREAL_NVP(steamContentId), CEREAL_NVP(tags), CEREAL_NVP(includes),
|
|
CEREAL_NVP_("requires", _requires), CEREAL_NVP(priority));
|
|
|
|
m.SetName(name);
|
|
m.SetFriendlyName(friendlyName);
|
|
m.SetDescription(description);
|
|
m.SetAuthor(author);
|
|
m.SetVersion(version);
|
|
m.SetLink(link);
|
|
m.SetSteamContentID(steamContentId);
|
|
m.SetTags(tags);
|
|
m.SetIncludes(includes);
|
|
m.SetRequires(_requires);
|
|
m.SetPriority(priority);
|
|
}
|
|
|
|
template <class Archive>
|
|
void Save(Archive &archive, Starbound::Metadata const &m) {
|
|
const std::string name = m.GetName();
|
|
const std::string friendlyName = m.GetFriendlyName();
|
|
const std::string description = m.GetDescription();
|
|
const std::string author = m.GetAuthor();
|
|
const std::string version = m.GetVersion();
|
|
const std::string link = m.GetLink();
|
|
const std::string steamContentId = m.GetSteamContentID();
|
|
const std::string tags = m.GetTags();
|
|
const std::vector<std::string> includes = m.GetIncludes();
|
|
const std::vector<std::string> _requires = m.GetRequires();
|
|
const uint32_t priority = m.GetPriority();
|
|
|
|
archive(CEREAL_NVP(name), CEREAL_NVP(friendlyName), CEREAL_NVP(description),
|
|
CEREAL_NVP(author), CEREAL_NVP(version), CEREAL_NVP(link),
|
|
CEREAL_NVP(steamContentId), CEREAL_NVP(tags), CEREAL_NVP(includes),
|
|
CEREAL_NVP_("requires", _requires), CEREAL_NVP(priority));
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
/*
|
|
if (!name.empty()) {
|
|
archive(CEREAL_NVP(name));
|
|
}
|
|
|
|
if (!friendlyName.empty()) {
|
|
archive(CEREAL_NVP(friendlyName));
|
|
}
|
|
|
|
if (!description.empty()) {
|
|
archive(CEREAL_NVP(description));
|
|
}
|
|
|
|
if (!author.empty()) {
|
|
archive(CEREAL_NVP(author));
|
|
}
|
|
|
|
if (!version.empty()) {
|
|
archive(CEREAL_NVP(version));
|
|
}
|
|
|
|
if (!link.empty()) {
|
|
archive(CEREAL_NVP(link));
|
|
}
|
|
|
|
if (!steamContentId.empty()) {
|
|
archive(CEREAL_NVP(steamContentId));
|
|
}
|
|
|
|
if (!tags.empty()) {
|
|
archive(CEREAL_NVP(tags));
|
|
}
|
|
|
|
if (!includes.empty()) {
|
|
archive(CEREAL_NVP(includes));
|
|
}
|
|
|
|
if (!_requires.empty()) {
|
|
archive(CEREAL_NVP_("requires", _requires));
|
|
}
|
|
|
|
if (priority > 0) {
|
|
archive(CEREAL_NVP(priority));
|
|
}
|
|
*/
|
|
}
|
|
} // namespace cereal
|
|
|
|
#endif // SPECIESGEN_STARBOUND_METADATA_H
|