-
This commit is contained in:
@@ -32,11 +32,11 @@ import haxework.frame.FrameSwitcher;
|
|||||||
class GuiBuilder {
|
class GuiBuilder {
|
||||||
|
|
||||||
public static function build(data:Dynamic, ?links:Dynamic):Dynamic {
|
public static function build(data:Dynamic, ?links:Dynamic):Dynamic {
|
||||||
return new GuiB(data, links).build();
|
return new GuiB(data, links, data._includes).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fill(object:Dynamic, data:Dynamic, ?links:Dynamic):Void {
|
public static function fill(object:Dynamic, data:Dynamic, ?links:Dynamic):Void {
|
||||||
new GuiF(object, data, links).fill();
|
new GuiF(object, data, links, data._includes).fill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,10 +44,12 @@ class GuiB {
|
|||||||
|
|
||||||
private var data:Dynamic;
|
private var data:Dynamic;
|
||||||
private var links:Dynamic;
|
private var links:Dynamic;
|
||||||
|
private var includes:Dynamic;
|
||||||
|
|
||||||
public function new(data:Dynamic, ?links:Dynamic) {
|
public function new(data:Dynamic, ?links:Dynamic, ?includes:Dynamic) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.links = links;
|
this.links = links;
|
||||||
|
this.includes = includes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function build():Dynamic {
|
public function build():Dynamic {
|
||||||
@@ -55,14 +57,14 @@ class GuiB {
|
|||||||
var type:String = data.type;
|
var type:String = data.type;
|
||||||
//Reflect.deleteField(data, "type");
|
//Reflect.deleteField(data, "type");
|
||||||
var object:Dynamic = instance(type);
|
var object:Dynamic = instance(type);
|
||||||
new GuiF(object, data, links).fill();
|
new GuiF(object, data, links, includes).fill();
|
||||||
var initMethod:Dynamic = Reflect.field(object, "init");
|
var initMethod:Dynamic = Reflect.field(object, "init");
|
||||||
if (initMethod != null) Reflect.callMethod(object, initMethod, []);
|
if (initMethod != null) Reflect.callMethod(object, initMethod, []);
|
||||||
return object;
|
return object;
|
||||||
} else if (Std.is(data, String)) {
|
} else if (Std.is(data, String)) {
|
||||||
return GuiF.convertString(data, links);
|
return GuiF.convertString(data, links);
|
||||||
} else {
|
} else {
|
||||||
new GuiF(data, data, links).fill();
|
new GuiF(data, data, links, includes).fill();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,11 +82,13 @@ class GuiF {
|
|||||||
private var object:Dynamic;
|
private var object:Dynamic;
|
||||||
private var data:Dynamic;
|
private var data:Dynamic;
|
||||||
private var links:Dynamic;
|
private var links:Dynamic;
|
||||||
|
private var includes:Dynamic;
|
||||||
|
|
||||||
public function new(object:Dynamic, data:Dynamic, ?links:Dynamic) {
|
public function new(object:Dynamic, data:Dynamic, ?links:Dynamic, ?includes:Dynamic) {
|
||||||
this.object = object;
|
this.object = object;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.links = links;
|
this.links = links;
|
||||||
|
this.includes = includes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function convertString(value:Dynamic, ?links:Dynamic):Dynamic {
|
public static function convertString(value:Dynamic, ?links:Dynamic):Dynamic {
|
||||||
@@ -114,10 +118,18 @@ class GuiF {
|
|||||||
var fields:Array<String> = Reflect.fields(data);
|
var fields:Array<String> = Reflect.fields(data);
|
||||||
for (field in fields) {
|
for (field in fields) {
|
||||||
if (field == "type") continue;
|
if (field == "type") continue;
|
||||||
|
if (field == "_includes") continue;
|
||||||
var value:Dynamic = Reflect.field(data, field);
|
var value:Dynamic = Reflect.field(data, field);
|
||||||
|
if (field == "_include") {
|
||||||
|
var data:Dynamic = includes == null ? null : Reflect.field(includes, value);
|
||||||
|
if (data != null) {
|
||||||
|
new GuiF(object, data, links).fill();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (Std.is(value, Array)) {
|
if (Std.is(value, Array)) {
|
||||||
var a:Array<Dynamic> = [];
|
var a:Array<Dynamic> = [];
|
||||||
for (o in cast(value, Array<Dynamic>)) a.push(new GuiB(o, links).build());
|
for (o in cast(value, Array<Dynamic>)) a.push(new GuiB(o, links, includes).build());
|
||||||
value = a;
|
value = a;
|
||||||
} else if (Std.is(value, String)) {
|
} else if (Std.is(value, String)) {
|
||||||
var s:String = cast(value, String);
|
var s:String = cast(value, String);
|
||||||
@@ -148,7 +160,7 @@ class GuiF {
|
|||||||
} else if (Std.is(value, Bool)) {
|
} else if (Std.is(value, Bool)) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var o:Dynamic = new GuiB(value, links).build();
|
var o:Dynamic = new GuiB(value, links, includes).build();
|
||||||
new GuiF(o, value, links).fill();
|
new GuiF(o, value, links).fill();
|
||||||
value = o;
|
value = o;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ class BaseLoader<T> implements ILoader<T> {
|
|||||||
public static var urlProcessors(default, null):Array<String->String> = new Array<String->String>();
|
public static var urlProcessors(default, null):Array<String->String> = new Array<String->String>();
|
||||||
public static function prepareUrl(url:String):String { for (p in urlProcessors) url = p(url); return url; }
|
public static function prepareUrl(url:String):String { for (p in urlProcessors) url = p(url); return url; }
|
||||||
|
|
||||||
|
public static var proxy(default, default):String->String;
|
||||||
|
|
||||||
|
|
||||||
public var timeout(default, default):Int;
|
public var timeout(default, default):Int;
|
||||||
public var busy(default, null):Bool;
|
public var busy(default, null):Bool;
|
||||||
@@ -56,6 +58,13 @@ class BaseLoader<T> implements ILoader<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function cancelTimeout():Void {
|
||||||
|
if (timer != null) {
|
||||||
|
timer.stop();
|
||||||
|
timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function fromBytes(data:ByteArray):ICallback<T> {
|
public function fromBytes(data:ByteArray):ICallback<T> {
|
||||||
if (busy) throw "Busy";
|
if (busy) throw "Busy";
|
||||||
busy = true;
|
busy = true;
|
||||||
@@ -114,6 +123,15 @@ class BaseLoader<T> implements ILoader<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onSecurityError(e:Event):Void {
|
||||||
|
if (proxy == null) {
|
||||||
|
onError(e);
|
||||||
|
} else {
|
||||||
|
cancelTimeout();
|
||||||
|
internalRequest(proxy(buildUrl()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function onError(e:Event):Void {
|
private function onError(e:Event):Void {
|
||||||
var c:ICallback<T> = callback;
|
var c:ICallback<T> = callback;
|
||||||
dispose();
|
dispose();
|
||||||
@@ -133,10 +151,7 @@ class BaseLoader<T> implements ILoader<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function dispose():Void {
|
private function dispose():Void {
|
||||||
if (timer != null) {
|
cancelTimeout();
|
||||||
timer.stop();
|
|
||||||
timer = null;
|
|
||||||
}
|
|
||||||
url = null;
|
url = null;
|
||||||
data = null;
|
data = null;
|
||||||
callback = null;
|
callback = null;
|
||||||
@@ -149,7 +164,7 @@ class BaseLoader<T> implements ILoader<T> {
|
|||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run():Void {
|
private function buildUrl():String {
|
||||||
var u:String = url;
|
var u:String = url;
|
||||||
if (data != null && method == URLRequestMethod.GET) {
|
if (data != null && method == URLRequestMethod.GET) {
|
||||||
var a:Array<String> = [];
|
var a:Array<String> = [];
|
||||||
@@ -158,7 +173,11 @@ class BaseLoader<T> implements ILoader<T> {
|
|||||||
}
|
}
|
||||||
u += "?" + a.join("&");
|
u += "?" + a.join("&");
|
||||||
}
|
}
|
||||||
internalRequest(prepareUrl(u));
|
return prepareUrl(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run():Void {
|
||||||
|
internalRequest(buildUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class BaseMediaLoader<T> extends BaseLoader<T> {
|
|||||||
loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
|
loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
|
||||||
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
|
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
|
||||||
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||||
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
|
||||||
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ class BaseMediaLoader<T> extends BaseLoader<T> {
|
|||||||
loader.contentLoaderInfo.removeEventListener(Event.INIT, onInit);
|
loader.contentLoaderInfo.removeEventListener(Event.INIT, onInit);
|
||||||
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
|
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
|
||||||
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);
|
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||||
loader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
loader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
|
||||||
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||||
#if flash try { loader.close(); } catch (error:Dynamic) {} #end
|
#if flash try { loader.close(); } catch (error:Dynamic) {} #end
|
||||||
loader = null;
|
loader = null;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class BaseURLLoader<T> extends BaseLoader<T> {
|
|||||||
loader.dataFormat = dataFormat;
|
loader.dataFormat = dataFormat;
|
||||||
loader.addEventListener(Event.COMPLETE, onComplete);
|
loader.addEventListener(Event.COMPLETE, onComplete);
|
||||||
loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||||
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
|
||||||
loader.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
loader.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ class BaseURLLoader<T> extends BaseLoader<T> {
|
|||||||
if (loader != null) {
|
if (loader != null) {
|
||||||
loader.removeEventListener(Event.COMPLETE, onComplete);
|
loader.removeEventListener(Event.COMPLETE, onComplete);
|
||||||
loader.removeEventListener(IOErrorEvent.IO_ERROR, onError);
|
loader.removeEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||||
loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
|
||||||
loader.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
loader.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||||
try { loader.close(); } catch (error:Dynamic) {}
|
try { loader.close(); } catch (error:Dynamic) {}
|
||||||
loader = null;
|
loader = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user