I have 2 exporter methods (planning to have more) that essentially take my sprite definition from my sprite maker, and export that into a PNG file and an XML file that describes the PNG. Right now, I have stuffed these two methods into my Sprite class for testing, but they don't really belong there. So I thought it would be good if I made an interface for exporters and importers, then have one class for each type of importer/exporter, right?
Now the problem is that my two methods don't have the same parameters, so I can't use an Interface very easily.
The first exporter is a an "organized" exporter, and it exports the frames in a manner that humans can easily follow, no restrictions. It would just take the sprite definition, and a file name (with no extension) then produce the pair of files.
The second exporter is an optimally packed exporter and would take the same parameters plus a maximum width and height. Right now it's not optimal, it doesn't re-size the frames and it just picks the next slot that fits. Maybe there are additional options (parameters) that I have not thought of yet for this method.
The XML is identical for the existing exporters, but the PNG differs. Some time down the road, I might like to have other types of meta-data exporters, like JSON.
For the existing exporters, they both follow this pattern:
I can provide a link to the code on request.
(I added "Importer" to the question because I will want to add importers to these exporters one day)
Any suggestions on how I might pull these exporters out of my Sprite class and how to keep them related?
I guess it would be best if you create some base export class that has only some basic features shared between all export classes like addSprite or saveToFile. after that you can create some other classes which inherit this one plus they have specific functions to add saving parameters, something like this:
class baseExported
{
public abstract void addSprite(Bitmap texture);
public abstract bool export(String target);
};
class ExporterA : baseExporter
{
public override void addSprite(...) {...};
public override bool export(...) {...};
}
class ExporterB : baseExporter
{
public override void addSprite(...) {...};
public override void setMaxDimentions(int maxHeight,int maxWidth) {...};
public override bool export(...) {...};
}
class ExporterC : baseExporter
{
public override void addSprite(...) {...};
public override void setMaxDimentions(int maxHeight,int maxWidth) {...};
public override void addMetaData(String someData) {...};
public override bool export(...) {...};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With