Use class reification for readability.
This commit is contained in:
@@ -30,7 +30,9 @@ class AssetsMacro
|
|||||||
if (fields != null)
|
if (fields != null)
|
||||||
{
|
{
|
||||||
#if !display
|
#if !display
|
||||||
var constructor = macro
|
var definition = macro class Temp
|
||||||
|
{
|
||||||
|
public function new(?length:Int, ?bytesData:haxe.io.BytesData)
|
||||||
{
|
{
|
||||||
var bytes = haxe.Resource.getBytes(resourceName);
|
var bytes = haxe.Resource.getBytes(resourceName);
|
||||||
#if html5
|
#if html5
|
||||||
@@ -40,25 +42,10 @@ class AssetsMacro
|
|||||||
#else
|
#else
|
||||||
super(bytes.length, bytes.b);
|
super(bytes.length, bytes.b);
|
||||||
#end
|
#end
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var args = [
|
fields.push(definition.fields[0]);
|
||||||
{name: "length", opt: true, type: macro:Int},
|
|
||||||
{name: "bytesData", opt: true, type: macro:haxe.io.BytesData}
|
|
||||||
];
|
|
||||||
fields.push(
|
|
||||||
{
|
|
||||||
name: "new",
|
|
||||||
access: [APublic],
|
|
||||||
kind: FFun(
|
|
||||||
{
|
|
||||||
args: args,
|
|
||||||
expr: constructor,
|
|
||||||
params: [],
|
|
||||||
ret: null
|
|
||||||
}),
|
|
||||||
pos: Context.currentPos()
|
|
||||||
});
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,29 +59,16 @@ class AssetsMacro
|
|||||||
if (fields != null)
|
if (fields != null)
|
||||||
{
|
{
|
||||||
#if !display
|
#if !display
|
||||||
var constructor = macro
|
var definition = macro class Temp
|
||||||
|
{
|
||||||
|
public function new(?length:Int, ?bytesData:haxe.io.BytesData)
|
||||||
{
|
{
|
||||||
var bytes = haxe.Resource.getBytes(resourceName);
|
var bytes = haxe.Resource.getBytes(resourceName);
|
||||||
super(bytes.b, bytes.length);
|
super(bytes.b, bytes.length);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var args = [
|
fields.push(definition.fields[0]);
|
||||||
{name: "length", opt: true, type: macro:Int},
|
|
||||||
{name: "bytesData", opt: true, type: macro:haxe.io.BytesData}
|
|
||||||
];
|
|
||||||
fields.push(
|
|
||||||
{
|
|
||||||
name: "new",
|
|
||||||
access: [APublic],
|
|
||||||
kind: FFun(
|
|
||||||
{
|
|
||||||
args: args,
|
|
||||||
expr: constructor,
|
|
||||||
params: [],
|
|
||||||
ret: null
|
|
||||||
}),
|
|
||||||
pos: Context.currentPos()
|
|
||||||
});
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,35 +82,18 @@ class AssetsMacro
|
|||||||
if (fields != null)
|
if (fields != null)
|
||||||
{
|
{
|
||||||
#if !display
|
#if !display
|
||||||
var constructor = macro
|
var definition = macro class Temp
|
||||||
|
{
|
||||||
|
public function new(?length:Int = 0)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
var bytes = haxe.Resource.getBytes(resourceName);
|
var bytes = haxe.Resource.getBytes(resourceName);
|
||||||
__fromBytes(bytes);
|
__fromBytes(bytes);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var args = [
|
fields.push(definition.fields[0]);
|
||||||
{
|
|
||||||
name: "length",
|
|
||||||
opt: true,
|
|
||||||
type: macro:Int,
|
|
||||||
value: macro 0
|
|
||||||
}
|
|
||||||
];
|
|
||||||
fields.push(
|
|
||||||
{
|
|
||||||
name: "new",
|
|
||||||
access: [APublic],
|
|
||||||
kind: FFun(
|
|
||||||
{
|
|
||||||
args: args,
|
|
||||||
expr: constructor,
|
|
||||||
params: [],
|
|
||||||
ret: null
|
|
||||||
}),
|
|
||||||
pos: Context.currentPos()
|
|
||||||
});
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,14 +157,12 @@ class AssetsMacro
|
|||||||
resourceType = "image/gif";
|
resourceType = "image/gif";
|
||||||
}
|
}
|
||||||
|
|
||||||
var fieldValue = {pos: position, expr: EConst(CString(resourceType))};
|
var definition = macro class Temp
|
||||||
fields.push(
|
|
||||||
{
|
{
|
||||||
kind: FVar(macro:String, fieldValue),
|
private static var resourceType:String = $v{ resourceType };
|
||||||
name: "resourceType",
|
};
|
||||||
access: [APrivate, AStatic],
|
|
||||||
pos: position
|
fields.push(definition.fields[0]);
|
||||||
});
|
|
||||||
|
|
||||||
var base64 = Base64.encode(bytes);
|
var base64 = Base64.encode(bytes);
|
||||||
Context.addResource(resourceName, Bytes.ofString(base64));
|
Context.addResource(resourceName, Bytes.ofString(base64));
|
||||||
@@ -217,14 +172,12 @@ class AssetsMacro
|
|||||||
Context.addResource(resourceName, bytes);
|
Context.addResource(resourceName, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
var fieldValue = {pos: position, expr: EConst(CString(resourceName))};
|
var definition = macro class Temp
|
||||||
fields.push(
|
|
||||||
{
|
{
|
||||||
kind: FVar(macro:String, fieldValue),
|
private static var resourceName:String = $v{ resourceName };
|
||||||
name: "resourceName",
|
};
|
||||||
access: [APrivate, AStatic],
|
|
||||||
pos: position
|
fields.push(definition.fields[0]);
|
||||||
});
|
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
|
|
||||||
@@ -294,35 +247,20 @@ class AssetsMacro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var fieldValue = {pos: position, expr: EConst(CString(resourceName))};
|
var definition = macro class Temp
|
||||||
fields.push(
|
|
||||||
{
|
{
|
||||||
kind: FVar(macro:String, fieldValue),
|
private static var resourceName:String = $v{ resourceName };
|
||||||
name: "resourceName",
|
|
||||||
access: [APublic, AStatic],
|
|
||||||
pos: position
|
|
||||||
});
|
|
||||||
|
|
||||||
var constructor = macro
|
public function new()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
__fromBytes(haxe.Resource.getBytes(resourceName));
|
__fromBytes(haxe.Resource.getBytes(resourceName));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fields.push(
|
fields.push(definition.fields[0]);
|
||||||
{
|
fields.push(definition.fields[1]);
|
||||||
name: "new",
|
|
||||||
access: [APublic],
|
|
||||||
kind: FFun(
|
|
||||||
{
|
|
||||||
args: [],
|
|
||||||
expr: constructor,
|
|
||||||
params: [],
|
|
||||||
ret: null
|
|
||||||
}),
|
|
||||||
pos: Context.currentPos()
|
|
||||||
});
|
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
@@ -342,7 +280,12 @@ class AssetsMacro
|
|||||||
if (fields != null)
|
if (fields != null)
|
||||||
{
|
{
|
||||||
#if !display
|
#if !display
|
||||||
var constructor = macro
|
var definition = macro class Temp
|
||||||
|
{
|
||||||
|
public function new(?buffer:lime.graphics.ImageBuffer,
|
||||||
|
?offsetX:Int, ?offsetY:Int, ?width:Int, ?height:Int,
|
||||||
|
?color:Null<Int>, ?type:lime.graphics.ImageType
|
||||||
|
#if html5 , ?onload:Dynamic = true #end)
|
||||||
{
|
{
|
||||||
#if html5
|
#if html5
|
||||||
super();
|
super();
|
||||||
@@ -376,85 +319,18 @@ class AssetsMacro
|
|||||||
|
|
||||||
__fromBytes(haxe.Resource.getBytes(resourceName), null);
|
__fromBytes(haxe.Resource.getBytes(resourceName), null);
|
||||||
#end
|
#end
|
||||||
};
|
|
||||||
|
|
||||||
var args = [
|
|
||||||
{
|
|
||||||
name: "buffer",
|
|
||||||
opt: true,
|
|
||||||
type: macro:lime.graphics.ImageBuffer,
|
|
||||||
value: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "offsetX",
|
|
||||||
opt: true,
|
|
||||||
type: macro:Int,
|
|
||||||
value: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "offsetY",
|
|
||||||
opt: true,
|
|
||||||
type: macro:Int,
|
|
||||||
value: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "width",
|
|
||||||
opt: true,
|
|
||||||
type: macro:Int,
|
|
||||||
value: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "height",
|
|
||||||
opt: true,
|
|
||||||
type: macro:Int,
|
|
||||||
value: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "color",
|
|
||||||
opt: true,
|
|
||||||
type: macro:Null<Int>,
|
|
||||||
value: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "type",
|
|
||||||
opt: true,
|
|
||||||
type: macro:lime.graphics.ImageType,
|
|
||||||
value: null
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
|
||||||
#if html5
|
#if html5
|
||||||
args.push(
|
public static var preload:js.html.Image;
|
||||||
{
|
#end
|
||||||
name: "onload",
|
};
|
||||||
opt: true,
|
|
||||||
type: macro:Dynamic,
|
#if html5
|
||||||
value: null
|
fields.push(definition.fields[1]);
|
||||||
});
|
|
||||||
fields.push(
|
|
||||||
{
|
|
||||||
kind: FVar(macro:js.html.Image, null),
|
|
||||||
name: "preload",
|
|
||||||
doc: null,
|
|
||||||
meta: [],
|
|
||||||
access: [APublic, AStatic],
|
|
||||||
pos: Context.currentPos()
|
|
||||||
});
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
fields.push(
|
fields.push(definition.fields[0]);
|
||||||
{
|
|
||||||
name: "new",
|
|
||||||
access: [APublic],
|
|
||||||
kind: FFun(
|
|
||||||
{
|
|
||||||
args: args,
|
|
||||||
expr: constructor,
|
|
||||||
params: [],
|
|
||||||
ret: null
|
|
||||||
}),
|
|
||||||
pos: Context.currentPos()
|
|
||||||
});
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,48 +344,20 @@ class AssetsMacro
|
|||||||
if (fields != null)
|
if (fields != null)
|
||||||
{
|
{
|
||||||
#if (openfl && !html5 && !display) // CFFILoader.h(248) : NOT Implemented:api_buffer_data
|
#if (openfl && !html5 && !display) // CFFILoader.h(248) : NOT Implemented:api_buffer_data
|
||||||
|
var definition = macro class Temp
|
||||||
var constructor = macro
|
{
|
||||||
|
public function new(?stream:openfl.net.URLRequest,
|
||||||
|
?context:openfl.media.SoundLoaderContext,
|
||||||
|
?forcePlayAsMusic:Bool = false)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
var byteArray = openfl.utils.ByteArray.fromBytes(haxe.Resource.getBytes(resourceName));
|
var byteArray = openfl.utils.ByteArray.fromBytes(haxe.Resource.getBytes(resourceName));
|
||||||
loadCompressedDataFromByteArray(byteArray, byteArray.length, forcePlayAsMusic);
|
loadCompressedDataFromByteArray(byteArray, byteArray.length, forcePlayAsMusic);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var args = [
|
fields.push(definition.fields[0]);
|
||||||
{
|
|
||||||
name: "stream",
|
|
||||||
opt: true,
|
|
||||||
type: macro:openfl.net.URLRequest,
|
|
||||||
value: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "context",
|
|
||||||
opt: true,
|
|
||||||
type: macro:openfl.media.SoundLoaderContext,
|
|
||||||
value: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "forcePlayAsMusic",
|
|
||||||
opt: true,
|
|
||||||
type: macro:Bool,
|
|
||||||
value: macro false
|
|
||||||
}
|
|
||||||
];
|
|
||||||
fields.push(
|
|
||||||
{
|
|
||||||
name: "new",
|
|
||||||
access: [APublic],
|
|
||||||
kind: FFun(
|
|
||||||
{
|
|
||||||
args: args,
|
|
||||||
expr: constructor,
|
|
||||||
params: [],
|
|
||||||
ret: null
|
|
||||||
}),
|
|
||||||
pos: Context.currentPos()
|
|
||||||
});
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user