diff --git a/README.md b/README.md index 7fd00eb..674ec62 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # actionheadergen -This tool automatically generates C++ headers containing enums representing the action index found in LEGO Island Inferleaf (.SI) files. While it is primarily designed to solve a glaring labor issue with manually inserting thousands of action entries in the ongoing [LEGO Island decompilation](https://github.com/isledecomp/isle), it could be repurposed for other uses as well. +This tool automatically generates C++ headers containing enums representing the action index found in LEGO Island Interleaf (.SI) files. While it is primarily designed to solve a glaring labor issue with manually inserting thousands of action entries in the ongoing [LEGO Island decompilation](https://github.com/isledecomp/isle), it could be repurposed for other uses as well. ## Background @@ -36,4 +36,4 @@ The code in this repository should be cross-platform, aside from the use of dire Simply point to either a singular Interleaf file that you’d like to generate a header of, or a directory containing multiple Interleaf files. This can also simply be your “SCRIPTS” folder in your LEGO Island installation. Make sure to additionally provide an output directory for the generated headers to go. -If all goes well, you can find the generated headers in the output directory. \ No newline at end of file +If all goes well, you can find the generated headers in the output directory. diff --git a/src/interleafhandler.cpp b/src/interleafhandler.cpp index 63dead6..340b508 100644 --- a/src/interleafhandler.cpp +++ b/src/interleafhandler.cpp @@ -1,5 +1,7 @@ #include "interleafhandler.h" +typedef std::map ActionMap; + si::Interleaf::Error InterleafHandler::ReadInterleaf(char *p_filePath) { // this is basically a wrapper function for libweaver's @@ -17,22 +19,38 @@ bool InterleafHandler::SortActionsIntoVector() // get the amount of actions in this Interleaf m_actionCount = m_inlf.GetChildCount(); - // prepare our vector for use + // prepare our vector and map for use m_actionVector = new std::vector; + + std::map actionMap; - // itereate through every action in our action count + // iterate through every action in our action count for (size_t i = 0; i < m_actionCount; i++) { // get the action as Core initially si::Core *actionAsCore = m_inlf.GetChildAt(i); // Core doesn't provide some of the data we need, so we get the // action as Object, so then we can retrieve the name of the action - if (si::Object *actionAsObject = dynamic_cast(actionAsCore)) { - // push the name of the action into the vector - m_actionVector->push_back(actionAsObject->name().c_str()); + if (si::Object *actionAsObject = dynamic_cast(actionAsCore)) { + // check for sub-objects + for (si::Core::Children::const_iterator it = actionAsObject->GetChildren().cbegin(); it != actionAsObject->GetChildren().cend(); it++) { + // we have sub-objects, so we need to account for these + si::Object *subObject = static_cast(*it); + actionMap[subObject->id()] = subObject->name().c_str(); + } + + // push the name of the action and the index into the map + actionMap[i] = actionAsObject->name().c_str(); } } + // finished, so let's construct the ordered vector + // by sorting all of the actions in the map by index + m_actionVector->reserve(actionMap.size()); + for (ActionMap::const_iterator it = actionMap.begin(); it!= actionMap.end(); it++) { + m_actionVector->push_back(it->second); + } + // success return true; } diff --git a/src/main.cpp b/src/main.cpp index 63dfc17..c5704a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,12 +36,13 @@ bool RecursivelyFindInterleaf(const char *p_path, std::vector &p_in } else { if (strcasestr(dentry->d_name, ".si") != NULL) { - // found an Interleaf file, return it + // found an Interleaf file char fullPathBuffer[1024]; // construct the full path to the file first snprintf(fullPathBuffer, sizeof(fullPathBuffer), "%s/%s", p_path, dentry->d_name); + // push it to the vector p_interleafFiles.push_back(fullPathBuffer); } }