From 00c120f5a080322ccfdc83687accb00ec2b8bffb Mon Sep 17 00:00:00 2001 From: melchior Date: Mon, 23 Dec 2019 17:42:02 -0500 Subject: [PATCH] re-load partial map metadata --- Automap/Automap_Internals.cs | 85 ++++++++++++++++++++++++++++++++++++++++---- Automap/Data/ColumnMeta.cs | 10 +++++- Automap/Data/Designator.cs | 2 +- 3 files changed, 89 insertions(+), 8 deletions(-) diff --git a/Automap/Automap_Internals.cs b/Automap/Automap_Internals.cs index a8e140e..498ead3 100644 --- a/Automap/Automap_Internals.cs +++ b/Automap/Automap_Internals.cs @@ -6,6 +6,8 @@ using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; +using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Web.UI; @@ -52,6 +54,7 @@ namespace Automap chunkTopMetadata = new ColumnsMetadata(startChunkColumn); Logger.Notification("AUTOMAP Start {0}", startChunkColumn); + Reload_Metadata( ); ClientAPI.Event.ChunkDirty += ChunkAChanging; @@ -141,6 +144,7 @@ namespace Automap } if (updatedChunks > 0) { + //TODO: ONLY update if chunk bounds have changed! lastUpdate = updatedChunks; GenerateMapHTML( ); updatedChunks = 0; @@ -405,13 +409,26 @@ namespace Automap // Tooltip text tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltiptext"); tableWriter.RenderBeginTag(HtmlTextWriterTag.Span); - tableWriter.WriteEncodedText($"{meta.Location.PrettyCoords(ClientAPI)} "+ - $" Max-Height: {meta.YMax}, Temp: {meta.Temperature.ToString("F1")}" - ); - tableWriter.RenderEndTag( );// - + StringBuilder tooltipText = new StringBuilder( ); + tooltipText.Append($"{meta.Location.PrettyCoords(ClientAPI)} "); + tooltipText.Append($" Max-Height: {meta.YMax}, Temp: {meta.Temperature.ToString("F1")} " ); + tooltipText.Append($" Rainfall: {meta.Rainfall.ToString("F1")}, "); + tooltipText.Append($" Shrubs: {meta.ShrubDensity.ToString("F1")}, "); + tooltipText.Append($" Forest: {meta.ForestDensity.ToString("F1")}, "); + tooltipText.Append($" Fertility: {meta.Fertility.ToString("F1")}, "); + if (meta.RockRatio != null) { + foreach (KeyValuePair blockID in meta.RockRatio) { + var block = ClientAPI.World.GetBlock(blockID.Key); + tooltipText.AppendFormat(" {0} × {1},\t", block.Code.GetName( ), meta.RockRatio[blockID.Key]); + } + } + + tableWriter.WriteEncodedText(tooltipText.ToString() ); + + tableWriter.RenderEndTag( );// + tableWriter.RenderEndTag( );// --tooltip enclosure } @@ -488,14 +505,70 @@ namespace Automap mapChunk.YMax, mostActiveCol.Key.Y * ClientAPI.World.BlockAccessor.ChunkSize); - var climate = ClientAPI.World.BlockAccessor.GetClimateAt(equivBP); + var climate = ClientAPI.World.BlockAccessor.GetClimateAt(equivBP); data.Temperature = climate.Temperature; + data.Fertility = climate.Fertility; + data.ForestDensity = climate.ForestDensity; + data.Rainfall = climate.Rainfall; + data.ShrubDensity = climate.ShrubDensity; + data.YMax = mapChunk.YMax; + + /* Only present on server.... + if (mapChunk.TopRockIdMap != null) { + foreach (var topRockId in mapChunk.TopRockIdMap) { + + if (data.RockRatio.ContainsKey(topRockId)) { data.RockRatio[topRockId]++; } + else { data.RockRatio.Add(topRockId, 1); } + } + }*/ return data; } + + /// + /// Reload chunk bounds from chunk shards + /// + /// The metadata. + private void Reload_Metadata( ) + { + string chunkFile_filter = @"*_*.png"; + Regex chunkShardRegex = new Regex(@"(?[\d]+)_(?[\d]+).png", RegexOptions.Singleline); + + var worldmapDir = new DirectoryInfo(path); + + if (worldmapDir.Exists) { + + var files = worldmapDir.GetFiles(chunkFile_filter); + + if (files.Length > 0) { + #if DEBUG + Logger.VerboseDebug("{0} Existing world chunk shards", files.Length); + #endif + + foreach (var shardFile in files) { + var result = chunkShardRegex.Match(shardFile.Name); + if (result.Success) { + int X_chunk_pos = int.Parse(result.Groups["X"].Value ); + int Z_chunk_pos = int.Parse(result.Groups["Z"].Value ); + //TODO: METADATA from shard + chunkTopMetadata.Add(new ColumnMeta(new Vec2i(X_chunk_pos, Z_chunk_pos))); + } + } + + } + } + else { + #if DEBUG + Logger.VerboseDebug("Could not open world map directory"); + #endif + } + + + + } } } \ No newline at end of file diff --git a/Automap/Data/ColumnMeta.cs b/Automap/Data/ColumnMeta.cs index 8f886d8..30ca868 100644 --- a/Automap/Data/ColumnMeta.cs +++ b/Automap/Data/ColumnMeta.cs @@ -12,8 +12,12 @@ namespace Automap { public Vec2i Location; public float Temperature;// Temperature - public int YMax;// Y feature height + public ushort YMax;// Y feature height public Dictionary RockRatio;//(surface) Geographic region (rock) Ratio. [BlockID * count] + public float Fertility; + public float ForestDensity; + public float Rainfall; + public float ShrubDensity; public ColumnMeta(Vec2i loc) { @@ -21,6 +25,10 @@ namespace Automap Temperature = 0f; YMax = 0; RockRatio = new Dictionary( 10 ); + Fertility = 0f; + ForestDensity = 0f; + Rainfall = 0f; + ShrubDensity = 0f; } } diff --git a/Automap/Data/Designator.cs b/Automap/Data/Designator.cs index 207bede..c2d36b3 100644 --- a/Automap/Data/Designator.cs +++ b/Automap/Data/Designator.cs @@ -43,7 +43,7 @@ namespace Automap public override string ToString( ) { - return Pattern.ToShortString() +"-"+ OverwriteColor.Name + "-" + Material ?? ""; + return Pattern.ToShortString() +"|"+ OverwriteColor.Name + "|" + Material ?? ""; } } } -- 2.11.0