change type field to @type

This commit is contained in:
2015-08-05 15:40:36 +03:00
parent 2669e56e06
commit 56d8509f8a
2 changed files with 23 additions and 23 deletions

View File

@@ -1,50 +1,50 @@
{ {
"type":"haxework.gui.VGroupView", "@type":"haxework.gui.VGroupView",
"paddings":20, "paddings":20,
"layoutMargin":10, "layoutMargin":10,
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"}, "skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"},
"views":[ "views":[
{ {
"type":"haxework.gui.SpriteView", "@type":"haxework.gui.SpriteView",
"pWidth":100, "pWidth":100,
"pHeight":100, "pHeight":100,
"leftMargin":5, "leftMargin":5,
"rightMargin":10, "rightMargin":10,
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"} "skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"}
}, },
{ {
"type":"haxework.gui.SpriteView", "@type":"haxework.gui.SpriteView",
"vAlign":"BOTTOM", "vAlign":"BOTTOM",
"width":50, "width":50,
"height":50, "height":50,
"leftMargin":5, "leftMargin":5,
"rightMargin":10, "rightMargin":10,
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x0000ff"} "skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0x0000ff"}
}, },
{ {
"id":"panel", "id":"panel",
"type":"haxework.gui.HGroupView", "@type":"haxework.gui.HGroupView",
"layoutHAlign":"RIGHT", "layoutHAlign":"RIGHT",
"pWidth":100, "pWidth":100,
"height":30, "height":30,
"paddings":3, "paddings":3,
"layoutMargin":3, "layoutMargin":3,
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xffff00"}, "skin":{"@type":"haxework.gui.skin.ColorSkin", "color":"0xffff00"},
"views":[ "views":[
{ {
"id":"button1", "id":"button1",
"type":"haxework.gui.ButtonView", "@type":"haxework.gui.ButtonView",
"width":100, "width":100,
"pHeight":100, "pHeight":100,
"skin":{"type":"haxework.gui.skin.ButtonColorSkin", "color":"0xcc0000"}, "skin":{"@type":"haxework.gui.skin.ButtonColorSkin", "color":"0xcc0000"},
"text":"Text1", "text":"Text1",
"onPress":"@link:listener" "onPress":"@link:listener"
}, },
{ {
"id":"button2", "id":"button2",
"type":"haxework.gui.ButtonView", "@type":"haxework.gui.ButtonView",
"contentSize":true, "contentSize":true,
"skin":{"type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cc00"}, "skin":{"@type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cc00"},
"text":"Text2", "text":"Text2",
"fontFamily":"Georgia", "fontFamily":"Georgia",
"fontColor":"0xffffff", "fontColor":"0xffffff",
@@ -52,9 +52,9 @@
}, },
{ {
"id":"button3", "id":"button3",
"type":"haxework.gui.ButtonView", "@type":"haxework.gui.ButtonView",
"contentSize":true, "contentSize":true,
"skin":{"type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cccc"}, "skin":{"@type":"haxework.gui.skin.ButtonColorSkin", "color":"0x00cccc"},
"text":"Text 3333333333 ddd", "text":"Text 3333333333 ddd",
"fontFamily":"Tahoma", "fontFamily":"Tahoma",
"fontColor":"0xff0000", "fontColor":"0xff0000",

View File

@@ -90,14 +90,14 @@ class Builder {
} else if (Std.is(value, Float) || (Std.is(value, Bool))) { } else if (Std.is(value, Float) || (Std.is(value, Bool))) {
value; value;
} else if (value != null) { } else if (value != null) {
if (Reflect.hasField(value, "type")) { if (Reflect.hasField(value, "@type")) {
var n = "a" + i++; var n = "a" + i++;
var type = Reflect.field(value, "type"); var type = Reflect.field(value, "@type");
exprs.push(Context.parse("var " + n + " = new " + type + "()", getPosition(position))); exprs.push(Context.parse("var " + n + " = new " + type + "()", getPosition(position)));
createElement(value, n); createElement(value, n);
n; n;
} else { } else {
Context.error("Need type field", getPosition(position)); Context.error("Need @type field", getPosition(position));
null; null;
} }
} else { } else {
@@ -106,8 +106,8 @@ class Builder {
} }
private function createElement(template:Dynamic, name:String):String { private function createElement(template:Dynamic, name:String):String {
if (Reflect.hasField(template, "style")) { if (Reflect.hasField(template, "@style")) {
var s = Reflect.field(style, Reflect.field(template, "style")); var s = Reflect.field(style, Reflect.field(template, "@style"));
for (key in Reflect.fields(s)) { for (key in Reflect.fields(s)) {
if (key.charAt(0) != "$" && !Reflect.hasField(template, key)) { if (key.charAt(0) != "$" && !Reflect.hasField(template, key)) {
Reflect.setField(template, key, Reflect.field(s, key)); Reflect.setField(template, key, Reflect.field(s, key));
@@ -118,9 +118,9 @@ class Builder {
if (Reflect.hasField(template, "id")) { if (Reflect.hasField(template, "id")) {
var id = Reflect.field(template, "id"); var id = Reflect.field(template, "id");
var type = Reflect.field(template, "type"); var type = Reflect.field(template, "@type");
var expr = Context.parse("var a:" + type, getPosition()); var expr = Context.parse("var a:" + type, getPosition());
var type = switch (expr.expr) { var complexType = switch (expr.expr) {
case EVars(vars): vars[0].type; case EVars(vars): vars[0].type;
case _: null; case _: null;
} }
@@ -128,13 +128,13 @@ class Builder {
name: id, name: id,
access: [APublic], access: [APublic],
pos: getPosition(), pos: getPosition(),
kind: FProp("default", "null", type) kind: FProp("default", "null", complexType)
}); });
exprs.push(Context.parse("this." + id + " = " + name, getPosition())); exprs.push(Context.parse("this." + id + " = " + name, getPosition()));
} }
for (key in Reflect.fields(template)) { for (key in Reflect.fields(template)) {
if (key.charAt(0) == "$" || ["type", "style"].indexOf(key) > -1) continue; if (key.charAt(0) == "$" || key.charAt(0) == "@") continue;
var position = Reflect.field(template, "$" + key); var position = Reflect.field(template, "$" + key);
var value = getValue(name, key, Reflect.field(template, key), position); var value = getValue(name, key, Reflect.field(template, key), position);
if (value != null) { if (value != null) {