Support for getting type names from TypeLibrary.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -11,15 +11,15 @@ uint8_t TypeLibrary::RegisterType(const ArbUt::StringView& key) {
|
||||
}
|
||||
return _types.Count() - 1;
|
||||
}
|
||||
uint8_t TypeLibrary::RegisterType(uint32_t key) {
|
||||
_types.Insert(key, _types.Count());
|
||||
_effectiveness.Resize(_types.Count());
|
||||
for (auto& eff : _effectiveness) {
|
||||
eff.Resize(_types.Count(), 1);
|
||||
}
|
||||
return _types.Count() - 1;
|
||||
}
|
||||
|
||||
void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) {
|
||||
_effectiveness[attacking][defensive] = effectiveness;
|
||||
}
|
||||
const ArbUt::StringView& TypeLibrary::GetTypeName(uint8_t type) const {
|
||||
for (auto& kv : _types) {
|
||||
if (kv.second == type) {
|
||||
return kv.first;
|
||||
}
|
||||
}
|
||||
THROW_CREATURE("Name requested for unknown type: " << (uint32_t)type);
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class TypeLibrary {
|
||||
ArbUt::Dictionary<uint32_t, uint8_t> _types;
|
||||
ArbUt::Dictionary<ArbUt::StringView, uint8_t> _types;
|
||||
ArbUt::List<ArbUt::List<float>> _effectiveness;
|
||||
|
||||
public:
|
||||
TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::Dictionary<uint32_t, uint8_t>(initialCapacity)) {}
|
||||
TypeLibrary(size_t initialCapacity = 20)
|
||||
: _types(ArbUt::Dictionary<ArbUt::StringView, uint8_t>(initialCapacity)) {}
|
||||
|
||||
inline uint8_t GetTypeId(const ArbUt::BasicStringView& key) const { return _types.Get(key); }
|
||||
inline uint8_t GetTypeId(uint32_t s) const { return _types.Get(s); }
|
||||
inline uint8_t GetTypeId(const ArbUt::StringView& key) const { return _types.Get(key); }
|
||||
[[nodiscard]] inline float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
|
||||
try {
|
||||
return _effectiveness[attacking][defensive];
|
||||
@@ -34,9 +34,9 @@ namespace CreatureLib::Library {
|
||||
return init * GetSingleEffectiveness(attacking, defense);
|
||||
});
|
||||
}
|
||||
const ArbUt::StringView& GetTypeName(uint8_t type) const;
|
||||
|
||||
uint8_t RegisterType(const ArbUt::StringView& typeName);
|
||||
uint8_t RegisterType(uint32_t typeHash);
|
||||
void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user