Make DataLibrary use unique_ptr.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c056ddc6b3
commit
b17c0648ff
|
@ -11,7 +11,7 @@ export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, Librar
|
||||||
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }
|
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }
|
||||||
|
|
||||||
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
||||||
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
|
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().operator->(); }
|
||||||
|
|
||||||
SIMPLE_GET_FUNC(DataLibrary, GetSettings, const LibrarySettings*);
|
SIMPLE_GET_FUNC(DataLibrary, GetSettings, const LibrarySettings*);
|
||||||
SIMPLE_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*);
|
SIMPLE_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*);
|
||||||
|
|
|
@ -24,25 +24,25 @@ BattleLibrary::~BattleLibrary() {
|
||||||
delete _miscLibrary;
|
delete _miscLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::LibrarySettings* BattleLibrary::GetSettings() const noexcept {
|
const std::unique_ptr<CreatureLib::Library::LibrarySettings>& BattleLibrary::GetSettings() const noexcept {
|
||||||
return _staticLib->GetSettings();
|
return _staticLib->GetSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const BattleStatCalculator* BattleLibrary::GetStatCalculator() const noexcept { return _statCalculator; }
|
const BattleStatCalculator* BattleLibrary::GetStatCalculator() const noexcept { return _statCalculator; }
|
||||||
|
|
||||||
const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const noexcept {
|
const std::unique_ptr<CreatureLib::Library::SpeciesLibrary>& BattleLibrary::GetSpeciesLibrary() const noexcept {
|
||||||
return _staticLib->GetSpeciesLibrary();
|
return _staticLib->GetSpeciesLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const noexcept {
|
const std::unique_ptr<CreatureLib::Library::ItemLibrary>& BattleLibrary::GetItemLibrary() const noexcept {
|
||||||
return _staticLib->GetItemLibrary();
|
return _staticLib->GetItemLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::AttackLibrary* BattleLibrary::GetAttackLibrary() const noexcept {
|
const std::unique_ptr<CreatureLib::Library::AttackLibrary>& BattleLibrary::GetAttackLibrary() const noexcept {
|
||||||
return _staticLib->GetAttackLibrary();
|
return _staticLib->GetAttackLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::TypeLibrary* BattleLibrary::GetTypeLibrary() const noexcept {
|
const std::unique_ptr<CreatureLib::Library::TypeLibrary>& BattleLibrary::GetTypeLibrary() const noexcept {
|
||||||
return _staticLib->GetTypeLibrary();
|
return _staticLib->GetTypeLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,12 @@ namespace CreatureLib::Battling {
|
||||||
~BattleLibrary();
|
~BattleLibrary();
|
||||||
inline const Library::DataLibrary* GetStaticLib() const noexcept { return _staticLib; }
|
inline const Library::DataLibrary* GetStaticLib() const noexcept { return _staticLib; }
|
||||||
|
|
||||||
[[nodiscard]] const Library::LibrarySettings* GetSettings() const noexcept;
|
[[nodiscard]] const std::unique_ptr<Library::LibrarySettings>& GetSettings() const noexcept;
|
||||||
[[nodiscard]] const Library::SpeciesLibrary* GetSpeciesLibrary() const noexcept;
|
[[nodiscard]] const std::unique_ptr<Library::SpeciesLibrary>& GetSpeciesLibrary() const noexcept;
|
||||||
[[nodiscard]] const Library::ItemLibrary* GetItemLibrary() const noexcept;
|
[[nodiscard]] const std::unique_ptr<Library::ItemLibrary>& GetItemLibrary() const noexcept;
|
||||||
[[nodiscard]] const Library::AttackLibrary* GetAttackLibrary() const noexcept;
|
[[nodiscard]] const std::unique_ptr<Library::AttackLibrary>& GetAttackLibrary() const noexcept;
|
||||||
[[nodiscard]] const Library::TypeLibrary* GetTypeLibrary() const noexcept;
|
[[nodiscard]] const std::unique_ptr<Library::TypeLibrary>& GetTypeLibrary() const noexcept;
|
||||||
[[nodiscard]] const Library::GrowthRateLibrary* GetGrowthRateLibrary() const noexcept {
|
[[nodiscard]] const std::unique_ptr<Library::GrowthRateLibrary>& GetGrowthRateLibrary() const noexcept {
|
||||||
return _staticLib->GetGrowthRates();
|
return _staticLib->GetGrowthRates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,28 +13,4 @@ CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, Creatu
|
||||||
AssertNotNull(_items)
|
AssertNotNull(_items)
|
||||||
AssertNotNull(_growthRates)
|
AssertNotNull(_growthRates)
|
||||||
AssertNotNull(_typeLibrary)
|
AssertNotNull(_typeLibrary)
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::LibrarySettings* CreatureLib::Library::DataLibrary::GetSettings() const noexcept {
|
|
||||||
return _settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CreatureLib::Library::SpeciesLibrary* CreatureLib::Library::DataLibrary::GetSpeciesLibrary() const noexcept {
|
|
||||||
return _species;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CreatureLib::Library::AttackLibrary* CreatureLib::Library::DataLibrary::GetAttackLibrary() const noexcept {
|
|
||||||
return _attacks;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CreatureLib::Library::ItemLibrary* CreatureLib::Library::DataLibrary::GetItemLibrary() const noexcept {
|
|
||||||
return _items;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CreatureLib::Library::GrowthRateLibrary* CreatureLib::Library::DataLibrary::GetGrowthRates() const noexcept {
|
|
||||||
return _growthRates;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CreatureLib::Library::TypeLibrary* CreatureLib::Library::DataLibrary::GetTypeLibrary() const noexcept {
|
|
||||||
return _typeLibrary;
|
|
||||||
}
|
|
|
@ -14,32 +14,26 @@ namespace CreatureLib::Library {
|
||||||
*/
|
*/
|
||||||
class DataLibrary {
|
class DataLibrary {
|
||||||
private:
|
private:
|
||||||
const LibrarySettings* _settings;
|
const std::unique_ptr<LibrarySettings> _settings;
|
||||||
const SpeciesLibrary* _species;
|
const std::unique_ptr<SpeciesLibrary> _species;
|
||||||
const AttackLibrary* _attacks;
|
const std::unique_ptr<AttackLibrary> _attacks;
|
||||||
const ItemLibrary* _items;
|
const std::unique_ptr<ItemLibrary> _items;
|
||||||
const GrowthRateLibrary* _growthRates;
|
const std::unique_ptr<GrowthRateLibrary> _growthRates;
|
||||||
const TypeLibrary* _typeLibrary;
|
const std::unique_ptr<TypeLibrary> _typeLibrary;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
|
DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
|
||||||
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
|
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
|
||||||
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary);
|
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary);
|
||||||
|
|
||||||
virtual ~DataLibrary() {
|
virtual ~DataLibrary() {}
|
||||||
delete _species;
|
|
||||||
delete _attacks;
|
|
||||||
delete _items;
|
|
||||||
delete _growthRates;
|
|
||||||
delete _typeLibrary;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] const LibrarySettings* GetSettings() const noexcept;
|
[[nodiscard]] const std::unique_ptr<LibrarySettings>& GetSettings() const noexcept { return _settings; }
|
||||||
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const noexcept;
|
[[nodiscard]] const std::unique_ptr<SpeciesLibrary>& GetSpeciesLibrary() const noexcept { return _species; }
|
||||||
[[nodiscard]] const AttackLibrary* GetAttackLibrary() const noexcept;
|
[[nodiscard]] const std::unique_ptr<AttackLibrary>& GetAttackLibrary() const noexcept { return _attacks; }
|
||||||
[[nodiscard]] const ItemLibrary* GetItemLibrary() const noexcept;
|
[[nodiscard]] const std::unique_ptr<ItemLibrary>& GetItemLibrary() const noexcept { return _items; }
|
||||||
[[nodiscard]] const GrowthRateLibrary* GetGrowthRates() const noexcept;
|
[[nodiscard]] const std::unique_ptr<GrowthRateLibrary>& GetGrowthRates() const noexcept { return _growthRates; }
|
||||||
[[nodiscard]] const TypeLibrary* GetTypeLibrary() const noexcept;
|
[[nodiscard]] const std::unique_ptr<TypeLibrary>& GetTypeLibrary() const noexcept { return _typeLibrary; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
|
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
|
||||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
const auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||||
auto a1 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
auto a1 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||||
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||||
|
@ -52,7 +52,7 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]")
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
|
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
|
||||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
const auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||||
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||||
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||||
|
@ -74,7 +74,7 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
|
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
|
||||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
const auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||||
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||||
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||||
|
@ -96,7 +96,7 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]")
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
|
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
|
||||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
const auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||||
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||||
auto a2 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
auto a2 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
|
||||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||||
|
|
Loading…
Reference in New Issue