Skip to content

Commit bc4ddb6

Browse files
fix: handle inline border defs in sand/sandstone brushes, separate error handling for brush loaders
1 parent 252011e commit bc4ddb6

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/App/BrushData.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public sealed class GroundBorderRef
7575
public int BorderId { get; set; }
7676
public string? To { get; set; } // brush name or "none"
7777
public bool Super { get; set; }
78+
/// <summary>True when this is an inline border definition (has borderitem children, no id).</summary>
79+
public bool Inline { get; set; }
80+
public ushort GroundEquivalent { get; set; }
81+
public Dictionary<string, ushort> InlineEdges { get; set; } = [];
7882
}
7983

8084
// ── Wall brush ──
@@ -249,13 +253,26 @@ private static void LoadGrounds(string path, BrushCatalog db)
249253

250254
foreach (var border in el.Elements("border"))
251255
{
252-
def.Borders.Add(new GroundBorderRef
256+
var bref = new GroundBorderRef
253257
{
254258
Align = (string?)border.Attribute("align") ?? "",
255259
BorderId = (int?)border.Attribute("id") ?? 0,
256260
To = (string?)border.Attribute("to"),
257261
Super = (string?)border.Attribute("super") == "true",
258-
});
262+
};
263+
// Handle inline border definitions (have <borderitem> children but no id)
264+
if (border.Attribute("id") == null && border.HasElements)
265+
{
266+
bref.Inline = true;
267+
bref.GroundEquivalent = (ushort?)(int?)border.Attribute("ground_equivalent") ?? 0;
268+
foreach (var bi in border.Elements("borderitem"))
269+
{
270+
var edge = (string?)bi.Attribute("edge") ?? "";
271+
var itemId = (ushort?)(int?)bi.Attribute("item") ?? 0;
272+
if (itemId > 0) bref.InlineEdges[edge] = itemId;
273+
}
274+
}
275+
def.Borders.Add(bref);
259276
}
260277

261278
foreach (var friend in el.Elements("friend"))

src/App/ViewModels/MainWindowViewModel.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,10 +2535,12 @@ private void InitializePalette()
25352535

25362536
private void LoadBrushDatabase()
25372537
{
2538+
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
2539+
var brushDir = Path.Combine(baseDir, "data", "brushes");
2540+
2541+
// Load OTB autobordering system
25382542
try
25392543
{
2540-
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
2541-
var brushDir = Path.Combine(baseDir, "data", "brushes");
25422544
var bordersPath = Path.Combine(brushDir, "borders.xml");
25432545
var groundsPath = Path.Combine(brushDir, "grounds.xml");
25442546
if (File.Exists(bordersPath) && File.Exists(groundsPath))
@@ -2547,8 +2549,15 @@ private void LoadBrushDatabase()
25472549
OnPropertyChanged(nameof(BrushDb));
25482550
AddMapLog($"Brush system loaded: {BrushDb.GroundBrushes.Count} ground brushes, {BrushDb.AutoBorders.Count} borders");
25492551
}
2552+
}
2553+
catch (Exception ex)
2554+
{
2555+
AddMapLog($"Brush system error: {ex.Message}");
2556+
}
25502557

2551-
// Load full catalog (all brush types + tilesets)
2558+
// Load full catalog (all brush types + tilesets)
2559+
try
2560+
{
25522561
if (Directory.Exists(brushDir))
25532562
{
25542563
BrushCatalog = BrushXmlLoader.LoadFromDirectory(brushDir);
@@ -2559,7 +2568,7 @@ private void LoadBrushDatabase()
25592568
}
25602569
catch (Exception ex)
25612570
{
2562-
AddMapLog($"Brush load error: {ex.Message}");
2571+
AddMapLog($"Brush catalog error: {ex.Message}");
25632572
}
25642573
}
25652574

src/OTB/BrushSystem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ private void LoadGrounds(string path)
159159
// Border rules
160160
foreach (var borderEl in el.Elements("border"))
161161
{
162+
// Skip inline border definitions (they have <borderitem> children but no id)
163+
if (borderEl.Attribute("id") == null) continue;
162164
brush.Borders.Add(new BorderBlock
163165
{
164166
IsOuter = (string?)borderEl.Attribute("align") == "outer",

0 commit comments

Comments
 (0)