Now with some basic loading of the xml file

This commit is contained in:
Daniel Collin 2012-10-24 00:06:03 +02:00
parent 2e9b1e2bd9
commit dd0bc8b750
3 changed files with 93 additions and 3 deletions

View File

@ -5,6 +5,7 @@
#include <string.h>
#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);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

16
test.rocket Executable file
View File

@ -0,0 +1,16 @@
<tracks rows="128">
<track name="intro_image">
<key row="32" value="3.000000" interpolation="0"/>
<key row="96" value="5.000000" interpolation="0"/>
<key row="104" value="5.000000" interpolation="0"/>
<key row="112" value="12346.000000" interpolation="0"/>
<key row="115" value="12.000000" interpolation="0"/>
</track>
<track name="foobar">
<key row="32" value="3.000000" interpolation="1"/>
<key row="96" value="5.000000" interpolation="1"/>
<key row="104" value="5.000000" interpolation="0"/>
<key row="112" value="12346.000000" interpolation="0"/>
<key row="115" value="12.000000" interpolation="0"/>
</track>
</tracks>

View File

@ -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-*-*" } },
},