console: simplify Assets.hx compile conditionals

This commit is contained in:
James Gray
2016-02-23 19:29:24 -06:00
parent aec635bbd2
commit dc727a8ccb

View File

@@ -1164,17 +1164,16 @@ class Assets {
var fields = embedData (":file");
#if lime_console
if (false) {
#else
if (fields != null) {
#end
var constructor = macro {
#if lime_console
throw "not implemented";
#else
var bytes = haxe.Resource.getBytes (resourceName);
super (bytes.length, bytes.b);
#end
};
@@ -1192,18 +1191,19 @@ class Assets {
var fields = embedData (":file");
#if lime_console
if (false) {
#else
if (fields != null) {
#end
var constructor = macro {
super ();
#if lime_console
throw "not implemented";
#else
var bytes = haxe.Resource.getBytes (resourceName);
__fromBytes (bytes);
#end
};
@@ -1217,50 +1217,6 @@ class Assets {
}
#if lime_console
private static function embedData (metaName:String, encode:Bool = false):Array<Field> {
var classType = Context.getLocalClass().get();
var metaData = classType.meta.get();
var position = Context.currentPos();
var fields = Context.getBuildFields();
for (meta in metaData) {
if (meta.name != metaName || meta.params.length <= 0) {
continue;
}
switch (meta.params[0].expr) {
case EConst(CString(filePath)):
var fieldValue = {
pos: position,
expr: EConst(CString(filePath))
};
fields.push ({
kind: FVar(macro :String, fieldValue),
name: "filePath",
access: [ APrivate, AStatic ],
pos: position
});
return fields;
default:
}
}
return null;
}
#else
private static function embedData (metaName:String, encode:Bool = false):Array<Field> {
var classType = Context.getLocalClass().get();
@@ -1278,6 +1234,21 @@ class Assets {
case EConst(CString(filePath)):
#if lime_console
var fieldValue = {
pos: position,
expr: EConst(CString(filePath))
};
fields.push ({
kind: FVar(macro :String, fieldValue),
name: "filePath",
access: [ APrivate, AStatic ],
pos: position
});
#else
var path = filePath;
if (!sys.FileSystem.exists(filePath)) {
path = Context.resolvePath (filePath);
@@ -1314,6 +1285,8 @@ class Assets {
var fieldValue = { pos: position, expr: EConst(CString(resourceName)) };
fields.push ({ kind: FVar(macro :String, fieldValue), name: "resourceName", access: [ APrivate, AStatic ], pos: position });
#end
return fields;
default:
@@ -1329,12 +1302,10 @@ class Assets {
return null;
}
#end
macro public static function embedFont ():Array<Field> {
var fields = null;
var classType = Context.getLocalClass().get();
@@ -1374,6 +1345,10 @@ class Assets {
}
if (path != null && path != "") {
#if lime_console
throw "not implemented";
#end
#if html5
Sys.command ("haxelib", [ "run", "lime", "generate", "-font-hash", sys.FileSystem.fullPath(path) ]);