From fd4c16439c44311f1a396a5a236dafa49dd2c87d Mon Sep 17 00:00:00 2001 From: ABKQPO <93412322+ABKQPO@users.noreply.github.com> Date: Mon, 5 Oct 2026 05:54:58 +0800 Subject: [PATCH] Fix numeric parsing issues --- .../guidenh/guide/compiler/tags/MdxAttrs.java | 16 +++++++++---- .../guide/compiler/tags/RecipeCompiler.java | 6 ++--- .../compiler/tags/chart/ChartAttrParser.java | 2 +- .../functiongraph/FunctionGraphAttrs.java | 24 +++++++++---------- .../guidenh/guide/scene/SceneTagCompiler.java | 6 ++--- .../StructureLibSceneConditionParser.java | 2 +- .../ImportStructureElementCompiler.java | 9 +++---- .../scene/element/WeatherElementCompiler.java | 6 ++--- .../compiler/QuestCardCompiler.java | 2 +- 9 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/MdxAttrs.java b/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/MdxAttrs.java index 309bee910..29cf839ea 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/MdxAttrs.java +++ b/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/MdxAttrs.java @@ -148,14 +148,22 @@ public static float getFloat(MdxJsxElementFields el, String name, float defaultV public static int getInt(PageCompiler compiler, LytErrorSink errorSink, MdxJsxElementFields el, String name, int defaultValue) { - var attrValue = getString(compiler, errorSink, el, name, null); - if (attrValue == null) { + var attribute = el.getAttribute(name); + if (attribute == null) { + return defaultValue; + } + String attrValue; + if (attribute.hasExpressionValue()) { + attrValue = attribute.getExpressionValue(); + } else if (attribute.hasStringValue()) { + attrValue = attribute.getStringValue(); + } else { return defaultValue; } try { - return Integer.parseInt(attrValue); + return Integer.parseInt(attrValue.trim()); } catch (NumberFormatException e) { - errorSink.appendError(compiler, "Malformed integer value: '" + attrValue + "'", el); + errorSink.appendError(compiler, "Malformed integer for '" + name + "': '" + attrValue + "'", el); return defaultValue; } } diff --git a/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/RecipeCompiler.java b/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/RecipeCompiler.java index e85e1ca08..7dce43aef 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/RecipeCompiler.java +++ b/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/RecipeCompiler.java @@ -72,7 +72,7 @@ protected void compile(PageCompiler compiler, LytBlockContainer parent, MdxJsxEl MdxAttrs.getString(compiler, parent, el, "handlerWhitelist", null)); List handlerBlacklist = parseNameList( MdxAttrs.getString(compiler, parent, el, "handlerBlacklist", null)); - String handlerOrderStr = MdxAttrs.getString(compiler, parent, el, "handlerOrder", null); + String handlerOrderStr = el.getAttributeString("handlerOrder", null); int handlerOrder = -1; if (handlerOrderStr != null && !handlerOrderStr.isEmpty()) { try { @@ -82,7 +82,7 @@ protected void compile(PageCompiler compiler, LytBlockContainer parent, MdxJsxEl return; } } - String recipeIndexStr = MdxAttrs.getString(compiler, parent, el, "recipeIndex", null); + String recipeIndexStr = el.getAttributeString("recipeIndex", null); int exactRecipeIndex = -1; if (recipeIndexStr != null && !recipeIndexStr.isEmpty()) { try { @@ -100,7 +100,7 @@ protected void compile(PageCompiler compiler, LytBlockContainer parent, MdxJsxEl FilterExpr inputExpr = parseFilterExpr(compiler, parent, el, "input", defaultNs); FilterExpr outputExpr = parseFilterExpr(compiler, parent, el, "output", defaultNs); - String limitStr = MdxAttrs.getString(compiler, parent, el, "limit", null); + String limitStr = el.getAttributeString("limit", null); int limit = multi ? Integer.MAX_VALUE : 1; if (limitStr != null && !limitStr.isEmpty()) { try { diff --git a/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/chart/ChartAttrParser.java b/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/chart/ChartAttrParser.java index 8dba99f89..262e6fe0b 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/chart/ChartAttrParser.java +++ b/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/chart/ChartAttrParser.java @@ -199,7 +199,7 @@ public static CornerLegendPosition parseCornerLegendPosition(String s, CornerLeg * Parse a boxed {@link Double}; null means "auto". */ public static Double parseBoxedDouble(MdxJsxElementFields el, String name) { - String s = MdxAttrs.getString(el, name, null); + String s = el.getAttributeString(name, null); if (s == null) { return null; } diff --git a/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/functiongraph/FunctionGraphAttrs.java b/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/functiongraph/FunctionGraphAttrs.java index 9f2df599c..90876ec4e 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/functiongraph/FunctionGraphAttrs.java +++ b/src/main/java/com/hfstudio/guidenh/guide/compiler/tags/functiongraph/FunctionGraphAttrs.java @@ -84,8 +84,8 @@ public static void applyRange(LytFunctionGraph graph, PageCompiler compiler, Lyt } else { String domain = MdxAttrs.getString(compiler, sink, el, "domain", null); double[] domainRange = domain != null ? parseRange(domain) : null; - double xMin = parseDouble(MdxAttrs.getString(compiler, sink, el, "xMin", null), Double.NaN); - double xMax = parseDouble(MdxAttrs.getString(compiler, sink, el, "xMax", null), Double.NaN); + double xMin = parseDouble(el.getAttributeString("xMin", null), Double.NaN); + double xMax = parseDouble(el.getAttributeString("xMax", null), Double.NaN); if (domainRange != null && Double.isNaN(xMin) && Double.isNaN(xMax)) { xMin = domainRange[0]; xMax = domainRange[1]; @@ -99,17 +99,17 @@ public static void applyRange(LytFunctionGraph graph, PageCompiler compiler, Lyt double[] r = parseRange(yRange); graph.setExplicitYRange(r[0], r[1]); } else { - double yMin = parseDouble(MdxAttrs.getString(compiler, sink, el, "yMin", null), Double.NaN); - double yMax = parseDouble(MdxAttrs.getString(compiler, sink, el, "yMax", null), Double.NaN); + double yMin = parseDouble(el.getAttributeString("yMin", null), Double.NaN); + double yMax = parseDouble(el.getAttributeString("yMax", null), Double.NaN); if (!Double.isNaN(yMin) || !Double.isNaN(yMax)) { graph.setExplicitYRange(yMin, yMax); } } - double xStep = parseDouble(MdxAttrs.getString(compiler, sink, el, "xStep", null), Double.NaN); + double xStep = parseDouble(el.getAttributeString("xStep", null), Double.NaN); if (!Double.isNaN(xStep)) { graph.setExplicitXStep(xStep); } - double yStep = parseDouble(MdxAttrs.getString(compiler, sink, el, "yStep", null), Double.NaN); + double yStep = parseDouble(el.getAttributeString("yStep", null), Double.NaN); if (!Double.isNaN(yStep)) { graph.setExplicitYStep(yStep); } @@ -136,8 +136,8 @@ public static FunctionPlot parsePlot(PageCompiler compiler, LytErrorSink sink, M boolean showFunction = MdxAttrs.getBoolean(compiler, sink, el, "showFunction", true); boolean showValues = MdxAttrs.getBoolean(compiler, sink, el, "showValues", true); AutoPointSpec autoPointSpec = parseAutoPointSpec( - MdxAttrs.getString(compiler, sink, el, "pointEveryX", null), - MdxAttrs.getString(compiler, sink, el, "pointEveryY", null), + el.getAttributeString("pointEveryX", null), + el.getAttributeString("pointEveryY", null), MdxAttrs.getString(compiler, sink, el, "autoPointLabel", null), MdxAttrs.getString(compiler, sink, el, "autoPointColor", null), color); @@ -162,16 +162,16 @@ public static MarkedPoint parsePoint(PageCompiler compiler, LytErrorSink sink, M : ColorUtils.WHITE.getColor(); String label = MdxAttrs.getString(compiler, sink, el, "label", null); - double xValue = parseDouble(MdxAttrs.getString(compiler, sink, el, "x", null), Double.NaN); - double yValue = parseDouble(MdxAttrs.getString(compiler, sink, el, "y", null), Double.NaN); + double xValue = parseDouble(el.getAttributeString("x", null), Double.NaN); + double yValue = parseDouble(el.getAttributeString("y", null), Double.NaN); if (!Double.isNaN(xValue) && !Double.isNaN(yValue)) { return new MarkedPoint(MarkedPoint.MODE_EXPLICIT, -1, xValue, yValue, color, false, label); } int plotIndex = MdxAttrs.getInt(compiler, sink, el, "plot", -1); if (plotIndex >= 0) { - double atX = parseDouble(MdxAttrs.getString(compiler, sink, el, "atX", null), Double.NaN); - double atY = parseDouble(MdxAttrs.getString(compiler, sink, el, "atY", null), Double.NaN); + double atX = parseDouble(el.getAttributeString("atX", null), Double.NaN); + double atY = parseDouble(el.getAttributeString("atY", null), Double.NaN); if (!Double.isNaN(atX)) { return new MarkedPoint(MarkedPoint.MODE_PLOT_AT_X, plotIndex, atX, 0d, color, colorInherit, label); } diff --git a/src/main/java/com/hfstudio/guidenh/guide/scene/SceneTagCompiler.java b/src/main/java/com/hfstudio/guidenh/guide/scene/SceneTagCompiler.java index 4183bdea0..e2faf77e2 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/scene/SceneTagCompiler.java +++ b/src/main/java/com/hfstudio/guidenh/guide/scene/SceneTagCompiler.java @@ -87,10 +87,8 @@ public void onExtensionsBuilt(ExtensionCollection extensions) { @Override protected void compile(PageCompiler compiler, LytBlockContainer parent, MdxJsxElementFields el) { // Width and height - String rawWidth = MdxAttrs.getString(compiler, parent, el, "width", null); - String rawHeight = MdxAttrs.getString(compiler, parent, el, "height", null); - boolean explicitWidth = rawWidth != null; - boolean explicitHeight = rawHeight != null; + boolean explicitWidth = el.getAttribute("width") != null; + boolean explicitHeight = el.getAttribute("height") != null; int w = MdxAttrs.getInt(compiler, parent, el, "width", DEFAULT_WIDTH); int h = MdxAttrs.getInt(compiler, parent, el, "height", DEFAULT_HEIGHT); diff --git a/src/main/java/com/hfstudio/guidenh/guide/scene/StructureLibSceneConditionParser.java b/src/main/java/com/hfstudio/guidenh/guide/scene/StructureLibSceneConditionParser.java index 6a959f0d9..8bf33d0a5 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/scene/StructureLibSceneConditionParser.java +++ b/src/main/java/com/hfstudio/guidenh/guide/scene/StructureLibSceneConditionParser.java @@ -15,7 +15,7 @@ private StructureLibSceneConditionParser() {} public static StructureLibSceneCondition parse(PageCompiler compiler, LytErrorSink errorSink, MdxJsxElementFields element) { String structureName = MdxAttrs.getString(compiler, errorSink, element, "showWhenStructure", null); - String tierExpression = MdxAttrs.getString(compiler, errorSink, element, "showWhenTier", null); + String tierExpression = element.getAttributeString("showWhenTier", null); String channelExpression = MdxAttrs.getString(compiler, errorSink, element, "showWhenChannels", null); try { return StructureLibSceneCondition.parse(structureName, tierExpression, channelExpression); diff --git a/src/main/java/com/hfstudio/guidenh/guide/scene/element/ImportStructureElementCompiler.java b/src/main/java/com/hfstudio/guidenh/guide/scene/element/ImportStructureElementCompiler.java index 292f10b5a..10a331ac9 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/scene/element/ImportStructureElementCompiler.java +++ b/src/main/java/com/hfstudio/guidenh/guide/scene/element/ImportStructureElementCompiler.java @@ -102,14 +102,11 @@ public void compile(GuidebookLevel level, CameraSettings camera, PageCompiler co } } - int offsetX = MdxAttrs.getString(compiler, errorSink, el, "offsetX", null) != null - ? MdxAttrs.getInt(compiler, errorSink, el, "offsetX", 0) + int offsetX = el.getAttribute("offsetX") != null ? MdxAttrs.getInt(compiler, errorSink, el, "offsetX", 0) : MdxAttrs.getInt(compiler, errorSink, el, "x", 0); - int offsetY = MdxAttrs.getString(compiler, errorSink, el, "offsetY", null) != null - ? MdxAttrs.getInt(compiler, errorSink, el, "offsetY", 0) + int offsetY = el.getAttribute("offsetY") != null ? MdxAttrs.getInt(compiler, errorSink, el, "offsetY", 0) : MdxAttrs.getInt(compiler, errorSink, el, "y", 0); - int offsetZ = MdxAttrs.getString(compiler, errorSink, el, "offsetZ", null) != null - ? MdxAttrs.getInt(compiler, errorSink, el, "offsetZ", 0) + int offsetZ = el.getAttribute("offsetZ") != null ? MdxAttrs.getInt(compiler, errorSink, el, "offsetZ", 0) : MdxAttrs.getInt(compiler, errorSink, el, "z", 0); boolean formed = SceneStructureOptions.isFormed(compiler, errorSink, el); diff --git a/src/main/java/com/hfstudio/guidenh/guide/scene/element/WeatherElementCompiler.java b/src/main/java/com/hfstudio/guidenh/guide/scene/element/WeatherElementCompiler.java index 98a17ff40..1b8821b36 100644 --- a/src/main/java/com/hfstudio/guidenh/guide/scene/element/WeatherElementCompiler.java +++ b/src/main/java/com/hfstudio/guidenh/guide/scene/element/WeatherElementCompiler.java @@ -37,10 +37,8 @@ public void compile(GuidebookLevel level, CameraSettings camera, PageCompiler co weatherName = MdxAttrs.getString(compiler, errorSink, el, "type", "rain"); } GuidebookSceneWeatherType weatherType = GuidebookSceneWeatherType.fromSerializedName(weatherName); - int[] xValues = GuidebookSceneWeatherSupport - .parseAxisValues(MdxAttrs.getString(compiler, errorSink, el, "x", null)); - int[] zValues = GuidebookSceneWeatherSupport - .parseAxisValues(MdxAttrs.getString(compiler, errorSink, el, "z", null)); + int[] xValues = GuidebookSceneWeatherSupport.parseAxisValues(el.getAttributeString("x", null)); + int[] zValues = GuidebookSceneWeatherSupport.parseAxisValues(el.getAttributeString("z", null)); int density = Math.max( 1, MdxAttrs diff --git a/src/main/java/com/hfstudio/guidenh/integration/betterquesting/compiler/QuestCardCompiler.java b/src/main/java/com/hfstudio/guidenh/integration/betterquesting/compiler/QuestCardCompiler.java index bf2ac1a2c..a1a4680e9 100644 --- a/src/main/java/com/hfstudio/guidenh/integration/betterquesting/compiler/QuestCardCompiler.java +++ b/src/main/java/com/hfstudio/guidenh/integration/betterquesting/compiler/QuestCardCompiler.java @@ -39,7 +39,7 @@ protected void compile(PageCompiler compiler, LytBlockContainer parent, MdxJsxEl parent.appendError(compiler, "QuestCard id is not a valid BetterQuesting quest id: " + idAttr, el); return; } - boolean showDesc = !"false".equalsIgnoreCase(MdxAttrs.getString(compiler, parent, el, "show_desc", "true")); + boolean showDesc = MdxAttrs.getBoolean(compiler, parent, el, "show_desc", true); boolean showTooltip = QuestTagSupport.resolveShowTooltip(compiler, parent, el); QuestCardPlaceholder ph = new QuestCardPlaceholder(questId, showDesc, showTooltip);