mirror of
https://github.com/isledecomp/actionheadergen.git
synced 2024-11-26 17:26:10 -05:00
add support for sub-objects
This commit is contained in:
parent
f630955e25
commit
b4f0776125
3 changed files with 27 additions and 8 deletions
|
@ -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.
|
||||
If all goes well, you can find the generated headers in the output directory.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "interleafhandler.h"
|
||||
|
||||
typedef std::map<size_t, const char*> 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<const char *>;
|
||||
|
||||
std::map<size_t, const char *> 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<si::Object*>(actionAsCore)) {
|
||||
// push the name of the action into the vector
|
||||
m_actionVector->push_back(actionAsObject->name().c_str());
|
||||
if (si::Object *actionAsObject = dynamic_cast<si::Object *>(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<si::Object *>(*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;
|
||||
}
|
||||
|
|
|
@ -36,12 +36,13 @@ bool RecursivelyFindInterleaf(const char *p_path, std::vector<std::string> &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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue