aug ArrayObject to have a uniquePair command

like uniqueket and uniquevalue, removes duplicate entries, but only if *both* match
also, use that for the populateAllFonts() cache generator
This commit is contained in:
AzaezelX 2024-03-03 22:04:09 -06:00
parent 242e029c21
commit 24562e6758
3 changed files with 28 additions and 2 deletions

View file

@ -404,6 +404,22 @@ void ArrayObject::uniqueKey()
//-----------------------------------------------------------------------------
void ArrayObject::uniquePair()
{
for (S32 i = 0; i < mArray.size(); i++)
{
for (S32 j = i + 1; j < mArray.size(); j++)
{
if (isEqual(mArray[i].key, mArray[j].key) && isEqual(mArray[i].value, mArray[j].value))
{
erase(j);
j--;
}
}
}
}
//-----------------------------------------------------------------------------
void ArrayObject::duplicate(ArrayObject* obj)
{
empty();
@ -740,6 +756,12 @@ DefineEngineMethod( ArrayObject, uniqueKey, void, (),,
object->uniqueKey();
}
DefineEngineMethod(ArrayObject, uniquePair, void, (), ,
"Removes any elements that have duplicated key and value pairs (leaving the first instance)")
{
object->uniquePair();
}
DefineEngineMethod( ArrayObject, duplicate, bool, ( ArrayObject* target ),,
"Alters array into an exact duplicate of the target array.\n"
"@param target ArrayObject to duplicate\n" )