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;
|
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"
|
#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)
|
void S4Importer::LoadSavedGame(const utf8 * path)
|
||||||
{
|
{
|
||||||
if (!rct1_read_sv4(path, &_s4)) {
|
if (!rct1_read_sv4(path, &_s4)) {
|
||||||
|
@ -106,7 +111,7 @@ void S4Importer::Initialise()
|
||||||
|
|
||||||
void S4Importer::CreateAvailableObjectMappings()
|
void S4Importer::CreateAvailableObjectMappings()
|
||||||
{
|
{
|
||||||
// Add defaults
|
// Add default scenery groups
|
||||||
_sceneryGroupEntries.AddRange({
|
_sceneryGroupEntries.AddRange({
|
||||||
"SCGTREES",
|
"SCGTREES",
|
||||||
"SCGPATHX",
|
"SCGPATHX",
|
||||||
|
@ -116,6 +121,7 @@ void S4Importer::CreateAvailableObjectMappings()
|
||||||
"SCGWALLS"
|
"SCGWALLS"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add default footpaths
|
||||||
_pathEntries.AddRange({
|
_pathEntries.AddRange({
|
||||||
"PATHASH ",
|
"PATHASH ",
|
||||||
"PATHCRZY",
|
"PATHCRZY",
|
||||||
|
@ -159,11 +165,7 @@ void S4Importer::CreateAvailableObjectMappings()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t index = entries->IndexOf([objectName](const char * x) -> bool
|
if (!entries->Contains(objectName, ObjectNameComparer))
|
||||||
{
|
|
||||||
return String::Equals(x, objectName, true);
|
|
||||||
});
|
|
||||||
if (index == SIZE_MAX)
|
|
||||||
{
|
{
|
||||||
entries->Add(objectName);
|
entries->Add(objectName);
|
||||||
}
|
}
|
||||||
|
@ -358,9 +360,18 @@ void S4Importer::AddEntryForPath(uint8 pathType)
|
||||||
if (_pathTypeToEntryMap[pathType] == 255)
|
if (_pathTypeToEntryMap[pathType] == 255)
|
||||||
{
|
{
|
||||||
const char * entryName = RCT1::GetPathObject(pathType);
|
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();
|
_pathTypeToEntryMap[pathType] = (uint8)_pathEntries.GetCount();
|
||||||
_pathEntries.Add(entryName);
|
_pathEntries.Add(entryName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void S4Importer::AddEntryForPathAddition(uint8 pathAdditionType)
|
void S4Importer::AddEntryForPathAddition(uint8 pathAdditionType)
|
||||||
|
|
Loading…
Reference in New Issue