mirror of
https://github.com/isledecomp/actionheadergen.git
synced 2024-11-27 01:35:32 -05:00
handle duplicate object names
This commit is contained in:
parent
0aacb74ca3
commit
4ef5b7e066
2 changed files with 30 additions and 0 deletions
|
@ -12,6 +12,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AddActionsToMap(si::Core *p_object);
|
void AddActionsToMap(si::Core *p_object);
|
||||||
|
void ProcessDuplicates();
|
||||||
si::Interleaf m_inlf;
|
si::Interleaf m_inlf;
|
||||||
size_t m_actionCount;
|
size_t m_actionCount;
|
||||||
std::map<size_t, std::string> *m_actionMap;
|
std::map<size_t, std::string> *m_actionMap;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "interleafhandler.h"
|
#include "interleafhandler.h"
|
||||||
|
|
||||||
|
typedef std::map<size_t, std::string> ActionMap;
|
||||||
|
|
||||||
si::Interleaf::Error InterleafHandler::ReadInterleaf(char *p_filePath)
|
si::Interleaf::Error InterleafHandler::ReadInterleaf(char *p_filePath)
|
||||||
{
|
{
|
||||||
// this is basically a wrapper function for libweaver's
|
// this is basically a wrapper function for libweaver's
|
||||||
|
@ -25,6 +27,9 @@ bool InterleafHandler::StartActionSorting()
|
||||||
AddActionsToMap(m_inlf.GetChildAt(i));
|
AddActionsToMap(m_inlf.GetChildAt(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process duplicates in the map
|
||||||
|
ProcessDuplicates();
|
||||||
|
|
||||||
// success
|
// success
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -55,3 +60,27 @@ void InterleafHandler::AddActionsToMap(si::Core *p_object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InterleafHandler::ProcessDuplicates()
|
||||||
|
{
|
||||||
|
// some Interleaf files can have duplicate object names,
|
||||||
|
// which is obviously bad in the context of an enum
|
||||||
|
// where every label is expected to be unique
|
||||||
|
|
||||||
|
ActionMap::iterator it = m_actionMap->begin();
|
||||||
|
std::string prevName = it->second;
|
||||||
|
|
||||||
|
for (++it; it != m_actionMap->end(); it++) {
|
||||||
|
if (it->second == prevName) {
|
||||||
|
// found a dupe, append the object ID to its name
|
||||||
|
it->second += "_" + std::to_string(it->first);
|
||||||
|
// retroactively append the object ID to the original as well
|
||||||
|
ActionMap::iterator prevIt = it;
|
||||||
|
--prevIt;
|
||||||
|
prevIt->second += "_" + std::to_string(prevIt->first);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prevName = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue