Author Topic: Exporting all graphic sheets  (Read 4235 times)

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Exporting all graphic sheets
« on: 2011-02-16, 01:39:23 PM »
Hi!

I wondered if there was a way to make a massive export of all graphic sheets from a sgdk2 file.  Giving the name of the graphic sheet to the exported png file seems fine.  If, not, I'll download the SGDK2 source and try to alter the program to make it happen.  I don't want to export and name manually my 350 graphic sheets...  oO

Thanks! :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Exporting all graphic sheets
« Reply #1 on: 2011-02-16, 01:44:08 PM »
All of the graphics are stored in the SGDK2 file, which is just an XML file.  You should be able to write a simple program to extract all the graphic sheets from that without needing to deal with the SGDK2 source.  I'm not sure what format the images are in, but I imagine it's just Base-64-encoded PNG files.
Edward Dassmesser

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Exporting all graphic sheets
« Reply #2 on: 2011-02-16, 01:49:43 PM »
Yeah, it's the encoding-decoding part that I don't know how to deal with, that's why I would download the source to see how it's done.  Otherwise, like you say, a little program with x-path to locate graphics sheets and it's a go. :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Exporting all graphic sheets
« Reply #3 on: 2011-02-16, 08:37:54 PM »
Actually, you shouldn't need to worry about encoding/decoding at all.  You could let a browser do it for you, using data URLs.  Let me see if I can whip up an xslt...
Edward Dassmesser

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Exporting all graphic sheets
« Reply #4 on: 2011-02-16, 09:00:42 PM »
Okay, so here we go.  Put the following in a file called "images.xsl" in the same directory as your sgdk2 file.

Code: ("images.xsl") [Select]
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <xsl:apply-templates select="ProjectDataset/GraphicSheet"/>
  </body>
  </html>
</xsl:template>

<xsl:template match="GraphicSheet">
 <xsl:param name="imagedata" select="."/>
 <img src="data:image/png;base64,{$imagedata}" />
</xsl:template>

</xsl:stylesheet>

Then edit the .sgdk2 file and add the following line just below the first line of the file:

Code: ("MyFile.sgdk2") [Select]
<?xml-stylesheet href="images.xsl" type="text/xsl"?>

So it should look like this:

Code: [Select]
<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet href="images.xsl" type="text/xsl"?>
<ProjectDataset>

Now open your sgdk2 file in Firefox or Chrome.  All of your images should show up.  This might be a little slow with 300 images, but hopefully not too bad.  The reason it works is because SGDK2 stores images in Base64 format, which Firefox and Chrome understand and can decode as images if you specify them as data URLs.  Then you'll need some way to save all the images.  I imagine there are a plethora of plugins for Firefox or Chrome which could do the job for you.

I gotta say, I don't do much programming in XSL.  It's impressive what you can do with so little work (although a lot of the work I would have had to do is mitigated by the fact that SGDK2 saves in XML files and Firefox understands data URLs)
« Last Edit: 2011-02-16, 09:03:51 PM by durnurd »
Edward Dassmesser

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Exporting all graphic sheets
« Reply #5 on: 2011-02-16, 09:37:20 PM »
Hum, I followed your instructions but images don't show up, I still see the whole content of the sgdk2 file as text (using FireFox 3.6.13).
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Exporting all graphic sheets
« Reply #6 on: 2011-02-16, 09:55:21 PM »
Oh well, I made the program.  It works well.  I attached it if someone is interested in using it.  Decoding was easier than I thought! :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Exporting all graphic sheets
« Reply #7 on: 2011-02-16, 10:38:54 PM »
Hmm... I will admit that I didn't test it too much, but it did work with one file.  Since you've got all the files, I guess it doesn't matter now, but out of curiousity, what happens if you rename the file with a .xml extension instead of .sgdk2?
Edward Dassmesser

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Exporting all graphic sheets
« Reply #8 on: 2011-02-17, 09:57:52 PM »
Yup, if I change file extension to .xml, firefox displays all images form the file and nothing else.  Interesting!

Thanks durnurd!
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com