Fix incorrect .tmx parsing of TextObject

This commit is contained in:
Daniel Cronqvist 2025-04-26 21:37:25 +02:00
parent d86ad2dc10
commit 26a179efb7

View file

@ -242,15 +242,15 @@ public abstract partial class TmxReaderBase
internal TextObject ReadTextObject() internal TextObject ReadTextObject()
{ {
// Attributes // Attributes
var fontFamily = _reader.GetOptionalAttribute("fontfamily") ?? "sans-serif"; var fontFamily = _reader.GetOptionalAttribute("fontfamily").GetValueOr("sans-serif");
var pixelSize = _reader.GetOptionalAttributeParseable<int>("pixelsize") ?? 16; var pixelSize = _reader.GetOptionalAttributeParseable<int>("pixelsize").GetValueOr(16);
var wrap = _reader.GetOptionalAttributeParseable<bool>("wrap") ?? false; var wrap = _reader.GetOptionalAttributeParseable<int>("wrap").GetValueOr(0) == 1;
var color = _reader.GetOptionalAttributeClass<TiledColor>("color") ?? TiledColor.Parse("#000000", CultureInfo.InvariantCulture); var color = _reader.GetOptionalAttributeClass<TiledColor>("color").GetValueOr(TiledColor.Parse("#000000", CultureInfo.InvariantCulture));
var bold = _reader.GetOptionalAttributeParseable<bool>("bold") ?? false; var bold = _reader.GetOptionalAttributeParseable<int>("bold").GetValueOr(0) == 1;
var italic = _reader.GetOptionalAttributeParseable<bool>("italic") ?? false; var italic = _reader.GetOptionalAttributeParseable<int>("italic").GetValueOr(0) == 1;
var underline = _reader.GetOptionalAttributeParseable<bool>("underline") ?? false; var underline = _reader.GetOptionalAttributeParseable<int>("underline").GetValueOr(0) == 1;
var strikeout = _reader.GetOptionalAttributeParseable<bool>("strikeout") ?? false; var strikeout = _reader.GetOptionalAttributeParseable<int>("strikeout").GetValueOr(0) == 1;
var kerning = _reader.GetOptionalAttributeParseable<bool>("kerning") ?? true; var kerning = _reader.GetOptionalAttributeParseable<int>("kerning").GetValueOr(1) == 1;
var hAlign = _reader.GetOptionalAttributeEnum<TextHorizontalAlignment>("halign", s => s switch var hAlign = _reader.GetOptionalAttributeEnum<TextHorizontalAlignment>("halign", s => s switch
{ {
"left" => TextHorizontalAlignment.Left, "left" => TextHorizontalAlignment.Left,
@ -258,14 +258,14 @@ public abstract partial class TmxReaderBase
"right" => TextHorizontalAlignment.Right, "right" => TextHorizontalAlignment.Right,
"justify" => TextHorizontalAlignment.Justify, "justify" => TextHorizontalAlignment.Justify,
_ => throw new InvalidOperationException($"Unknown horizontal alignment '{s}'") _ => throw new InvalidOperationException($"Unknown horizontal alignment '{s}'")
}) ?? TextHorizontalAlignment.Left; }).GetValueOr(TextHorizontalAlignment.Left);
var vAlign = _reader.GetOptionalAttributeEnum<TextVerticalAlignment>("valign", s => s switch var vAlign = _reader.GetOptionalAttributeEnum<TextVerticalAlignment>("valign", s => s switch
{ {
"top" => TextVerticalAlignment.Top, "top" => TextVerticalAlignment.Top,
"center" => TextVerticalAlignment.Center, "center" => TextVerticalAlignment.Center,
"bottom" => TextVerticalAlignment.Bottom, "bottom" => TextVerticalAlignment.Bottom,
_ => throw new InvalidOperationException($"Unknown vertical alignment '{s}'") _ => throw new InvalidOperationException($"Unknown vertical alignment '{s}'")
}) ?? TextVerticalAlignment.Top; }).GetValueOr(TextVerticalAlignment.Top);
// Elements // Elements
var text = _reader.ReadElementContentAsString("text", ""); var text = _reader.ReadElementContentAsString("text", "");