From de7bd6de8cb8d82d5afdefc808076abce3bc507c Mon Sep 17 00:00:00 2001 From: Julian Silden Langlo Date: Sun, 7 Nov 2021 23:37:50 +0100 Subject: [PATCH] Update Text renderer. --- TravellerRenderer/TextRenderer.cs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/TravellerRenderer/TextRenderer.cs b/TravellerRenderer/TextRenderer.cs index bd9ab23b7..7c8d9aa94 100644 --- a/TravellerRenderer/TextRenderer.cs +++ b/TravellerRenderer/TextRenderer.cs @@ -1,4 +1,6 @@ -namespace TravellerRenderer; +using System.Text; + +namespace TravellerRenderer; public class TextRenderer { public static string Name = "Text Grid Renderer"; @@ -32,11 +34,11 @@ public static async Task RenderWorldsTwoLine(List worlds, int X1, var offset = 1 + i % 2; for (int j = 0; j < rows; i++) { - var world = worlds[0]; // Replace with LINQ query that gets world with matching position. - world ??= {" ", "____"}; - var parts = WorldToTwoStrings(world); - parts[i*2+offset].Append(parts[0]+@"\") - parts[i*2+offset+1].Append(parts[1]+"/") + var world = (from entry in worlds where (entry.Position == new Position(X1 + i, Y1 + j)) select entry).FirstOrDefault(); + + var worldParts = WorldToTwoStrings(world); + parts[i * 2 + offset].Append(worldParts[0] + @"\"); + parts[i * 2 + offset + 1].Append(worldParts[1] + "/"); } } @@ -63,7 +65,15 @@ public static async Task RenderWorldsFourLine(List worlds, int X, public static List WorldToTwoStrings(World world) { - var strings = new List(4); + var strings = new List(2); + + if (world == null) + { + strings.Add(" "); + strings.Add("____"); + return strings; + } + // Lines are 4 characters each. For the lowest line, if they're used the underlines disappear. var gasGiant = world.GasGiants > 0 ? 'G' : ' ';