mirror of
https://github.com/isledecomp/actionheadergen.git
synced 2024-12-02 12:06:51 -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
|
# 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
|
## Background
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "interleafhandler.h"
|
#include "interleafhandler.h"
|
||||||
|
|
||||||
|
typedef std::map<size_t, const char*> 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
|
||||||
|
@ -17,22 +19,38 @@ bool InterleafHandler::SortActionsIntoVector()
|
||||||
// get the amount of actions in this Interleaf
|
// get the amount of actions in this Interleaf
|
||||||
m_actionCount = m_inlf.GetChildCount();
|
m_actionCount = m_inlf.GetChildCount();
|
||||||
|
|
||||||
// prepare our vector for use
|
// prepare our vector and map for use
|
||||||
m_actionVector = new std::vector<const char *>;
|
m_actionVector = new std::vector<const char *>;
|
||||||
|
|
||||||
// itereate through every action in our action count
|
std::map<size_t, const char *> actionMap;
|
||||||
|
|
||||||
|
// iterate through every action in our action count
|
||||||
for (size_t i = 0; i < m_actionCount; i++) {
|
for (size_t i = 0; i < m_actionCount; i++) {
|
||||||
// get the action as Core initially
|
// get the action as Core initially
|
||||||
si::Core *actionAsCore = m_inlf.GetChildAt(i);
|
si::Core *actionAsCore = m_inlf.GetChildAt(i);
|
||||||
|
|
||||||
// Core doesn't provide some of the data we need, so we get the
|
// 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
|
// action as Object, so then we can retrieve the name of the action
|
||||||
if (si::Object *actionAsObject = dynamic_cast<si::Object*>(actionAsCore)) {
|
if (si::Object *actionAsObject = dynamic_cast<si::Object *>(actionAsCore)) {
|
||||||
// push the name of the action into the vector
|
// check for sub-objects
|
||||||
m_actionVector->push_back(actionAsObject->name().c_str());
|
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
|
// success
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,12 +36,13 @@ bool RecursivelyFindInterleaf(const char *p_path, std::vector<std::string> &p_in
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (strcasestr(dentry->d_name, ".si") != NULL) {
|
if (strcasestr(dentry->d_name, ".si") != NULL) {
|
||||||
// found an Interleaf file, return it
|
// found an Interleaf file
|
||||||
char fullPathBuffer[1024];
|
char fullPathBuffer[1024];
|
||||||
|
|
||||||
// construct the full path to the file first
|
// construct the full path to the file first
|
||||||
snprintf(fullPathBuffer, sizeof(fullPathBuffer), "%s/%s", p_path, dentry->d_name);
|
snprintf(fullPathBuffer, sizeof(fullPathBuffer), "%s/%s", p_path, dentry->d_name);
|
||||||
|
|
||||||
|
// push it to the vector
|
||||||
p_interleafFiles.push_back(fullPathBuffer);
|
p_interleafFiles.push_back(fullPathBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue