Author Topic: XML module WIP - Who wants to create layouts in xml? :)  (Read 18736 times)

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
XML module WIP - Who wants to create layouts in xml? :)
« on: May 24, 2015, 01:17:05 AM »
Early phases here, but a lot of possibilities once it's working well. I've got crude xml loading, and I have a custom layout that reads a "Theme.xml" file and creates the layout based on it. This can open up the possibility of reading xml themes from other FE's - although it'd have to be coded to support the format, and may be missing features that don't translate to AM.

My plan for now is to make a layout that can read multiple themes from the layout folder, just choose them from the layout options. If you have suggestions or thoughts, let me know.




raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #1 on: May 24, 2015, 09:16:45 AM »
looks good, I look forward to updates!

I guess with this, your animate module and the loader functionality for layouts from other frontends, we should now have all the pieces to start throwing stuff around if attractmode gets fed a HyperSpin theme :)

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #2 on: May 24, 2015, 10:50:28 AM »
That and others could work as well.. similar to how you load in the mala stuff we would just need a function that would convert the original layout to AM objects/animations/sounds/etc...

The nice thing here is we can make xml work for any modules type stuff - so let's say a grid object could be something like:
Code: [Select]
<grid x="0" y="0" width="640" height="360" entries="9" art="snap" />
The same way I see adding animations with my animate module in xml..

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #3 on: May 25, 2015, 01:48:14 PM »
So looking through the Mala code and some other FEs,  I started incorporating INI and TXT file reading also :) Here's one of my old Mamewah layouts converted over which layout files use fixed text lines (non-ini format):



Right now, I have a "fileformat.nut" module which reads xml, ini and txt files, and a "layouts.nut" module, which provides classes you can extend that will convert various FE layout formats to AM layout objects.

Still a ways to go to get everything working properly and for each different FE theme, but the possibility is there. Hyperspin would still take a lot of time and effort since there is so much customization and things that aren't supported in AM yet (different themes for different systems, swf file support, zip files, etc)
« Last Edit: May 25, 2015, 02:05:48 PM by liquid8d »

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #4 on: May 25, 2015, 10:19:39 PM »
Here is the 'basic' AttractMode layout, converted to XML :)


liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #5 on: May 25, 2015, 10:28:44 PM »
And here is the default mamewah layout, loaded from the mamewah layout.lay... I couldn't get 'System' font to work, but other than that, it looks pretty good:


omegaman

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #6 on: May 26, 2015, 07:49:03 AM »
Liquid-

Looking good man. In this case, I think using xml to convert layouts is a great idea because it's good for schema etc...  but in general, I find it harder to read and edit than say a delimited file. 

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #7 on: May 26, 2015, 08:10:14 AM »
Do you mean like a delimited line-to-object type thing?
Code: [Select]
layout;640;480
artwork;348;152;262;262;snap
artwork;348;64;262;72;marquee
listbox;32;64;262;352;16;255;255;0;0;0;bold
...

We could pretty much add any file format, and have it parsed - it's just a matter of writing a parsing function and adding the AM objects based on it. You could have 3 parsing functions for an AM layout - XML, INI and TXT and read a layout created in any of the 3 - as long as a proper schema / format has been determined for that file type. I will probably improve the classes I'm making to do just that - still needs some tweaking.

If you have a good editor XML isn't too bad when it closes tags and quotes for you and the author formats it in a more reader-friendly way :) A few FE's have GUI designers - and I even started playing with a WIP designer, so then you wouldn't need to worry about writing the XML - just drag and drop design and save as a supported format.
[/code]

verion

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 861
    • View Profile
    • new projects
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #8 on: May 26, 2015, 10:34:06 AM »
Is this about using .xml or just importing .xml?
Is there any advantage in .xml vs .nut? except importing other themes?

I'm planning to make .nut syntax highlighting for brackets, because non-highlighted code editing is horrible. But with that sorted out .nut structure is ok for me.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #9 on: May 26, 2015, 01:00:10 PM »
It does a few things...

1) The file-format module can parse in .xml, .ini or other .txt files, making it easier to read content into your layout from files of that type. Ideally, I'd like these functions to also allow you to write to those formats too.

2) The 'convert-layout' module can create Attract Mode layouts with say an .xml format. You could do basic creating objects without having to 'code' a layout.

3) The 'convert-layout' modules can also import other FE layouts from one of those structured file formats. A parser has to be written for other FEs to convert it to an AM layout.

This wouldn't take the place of .nut but benefits users that don't want to or know how to "code" layouts, just want to import a layout from another FE, or for those that would prefer an easier way to create simple object layouts.

The .nut script files will always give you more control over what you can do with a layout since you have direct access to using classes, functions and create your own scripting.

That said down the road, this could potentially help separate GUI objects from  your code by using an .xml (or other format) for the objects, and a .nut for any specialized scripting of them.

As for syntax highlighting - I found a plugin for Notepad++ that does squirrel .nut pretty well, I think it's this one:
http://forum.liberty-unleashed.co.uk/index.php?topic=442.0

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #10 on: May 26, 2015, 01:18:02 PM »
I'm gonna throw a few things on here I have noticed so far that will be helpful down the road for supporting other layouts or enhancing AM in general.

Not supported:
.zip file resource support
.swf support
.svg support
.otf/.ttf fonts? (not sure if supported)

Could be done, but a module or built-in support would be helpful:
per system 'layouts'
gui system - buttons, check boxes, up/down/left/right/select/cancel navigation etc..
layout 'views' - a way to create multiple views in a layout and show/hide them when needed
dynamic images support (for [Manufacturer], etc) - I submitted a ticket for this
expanded grid/conveyor?

Just things to think about :)

verion

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 861
    • View Profile
    • new projects
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #11 on: May 26, 2015, 01:36:32 PM »
I'm on OS X, so unfortunately notepad++ is no good for me.

I've started separated topic about editors with syntax highlighting, and posted your link.
http://forum.attractmode.org/index.php?topic=213.0

omegaman

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #12 on: May 26, 2015, 01:59:38 PM »
Liquid8d-

I use notepad++ and love it. Let me be the first to say - It will be an auspicious day when we have .zip and .swf support.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #13 on: May 27, 2015, 03:01:47 PM »
Worked a bit on the classes, here's a little technical look at how things are going:

file-format.nut
Code: [Select]
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
Code: [Select]
  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:
Code: [Select]
   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:
Code: [Select]
  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.
« Last Edit: May 27, 2015, 03:11:02 PM by liquid8d »

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: XML module WIP - Who wants to create layouts in xml? :)
« Reply #14 on: May 31, 2015, 02:04:19 PM »
This one will be a bit trickier - RetroFE. Here's some WIP: