diff --git a/ogl_editor/src/Editor.c b/ogl_editor/src/Editor.c index 8bef947..75bb3a1 100644 --- a/ogl_editor/src/Editor.c +++ b/ogl_editor/src/Editor.c @@ -5,6 +5,7 @@ #include #include "Dialog.h" #include "Editor.h" +#include "External/mxml/mxml.h" typedef struct RETrack { @@ -245,14 +246,85 @@ void Editor_keyDown(int key) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +static void parseXml(mxml_node_t* rootNode) +{ + // find the tracks element + + mxml_node_t* node = mxmlFindElement(rootNode, rootNode, "tracks", NULL, NULL, MXML_NO_DESCEND); + + if (!node) + { + node = mxmlFindElement(rootNode, rootNode, "tracks", NULL, NULL, MXML_DESCEND_FIRST); + + if (!node) + { + // TODO: Report back that we couldn't find tracks in xml file + // Dialog_showError(...) + + printf("No tracks found\n"); + + return; + } + } + + // Traverse the tracks node data + + while (1) + { + node = mxmlWalkNext(node, rootNode, MXML_DESCEND); + + if (!node) + break; + + switch (mxmlGetType(node)) + { + case MXML_ELEMENT: + { + const char* element_name = mxmlGetElement(node); + + if (!strcmp("track", element_name)) + { + // TODO: Create the new track/channel here + + printf("Creating track/channel with name %s\n", mxmlElementGetAttr(node, "name")); + } + else if (!strcmp("key", element_name)) + { + const char* row = mxmlElementGetAttr(node, "row"); + const char* value = mxmlElementGetAttr(node, "value"); + const char* interpolation = mxmlElementGetAttr(node, "interpolation"); + + printf("Adding key: row %s | value %s | interpolation %s\n", row, value, interpolation); + } + } + + default: break; + } + } +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + static void onOpen() { + FILE* fp; + mxml_node_t* tree; char path[512]; if (!Dialog_open(path)) return; - printf("%s\n", path); + if (!(fp = fopen(path, "r"))) + return; + + if (!(tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK))) + { + fclose(fp); + return; + } + + parseXml(tree); + mxmlDelete(tree); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/test.rocket b/test.rocket new file mode 100755 index 0000000..0bc2450 --- /dev/null +++ b/test.rocket @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/units.lua b/units.lua index 40204e5..8a0221a 100644 --- a/units.lua +++ b/units.lua @@ -2,7 +2,7 @@ StaticLibrary { Name = "mxml", Env = { - CPPPATH = { "." }, + CPPPATH = { ".", "ogl_rocket/src/External/mxml" }, PROGOPTS = { { "/SUBSYSTEM:WINDOWS", "/DEBUG"; Config = { "win32-*-*", "win64-*-*" } }, }, @@ -72,7 +72,9 @@ Program { Name = "editor", Env = { - CPPPATH = { ".", "ogl_editor/src", "../emgui/src", "../../../../../emgui/src" }, + CPPPATH = { ".", "ogl_editor/src", + "../emgui/src", "../../../../../emgui/src", + "ogl_editor/External/mxml" }, PROGOPTS = { { "/SUBSYSTEM:WINDOWS", "/DEBUG"; Config = { "win32-*-*", "win64-*-*" } }, },