Adds support for changing variant by variant name.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-11-21 13:44:48 +01:00
parent 9270dcca8c
commit 40d6e8a389
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 10 additions and 1 deletions

View File

@ -56,6 +56,14 @@ namespace CreatureLib::Battling {
ChangeVariant(variant); ChangeVariant(variant);
} }
void Battling::Creature::ChangeVariant(const ArbUt::StringView& variantName) {
auto opt = _species->TryGetVariant(variantName);
if (!opt.has_value()) {
THROW("Unknown variant: ", variantName);
}
ChangeVariant(opt.value());
}
void Creature::ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant) { void Creature::ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant) {
_variant = variant; _variant = variant;
@ -430,4 +438,4 @@ Battling::Creature::~Creature() {
if (_battleData.OnBattleField && _battleData.Side.HasValue()) { if (_battleData.OnBattleField && _battleData.Side.HasValue()) {
_battleData.Side.GetValue()->ForceClearCreature(_battleData.Index.GetCreatureIndex()); _battleData.Side.GetValue()->ForceClearCreature(_battleData.Index.GetCreatureIndex());
} }
} }

View File

@ -92,6 +92,7 @@ namespace CreatureLib::Battling {
inline const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& GetVariant() const noexcept { return _variant; } inline const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& GetVariant() const noexcept { return _variant; }
virtual void ChangeSpecies(const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species, virtual void ChangeSpecies(const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant); const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant);
virtual void ChangeVariant(const ArbUt::StringView& variantName);
virtual void ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant); virtual void ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant);
inline level_int_t GetLevel() const noexcept { return _level; } inline level_int_t GetLevel() const noexcept { return _level; }
inline uint32_t GetExperience() const noexcept { return _experience; } inline uint32_t GetExperience() const noexcept { return _experience; }