Made SpeciesVariant follow PIMPL idiom.
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
6189919496
commit
fbdeaf9e9c
|
@ -1,16 +1,122 @@
|
|||
#include "SpeciesVariant.hpp"
|
||||
|
||||
const CreatureLib::Library::TalentIndex
|
||||
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::StringView& talent) const {
|
||||
for (size_t i = 0; i < _talents.Count(); i++) {
|
||||
if (_talents.At(i) == talent) {
|
||||
return TalentIndex(false, i);
|
||||
namespace CreatureLib::Library {
|
||||
struct SpeciesVariant::impl {
|
||||
private:
|
||||
ArbUt::StringView _name;
|
||||
float _height;
|
||||
float _weight;
|
||||
uint32_t _baseExperience;
|
||||
ArbUt::List<uint8_t> _types;
|
||||
Library::StatisticSet<uint16_t> _baseStatistics;
|
||||
ArbUt::List<ArbUt::StringView> _talents;
|
||||
ArbUt::List<ArbUt::StringView> _secretTalents;
|
||||
std::unique_ptr<const LearnableAttacks> _attacks;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
impl(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
const ArbUt::List<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
|
||||
const ArbUt::List<ArbUt::StringView>& talents, const ArbUt::List<ArbUt::StringView>& secretTalents,
|
||||
const LearnableAttacks* attacks, std::unordered_set<uint32_t> flags)
|
||||
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)),
|
||||
_baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks),
|
||||
_flags(flags){};
|
||||
|
||||
inline const ArbUt::StringView& GetName() const { return _name; }
|
||||
inline float GetHeight() const { return _height; }
|
||||
inline float GetWeight() const { return _weight; }
|
||||
inline uint32_t GetBaseExperience() const { return _baseExperience; }
|
||||
|
||||
[[nodiscard]] inline size_t GetTypeCount() const { return _types.Count(); }
|
||||
[[nodiscard]] inline uint8_t GetType(size_t index) const { return _types[index]; }
|
||||
[[nodiscard]] inline const ArbUt::List<uint8_t>& GetTypes() const { return _types; }
|
||||
[[nodiscard]] inline uint16_t GetStatistic(Library::Statistic stat) const {
|
||||
return _baseStatistics.GetStat(stat);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < _secretTalents.Count(); i++) {
|
||||
if (_secretTalents.At(i) == talent) {
|
||||
return TalentIndex(true, i);
|
||||
[[nodiscard]] inline size_t GetTalentCount() const noexcept { return _talents.Count(); }
|
||||
[[nodiscard]] inline size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
|
||||
[[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const {
|
||||
if (index.IsSecret() && _secretTalents.Count() > 0) {
|
||||
auto i = index.GetIndex();
|
||||
if (i > _secretTalents.Count())
|
||||
i = _secretTalents.Count();
|
||||
return _secretTalents.At(i);
|
||||
}
|
||||
auto i = index.GetIndex();
|
||||
if (i > _talents.Count())
|
||||
i = _talents.Count();
|
||||
return _talents.At(i);
|
||||
}
|
||||
[[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const {
|
||||
for (size_t i = 0; i < _talents.Count(); i++) {
|
||||
if (_talents.At(i) == talent) {
|
||||
return TalentIndex(false, i);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < _secretTalents.Count(); i++) {
|
||||
if (_secretTalents.At(i) == talent) {
|
||||
return TalentIndex(true, i);
|
||||
}
|
||||
}
|
||||
THROW("The given talent is not a valid talent for this creature.");
|
||||
}
|
||||
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::LearnableAttacks>
|
||||
GetLearnableAttacks() const {
|
||||
return _attacks;
|
||||
}
|
||||
[[nodiscard]] inline TalentIndex GetRandomTalent(ArbUt::Random& rand) const noexcept {
|
||||
return TalentIndex(false, rand.Get(_talents.Count()));
|
||||
}
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetTalents() const { return _talents; }
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const { return _secretTalents; }
|
||||
|
||||
inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
|
||||
return this->_flags.find(key) != this->_flags.end();
|
||||
}
|
||||
inline bool HasFlag(uint32_t keyHash) const noexcept {
|
||||
return this->_flags.find(keyHash) != this->_flags.end();
|
||||
}
|
||||
};
|
||||
|
||||
SpeciesVariant::SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
const ArbUt::List<uint8_t>& types, StatisticSet<uint16_t> baseStats,
|
||||
const ArbUt::List<ArbUt::StringView>& talents,
|
||||
const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks,
|
||||
const std::unordered_set<uint32_t>& flags)
|
||||
: _impl(new impl(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks,
|
||||
flags)) {}
|
||||
|
||||
#define ImplGetter(type, func) \
|
||||
type SpeciesVariant::func() const noexcept { return _impl->func(); }
|
||||
|
||||
ImplGetter(const ArbUt::StringView&, GetName);
|
||||
ImplGetter(float, GetHeight);
|
||||
ImplGetter(float, GetWeight);
|
||||
ImplGetter(uint32_t, GetBaseExperience);
|
||||
ImplGetter(size_t, GetTypeCount);
|
||||
uint8_t SpeciesVariant::GetType(size_t index) const { return _impl->GetType(index); }
|
||||
ImplGetter(const ArbUt::List<uint8_t>&, GetTypes);
|
||||
uint16_t SpeciesVariant::GetStatistic(Library::Statistic stat) const noexcept { return _impl->GetStatistic(stat); }
|
||||
|
||||
ImplGetter(size_t, GetTalentCount);
|
||||
ImplGetter(size_t, GetSecretTalentCount);
|
||||
const ArbUt::StringView& SpeciesVariant::GetTalent(const TalentIndex& index) const {
|
||||
return _impl->GetTalent(index);
|
||||
}
|
||||
THROW("The given talent is not a valid talent for this creature.");
|
||||
TalentIndex SpeciesVariant::GetTalentIndex(const ArbUt::StringView& talent) const {
|
||||
return _impl->GetTalentIndex(talent);
|
||||
}
|
||||
ImplGetter(ArbUt::BorrowedPtr<const LearnableAttacks>, GetLearnableAttacks);
|
||||
TalentIndex SpeciesVariant::GetRandomTalent(ArbUt::Random& rand) const noexcept {
|
||||
return _impl->GetRandomTalent(rand);
|
||||
}
|
||||
ImplGetter(const ArbUt::List<ArbUt::StringView>&, GetTalents);
|
||||
ImplGetter(const ArbUt::List<ArbUt::StringView>&, GetSecretTalents);
|
||||
|
||||
bool SpeciesVariant::HasFlag(const ArbUt::StringView& key) const noexcept { return _impl->HasFlag(key); }
|
||||
bool SpeciesVariant::HasFlag(uint32_t keyHash) const noexcept { return _impl->HasFlag(keyHash); }
|
||||
|
||||
SpeciesVariant::~SpeciesVariant() = default;
|
||||
}
|
|
@ -10,74 +10,41 @@ namespace CreatureLib::Library {
|
|||
\brief A single species can have more than one variant. This class holds the data for those variants.
|
||||
*/
|
||||
class SpeciesVariant {
|
||||
protected:
|
||||
ArbUt::StringView _name;
|
||||
float _height;
|
||||
float _weight;
|
||||
uint32_t _baseExperience;
|
||||
|
||||
private:
|
||||
ArbUt::List<uint8_t> _types;
|
||||
Library::StatisticSet<uint16_t> _baseStatistics;
|
||||
ArbUt::List<ArbUt::StringView> _talents;
|
||||
ArbUt::List<ArbUt::StringView> _secretTalents;
|
||||
std::unique_ptr<const LearnableAttacks> _attacks;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
struct impl;
|
||||
std::unique_ptr<impl> _impl;
|
||||
|
||||
protected:
|
||||
private:
|
||||
public:
|
||||
SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
const ArbUt::List<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
|
||||
const ArbUt::List<ArbUt::StringView>& talents,
|
||||
const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks,
|
||||
std::unordered_set<uint32_t> flags = {})
|
||||
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)),
|
||||
_baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks),
|
||||
_flags(flags){};
|
||||
virtual ~SpeciesVariant() = default;
|
||||
const std::unordered_set<uint32_t>& flags = {});
|
||||
virtual ~SpeciesVariant();
|
||||
|
||||
inline const ArbUt::StringView& GetName() const { return _name; }
|
||||
inline float GetHeight() const { return _height; }
|
||||
inline float GetWeight() const { return _weight; }
|
||||
inline uint32_t GetBaseExperience() const { return _baseExperience; }
|
||||
const ArbUt::StringView& GetName() const noexcept;
|
||||
float GetHeight() const noexcept;
|
||||
float GetWeight() const noexcept;
|
||||
uint32_t GetBaseExperience() const noexcept;
|
||||
|
||||
[[nodiscard]] inline size_t GetTypeCount() const { return _types.Count(); }
|
||||
[[nodiscard]] inline uint8_t GetType(size_t index) const { return _types[index]; }
|
||||
[[nodiscard]] inline const ArbUt::List<uint8_t>& GetTypes() const { return _types; }
|
||||
[[nodiscard]] inline uint16_t GetStatistic(Library::Statistic stat) const {
|
||||
return _baseStatistics.GetStat(stat);
|
||||
}
|
||||
[[nodiscard]] inline size_t GetTalentCount() const noexcept { return _talents.Count(); }
|
||||
[[nodiscard]] inline size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
|
||||
[[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const {
|
||||
if (index.IsSecret() && _secretTalents.Count() > 0) {
|
||||
auto i = index.GetIndex();
|
||||
if (i > _secretTalents.Count())
|
||||
i = _secretTalents.Count();
|
||||
return _secretTalents.At(i);
|
||||
}
|
||||
auto i = index.GetIndex();
|
||||
if (i > _talents.Count())
|
||||
i = _talents.Count();
|
||||
return _talents.At(i);
|
||||
}
|
||||
[[nodiscard]] const TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const;
|
||||
[[nodiscard]] size_t GetTypeCount() const noexcept;
|
||||
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||
[[nodiscard]] const ArbUt::List<uint8_t>& GetTypes() const noexcept;
|
||||
[[nodiscard]] uint16_t GetStatistic(Library::Statistic stat) const noexcept;
|
||||
[[nodiscard]] size_t GetTalentCount() const noexcept;
|
||||
[[nodiscard]] size_t GetSecretTalentCount() const noexcept;
|
||||
[[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const;
|
||||
[[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const;
|
||||
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::LearnableAttacks>
|
||||
GetLearnableAttacks() const {
|
||||
return _attacks;
|
||||
}
|
||||
[[nodiscard]] inline TalentIndex GetRandomTalent(ArbUt::Random& rand) const noexcept {
|
||||
return TalentIndex(false, rand.Get(_talents.Count()));
|
||||
}
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetTalents() const { return _talents; }
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const { return _secretTalents; }
|
||||
[[nodiscard]] ArbUt::BorrowedPtr<const LearnableAttacks> GetLearnableAttacks() const noexcept;
|
||||
[[nodiscard]] TalentIndex GetRandomTalent(ArbUt::Random& rand) const noexcept;
|
||||
[[nodiscard]] const ArbUt::List<ArbUt::StringView>& GetTalents() const noexcept;
|
||||
[[nodiscard]] const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const noexcept;
|
||||
|
||||
inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
|
||||
return this->_flags.find(key) != this->_flags.end();
|
||||
}
|
||||
inline bool HasFlag(uint32_t keyHash) const noexcept {
|
||||
return this->_flags.find(keyHash) != this->_flags.end();
|
||||
}
|
||||
bool HasFlag(const ArbUt::StringView& key) const noexcept;
|
||||
bool HasFlag(uint32_t keyHash) const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue