Implements outlines for ItemLibrary, MoveLibrary and implements NatureLibrary.

This commit is contained in:
Deukhoofd 2019-12-30 16:19:53 +01:00
parent 9a45d34f9f
commit bb1791b3ae
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
14 changed files with 182 additions and 19 deletions

View File

@ -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)

View File

@ -0,0 +1 @@
#include "Item.hpp"

View File

@ -0,0 +1,9 @@
#ifndef PKMNLIB_ITEM_HPP
#define PKMNLIB_ITEM_HPP
#include <Library/Items/Item.hpp>
namespace PkmnLib::Library {
class Item : public CreatureLib::Library::Item {};
}
#endif // PKMNLIB_ITEM_HPP

View File

@ -0,0 +1 @@
#include "ItemLibrary.hpp"

View File

@ -0,0 +1,19 @@
#ifndef PKMNLIB_ITEMLIBRARY_HPP
#define PKMNLIB_ITEMLIBRARY_HPP
#include <Library/ItemLibrary.hpp>
#include "Item.hpp"
namespace PkmnLib::Library {
class ItemLibrary : public CreatureLib::Library::ItemLibrary {
public:
const Item* GetItem(const std::string& name) const {
return reinterpret_cast<const Item*>(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

View File

@ -1,4 +1 @@
#include "MoveLibrary.hpp"
const CreatureLib::Library::AttackData* PkmnLib::Library::MoveLibrary::operator[](const std::string& name) const {
return AttackLibrary::operator[](name);
}

View File

@ -2,10 +2,25 @@
#define PKMNLIB_MOVELIBRARY_HPP
#include <Library/AttackLibrary.hpp>
#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<const MoveData*>(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);
}
};
}

View File

@ -0,0 +1 @@
#include "Nature.hpp"

View File

@ -0,0 +1,22 @@
#ifndef PKMNLIB_NATURE_HPP
#define PKMNLIB_NATURE_HPP
#include <Core/Statistic.hpp>
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

View File

@ -0,0 +1 @@
#include "NatureLibrary.hpp"

View File

@ -0,0 +1,49 @@
#ifndef PKMNLIB_NATURELIBRARY_HPP
#define PKMNLIB_NATURELIBRARY_HPP
#include <Core/Exceptions/CreatureException.hpp>
#include <unordered_map>
#include <vector>
#include "Nature.hpp"
namespace PkmnLib::Library {
class NatureLibrary {
private:
std::unordered_map<std::string, uint8_t> _keyLookup;
std::vector<Nature> _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

View File

@ -2,19 +2,40 @@
#define PKMNLIB_POKEMONLIBRARY_HPP
#include <Library/DataLibrary.hpp>
#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<const PkmnLib::Library::SpeciesLibrary*>(
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;
}
};
}

20
src/Library/Statistic.hpp Normal file
View File

@ -0,0 +1,20 @@
#ifndef PKMNLIB_STATISTIC_HPP
#define PKMNLIB_STATISTIC_HPP
#include <Core/Statistic.hpp>
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

View File

@ -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