This commit is contained in:
2015-05-21 17:41:43 +03:00
parent 448e48e803
commit 9b80d545c1
2 changed files with 18 additions and 3 deletions

View File

@@ -27,11 +27,19 @@ import haxework.gui.skin.BitmapSkin;
import haxework.gui.skin.ButtonColorSkin; import haxework.gui.skin.ButtonColorSkin;
import haxework.gui.skin.ButtonBitmapSkin; import haxework.gui.skin.ButtonBitmapSkin;
import haxework.gui.skin.ProgressSkin; import haxework.gui.skin.ProgressSkin;
import haxework.frame.FrameSwitcher; import haxework.frame.FrameSwitcher;
class GuiBuilder { class GuiBuilder {
private static var cache:Map<String, Dynamic> = new Map<String, Dynamic>();
private static function getResource(resource:String):Dynamic {
if (!cache.exists(resource)) {
cache.set(resource, Json.parse(Assets.getText(resource)));
}
return cache.get(resource);
}
public static function build(data:Dynamic, ?links:Dynamic):Dynamic { public static function build(data:Dynamic, ?links:Dynamic):Dynamic {
return new GuiB(data, links, data._includes).build(); return new GuiB(data, links, data._includes).build();
} }
@@ -41,10 +49,16 @@ class GuiBuilder {
} }
public static function buildFromAssets(resource:String, ?key:String = null, ?links:Dynamic = null):Dynamic { public static function buildFromAssets(resource:String, ?key:String = null, ?links:Dynamic = null):Dynamic {
var form:Dynamic = Json.parse(Assets.getText(resource)); var form:Dynamic = getResource(resource);
if (key != null) form = Reflect.field(form, key); if (key != null) form = Reflect.field(form, key);
return build(form, links); return build(form, links);
} }
public static function fillFromAssets(object:Dynamic, resource:String, ?key:String = null, ?links:Dynamic = null):Void {
var form:Dynamic = getResource(resource);
if (key != null) form = Reflect.field(form, key);
fill(object, form, links);
}
} }
class GuiB { class GuiB {
@@ -125,7 +139,7 @@ class GuiF {
public function fill() { public function fill() {
if (Reflect.hasField(data, "style")) { if (Reflect.hasField(data, "style")) {
var style = Provider.get(IResources).styles.get(Reflect.field(data, "style")); var style = Provider.get(IResources).styles.get(Reflect.field(data, "style"));
for (key in Reflect.fields(style)) { for (key in Reflect.fields(style)) if (!Reflect.hasField(data, key)) {
Reflect.setField(data, key, Reflect.field(style, key)); Reflect.setField(data, key, Reflect.field(style, key));
} }
} }

View File

@@ -21,6 +21,7 @@ import flash.display.Graphics;
class DrawUtil { class DrawUtil {
public static function draw(graphics:Graphics, image:BitmapData, rect:Rectangle, ?fillType:FillType = null, ?color:Int = -1, ?clear:Bool = true):Void { public static function draw(graphics:Graphics, image:BitmapData, rect:Rectangle, ?fillType:FillType = null, ?color:Int = -1, ?clear:Bool = true):Void {
if (image == null) return;
if (fillType == null) fillType = FillType.DEFAULT; if (fillType == null) fillType = FillType.DEFAULT;
if (clear) graphics.clear(); if (clear) graphics.clear();
if (color > -1) { if (color > -1) {