// Path: src/com/ganggarrison/gmdec/DeferredReferenceCreatorNotifier.java
// public class DeferredReferenceCreatorNotifier {
// 	private Set<DeferredReferenceCreator> drcSet = new HashSet<DeferredReferenceCreator>();
// 
// 	public void addDeferredReferenceCreator(DeferredReferenceCreator drc) {
// 		drcSet.add(drc);
// 	}
// 
// 	public void createReferences(GmFile gmf) {
// 		for (DeferredReferenceCreator drc : drcSet) {
// 			drc.createReferences(gmf);
// 		}
// 	}
// }
// 
// Path: src/com/ganggarrison/gmdec/ResourceTreeEntry.java
// public class ResourceTreeEntry {
// 	public String name;
// 	public String filename;
// 	public Type type;
// 
// 	public ResourceTreeEntry(String name, String filename, Type type) {
// 		this.name = name;
// 		this.filename = filename;
// 		this.type = type;
// 	}
// 
// 	public ResourceTreeEntry() {
// 	}
// 
// 	public String getFilename() {
// 		String result;
// 		if (filename != null && !filename.isEmpty()) {
// 			result = filename;
// 		} else {
// 			result = name;
// 		}
// 		if (FileTools.isGoodFilename(result)) {
// 			return result;
// 		} else {
// 			throw new IllegalStateException("Bad filename in resource list: " + result);
// 		}
// 	}
// 
// 	public static enum Type {
// 		RESOURCE, GROUP
// 	}
// }
// 
// Path: src/com/ganggarrison/gmdec/xml/BackgroundXmlFormat.java
// public class BackgroundXmlFormat extends XmlFormat<Background> {
// 	@Override
// 	public void write(Background background, XmlWriter writer) {
// 		writer.startElement("background");
// 		{
// 			writeIdAttribute(background, writer);
// 			boolean useAsTileset = background.get(PBackground.USE_AS_TILESET);
// 			writer.putElement("useAsTileset", useAsTileset);
// 			if (useAsTileset || !GmkSplitter.omitDisabledFields) {
// 				writer.startElement("tiles");
// 				int width = background.get(PBackground.TILE_WIDTH);
// 				int height = background.get(PBackground.TILE_HEIGHT);
// 				writeDimension(writer, "size", new Dimension(width, height));
// 
// 				int offsetX = background.get(PBackground.H_OFFSET);
// 				int offsetY = background.get(PBackground.V_OFFSET);
// 				writePoint(writer, "offset", new Point(offsetX, offsetY));
// 
// 				int sepX = background.get(PBackground.H_SEP);
// 				int sepY = background.get(PBackground.V_SEP);
// 				writePoint(writer, "separation", new Point(sepX, sepY));
// 				writer.endElement();
// 			}
// 			writer.putElement("preload", background.get(PBackground.PRELOAD));
// 			writer.putElement("smoothEdges", background.get(PBackground.SMOOTH_EDGES));
// 			writer.putElement("transparent", background.get(PBackground.TRANSPARENT));
// 		}
// 		writer.endElement();
// 	}
// 
// 	@Override
// 	public Background read(XmlReader reader, DeferredReferenceCreatorNotifier notifier) {
// 		Background background = new Background();
// 		reader.enterElement("background");
// 		{
// 			readIdAttribute(background, reader);
// 			boolean useAsTileset = reader.getBoolElement("useAsTileset");
// 			background.put(PBackground.USE_AS_TILESET, useAsTileset);
// 			if (useAsTileset || !GmkSplitter.omitDisabledFields) {
// 				reader.enterElement("tiles");
// 				Dimension size = readDimension(reader, "size");
// 				background.put(PBackground.TILE_WIDTH, size.width);
// 				background.put(PBackground.TILE_HEIGHT, size.height);
// 
// 				Point offset = readPoint(reader, "offset");
// 				background.put(PBackground.H_OFFSET, offset.x);
// 				background.put(PBackground.V_OFFSET, offset.y);
// 
// 				Point separation = readPoint(reader, "separation");
// 				background.put(PBackground.H_SEP, separation.x);
// 				background.put(PBackground.V_SEP, separation.y);
// 				reader.leaveElement();
// 			}
// 			background.put(PBackground.PRELOAD, reader.getBoolElement("preload"));
// 			background.put(PBackground.SMOOTH_EDGES, reader.getBoolElement("smoothEdges"));
// 			background.put(PBackground.TRANSPARENT, reader.getBoolElement("transparent"));
// 		}
// 		reader.leaveElement();
// 		return background;
// 	}
// }


import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.lateralgm.file.GmFile;
import org.lateralgm.resources.Background;
import com.ganggarrison.gmdec.DeferredReferenceCreatorNotifier;
import com.ganggarrison.gmdec.ResourceTreeEntry;
import com.ganggarrison.gmdec.xml.BackgroundXmlFormat;

/*
 * Copyright (C) 2010 Medo <smaxein@googlemail.com>
 * 
 * This file is part of GmkSplitter.
 * GmkSplitter is free software and comes with ABSOLUTELY NO WARRANTY.
 * See LICENSE for details.
 */
package com.ganggarrison.gmdec.files;





