Tests and tweaks for the Nature Library.

This commit is contained in:
2019-12-31 10:39:20 +01:00
parent bb1791b3ae
commit e5cb857ea8
3 changed files with 105 additions and 10 deletions

View File

@@ -10,16 +10,23 @@ namespace PkmnLib::Library {
private:
std::unordered_map<std::string, uint8_t> _keyLookup;
std::vector<Nature> _natures;
uint8_t _current = 0;
public:
void LoadNature(const std::string& name, const Nature& nature) {
NatureLibrary(uint8_t size = 32)
: _keyLookup(std::unordered_map<std::string, uint8_t>(size)), _natures(std::vector<Nature>(size)) {}
uint8_t LoadNature(const std::string& name, const Nature& nature) {
auto find = _keyLookup.find(name);
if (find != _keyLookup.end()) {
auto key = _keyLookup[name];
_natures[key] = nature;
return key;
} else {
_keyLookup[name] = _natures.size();
_natures.push_back(nature);
auto key = _current;
_keyLookup[name] = key;
_natures[_current++] = nature;
return key;
}
}
@@ -31,17 +38,14 @@ namespace PkmnLib::Library {
return _natures[_keyLookup.at(name)];
}
const Nature& GetNature(uint8_t id) const{
return _natures[id];
}
const Nature& GetNature(uint8_t id) const { return _natures[id]; }
uint8_t GetNatureId(const std::string& name) const{
uint8_t GetNatureIdByName(const std::string& name) const {
auto find = _keyLookup.find(name);
if (find == _keyLookup.end()) {
throw CreatureException("Invalid nature name.");
}
return _keyLookup.at(name);
}
};
}