Last active
December 23, 2015 05:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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