mirror of https://github.com/OpenRCT2/OpenRCT2.git
prevent adding duplicate footpath entries
This commit is contained in:
parent
228af15a30
commit
fb192bba0e
|
@ -111,4 +111,27 @@ public:
|
|||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
size_t IndexOf(T item, std::function<bool(T, T)> comparer)
|
||||
{
|
||||
for (size_t i = 0; i < this->size(); i++)
|
||||
{
|
||||
T element = std::vector<T>::operator[](i);
|
||||
if (comparer(item, element))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
bool Contains(std::function<bool(T)> predicate)
|
||||
{
|
||||
return IndexOf(predicate) != SIZE_MAX;
|
||||
}
|
||||
|
||||
bool Contains(T item, std::function<bool(T, T)> comparer)
|
||||
{
|
||||
return IndexOf(item, comparer) != SIZE_MAX;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -28,6 +28,11 @@ extern "C"
|
|||
#include "../world/scenery.h"
|
||||
}
|
||||
|
||||
static bool ObjectNameComparer(const char * a, const char * b)
|
||||
{
|
||||
return String::Equals(a, b, true);
|
||||
}
|
||||
|
||||
void S4Importer::LoadSavedGame(const utf8 * path)
|
||||
{
|
||||
if (!rct1_read_sv4(path, &_s4)) {
|
||||
|
@ -106,7 +111,7 @@ void S4Importer::Initialise()
|
|||
|
||||
void S4Importer::CreateAvailableObjectMappings()
|
||||
{
|
||||
// Add defaults
|
||||
// Add default scenery groups
|
||||
_sceneryGroupEntries.AddRange({
|
||||
"SCGTREES",
|
||||
"SCGPATHX",
|
||||
|
@ -116,6 +121,7 @@ void S4Importer::CreateAvailableObjectMappings()
|
|||
"SCGWALLS"
|
||||
});
|
||||
|
||||
// Add default footpaths
|
||||
_pathEntries.AddRange({
|
||||
"PATHASH ",
|
||||
"PATHCRZY",
|
||||
|
@ -159,11 +165,7 @@ void S4Importer::CreateAvailableObjectMappings()
|
|||
break;
|
||||
}
|
||||
|
||||
size_t index = entries->IndexOf([objectName](const char * x) -> bool
|
||||
{
|
||||
return String::Equals(x, objectName, true);
|
||||
});
|
||||
if (index == SIZE_MAX)
|
||||
if (!entries->Contains(objectName, ObjectNameComparer))
|
||||
{
|
||||
entries->Add(objectName);
|
||||
}
|
||||
|
@ -358,10 +360,19 @@ void S4Importer::AddEntryForPath(uint8 pathType)
|
|||
if (_pathTypeToEntryMap[pathType] == 255)
|
||||
{
|
||||
const char * entryName = RCT1::GetPathObject(pathType);
|
||||
|
||||
size_t index = _pathEntries.IndexOf(entryName, ObjectNameComparer);
|
||||
if (index != SIZE_MAX)
|
||||
{
|
||||
_pathTypeToEntryMap[pathType] = (uint8)index;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pathTypeToEntryMap[pathType] = (uint8)_pathEntries.GetCount();
|
||||
_pathEntries.Add(entryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void S4Importer::AddEntryForPathAddition(uint8 pathAdditionType)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue