Introduce const ObjectList::FindLegacy (#23315)

This commit is contained in:
Aaron van Geffen 2024-12-04 09:50:48 +01:00 committed by GitHub
parent 2f450212a5
commit a55a690db3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View file

@ -170,12 +170,27 @@ void ObjectList::SetObject(ObjectType type, ObjectEntryIndex index, std::string_
SetObject(index, entry);
}
ObjectEntryIndex ObjectList::Find(ObjectType type, std::string_view identifier)
ObjectEntryIndex ObjectList::Find(ObjectType type, std::string_view identifier) const
{
auto& subList = GetList(type);
for (size_t i = 0; i < subList.size(); i++)
{
if (subList[i].Identifier == identifier)
if (subList[i].Generation == ObjectGeneration::JSON && subList[i].Identifier == identifier)
{
return static_cast<ObjectEntryIndex>(i);
}
}
return OBJECT_ENTRY_INDEX_NULL;
}
// Intended to be used to find non-custom legacy objects. For internal use only.
ObjectEntryIndex ObjectList::FindLegacy(ObjectType type, std::string_view identifier) const
{
auto& subList = GetList(type);
for (size_t i = 0; i < subList.size(); i++)
{
if (subList[i].Generation == ObjectGeneration::DAT && subList[i].Entry.GetName() == identifier
&& subList[i].Entry.GetSourceGame() != ObjectSourceGame::Custom)
{
return static_cast<ObjectEntryIndex>(i);
}

View file

@ -25,7 +25,8 @@ public:
const ObjectEntryDescriptor& GetObject(ObjectType type, ObjectEntryIndex index) const;
void SetObject(ObjectEntryIndex index, const ObjectEntryDescriptor& entry);
void SetObject(ObjectType type, ObjectEntryIndex index, std::string_view identifier);
ObjectEntryIndex Find(ObjectType type, std::string_view identifier);
ObjectEntryIndex Find(ObjectType type, std::string_view identifier) const;
ObjectEntryIndex FindLegacy(ObjectType type, std::string_view identifier) const;
struct const_iterator
{