diff --git a/CInterface/Battling/Creature.cpp b/CInterface/Battling/Creature.cpp index 2ffc7d9..ef87dc3 100644 --- a/CInterface/Battling/Creature.cpp +++ b/CInterface/Battling/Creature.cpp @@ -79,8 +79,8 @@ export uint8_t CreatureLib_Creature_RestoreAllAttackUses(Creature* p) { Try(p->R export bool CreatureLib_Creature_GetRealTalentIsSecret(const Creature* p) { return p->GetRealTalent().IsSecret(); } export bool CreatureLib_Creature_GetRealTalentIndex(const Creature* p) { return p->GetRealTalent().GetIndex(); } -export uint8_t CreatureLib_Creature_GetActiveTalent(const Creature* p, const char*& out) { - Try(out = p->GetActiveTalent().c_str();) +export uint8_t CreatureLib_Creature_GetActiveTalent(const Creature* p, const CreatureLib::Library::Talent*& out) { + Try(out = p->GetActiveTalent().GetRaw();) } export uint8_t CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) { Try(p->OverrideActiveTalent(ArbUt::StringView(talent));) diff --git a/CInterface/Library/DataLibrary.cpp b/CInterface/Library/DataLibrary.cpp index 76079d6..db8b32a 100644 --- a/CInterface/Library/DataLibrary.cpp +++ b/CInterface/Library/DataLibrary.cpp @@ -4,8 +4,9 @@ using namespace CreatureLib::Library; export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, LibrarySettings* settings, SpeciesLibrary* species, AttackLibrary* attacks, ItemLibrary* items, - GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary) { - Try(out = new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary);) + GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary, + TalentLibrary* talentLibrary) { + Try(out = new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary, talentLibrary);) } export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; } @@ -15,4 +16,5 @@ SMART_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*); SMART_GET_FUNC(DataLibrary, GetAttackLibrary, const AttackLibrary*); SMART_GET_FUNC(DataLibrary, GetItemLibrary, const ItemLibrary*); SMART_GET_FUNC(DataLibrary, GetGrowthRates, const GrowthRateLibrary*); -SMART_GET_FUNC(DataLibrary, GetTypeLibrary, const TypeLibrary*); \ No newline at end of file +SMART_GET_FUNC(DataLibrary, GetTypeLibrary, const TypeLibrary*); +SMART_GET_FUNC(DataLibrary, GetTalentLibrary, const TalentLibrary*); \ No newline at end of file diff --git a/CInterface/Library/SpeciesVariant.cpp b/CInterface/Library/SpeciesVariant.cpp index bc648cd..e53ad45 100644 --- a/CInterface/Library/SpeciesVariant.cpp +++ b/CInterface/Library/SpeciesVariant.cpp @@ -7,8 +7,8 @@ export SpeciesVariant* CreatureLib_SpeciesVariant_Construct(const char* name, float height, float weight, uint32_t baseExperience, uint8_t types[], size_t typeLength, uint16_t baseHealth, uint16_t baseAttack, uint16_t baseDefense, uint16_t baseMagicalAttack, uint16_t baseMagicalDefense, - uint16_t baseSpeed, const char* talents[], size_t talentsLength, - const char* secretTalents[], size_t secretTalentsLength, + uint16_t baseSpeed, const Talent* talents[], size_t talentsLength, + const Talent* secretTalents[], size_t secretTalentsLength, const LearnableAttacks* attacks, const char* flags[], size_t flagsCount) { std::unordered_set conversedFlags(flagsCount); @@ -16,13 +16,13 @@ CreatureLib_SpeciesVariant_Construct(const char* name, float height, float weigh conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i])); } - auto talentsWrapped = ArbUt::List(talentsLength); + auto talentsWrapped = ArbUt::List>(talentsLength); for (size_t i = 0; i < talentsLength; i++) { - talentsWrapped.Append(ArbUt::StringView(talents[i])); + talentsWrapped.Append(talents[i]); } - auto secretTalentsWrapped = ArbUt::List(secretTalentsLength); + auto secretTalentsWrapped = ArbUt::List>(secretTalentsLength); for (size_t i = 0; i < secretTalentsLength; i++) { - secretTalentsWrapped.Append(ArbUt::StringView(secretTalents[i])); + secretTalentsWrapped.Append(secretTalents[i]); } return new SpeciesVariant( @@ -45,8 +45,8 @@ export uint16_t CreatureLib_SpeciesVariant_GetStatistic(SpeciesVariant* p, Creat } SIMPLE_GET_FUNC(SpeciesVariant, GetTalentCount, size_t); SIMPLE_GET_FUNC(SpeciesVariant, GetSecretTalentCount, size_t); -export uint8_t CreatureLib_SpeciesVariant_GetTalent(SpeciesVariant* p, bool secret, uint8_t index, const char*& out) { - Try(out = p->GetTalent(TalentIndex(secret, index)).c_str();) +export uint8_t CreatureLib_SpeciesVariant_GetTalent(SpeciesVariant* p, bool secret, uint8_t index, const Talent*& out) { + Try(out = p->GetTalent(TalentIndex(secret, index)).GetRaw();) } export const LearnableAttacks* CreatureLib_SpeciesVariant_GetLearnableAttacks(SpeciesVariant* p) { return p->GetLearnableAttacks().GetRaw(); diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 9608d2a..93e1f55 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -20,8 +20,11 @@ namespace CreatureLib::Battling { _weight(variant->GetWeight()), _height(variant->GetHeight()), _nickname(std::move(nickname)), _talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks), _allowedExperienceGain(allowedExperienceGain) { - _activeTalent = - std::unique_ptr(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent())); + _activeTalent = std::unique_ptr( + _library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect())); + if (_activeTalent != nullptr) { + _activeTalent->OnInitialize(GetActiveTalent()->GetParameters()); + } for (auto t : _variant->GetTypes()) { _types.push_back(t); } @@ -65,8 +68,11 @@ namespace CreatureLib::Battling { _height = variant->GetHeight(); // Grab the new active talent. - _activeTalent = - std::unique_ptr(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent())); + _activeTalent = std::unique_ptr( + _library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect())); + if (_activeTalent != nullptr) { + _activeTalent->OnInitialize(GetActiveTalent()->GetParameters()); + } // We modify the health of the creature by the change in its max health. auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health); @@ -96,9 +102,9 @@ namespace CreatureLib::Battling { RecalculateFlatStats(); } - const ArbUt::StringView& Creature::GetActiveTalent() const { - if (_hasOverridenTalent) { - return _overridenTalentName; + ArbUt::BorrowedPtr Creature::GetActiveTalent() const { + if (_hasOverridenTalent && _overridenTalent.HasValue()) { + return _overridenTalent.GetValue(); } return _variant->GetTalent(_talentIndex); } @@ -233,7 +239,7 @@ namespace CreatureLib::Battling { _activeTalent->OnRemove(); _activeTalent.reset(this->_library->LoadScript(this, ScriptCategory::Talent, talent)); } - _overridenTalentName = talent; + _overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->Get(talent); } const std::vector& Creature::GetTypes() const noexcept { return _types; } @@ -384,7 +390,7 @@ namespace CreatureLib::Battling { c->_activeTalent = std::unique_ptr(_activeTalent->Clone(c)); } c->_hasOverridenTalent = _hasOverridenTalent; - c->_overridenTalentName = _overridenTalentName; + c->_overridenTalent = _overridenTalent; if (_status != nullptr) { c->_status = std::unique_ptr(_status->Clone(c)); } diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 24e81ff..99b16ed 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -56,7 +56,7 @@ namespace CreatureLib::Battling { std::unique_ptr _activeTalent = {}; bool _hasOverridenTalent = false; - ArbUt::StringView _overridenTalentName = {}; + ArbUt::OptionalBorrowedPtr _overridenTalent = {}; ArbUt::OptionalUniquePtrList _attacks = {}; bool _allowedExperienceGain = {}; @@ -144,7 +144,7 @@ namespace CreatureLib::Battling { } inline void SetNickname(std::string nickname) noexcept { _nickname = nickname; } const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; } - const ArbUt::StringView& GetActiveTalent() const; + ArbUt::BorrowedPtr GetActiveTalent() const; /// Are we allowed to use this creature in a battle? [[nodiscard]] virtual bool IsUsable() const noexcept; diff --git a/src/Library/CreatureData/SpeciesVariant.cpp b/src/Library/CreatureData/SpeciesVariant.cpp index 510b693..f9ebbc4 100644 --- a/src/Library/CreatureData/SpeciesVariant.cpp +++ b/src/Library/CreatureData/SpeciesVariant.cpp @@ -9,16 +9,17 @@ namespace CreatureLib::Library { uint32_t _baseExperience; ArbUt::List _types; Library::StatisticSet _baseStatistics; - ArbUt::List _talents; - ArbUt::List _secretTalents; + ArbUt::List> _talents; + ArbUt::List> _secretTalents; std::unique_ptr _attacks; std::unordered_set _flags; public: impl(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience, ArbUt::List types, Library::StatisticSet baseStats, - ArbUt::List talents, ArbUt::List secretTalents, - const LearnableAttacks* attacks, std::unordered_set flags) + ArbUt::List> talents, + ArbUt::List> secretTalents, const LearnableAttacks* attacks, + std::unordered_set flags) : _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types(std::move((types))), _baseStatistics(baseStats), _talents(std::move(talents)), _secretTalents(std::move(secretTalents)), _attacks(attacks), _flags(std::move(flags)){}; @@ -36,7 +37,7 @@ namespace CreatureLib::Library { } [[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 { + [[nodiscard]] const ArbUt::BorrowedPtr& GetTalent(const TalentIndex& index) const { if (index.IsSecret() && _secretTalents.Count() > 0) { auto i = index.GetIndex(); if (i > _secretTalents.Count()) { @@ -50,7 +51,7 @@ namespace CreatureLib::Library { } return _talents.At(i); } - [[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const { + [[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::BorrowedPtr& talent) const { for (size_t i = 0; i < _talents.Count(); i++) { if (_talents.At(i) == talent) { return TalentIndex(false, i); @@ -63,6 +64,19 @@ namespace CreatureLib::Library { } THROW("The given talent is not a valid talent for this creature."); } + [[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talentName) const { + for (size_t i = 0; i < _talents.Count(); i++) { + if (_talents.At(i)->GetName() == talentName) { + return TalentIndex(false, i); + } + } + for (size_t i = 0; i < _secretTalents.Count(); i++) { + if (_secretTalents.At(i)->GetName() == talentName) { + return TalentIndex(true, i); + } + } + THROW("The given talent name is not a valid talent for this creature."); + } [[nodiscard]] inline ArbUt::BorrowedPtr GetLearnableAttacks() const { @@ -71,8 +85,12 @@ namespace CreatureLib::Library { [[nodiscard]] inline TalentIndex GetRandomTalent(ArbUt::Random& rand) const noexcept { return TalentIndex(false, rand.Get(_talents.Count())); } - [[nodiscard]] inline const ArbUt::List& GetTalents() const { return _talents; } - [[nodiscard]] inline const ArbUt::List& GetSecretTalents() const { return _secretTalents; } + [[nodiscard]] inline const ArbUt::List>& GetTalents() const { + return _talents; + } + [[nodiscard]] inline const ArbUt::List>& GetSecretTalents() const { + return _secretTalents; + } inline bool HasFlag(const ArbUt::StringView& key) const noexcept { return this->_flags.find(key) != this->_flags.end(); @@ -84,9 +102,9 @@ namespace CreatureLib::Library { SpeciesVariant::SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience, const ArbUt::List& types, StatisticSet baseStats, - const ArbUt::List& talents, - const ArbUt::List& secretTalents, const LearnableAttacks* attacks, - const std::unordered_set& flags) + const ArbUt::List>& talents, + const ArbUt::List>& secretTalents, + const LearnableAttacks* attacks, const std::unordered_set& flags) : _impl(new impl(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks, flags)) {} SpeciesVariant::~SpeciesVariant() = default; @@ -105,18 +123,21 @@ namespace CreatureLib::Library { ImplGetter(size_t, GetTalentCount); ImplGetter(size_t, GetSecretTalentCount); - const ArbUt::StringView& SpeciesVariant::GetTalent(const TalentIndex& index) const { + const ArbUt::BorrowedPtr& SpeciesVariant::GetTalent(const TalentIndex& index) const { return _impl->GetTalent(index); } - TalentIndex SpeciesVariant::GetTalentIndex(const ArbUt::StringView& talent) const { + TalentIndex SpeciesVariant::GetTalentIndex(const ArbUt::BorrowedPtr& talent) const { return _impl->GetTalentIndex(talent); } + TalentIndex SpeciesVariant::GetTalentIndex(const ArbUt::StringView& talentName) const { + return _impl->GetTalentIndex(talentName); + } ImplGetter(ArbUt::BorrowedPtr, GetLearnableAttacks); TalentIndex SpeciesVariant::GetRandomTalent(ArbUt::Random& rand) const noexcept { return _impl->GetRandomTalent(rand); } - ImplGetter(const ArbUt::List&, GetTalents); - ImplGetter(const ArbUt::List&, GetSecretTalents); + ImplGetter(const ArbUt::List>&, GetTalents); + ImplGetter(const ArbUt::List>&, 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); } diff --git a/src/Library/CreatureData/SpeciesVariant.hpp b/src/Library/CreatureData/SpeciesVariant.hpp index d1d086d..88b3787 100644 --- a/src/Library/CreatureData/SpeciesVariant.hpp +++ b/src/Library/CreatureData/SpeciesVariant.hpp @@ -3,6 +3,7 @@ #include "../StatisticSet.hpp" #include "LearnableAttacks.hpp" +#include "Talent.hpp" #include "TalentIndex.hpp" namespace CreatureLib::Library { @@ -28,9 +29,9 @@ namespace CreatureLib::Library { /// @param flags A set of flags for use by the developer. These can be used for easy grouping. SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience, const ArbUt::List& types, Library::StatisticSet baseStats, - const ArbUt::List& talents, - const ArbUt::List& secretTalents, const LearnableAttacks* attacks, - const std::unordered_set& flags = {}); + const ArbUt::List>& talents, + const ArbUt::List>& secretTalents, + const LearnableAttacks* attacks, const std::unordered_set& flags = {}); virtual ~SpeciesVariant(); /// @brief Returns the unique name of the variant. @@ -70,11 +71,15 @@ namespace CreatureLib::Library { /// @brief Returns a talent name at a specified TalentIndex. /// @param index Whether it's a secret talent, and which index to get. /// @return The name of the talent at the given TalentIndex. - [[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const; - /// @brief Search for the index of a talent with a name. - /// @param talent The name that's being looked for. + [[nodiscard]] const ArbUt::BorrowedPtr& GetTalent(const TalentIndex& index) const; + /// @brief Search for the index of a specific talent. + /// @param talent The talent that's being looked for. /// @return The index of the talent. - [[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const; + [[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::BorrowedPtr& talent) const; + /// @brief Search for the index of a talent with a name. + /// @param talentName The name that's being looked for. + /// @return The index of the talent. + [[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talentName) const; /// @brief Returns the attacks the variant can learn. /// @return The attacks the variant can learn. @@ -85,10 +90,10 @@ namespace CreatureLib::Library { [[nodiscard]] TalentIndex GetRandomTalent(ArbUt::Random& rand) const noexcept; /// @brief Returns a list of talents of the variant. /// @return A list of talents of the variant. - [[nodiscard]] const ArbUt::List& GetTalents() const noexcept; + [[nodiscard]] const ArbUt::List>& GetTalents() const noexcept; /// @brief Returns a list of secret talents of the variant. /// @return A list of secret talents of the variant. - [[nodiscard]] const ArbUt::List& GetSecretTalents() const noexcept; + [[nodiscard]] const ArbUt::List>& GetSecretTalents() const noexcept; /// @brief Checks whether the species has a specific flag. /// @param key The flag to check for. diff --git a/src/Library/CreatureData/Talent.hpp b/src/Library/CreatureData/Talent.hpp new file mode 100644 index 0000000..f9ee41d --- /dev/null +++ b/src/Library/CreatureData/Talent.hpp @@ -0,0 +1,25 @@ +#ifndef CREATURELIB_TALENT_HPP +#define CREATURELIB_TALENT_HPP +#include +#include +#include +#include "../EffectParameter.hpp" + +namespace CreatureLib::Library { + class Talent { + public: + Talent(const ArbUt::StringView& name, const ArbUt::StringView& effect, ArbUt::List parameters) + : _name(name), _effect(effect), _parameters(std::move(parameters)) {} + + [[nodiscard]] inline const ArbUt::StringView& GetName() const noexcept { return _name; } + [[nodiscard]] inline const ArbUt::StringView& GetEffect() const noexcept { return _effect; } + [[nodiscard]] inline const ArbUt::List& GetParameters() const noexcept { return _parameters; } + + private: + ArbUt::StringView _name; + ArbUt::StringView _effect; + ArbUt::List _parameters; + }; +} + +#endif // CREATURELIB_TALENT_HPP diff --git a/src/Library/DataLibrary.cpp b/src/Library/DataLibrary.cpp index 6fe16c7..a44930a 100644 --- a/src/Library/DataLibrary.cpp +++ b/src/Library/DataLibrary.cpp @@ -4,13 +4,14 @@ CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, Creatu CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates, - TypeLibrary* typeLibrary) + TypeLibrary* typeLibrary, TalentLibrary* talentLibrary) : _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates), - _typeLibrary(typeLibrary) { + _typeLibrary(typeLibrary), _talentLibrary(talentLibrary) { EnsureNotNull(_settings) EnsureNotNull(_species) EnsureNotNull(_attacks) EnsureNotNull(_items) EnsureNotNull(_growthRates) EnsureNotNull(_typeLibrary) + EnsureNotNull(_talentLibrary) } \ No newline at end of file diff --git a/src/Library/DataLibrary.hpp b/src/Library/DataLibrary.hpp index 8ec3905..b3649ee 100644 --- a/src/Library/DataLibrary.hpp +++ b/src/Library/DataLibrary.hpp @@ -6,6 +6,7 @@ #include "ItemLibrary.hpp" #include "LibrarySettings.hpp" #include "SpeciesLibrary.hpp" +#include "TalentLibrary.hpp" #include "TypeLibrary.hpp" namespace CreatureLib::Library { @@ -20,11 +21,13 @@ namespace CreatureLib::Library { std::unique_ptr _items; std::unique_ptr _growthRates; std::unique_ptr _typeLibrary; + std::unique_ptr _talentLibrary; public: DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species, CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items, - CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary); + CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary, + TalentLibrary* talentLibrary); virtual ~DataLibrary() {} @@ -46,6 +49,9 @@ namespace CreatureLib::Library { [[nodiscard]] inline const std::unique_ptr& GetTypeLibrary() const noexcept { return _typeLibrary; } + [[nodiscard]] inline const std::unique_ptr& GetTalentLibrary() const noexcept { + return _talentLibrary; + } }; } diff --git a/src/Library/TalentLibrary.hpp b/src/Library/TalentLibrary.hpp new file mode 100644 index 0000000..e857109 --- /dev/null +++ b/src/Library/TalentLibrary.hpp @@ -0,0 +1,14 @@ +#ifndef CREATURELIB_TALENTLIBRARY_HPP +#define CREATURELIB_TALENTLIBRARY_HPP + +#include "BaseLibrary.hpp" +#include "CreatureData/Talent.hpp" + +namespace CreatureLib::Library { + class TalentLibrary : public BaseLibrary { + public: + explicit TalentLibrary(size_t initialCapacity = 32) : BaseLibrary(initialCapacity){}; + }; +} + +#endif // CREATURELIB_TALENTLIBRARY_HPP diff --git a/tests/BattleTests/CreatureTests.cpp b/tests/BattleTests/CreatureTests.cpp index 16bc2d6..b536b25 100644 --- a/tests/BattleTests/CreatureTests.cpp +++ b/tests/BattleTests/CreatureTests.cpp @@ -51,7 +51,7 @@ TEST_CASE("Override Creature talent") { auto library = TestLibrary::Get(); auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create(); creature->OverrideActiveTalent("foobar"); - REQUIRE(creature->GetActiveTalent() == "foobar"); + REQUIRE(creature->GetActiveTalent()->GetName() == "foobar"_cnc); delete creature; } diff --git a/tests/LibraryTests/TestLibraryTests.cpp b/tests/LibraryTests/TestLibraryTests.cpp index 935e4e5..354f2df 100644 --- a/tests/LibraryTests/TestLibraryTests.cpp +++ b/tests/LibraryTests/TestLibraryTests.cpp @@ -4,12 +4,6 @@ #include "../../extern/doctest.hpp" #include "../TestLibrary/TestLibrary.hpp" -TEST_CASE("Can Create Species Library") { - auto l = TestLibrary::BuildSpeciesLibrary(); - REQUIRE(l != nullptr); - delete l; -} - TEST_CASE("Can Create Attack Library") { auto l = TestLibrary::BuildAttackLibrary(); REQUIRE(l != nullptr); diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 898de70..8d6b4c4 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -9,8 +9,9 @@ BattleLibrary* TestLibrary::_library = nullptr; BattleLibrary* TestLibrary::Get() { if (TestLibrary::_library == nullptr) { - auto l = new DataLibrary(new LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(), - BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary()); + auto talentLibrary = BuildTalentLibrary(); + auto l = new DataLibrary(new LibrarySettings(100, 4), BuildSpeciesLibrary(talentLibrary), BuildAttackLibrary(), + BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary(), talentLibrary); auto statCalc = new BattleStatCalculator(); auto battleLib = new BattleLibrary(l, statCalc, new DamageLibrary(), new ExperienceLibrary(), new ScriptResolver(), new MiscLibrary()); @@ -19,14 +20,15 @@ BattleLibrary* TestLibrary::Get() { return TestLibrary::_library; } -SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { +SpeciesLibrary* TestLibrary::BuildSpeciesLibrary(const TalentLibrary* talentLibrary) { auto l = new SpeciesLibrary(); l->Insert("testSpecies1"_cnc.GetHash(), - new CreatureSpecies(0, "testSpecies1"_cnc, - new SpeciesVariant("default"_cnc, 1, 1, 10, {0, 1}, - StatisticSet(10, 10, 10, 10, 10, 10), {"testTalent"_cnc}, - {"testSecretTalent"_cnc}, new LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 5)); + new CreatureSpecies( + 0, "testSpecies1"_cnc, + new SpeciesVariant("default"_cnc, 1, 1, 10, {0, 1}, StatisticSet(10, 10, 10, 10, 10, 10), + {talentLibrary->Get("testTalent"_cnc)}, + {talentLibrary->Get("testSecretTalent"_cnc)}, new LearnableAttacks(100)), + 0.5f, "testGrowthRate"_cnc, 5)); return l; } @@ -75,4 +77,12 @@ TypeLibrary* TestLibrary::BuildTypeLibrary() { return l; } +TalentLibrary* TestLibrary::BuildTalentLibrary() { + auto* lib = new TalentLibrary(); + lib->Insert("testTalent", new Talent("testTalent", "", {})); + lib->Insert("testSecretTalent", new Talent("testTalent", "", {})); + lib->Insert("foobar", new Talent("foobar", "", {})); + return lib; +} + #endif \ No newline at end of file diff --git a/tests/TestLibrary/TestLibrary.hpp b/tests/TestLibrary/TestLibrary.hpp index d54e6c8..f13b89b 100644 --- a/tests/TestLibrary/TestLibrary.hpp +++ b/tests/TestLibrary/TestLibrary.hpp @@ -12,11 +12,12 @@ class TestLibrary { static BattleLibrary* _library; public: - static SpeciesLibrary* BuildSpeciesLibrary(); + static SpeciesLibrary* BuildSpeciesLibrary(const TalentLibrary*); static AttackLibrary* BuildAttackLibrary(); static ItemLibrary* BuildItemLibrary(); static GrowthRateLibrary* BuildGrowthRateLibrary(); static TypeLibrary* BuildTypeLibrary(); + static TalentLibrary* BuildTalentLibrary(); static BattleLibrary* Get(); };