Skip to content

Instantly share code, notes, and snippets.

@bendmorris
Last active December 23, 2015 05:49
Show Gist options
  • Save bendmorris/6589375 to your computer and use it in GitHub Desktop.
Save bendmorris/6589375 to your computer and use it in GitHub Desktop.
nme/AssetData.hx: needed for openfl asset embedding when running headless and compiling without openfl
package nme;
import sys.FileSystem;
import openfl.Assets;
enum LibraryType {
SWF;
SWF_LITE;
XFL;
}
class AssetData {
public static var library:Map <String, LibraryType>;
public static var path:Map <String, String>;
public static var type:Map <String, AssetType>;
private static var initialized:Bool = false;
public static function setPaths(dir, new_dir, resource_type) {
var files = FileSystem.readDirectory(dir);
for (file in files) {
#if debug
trace(new_dir + '/' + file);
#end
if (FileSystem.isDirectory(dir + '/' + file))
setPaths(dir + '/' + file, new_dir + '/' + file, resource_type);
else {
AssetData.path.set(new_dir + '/' + file, dir + '/' + file);
AssetData.type.set(new_dir + '/' + file, Reflect.field(AssetType, resource_type.toUpperCase ()));
}
}
}
public static function initialize ():Void {
if (!initialized) {
path = new Map<String, String> ();
type = new Map<String, AssetType> ();
library = new Map<String, LibraryType> ();
setPaths("assets/graphics", "graphics", "image");
setPaths("assets/maps", "maps", "text");
setPaths("assets/data", "data", "text");
initialized = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment