Worked a bit on the classes, here's a little technical look at how things are going:
file-format.nut
class XML()
class INI()
class TXT()
class TXTContent()
class INIContent()
class XMLContent()
The XML, INI and TXT classes have a loadFile( filename ) function which returns the appropriate Content class. For xml, you get a squirrel table of nodes/attributes. For Ini, you get a squirrel table of sections/keys-values. For txt, you get an array of lines. From there, you can read any xml, ini or txt - you wouldn't have to use it to create a layout.
convert-layout.nut
class AMLayout()
{
settings = {}
objects = [];
scripts = [];
modules = [];
}
class LayoutFile()
{
content = null;
constructor( filename )
{
content = [file_type].loadFile( filename);
}
function file_type() { return "xml"; }
function parse( content ) { return am_layout; }
function translate( am_layout ) { return translated_am_layout; }
function create( translated_am_layout )
}
To take that information into a layout, convert-layout defines an AMLayout class of layout components ( objects, modules, etc.. ).
For various layout formats, you extend the LayoutFile class and write the parse, translate and create functions. parse is passed the content (XML, INI or TXT) so you parse that into the AMLayout format. translate is passed the AMLayout object that parse created and allows you to modify the content ( to substitute variables and such ). Then create is passed the translated AMLayout and creates the actual layout and objects.
A pseudo extended layout parser:
class SomeFrontendLayout extends LayoutFile
{
function file_type() { return "xml"; }
function parse( content )
{
local layout = AMLayout();
//parse content into AMLayout instance
}
function translate( layout )
{
//make changes to attributes, etc...
}
function create( layout )
{
foreach ( object in layout.objects )
{
if ( object.type == "text" ) fe.add_text( object.msg, object.x, object.y, object.width, object.height );
}
}
}
the final result is something like:
fe.load_module("convert-layout");
AttractModeLayout("attract/xml-layout/layout.xml");
//or
MamewahLayout("mamewah/default/layout.lay");
//or any other that a LayoutFile class has been written for
It's a pretty good system right now. I'll keep improving it - still have bugs with xml processing and want to refine the AMLayout class but overall it should be easy to start writing addon conversion classes - of course depending on what can be converted properly into AM based on the feature set.
Any thoughts or suggestions, let me know. I'll have the initial code on github in another couple days probably.