Support for getting Creature by ID.
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
9547b92f14
commit
fcdc58176f
|
@ -9,4 +9,8 @@ export const SpeciesLibrary* CreatureLib_SpeciesLibrary_Construct(size_t initial
|
|||
|
||||
export void CreatureLib_SpeciesLibrary_Destruct(const SpeciesLibrary* p) { delete p; }
|
||||
|
||||
BASELIBRARY(CreatureLib_SpeciesLibrary, SpeciesLibrary, CreatureSpecies);
|
||||
BASELIBRARY(CreatureLib_SpeciesLibrary, SpeciesLibrary, CreatureSpecies);
|
||||
|
||||
export const CreatureSpecies* CreatureLib_SpeciesLibrary_GetById(const SpeciesLibrary* p, uint16_t id) {
|
||||
return p->GetById(id).GetRaw();
|
||||
}
|
|
@ -23,12 +23,12 @@ namespace CreatureLib::Library {
|
|||
|
||||
virtual ~BaseLibrary() noexcept { _values.Clear(); }
|
||||
|
||||
inline void Insert(const ArbUt::StringView& key, const T* value) {
|
||||
inline virtual void Insert(const ArbUt::StringView& key, const T* value) {
|
||||
AssertNotNull(value)
|
||||
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
|
||||
_listValues.Append(key);
|
||||
}
|
||||
inline void Insert(uint32_t hashedKey, const T* value) {
|
||||
inline virtual void Insert(uint32_t hashedKey, const T* value) {
|
||||
AssertNotNull(value)
|
||||
_values.GetStdMap().insert({hashedKey, std::unique_ptr<const T>(value)});
|
||||
_listValues.Append(hashedKey);
|
||||
|
|
|
@ -9,8 +9,21 @@
|
|||
namespace CreatureLib::Library {
|
||||
class SpeciesLibrary : public BaseLibrary<CreatureSpecies> {
|
||||
private:
|
||||
ArbUt::Dictionary<uint16_t, ArbUt::BorrowedPtr<const CreatureSpecies>> _valuesById;
|
||||
|
||||
public:
|
||||
SpeciesLibrary(size_t initialCapacity = 32) : BaseLibrary(initialCapacity){};
|
||||
|
||||
void Insert(const ArbUt::StringView& key, const CreatureSpecies* value) override {
|
||||
BaseLibrary::Insert(key, value);
|
||||
_valuesById.Insert(value->GetId(), value);
|
||||
}
|
||||
void Insert(uint32_t hashedKey, const CreatureSpecies* value) override {
|
||||
BaseLibrary::Insert(hashedKey, value);
|
||||
_valuesById.Insert(value->GetId(), value);
|
||||
}
|
||||
|
||||
const ArbUt::BorrowedPtr<const CreatureSpecies>& GetById(uint16_t id) const { return _valuesById[id]; }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue