OSDN Git Service

re-load partial map metadata
authormelchior <melchior@users.osdn.me>
Mon, 23 Dec 2019 22:42:02 +0000 (17:42 -0500)
committermelchior <melchior@users.osdn.me>
Mon, 23 Dec 2019 22:42:02 +0000 (17:42 -0500)
Automap/Automap_Internals.cs
Automap/Data/ColumnMeta.cs
Automap/Data/Designator.cs

index a8e140e..498ead3 100644 (file)
@@ -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
                // <span class="tooltiptext">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( );//</span>
 
-               
+               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<int, uint> 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( );//</span>
+                                                                               
 
                tableWriter.RenderEndTag( );//</div> --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;
                }
+
+               /// <summary>
+               /// Reload chunk bounds from chunk shards
+               /// </summary>
+               /// <returns>The metadata.</returns>
+               private void Reload_Metadata( )
+               {
+               string chunkFile_filter = @"*_*.png";
+               Regex chunkShardRegex = new Regex(@"(?<X>[\d]+)_(?<Z>[\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
index 8f886d8..30ca868 100644 (file)
@@ -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<int,uint> 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<int, uint>( 10 );
+               Fertility = 0f;
+               ForestDensity = 0f;
+               Rainfall = 0f;
+               ShrubDensity = 0f;
                }
        }
 
index 207bede..c2d36b3 100644 (file)
@@ -43,7 +43,7 @@ namespace Automap
 
                public override string ToString( )
                {
-                       return Pattern.ToShortString() +"-"+ OverwriteColor.Name + "-" + Material ?? "";
+                       return Pattern.ToShortString() +"|"+ OverwriteColor.Name + "|" + Material ?? "";
                }
        }
 }