diff --git a/CInterface/Library/SpeciesLibrary.cpp b/CInterface/Library/SpeciesLibrary.cpp index c631b6c..a94ae28 100644 --- a/CInterface/Library/SpeciesLibrary.cpp +++ b/CInterface/Library/SpeciesLibrary.cpp @@ -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); \ No newline at end of file +BASELIBRARY(CreatureLib_SpeciesLibrary, SpeciesLibrary, CreatureSpecies); + +export const CreatureSpecies* CreatureLib_SpeciesLibrary_GetById(const SpeciesLibrary* p, uint16_t id) { + return p->GetById(id).GetRaw(); +} \ No newline at end of file diff --git a/src/Library/BaseLibrary.hpp b/src/Library/BaseLibrary.hpp index 5322d9d..bbcfcf8 100644 --- a/src/Library/BaseLibrary.hpp +++ b/src/Library/BaseLibrary.hpp @@ -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(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(value)}); _listValues.Append(hashedKey); diff --git a/src/Library/SpeciesLibrary.hpp b/src/Library/SpeciesLibrary.hpp index a92aae3..0cb57e8 100644 --- a/src/Library/SpeciesLibrary.hpp +++ b/src/Library/SpeciesLibrary.hpp @@ -9,8 +9,21 @@ namespace CreatureLib::Library { class SpeciesLibrary : public BaseLibrary { private: + ArbUt::Dictionary> _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& GetById(uint16_t id) const { return _valuesById[id]; } }; }