Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Converting a Marshaled Ruby file to XML?

I've been trying to make this work in various ways, the closest I've gotten is to use IronRuby to load the .NET XML serialization libraries to serialize the loaded data, but it still won't let me serialize anything into XML, and I don't seem to be able to collect the data for usage by using IronRuby in C# either.

In preference I would like to have a good way to convert the files to simple XML structures that I can de-serialize and write the necessary classes for in C#.

Imagine an output like this for a map data file:
Code:
<Map>

  <tileset_id>1</tileset_id>

  <width>50</width>

  <height>50</height>

  <autoplay_bgm>true</autoplay_bgm>

  <bgm>Track Name</bgm>

  <autoplay_bgs>true</autoplay_bgs>

  <bgs>Sound Name</bgs>

  <events>

    <Event>

      <id>1</id>

      <name>Event Name</name>

      <x>1</x>

      <y>1</y>

      <pages>

        <Page>

          <Condition>

            <switch1_valid>true</switch1_valid>

          </Condition>

          <graphic>data</graphic>

        </Page>

      </pages>

    </Event>

  </events>

</Map>
I just used the Map struct as an example. I didn't include all the attributes, just created the basic tree setup that I would like it to contain. This should be easily doable, but I'm still learning and I seem to be unable to find a solution.

As a note, it doesn't matter what medium is used to convert the files. The actual converting won't happen on runtime in the project I'm working on, just the deserialization of the files to load them into it.

Any help would be greatly appreciated!

Thanks,
Sarkilas
 
I actually did this. When I was working on RMPY I wrote a script that could convert all the classes to an XML type of thing so I could load them in my program. the result was files that were several megabytes unzipped. I only got it working for one class and I eventually stopped altogether in favor of my own serialization format, I made the rmpy format text based and supports recursive references.

since RMPY is now part of ARC and we've written a far more effective binary format I would be happy to give you the source for the RMPY. it should be a simple matter to write a de-serializer for C# if you have the ruby code and the format specification.

interested? send me a PM to let me know to comeback (I don't actually visit this forum enough to reliable check this topic)
 
I wouldn't bother with all the XML. The whole point of a .NET version of Ruby is for easily mixing and interfacing different languages. I made a quick sample of how to embed IronRuby and load a Ruby object up with C#.

http://pastebin.com/rpVuYPtb

This returns the loaded file as an object, which you can easily cast into the data type that it is. Here would be an example of its usage:

(this is assuming the object is an array, but you get the point)

Remember that any Ruby class that the data is saved as must also be defined in IronRuby's scope that is loading it.
Code:
object array = (RubyArray)LoadRubyObject(@"C:\Users\Me\Documents\RPGXP\Project\Data\Actors.rxdata");

MessageBox.Show(array[3].ToString())
In this example, you would need to ensure that RPG::Actor had been loaded into IronRuby's scope before attempting.

I can explain this better if need be. I am unsure how much you know about IronRuby and C#, and I am skipping a lot of minor details with the assumption that you know most of the basics. If you have any questions or need a specific thing explained a bit more, feel free to ask.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top