public class BackgroundFormat extends ResourceFormat<Background> {
	@Override
	public Background read(File path, ResourceTreeEntry entry, DeferredReferenceCreatorNotifier drcn)
			throws IOException {
		File imageFile = new File(path, baseFilename(entry) + ".png");

// Path: src/com/ganggarrison/gmdec/DeferredReferenceCreatorNotifier.java
// public class DeferredReferenceCreatorNotifier {
// 	private Set<DeferredReferenceCreator> drcSet = new HashSet<DeferredReferenceCreator>();
// 
// 	public void addDeferredReferenceCreator(DeferredReferenceCreator drc) {
// 		drcSet.add(drc);
// 	}
// 
// 	public void createReferences(GmFile gmf) {
// 		for (DeferredReferenceCreator drc : drcSet) {
// 			drc.createReferences(gmf);
// 		}
// 	}
// }
// 
// Path: src/com/ganggarrison/gmdec/ResourceTreeEntry.java
// public class ResourceTreeEntry {
// 	public String name;
// 	public String filename;
// 	public Type type;
// 
// 	public ResourceTreeEntry(String name, String filename, Type type) {
// 		this.name = name;
// 		this.filename = filename;
// 		this.type = type;
// 	}
// 
// 	public ResourceTreeEntry() {
// 	}
// 
// 	public String getFilename() {
// 		String result;
// 		if (filename != null && !filename.isEmpty()) {
// 			result = filename;
// 		} else {
// 			result = name;
// 		}
// 		if (FileTools.isGoodFilename(result)) {
// 			return result;
// 		} else {
// 			throw new IllegalStateException("Bad filename in resource list: " + result);
// 		}
// 	}
// 
// 	public static enum Type {
// 		RESOURCE, GROUP
// 	}
// }
// 
// Path: src/com/ganggarrison/gmdec/xml/BackgroundXmlFormat.java
// public class BackgroundXmlFormat extends XmlFormat<Background> {
// 	@Override
// 	public void write(Background background, XmlWriter writer) {
// 		writer.startElement("background");
// 		{
// 			writeIdAttribute(background, writer);
// 			boolean useAsTileset = background.get(PBackground.USE_AS_TILESET);
// 			writer.putElement("useAsTileset", useAsTileset);
// 			if (useAsTileset || !GmkSplitter.omitDisabledFields) {
// 				writer.startElement("tiles");
// 				int width = background.get(PBackground.TILE_WIDTH);
// 				int height = background.get(PBackground.TILE_HEIGHT);
// 				writeDimension(writer, "size", new Dimension(width, height));
// 
// 				int offsetX = background.get(PBackground.H_OFFSET);
// 				int offsetY = background.get(PBackground.V_OFFSET);
// 				writePoint(writer, "offset", new Point(offsetX, offsetY));
// 
// 				int sepX = background.get(PBackground.H_SEP);
// 				int sepY = background.get(PBackground.V_SEP);
// 				writePoint(writer, "separation", new Point(sepX, sepY));
// 				writer.endElement();
// 			}
// 			writer.putElement("preload", background.get(PBackground.PRELOAD));
// 			writer.putElement("smoothEdges", background.get(PBackground.SMOOTH_EDGES));
// 			writer.putElement("transparent", background.get(PBackground.TRANSPARENT));
// 		}
// 		writer.endElement();
// 	}
// 
// 	@Override
// 	public Background read(XmlReader reader, DeferredReferenceCreatorNotifier notifier) {
// 		Background background = new Background();
// 		reader.enterElement("background");
// 		{
// 			readIdAttribute(background, reader);
// 			boolean useAsTileset = reader.getBoolElement("useAsTileset");
// 			background.put(PBackground.USE_AS_TILESET, useAsTileset);
// 			if (useAsTileset || !GmkSplitter.omitDisabledFields) {
// 				reader.enterElement("tiles");
// 				Dimension size = readDimension(reader, "size");
// 				background.put(PBackground.TILE_WIDTH, size.width);
// 				background.put(PBackground.TILE_HEIGHT, size.height);
// 
// 				Point offset = readPoint(reader, "offset");
// 				background.put(PBackground.H_OFFSET, offset.x);
// 				background.put(PBackground.V_OFFSET, offset.y);
// 
// 				Point separation = readPoint(reader, "separation");
// 				background.put(PBackground.H_SEP, separation.x);
// 				background.put(PBackground.V_SEP, separation.y);
// 				reader.leaveElement();
// 			}
// 			background.put(PBackground.PRELOAD, reader.getBoolElement("preload"));
// 			background.put(PBackground.SMOOTH_EDGES, reader.getBoolElement("smoothEdges"));
// 			background.put(PBackground.TRANSPARENT, reader.getBoolElement("transparent"));
// 		}
// 		reader.leaveElement();
// 		return background;
// 	}
// }


// Path: src/com/ganggarrison/gmdec/files/BackgroundFormat.java
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.lateralgm.file.GmFile;
import org.lateralgm.resources.Background;
import com.ganggarrison.gmdec.DeferredReferenceCreatorNotifier;
import com.ganggarrison.gmdec.ResourceTreeEntry;
import com.ganggarrison.gmdec.xml.BackgroundXmlFormat;

/*
 * Copyright (C) 2010 Medo <smaxein@googlemail.com>
 * 
 * This file is part of GmkSplitter.
 * GmkSplitter is free software and comes with ABSOLUTELY NO WARRANTY.
 * See LICENSE for details.
 */
package com.ganggarrison.gmdec.files;





public class BackgroundFormat extends ResourceFormat<Background> {
	@Override
	public Background read(File path, ResourceTreeEntry entry, DeferredReferenceCreatorNotifier drcn)
			throws IOException {
		File imageFile = new File(path, baseFilename(entry) + ".png");

		Background background = new BackgroundXmlFormat()
