From bb1791b3ae1d955ff8acba8dfe1a27620ec6ee07 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 30 Dec 2019 16:19:53 +0100 Subject: [PATCH] Implements outlines for ItemLibrary, MoveLibrary and implements NatureLibrary. --- conanfile.py | 2 +- src/Library/Items/Item.cpp | 1 + src/Library/Items/Item.hpp | 9 +++++ src/Library/Items/ItemLibrary.cpp | 1 + src/Library/Items/ItemLibrary.hpp | 19 +++++++++++ src/Library/Moves/MoveLibrary.cpp | 3 -- src/Library/Moves/MoveLibrary.hpp | 17 +++++++++- src/Library/Natures/Nature.cpp | 1 + src/Library/Natures/Nature.hpp | 22 ++++++++++++ src/Library/Natures/NatureLibrary.cpp | 1 + src/Library/Natures/NatureLibrary.hpp | 49 +++++++++++++++++++++++++++ src/Library/PokemonLibrary.hpp | 37 +++++++++++++++----- src/Library/Statistic.hpp | 20 +++++++++++ tests/TestLibrary/TestLibrary.hpp | 19 +++++++---- 14 files changed, 182 insertions(+), 19 deletions(-) create mode 100644 src/Library/Items/Item.cpp create mode 100644 src/Library/Items/Item.hpp create mode 100644 src/Library/Items/ItemLibrary.cpp create mode 100644 src/Library/Items/ItemLibrary.hpp create mode 100644 src/Library/Natures/Nature.cpp create mode 100644 src/Library/Natures/Nature.hpp create mode 100644 src/Library/Natures/NatureLibrary.cpp create mode 100644 src/Library/Natures/NatureLibrary.hpp create mode 100644 src/Library/Statistic.hpp diff --git a/conanfile.py b/conanfile.py index 19b11f0..4901169 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,7 +12,7 @@ class PkmnLibConan(ConanFile): generators = "cmake" exports_sources = "*" compiler = "clang" - requires = "CreatureLib/d26670082260d3eaab2126dc02c5e2fe674e0076@creaturelib/master" + requires = "CreatureLib/db2eb0c3fa5d67b14c84b118cd2f69bbd209ddb9@creaturelib/master" def build(self): cmake = CMake(self) diff --git a/src/Library/Items/Item.cpp b/src/Library/Items/Item.cpp new file mode 100644 index 0000000..614ae00 --- /dev/null +++ b/src/Library/Items/Item.cpp @@ -0,0 +1 @@ +#include "Item.hpp" diff --git a/src/Library/Items/Item.hpp b/src/Library/Items/Item.hpp new file mode 100644 index 0000000..e76059e --- /dev/null +++ b/src/Library/Items/Item.hpp @@ -0,0 +1,9 @@ +#ifndef PKMNLIB_ITEM_HPP +#define PKMNLIB_ITEM_HPP + +#include +namespace PkmnLib::Library { + class Item : public CreatureLib::Library::Item {}; +} + +#endif // PKMNLIB_ITEM_HPP diff --git a/src/Library/Items/ItemLibrary.cpp b/src/Library/Items/ItemLibrary.cpp new file mode 100644 index 0000000..06f8145 --- /dev/null +++ b/src/Library/Items/ItemLibrary.cpp @@ -0,0 +1 @@ +#include "ItemLibrary.hpp" diff --git a/src/Library/Items/ItemLibrary.hpp b/src/Library/Items/ItemLibrary.hpp new file mode 100644 index 0000000..b6a0ce3 --- /dev/null +++ b/src/Library/Items/ItemLibrary.hpp @@ -0,0 +1,19 @@ +#ifndef PKMNLIB_ITEMLIBRARY_HPP +#define PKMNLIB_ITEMLIBRARY_HPP + +#include +#include "Item.hpp" +namespace PkmnLib::Library { + class ItemLibrary : public CreatureLib::Library::ItemLibrary { + public: + const Item* GetItem(const std::string& name) const { + return reinterpret_cast(CreatureLib::Library::ItemLibrary::GetItem(name)); + } + const Item* operator[](const std::string& name) const { return GetItem(name); } + void LoadItem(const std::string& name, const Item* item) { + CreatureLib::Library::ItemLibrary::LoadItem(name, item); + } + }; +} + +#endif // PKMNLIB_ITEMLIBRARY_HPP diff --git a/src/Library/Moves/MoveLibrary.cpp b/src/Library/Moves/MoveLibrary.cpp index 69a2090..da352c4 100644 --- a/src/Library/Moves/MoveLibrary.cpp +++ b/src/Library/Moves/MoveLibrary.cpp @@ -1,4 +1 @@ #include "MoveLibrary.hpp" -const CreatureLib::Library::AttackData* PkmnLib::Library::MoveLibrary::operator[](const std::string& name) const { - return AttackLibrary::operator[](name); -} diff --git a/src/Library/Moves/MoveLibrary.hpp b/src/Library/Moves/MoveLibrary.hpp index 5c887a8..14b982c 100644 --- a/src/Library/Moves/MoveLibrary.hpp +++ b/src/Library/Moves/MoveLibrary.hpp @@ -2,10 +2,25 @@ #define PKMNLIB_MOVELIBRARY_HPP #include +#include "MoveData.hpp" namespace PkmnLib::Library { class MoveLibrary : public CreatureLib::Library::AttackLibrary { public: - virtual const CreatureLib::Library::AttackData* operator[](const std::string& name) const; + virtual const MoveData* operator[](const std::string& name) const { return GetAttack(name); } + + const MoveData* GetMove(const std::string& name) const { return GetAttack(name); } + + const MoveData* GetAttack(const std::string& name) const { + return reinterpret_cast(CreatureLib::Library::AttackLibrary::GetAttack(name)); + } + void LoadAttack(const std::string& name, const MoveData* attack){ + CreatureLib::Library::AttackLibrary::LoadAttack(name, attack); + } + + void LoadMove(const std::string& name, const MoveData* attack){ + CreatureLib::Library::AttackLibrary::LoadAttack(name, attack); + } + }; } diff --git a/src/Library/Natures/Nature.cpp b/src/Library/Natures/Nature.cpp new file mode 100644 index 0000000..437d2fa --- /dev/null +++ b/src/Library/Natures/Nature.cpp @@ -0,0 +1 @@ +#include "Nature.hpp" diff --git a/src/Library/Natures/Nature.hpp b/src/Library/Natures/Nature.hpp new file mode 100644 index 0000000..3a6518c --- /dev/null +++ b/src/Library/Natures/Nature.hpp @@ -0,0 +1,22 @@ +#ifndef PKMNLIB_NATURE_HPP +#define PKMNLIB_NATURE_HPP + +#include +namespace PkmnLib::Library { + class Nature { + private: + float _increaseModifier; + float _decreaseModifier; + CreatureLib::Core::Statistic _increaseStat; + CreatureLib::Core::Statistic _decreaseStat; + + public: + [[nodiscard]] float GetIncreaseModifier() const { return _increaseModifier; } + [[nodiscard]] float GetDecreaseModifier() const { return _decreaseModifier; } + + [[nodiscard]] CreatureLib::Core::Statistic GetIncreasedStat() const { return _increaseStat; } + [[nodiscard]] CreatureLib::Core::Statistic GetDecreasedStat() const { return _decreaseStat; } + }; +} + +#endif // PKMNLIB_NATURE_HPP diff --git a/src/Library/Natures/NatureLibrary.cpp b/src/Library/Natures/NatureLibrary.cpp new file mode 100644 index 0000000..de49366 --- /dev/null +++ b/src/Library/Natures/NatureLibrary.cpp @@ -0,0 +1 @@ +#include "NatureLibrary.hpp" diff --git a/src/Library/Natures/NatureLibrary.hpp b/src/Library/Natures/NatureLibrary.hpp new file mode 100644 index 0000000..223b2c2 --- /dev/null +++ b/src/Library/Natures/NatureLibrary.hpp @@ -0,0 +1,49 @@ +#ifndef PKMNLIB_NATURELIBRARY_HPP +#define PKMNLIB_NATURELIBRARY_HPP + +#include +#include +#include +#include "Nature.hpp" +namespace PkmnLib::Library { + class NatureLibrary { + private: + std::unordered_map _keyLookup; + std::vector _natures; + + public: + void LoadNature(const std::string& name, const Nature& nature) { + auto find = _keyLookup.find(name); + if (find != _keyLookup.end()) { + auto key = _keyLookup[name]; + _natures[key] = nature; + } else { + _keyLookup[name] = _natures.size(); + _natures.push_back(nature); + } + } + + const Nature& GetNatureByName(const std::string& name) const { + auto find = _keyLookup.find(name); + if (find == _keyLookup.end()) { + throw CreatureException("Invalid nature name."); + } + return _natures[_keyLookup.at(name)]; + } + + const Nature& GetNature(uint8_t id) const{ + return _natures[id]; + } + + uint8_t GetNatureId(const std::string& name) const{ + auto find = _keyLookup.find(name); + if (find == _keyLookup.end()) { + throw CreatureException("Invalid nature name."); + } + return _keyLookup.at(name); + + } + }; +} + +#endif // PKMNLIB_NATURELIBRARY_HPP diff --git a/src/Library/PokemonLibrary.hpp b/src/Library/PokemonLibrary.hpp index a4c819e..c34c355 100644 --- a/src/Library/PokemonLibrary.hpp +++ b/src/Library/PokemonLibrary.hpp @@ -2,19 +2,40 @@ #define PKMNLIB_POKEMONLIBRARY_HPP #include +#include "Items/ItemLibrary.hpp" +#include "Moves/MoveLibrary.hpp" +#include "Natures/NatureLibrary.hpp" #include "Species/SpeciesLibrary.hpp" namespace PkmnLib::Library { class PokemonLibrary : public CreatureLib::Library::DataLibrary { + private: + const NatureLibrary* _natures; + public: - PokemonLibrary(CreatureLib::Library::LibrarySettings settings, PkmnLib::Library::SpeciesLibrary* species, - CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items, - CreatureLib::Library::GrowthRateLibrary* growthRates, - CreatureLib::Library::TypeLibrary* typeLibrary) - : DataLibrary(settings, species, attacks, items, growthRates, typeLibrary) {} - const PkmnLib::Library::SpeciesLibrary* GetSpeciesLibrary() const { - return reinterpret_cast( - CreatureLib::Library::DataLibrary::GetSpeciesLibrary()); + ~PokemonLibrary() override { + delete _natures; + } + + PokemonLibrary(CreatureLib::Library::LibrarySettings settings, SpeciesLibrary* species, MoveLibrary* moves, + ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates, + CreatureLib::Library::TypeLibrary* typeLibrary, NatureLibrary* natures) + : DataLibrary(settings, species, moves, items, growthRates, typeLibrary), _natures(natures) {} + + [[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const { + return (const SpeciesLibrary*)(CreatureLib::Library::DataLibrary::GetSpeciesLibrary()); + } + + [[nodiscard]] const MoveLibrary* GetMoveLibrary() const { + return (const MoveLibrary*)(CreatureLib::Library::DataLibrary::GetAttackLibrary()); + } + + [[nodiscard]] const ItemLibrary* GetItemLibrary() const { + return (const ItemLibrary*)(CreatureLib::Library::DataLibrary::GetItemLibrary()); + } + + [[nodiscard]] const NatureLibrary* GetNatureLibrary() const { + return _natures; } }; } diff --git a/src/Library/Statistic.hpp b/src/Library/Statistic.hpp new file mode 100644 index 0000000..6c74f67 --- /dev/null +++ b/src/Library/Statistic.hpp @@ -0,0 +1,20 @@ +#ifndef PKMNLIB_STATISTIC_HPP +#define PKMNLIB_STATISTIC_HPP + +#include +namespace PkmnLib::Library { + class Statistic { + public: + static constexpr const CreatureLib::Core::Statistic HealthPoints = CreatureLib::Core::Statistic::Health; + static constexpr const CreatureLib::Core::Statistic PhysicalAttack = + CreatureLib::Core::Statistic::PhysicalAttack; + static constexpr const CreatureLib::Core::Statistic PhysicalDefense = + CreatureLib::Core::Statistic::PhysicalDefense; + static constexpr const CreatureLib::Core::Statistic SpecialAttack = CreatureLib::Core::Statistic::MagicalAttack; + static constexpr const CreatureLib::Core::Statistic SpecialDefense = + CreatureLib::Core::Statistic::MagicalDefense; + static constexpr const CreatureLib::Core::Statistic Speed = CreatureLib::Core::Statistic::Speed; + }; +} + +#endif // PKMNLIB_STATISTIC_HPP diff --git a/tests/TestLibrary/TestLibrary.hpp b/tests/TestLibrary/TestLibrary.hpp index 396b563..ea17272 100644 --- a/tests/TestLibrary/TestLibrary.hpp +++ b/tests/TestLibrary/TestLibrary.hpp @@ -1,6 +1,7 @@ #ifndef PKMNLIB_TESTLIBRARY_HPP #define PKMNLIB_TESTLIBRARY_HPP +#include "../../src/Library/Moves/MoveLibrary.hpp" #include "../../src/Library/PokemonLibrary.hpp" class TestLibrary { private: @@ -16,8 +17,8 @@ public: static PkmnLib::Library::PokemonLibrary* BuildLibrary() { return new PkmnLib::Library::PokemonLibrary(CreatureLib::Library::LibrarySettings(100, 4), - BuildSpeciesLibrary(), BuildAttackLibrary(), BuildItemLibrary(), - BuildGrowthRateLibrary(), BuildTypeLibrary()); + BuildSpeciesLibrary(), BuildMoveLibrary(), BuildItemLibrary(), + BuildGrowthRateLibrary(), BuildTypeLibrary(), BuildNatureLibrary()); } static PkmnLib::Library::SpeciesLibrary* BuildSpeciesLibrary() { @@ -25,13 +26,13 @@ public: return lib; } - static CreatureLib::Library::AttackLibrary* BuildAttackLibrary() { - auto lib = new CreatureLib::Library::AttackLibrary(); + static PkmnLib::Library::MoveLibrary* BuildMoveLibrary() { + auto lib = new PkmnLib::Library::MoveLibrary(); return lib; } - static CreatureLib::Library::ItemLibrary* BuildItemLibrary() { - auto lib = new CreatureLib::Library::ItemLibrary(); + static PkmnLib::Library::ItemLibrary* BuildItemLibrary() { + auto lib = new PkmnLib::Library::ItemLibrary(); return lib; } @@ -44,6 +45,12 @@ public: auto lib = new CreatureLib::Library::TypeLibrary(); return lib; } + + static PkmnLib::Library::NatureLibrary* BuildNatureLibrary() { + auto lib = new PkmnLib::Library::NatureLibrary(); + return lib; + } + }; #endif // PKMNLIB_TESTLIBRARY_HPP