Tweaks and fixes for TypeLibrary
This commit is contained in:
parent
671077259e
commit
70ad3eb838
|
@ -47,16 +47,18 @@ namespace CreatureLib::Library {
|
|||
return true;
|
||||
}
|
||||
|
||||
inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
[[nodiscard]] inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return _values.at(name.GetHash());
|
||||
}
|
||||
inline const T* Get(uint32_t hashedKey) const { return _values.at(hashedKey); }
|
||||
[[nodiscard]] inline const T* Get(uint32_t hashedKey) const { return _values.at(hashedKey); }
|
||||
|
||||
inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); }
|
||||
inline const T* operator[](uint32_t hashedKey) const { return Get(hashedKey); }
|
||||
inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; }
|
||||
[[nodiscard]] inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return Get(name);
|
||||
}
|
||||
[[nodiscard]] inline const T* operator[](uint32_t hashedKey) const { return Get(hashedKey); }
|
||||
[[nodiscard]] inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; }
|
||||
|
||||
size_t GetCount() const { return _values.size(); }
|
||||
[[nodiscard]] size_t GetCount() const { return _values.size(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,14 @@ uint8_t TypeLibrary::RegisterType(const ConstString& key) {
|
|||
}
|
||||
return _types.size() - 1;
|
||||
}
|
||||
uint8_t TypeLibrary::RegisterType(uint32_t key) {
|
||||
_types.insert({key, _types.size()});
|
||||
_effectiveness.resize(_types.size());
|
||||
for (auto& eff : _effectiveness) {
|
||||
eff.resize(_types.size(), 1);
|
||||
}
|
||||
return _types.size() - 1;
|
||||
}
|
||||
|
||||
void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) {
|
||||
_effectiveness[attacking][defensive] = effectiveness;
|
||||
|
|
|
@ -16,10 +16,11 @@ namespace CreatureLib::Library {
|
|||
|
||||
uint8_t GetTypeId(const ConstString& s) const;
|
||||
uint8_t GetTypeId(uint32_t s) const;
|
||||
float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
|
||||
float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const;
|
||||
[[nodiscard]] float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
|
||||
[[nodiscard]] float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const;
|
||||
|
||||
uint8_t RegisterType(const ConstString& typeName);
|
||||
uint8_t RegisterType(uint32_t typeHash);
|
||||
void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue