Skip to content

Instantly share code, notes, and snippets.

/Levels.as
Created Mar 15, 2015

Embed
What would you like to do?
Embedded levels helper file for Dungeon project
package helpers {
import com.junkbyte.console.ConsoleChannel;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;
public class Levels extends Object {
[Embed(source="../../level/room1.xml", mimeType="application/octet-stream")]
public static const room1XML:Class;
[Embed(source="../../level/room2.xml", mimeType="application/octet-stream")]
public static const room2XML:Class;
[Embed(source="../../level/room3.xml", mimeType="application/octet-stream")]
public static const room3XML:Class;
[Embed(source="../../level/room4.xml", mimeType="application/octet-stream")]
public static const room4XML:Class;
[Embed(source="../../level/room5.xml", mimeType="application/octet-stream")]
public static const room5XML:Class;
[Embed(source="../../level/room6.xml", mimeType="application/octet-stream")]
public static const room6XML:Class;
[Embed(source="../../level/room7.xml", mimeType="application/octet-stream")]
public static const room7XML:Class;
[Embed(source="../../level/room8.xml", mimeType="application/octet-stream")]
public static const room8XML:Class;
[Embed(source="../../level/room9.xml", mimeType="application/octet-stream")]
public static const room9XML:Class;
[Embed(source="../../level/room10.xml", mimeType="application/octet-stream")]
public static const room10XML:Class;
[Embed(source="../../level/room11.xml", mimeType="application/octet-stream")]
public static const room11XML:Class;
[Embed(source="../../level/room12.xml", mimeType="application/octet-stream")]
public static const room12XML:Class;
// TODO maybe dependency injection based on whether we're in debug mode or not
public static function load(levelFile:File):XML {
new ConsoleChannel("Levels").info("Loading", levelFile.name);
return loadXMLFromEmbeddedAsset(levelFile);
// return loadXMLFromFile(levelFile);
}
private static function loadXMLFromFile(file:File):XML {
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);
var roomXML:XML = XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
return roomXML;
}
private static function loadXMLFromEmbeddedAsset(file:File):XML {
switch(file.name) {
case "room1.xml":
return XML(new room1XML());
case "room2.xml":
return XML(new room2XML());
case "room3.xml":
return XML(new room3XML());
case "room4.xml":
return XML(new room4XML());
case "room5.xml":
return XML(new room5XML());
case "room6.xml":
return XML(new room6XML());
case "room7.xml":
return XML(new room7XML());
case "room8.xml":
return XML(new room8XML());
case "room9.xml":
return XML(new room9XML());
case "room10.xml":
return XML(new room10XML());
case "room11.xml":
return XML(new room11XML());
case "room12.xml":
return XML(new room12XML());
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.