Reworked LearnedAttacks class, added C interface.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
60cbc80549
commit
3bca3c0673
|
@ -0,0 +1,20 @@
|
||||||
|
#include "../../src/Library/CreatureData/LearnableAttacks.hpp"
|
||||||
|
#define export extern "C"
|
||||||
|
using namespace CreatureLib::Library;
|
||||||
|
|
||||||
|
export LearnableAttacks* CreatureLib_LearnableAttacks_Construct(size_t levelAttackCapacity) {
|
||||||
|
return new LearnableAttacks(levelAttackCapacity);
|
||||||
|
};
|
||||||
|
|
||||||
|
export void CreatureLib_LearnableAttacks_Destruct(LearnableAttacks* p) { delete p; }
|
||||||
|
|
||||||
|
export void CreatureLib_LearnableAttacks_AddLevelMove(LearnableAttacks* p, uint8_t level, const AttackData* attack) {
|
||||||
|
p->AddLevelMove(level, attack);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AttackData* const* CreatureLib_LearnableAttacks_GetAttacksForLevel(LearnableAttacks* p, uint8_t level) {
|
||||||
|
return p->GetAttacksForLevel(level).data();
|
||||||
|
}
|
||||||
|
export size_t CreatureLib_LearnableAttacks_GetAttacksForLevelCount(LearnableAttacks* p, uint8_t level) {
|
||||||
|
return p->GetAttacksForLevel(level).size();
|
||||||
|
}
|
|
@ -2,8 +2,15 @@
|
||||||
|
|
||||||
using namespace CreatureLib::Library;
|
using namespace CreatureLib::Library;
|
||||||
|
|
||||||
void LearnableAttacks::AddLevelMove(uint8_t level, AttackData* attack) { _learnedByLevel[level].push_back(attack); }
|
void LearnableAttacks::AddLevelMove(uint8_t level, const AttackData* attack) {
|
||||||
|
auto find = _learnedByLevel.find(level);
|
||||||
const std::vector<const AttackData*>& LearnableAttacks::GetMovesForLevel(uint8_t level) const {
|
if (find != _learnedByLevel.end()) {
|
||||||
return _learnedByLevel[level];
|
find->second.push_back(attack);
|
||||||
|
} else {
|
||||||
|
_learnedByLevel.insert({level, {attack}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<const AttackData*>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const {
|
||||||
|
return _learnedByLevel.at(level);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
#ifndef CREATURELIB_LEARNABLEATTACKS_HPP
|
#ifndef CREATURELIB_LEARNABLEATTACKS_HPP
|
||||||
#define CREATURELIB_LEARNABLEATTACKS_HPP
|
#define CREATURELIB_LEARNABLEATTACKS_HPP
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../Attacks/AttackData.hpp"
|
#include "../Attacks/AttackData.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
class LearnableAttacks {
|
class LearnableAttacks {
|
||||||
std::vector<std::vector<const AttackData*>> _learnedByLevel;
|
std::unordered_map<uint8_t, std::vector<const AttackData*>> _learnedByLevel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LearnableAttacks(uint8_t maxLevel) : _learnedByLevel(std::vector<std::vector<const AttackData*>>(maxLevel)) {}
|
LearnableAttacks(size_t levelAttackCapacity)
|
||||||
|
: _learnedByLevel(std::unordered_map<uint8_t, std::vector<const AttackData*>>(levelAttackCapacity)) {}
|
||||||
|
|
||||||
void AddLevelMove(uint8_t level, AttackData* attack);
|
void AddLevelMove(uint8_t level, const AttackData* attack);
|
||||||
|
|
||||||
const std::vector<const AttackData*>& GetMovesForLevel(uint8_t level) const;
|
const std::vector<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue