From 9b80d545c1639ce0a1bb16d09cb0b43eaecde0dc Mon Sep 17 00:00:00 2001 From: shmyga Date: Thu, 21 May 2015 17:41:43 +0300 Subject: [PATCH] update --- haxework/gui/GuiBuilder.hx | 20 +++++++++++++++++--- haxework/gui/utils/DrawUtil.hx | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/haxework/gui/GuiBuilder.hx b/haxework/gui/GuiBuilder.hx index 8bfee6f..40b9c6a 100755 --- a/haxework/gui/GuiBuilder.hx +++ b/haxework/gui/GuiBuilder.hx @@ -27,11 +27,19 @@ import haxework.gui.skin.BitmapSkin; import haxework.gui.skin.ButtonColorSkin; import haxework.gui.skin.ButtonBitmapSkin; import haxework.gui.skin.ProgressSkin; - import haxework.frame.FrameSwitcher; class GuiBuilder { + private static var cache:Map = new Map(); + + 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 { 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 { - var form:Dynamic = Json.parse(Assets.getText(resource)); + var form:Dynamic = getResource(resource); if (key != null) form = Reflect.field(form, key); 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 { @@ -125,7 +139,7 @@ class GuiF { public function fill() { if (Reflect.hasField(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)); } } diff --git a/haxework/gui/utils/DrawUtil.hx b/haxework/gui/utils/DrawUtil.hx index b9df0eb..249e717 100755 --- a/haxework/gui/utils/DrawUtil.hx +++ b/haxework/gui/utils/DrawUtil.hx @@ -21,6 +21,7 @@ import flash.display.Graphics; class DrawUtil { 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 (clear) graphics.clear(); if (color > -1) {