From e93b2a0ba4ada9b87fa260b061703240454d829b Mon Sep 17 00:00:00 2001 From: "marcin.sciesinski" Date: Wed, 16 Oct 2019 23:03:43 -0700 Subject: [PATCH] Replaced all text rendering with textBox --- .../lotro/images/recipe/JSONImageRecipe.java | 40 +- .../src/main/resources/cardRecipe.json | 680 +++++++++--------- 2 files changed, 380 insertions(+), 340 deletions(-) diff --git a/gemp-lotr/gemp-lotr-images/src/main/java/com/gempukku/lotro/images/recipe/JSONImageRecipe.java b/gemp-lotr/gemp-lotr-images/src/main/java/com/gempukku/lotro/images/recipe/JSONImageRecipe.java index 617ac454a..95250812b 100644 --- a/gemp-lotr/gemp-lotr-images/src/main/java/com/gempukku/lotro/images/recipe/JSONImageRecipe.java +++ b/gemp-lotr/gemp-lotr-images/src/main/java/com/gempukku/lotro/images/recipe/JSONImageRecipe.java @@ -75,15 +75,6 @@ public class JSONImageRecipe implements ImageRecipe { }); }, x, y, width, height); - } else if (type.equalsIgnoreCase("text")) { - Function font = createFontProvider(jsonLayer.get("font")); - Function paint = createPaintProvider(jsonLayer.get("paint"), "black"); - final Function text = createStringProvider(jsonLayer.get("text")); - Function textBox = createTextBoxProvider(jsonLayer.get("box")); - Function dropShadow = createBooleanProvider(jsonLayer.get("dropShadow"), false); - - return new TextLayerRecipe( - font, text, paint, textBox, dropShadow); } else if (type.equalsIgnoreCase("textBox")) { final Function text = createStringArrayProvider(jsonLayer.get("text")); JSONObject object = (JSONObject) jsonLayer.get("font"); @@ -96,7 +87,7 @@ public class JSONImageRecipe implements ImageRecipe { Function> fontStyleProvider = map::get; Function textBox = createTextBoxProvider(jsonLayer.get("box")); - final Function minYStart = createFloatProvider(jsonLayer.get("minYStart")); + final Function minYStart = createFloatProvider(jsonLayer.get("minYStart"), 1f); Map yShiftsMap = (JSONObject) jsonLayer.get("yShifts"); return new TextBoxLayerRecipe( @@ -136,18 +127,14 @@ public class JSONImageRecipe implements ImageRecipe { if (value instanceof JSONObject) { JSONObject valueObj = (JSONObject) value; final String type = (String) valueObj.get("type"); - if (type.equalsIgnoreCase("appendText")) { - final JSONArray values = (JSONArray) valueObj.get("values"); - final List> list = (List>) values.stream().map(text -> createStringProvider(text)).collect(toList()); + if (type.equalsIgnoreCase("string")) { + final Function stringProvider = createStringProvider(valueObj.get("value")); return renderContext -> { - StringBuilder sb = new StringBuilder(); - for (Function valueProvider : list) { - final String textValue = valueProvider.apply(renderContext); - if (textValue != null) - sb.append(textValue); - } - return new String[]{sb.toString()}; + final String stringValue = stringProvider.apply(renderContext); + if (stringValue == null) + return new String[0]; + return new String[]{stringValue}; }; } else if (type.equalsIgnoreCase("append")) { final JSONArray values = (JSONArray) valueObj.get("values"); @@ -318,6 +305,19 @@ public class JSONImageRecipe implements ImageRecipe { return renderContext -> renderContext.getProperties().getProperty( propertyName.apply(renderContext)); + } else if (type.equalsIgnoreCase("appendText")) { + final JSONArray values = (JSONArray) stringObj.get("values"); + final List> list = (List>) values.stream().map(text -> createStringProvider(text)).collect(toList()); + + return renderContext -> { + StringBuilder sb = new StringBuilder(); + for (Function valueProvider : list) { + final String textValue = valueProvider.apply(renderContext); + if (textValue != null) + sb.append(textValue); + } + return sb.toString(); + }; } else if (type.equalsIgnoreCase("map")) { final Function key = createStringProvider(stringObj.get("key")); Map map = (Map) stringObj.get("map"); diff --git a/gemp-lotr/gemp-lotr-images/src/main/resources/cardRecipe.json b/gemp-lotr/gemp-lotr-images/src/main/resources/cardRecipe.json index 9f6e16e7b..1abb50858 100644 --- a/gemp-lotr/gemp-lotr-images/src/main/resources/cardRecipe.json +++ b/gemp-lotr/gemp-lotr-images/src/main/resources/cardRecipe.json @@ -134,34 +134,39 @@ "name": "isCharacter" }, "values": { - "type": "text", + "type": "textBox", "font": { - "type": "ttf", - "path": { - "type": "resolve", - "parent": { - "type": "property", - "name": "lotro.resources.folder" + "default": { + "type": "ttf", + "path": { + "type": "resolve", + "parent": { + "type": "property", + "name": "lotro.resources.folder" + }, + "child": { + "type": "property", + "name": "title.font" + } }, - "child": { + "size": { "type": "property", - "name": "title.font" - } - }, - "size": { - "type": "property", - "name": "title.size" - }, - "style": 0 + "name": "title.size" + }, + "style": 0 + } }, "text": { - "type": "replace", - "source": { - "type": "cardProperty", - "name": "title" - }, - "match": "*", - "with": "•" + "type": "string", + "value": { + "type": "replace", + "source": { + "type": "cardProperty", + "name": "title" + }, + "match": "*", + "with": "•" + } }, "box": { "type": "box", @@ -191,36 +196,41 @@ "true": 35, "false": 50 }, - "y": 600, + "y": 570, "layer": { - "type": "text", + "type": "textBox", "font": { - "type": "ttf", - "path": { - "type": "resolve", - "parent": { - "type": "property", - "name": "lotro.resources.folder" + "default": { + "type": "ttf", + "path": { + "type": "resolve", + "parent": { + "type": "property", + "name": "lotro.resources.folder" + }, + "child": { + "type": "property", + "name": "title.font" + } }, - "child": { + "size": { "type": "property", - "name": "title.font" - } - }, - "size": { - "type": "property", - "name": "title.size" - }, - "style": 0 + "name": "title.size" + }, + "style": 0 + } }, "text": { - "type": "replace", - "source": { - "type": "cardProperty", - "name": "title" - }, - "match": "*", - "with": "•" + "type": "string", + "value": { + "type": "replace", + "source": { + "type": "cardProperty", + "name": "title" + }, + "match": "*", + "with": "•" + } }, "box": { "type": "box", @@ -233,8 +243,8 @@ "true": 35, "false": 50 }, - "y": 600, - "width": 440, + "y": 570, + "width": 410, "height": 70, "horAlign": "right" } @@ -249,29 +259,34 @@ "name": "isCharacter" }, "values": { - "type": "text", + "type": "textBox", "font": { - "type": "ttf", - "path": { - "type": "resolve", - "parent": { - "type": "property", - "name": "lotro.resources.folder" + "default": { + "type": "ttf", + "path": { + "type": "resolve", + "parent": { + "type": "property", + "name": "lotro.resources.folder" + }, + "child": { + "type": "property", + "name": "subtitle.font" + } }, - "child": { + "size": { "type": "property", - "name": "subtitle.font" - } - }, - "size": { - "type": "property", - "name": "subtitle.size" - }, - "style": 0 + "name": "subtitle.size" + }, + "style": 0 + } }, "text": { - "type": "cardProperty", - "name": "subtitle" + "type": "string", + "value": { + "type": "cardProperty", + "name": "subtitle" + } }, "box": { "type": "box", @@ -295,29 +310,34 @@ "x": 65, "y": 600, "layer": { - "type": "text", + "type": "textBox", "font": { - "type": "ttf", - "path": { - "type": "resolve", - "parent": { - "type": "property", - "name": "lotro.resources.folder" + "default": { + "type": "ttf", + "path": { + "type": "resolve", + "parent": { + "type": "property", + "name": "lotro.resources.folder" + }, + "child": { + "type": "property", + "name": "subtitle.font" + } }, - "child": { + "size": { "type": "property", - "name": "subtitle.font" - } - }, - "size": { - "type": "property", - "name": "subtitle.size" - }, - "style": 0 + "name": "subtitle.size" + }, + "style": 0 + } }, "text": { - "type": "cardProperty", - "name": "subtitle" + "type": "string", + "value": { + "type": "cardProperty", + "name": "subtitle" + } }, "box": { "type": "box", @@ -332,31 +352,36 @@ }, { "comment": "Cost", - "type": "text", + "type": "textBox", "paint": "white", "dropShadow": true, "font": { - "type": "ttf", - "path": { - "type": "resolve", - "parent": { - "type": "property", - "name": "lotro.resources.folder" + "default": { + "type": "ttf", + "path": { + "type": "resolve", + "parent": { + "type": "property", + "name": "lotro.resources.folder" + }, + "child": { + "type": "property", + "name": "numbers.font" + } }, - "child": { + "size": { "type": "property", - "name": "numbers.font" - } - }, - "size": { - "type": "property", - "name": "numbers.size" - }, - "style": 0 + "name": "numbers.size" + }, + "style": 0 + } }, "text": { - "type": "cardProperty", - "name": "cost" + "type": "string", + "value": { + "type": "cardProperty", + "name": "cost" + } }, "box": { "type": "box", @@ -377,73 +402,76 @@ "values": { "type": "textBox", "text": { - "type": "appendText", - "values": [ - { - "comment": "Card type", - "type": "capitalize", - "value": { - "type": "cardProperty", - "name": "type" - } - }, - { - "comment": "Race", - "type": "optional", - "condition": { - "type": "cardHasProperty", - "name": "race" + "type": "string", + "value": { + "type": "appendText", + "values": [ + { + "comment": "Card type", + "type": "capitalize", + "value": { + "type": "cardProperty", + "name": "type" + } }, - "value": { - "type": "append", - "values": [ - " [bullet]•[/bullet] ", - { - "type": "capitalize", - "value": { - "type": "cardProperty", - "name": "race" + { + "comment": "Race", + "type": "optional", + "condition": { + "type": "cardHasProperty", + "name": "race" + }, + "value": { + "type": "append", + "values": [ + " [bullet]•[/bullet] ", + { + "type": "capitalize", + "value": { + "type": "cardProperty", + "name": "race" + } } - } - ] - } - }, - { - "comment": "Location", - "type": "optional", - "condition": { - "type": "cardHasPropertyValueIn", - "name": "keyword", - "values": [ - "lothlorien", - "rivendell", - "bree", - "edoras", - "shire" - ] + ] + } }, - "value": { - "type": "append", - "values": [ - " [bullet]•[/bullet] ", - { - "type": "capitalize", - "value": { - "type": "cardPropertyValueIn", - "name": "keyword", - "values": [ - "lothlorien", - "rivendell", - "bree", - "edoras", - "shire" - ] + { + "comment": "Location", + "type": "optional", + "condition": { + "type": "cardHasPropertyValueIn", + "name": "keyword", + "values": [ + "lothlorien", + "rivendell", + "bree", + "edoras", + "shire" + ] + }, + "value": { + "type": "append", + "values": [ + " [bullet]•[/bullet] ", + { + "type": "capitalize", + "value": { + "type": "cardPropertyValueIn", + "name": "keyword", + "values": [ + "lothlorien", + "rivendell", + "bree", + "edoras", + "shire" + ] + } } - } - ] + ] + } } - } - ] + ] + } }, "font": { "default": { @@ -507,102 +535,105 @@ "values": { "type": "textBox", "text": { - "type": "appendText", - "values": [ - { - "comment": "Card type", - "type": "capitalize", - "value": { - "type": "cardProperty", - "name": "type" - } - }, - { - "comment": "Race", - "type": "optional", - "condition": { - "type": "cardHasProperty", - "name": "race" + "type": "string", + "value": { + "type": "appendText", + "values": [ + { + "comment": "Card type", + "type": "capitalize", + "value": { + "type": "cardProperty", + "name": "type" + } }, - "value": { - "type": "append", - "values": [ - " [bullet]•[/bullet] ", - { - "type": "capitalize", - "value": { - "type": "cardProperty", - "name": "race" + { + "comment": "Race", + "type": "optional", + "condition": { + "type": "cardHasProperty", + "name": "race" + }, + "value": { + "type": "append", + "values": [ + " [bullet]•[/bullet] ", + { + "type": "capitalize", + "value": { + "type": "cardProperty", + "name": "race" + } } - } - ] - } - }, - { - "comment": "Possession class", - "type": "optional", - "condition": { - "type": "cardHasProperty", - "name": "possession" + ] + } }, - "value": { - "type": "append", - "values": [ - " [bullet]•[/bullet] ", - { - "type": "capitalize", - "value": { - "type": "cardProperty", - "name": "possession" + { + "comment": "Possession class", + "type": "optional", + "condition": { + "type": "cardHasProperty", + "name": "possession" + }, + "value": { + "type": "append", + "values": [ + " [bullet]•[/bullet] ", + { + "type": "capitalize", + "value": { + "type": "cardProperty", + "name": "possession" + } } - } - ] - } - }, - { - "comment": "Type keyword", - "type": "optional", - "condition": { - "type": "cardHasPropertyValueIn", - "name": "keyword", - "values": [ - "fellowship", - "shadow", - "maneuver", - "archery", - "assignment", - "skirmish", - "regroup", - "response", - "support area" - ] + ] + } }, - "value": { - "type": "append", - "values": [ - " [bullet]•[/bullet] ", - { - "type": "capitalize", - "value": { - "type": "cardPropertyValueIn", - "name": "keyword", - "values": [ - "fellowship", - "shadow", - "maneuver", - "archery", - "assignment", - "skirmish", - "regroup", - "response", - "support area" - ] + { + "comment": "Type keyword", + "type": "optional", + "condition": { + "type": "cardHasPropertyValueIn", + "name": "keyword", + "values": [ + "fellowship", + "shadow", + "maneuver", + "archery", + "assignment", + "skirmish", + "regroup", + "response", + "support area" + ] + }, + "value": { + "type": "append", + "values": [ + " [bullet]•[/bullet] ", + { + "type": "capitalize", + "value": { + "type": "cardPropertyValueIn", + "name": "keyword", + "values": [ + "fellowship", + "shadow", + "maneuver", + "archery", + "assignment", + "skirmish", + "regroup", + "response", + "support area" + ] + } } - } - ] + ] + } } - } - ] + ] + } }, "font": { "default": { @@ -686,33 +717,36 @@ "paint": "white", "dropShadow": true, "text": { - "type": "appendText", - "values": [ - { - "type": "optional", - "condition": { - "type": "cardHasProperty", - "name": "target" - }, - "value": { + "type": "string", + "value": { + "type": "appendText", + "values": [ + { "type": "optional", "condition": { - "type": "cardPropertyGreaterThanZero", + "type": "cardHasProperty", + "name": "target" + }, + "value": { + "type": "optional", + "condition": { + "type": "cardPropertyGreaterThanZero", + "name": "strength" + }, + "value": "[symbol]+[/symbol]" + } + }, + { + "type": "replace", + "source": { + "type": "cardProperty", "name": "strength" }, - "value": "[symbol]+[/symbol]" + "match": "-", + "with": "[symbol]-[/symbol]" } - }, - { - "type": "replace", - "source": { - "type": "cardProperty", - "name": "strength" - }, - "match": "-", - "with": "[symbol]-[/symbol]" - } - ] + ] + } }, "font": { "default": { @@ -800,33 +834,36 @@ "paint": "white", "dropShadow": true, "text": { - "type": "appendText", - "values": [ - { - "type": "optional", - "condition": { - "type": "cardHasProperty", - "name": "target" - }, - "value": { + "type": "string", + "value": { + "type": "appendText", + "values": [ + { "type": "optional", "condition": { - "type": "cardPropertyGreaterThanZero", + "type": "cardHasProperty", + "name": "target" + }, + "value": { + "type": "optional", + "condition": { + "type": "cardPropertyGreaterThanZero", + "name": "vitality" + }, + "value": "[symbol]+[/symbol]" + } + }, + { + "type": "replace", + "source": { + "type": "cardProperty", "name": "vitality" }, - "value": "[symbol]+[/symbol]" + "match": "-", + "with": "[symbol]-[/symbol]" } - }, - { - "type": "replace", - "source": { - "type": "cardProperty", - "name": "vitality" - }, - "match": "-", - "with": "[symbol]-[/symbol]" - } - ] + ] + } }, "font": { "default": { @@ -914,33 +951,36 @@ "paint": "white", "dropShadow": true, "text": { - "type": "appendText", - "values": [ - { - "type": "optional", - "condition": { - "type": "cardHasProperty", - "name": "target" - }, - "value": { + "type": "string", + "value": { + "type": "appendText", + "values": [ + { "type": "optional", "condition": { - "type": "cardPropertyGreaterThanZero", + "type": "cardHasProperty", + "name": "target" + }, + "value": { + "type": "optional", + "condition": { + "type": "cardPropertyGreaterThanZero", + "name": "resistance" + }, + "value": "[symbol]+[/symbol]" + } + }, + { + "type": "replace", + "source": { + "type": "cardProperty", "name": "resistance" }, - "value": "[symbol]+[/symbol]" + "match": "-", + "with": "[symbol]-[/symbol]" } - }, - { - "type": "replace", - "source": { - "type": "cardProperty", - "name": "resistance" - }, - "match": "-", - "with": "[symbol]-[/symbol]" - } - ] + ] + } }, "font": { "default": {