Change LibrarySettings to be a pointer instead of value, to allow for overriding in implementations.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-01 13:30:51 +01:00
parent 7e0a1ec033
commit dba271681d
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
7 changed files with 10 additions and 10 deletions

View File

@ -18,7 +18,7 @@ BattleLibrary::~BattleLibrary() {
delete _miscLibrary;
}
const CreatureLib::Library::LibrarySettings& BattleLibrary::GetSettings() const { return _staticLib->GetSettings(); }
const CreatureLib::Library::LibrarySettings* BattleLibrary::GetSettings() const { return _staticLib->GetSettings(); }
const BattleStatCalculator* BattleLibrary::GetStatCalculator() const { return _statCalculator; }

View File

@ -25,7 +25,7 @@ namespace CreatureLib::Battling {
~BattleLibrary();
inline const Library::DataLibrary* GetStaticLib() const { return _staticLib; }
[[nodiscard]] const Library::LibrarySettings& GetSettings() const;
[[nodiscard]] const Library::LibrarySettings* GetSettings() const;
[[nodiscard]] const Library::SpeciesLibrary* GetSpeciesLibrary() const;
[[nodiscard]] const Library::ItemLibrary* GetItemLibrary() const;
[[nodiscard]] const Library::AttackLibrary* GetAttackLibrary() const;

View File

@ -21,7 +21,7 @@ CreateCreature* CreateCreature::WithGender(Library::Gender gender) {
}
CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) {
if (_attacks.size() >= _library->GetSettings().GetMaximalMoves())
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves())
throw CreatureException("You have already set the maximum amount of allowed moves.");
auto attackData = _library->GetAttackLibrary()->GetAttack(attackName);

View File

@ -133,7 +133,7 @@ void Battling::Creature::GetActiveScripts(std::vector<ScriptWrapper>& scripts) {
}
void Battling::Creature::ClearVolatileScripts() { _volatile.Clear(); }
void Battling::Creature::AddExperience(uint32_t amount) {
auto maxLevel = _library->GetSettings().GetMaximalLevel();
auto maxLevel = _library->GetSettings()->GetMaximalLevel();
if (_level >= maxLevel) {
return;
}

View File

@ -1,6 +1,6 @@
#include "DataLibrary.hpp"
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::AttackLibrary* attacks,
CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates,
@ -8,7 +8,7 @@ CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings, Creatur
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
_typeLibrary(typeLibrary) {}
const CreatureLib::Library::LibrarySettings& CreatureLib::Library::DataLibrary::GetSettings() const {
const CreatureLib::Library::LibrarySettings* CreatureLib::Library::DataLibrary::GetSettings() const {
return _settings;
}

View File

@ -14,7 +14,7 @@ namespace CreatureLib::Library {
*/
class DataLibrary {
private:
const LibrarySettings _settings;
const LibrarySettings* _settings;
const SpeciesLibrary* _species;
const AttackLibrary* _attacks;
const ItemLibrary* _items;
@ -22,7 +22,7 @@ namespace CreatureLib::Library {
const TypeLibrary* _typeLibrary;
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::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary);
@ -34,7 +34,7 @@ namespace CreatureLib::Library {
delete _typeLibrary;
}
[[nodiscard]] const LibrarySettings& GetSettings() const;
[[nodiscard]] const LibrarySettings* GetSettings() const;
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const;
[[nodiscard]] const AttackLibrary* GetAttackLibrary() const;
[[nodiscard]] const ItemLibrary* GetItemLibrary() const;

View File

@ -10,7 +10,7 @@ BattleLibrary* TestLibrary::_library = nullptr;
BattleLibrary* TestLibrary::Get() {
if (TestLibrary::_library == nullptr) {
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
auto l = new DataLibrary(new LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
auto statCalc = new BattleStatCalculator();
auto battleLib = new BattleLibrary(l, statCalc, new DamageLibrary(), new ExperienceLibrary(),