From 62212ee5fcf9e7b00bba51bab1a1351b22515648 Mon Sep 17 00:00:00 2001 From: The Grand Dog Date: Wed, 26 Feb 2020 11:36:45 -0500 Subject: [PATCH] replaced the static static map with dynamic static map :) --- Automap/Data/EntitiesOfInterest.cs | 46 ++--- Automap/Data/EntityDesignator.cs | 28 ++- Automap/Data/PointOfInterest.cs | 21 +-- Automap/Designators/DefaultDesignators.cs | 12 +- Automap/Subsystems/AutomapSystem.cs | 216 ++--------------------- Automap/assets/automap/config/automap.html | 143 +++++++++++++++ Automap/assets/automap/config/automap_format.css | 75 -------- 7 files changed, 200 insertions(+), 341 deletions(-) create mode 100644 Automap/assets/automap/config/automap.html delete mode 100644 Automap/assets/automap/config/automap_format.css diff --git a/Automap/Data/EntitiesOfInterest.cs b/Automap/Data/EntitiesOfInterest.cs index 72b9f3e..ddb4053 100644 --- a/Automap/Data/EntitiesOfInterest.cs +++ b/Automap/Data/EntitiesOfInterest.cs @@ -5,46 +5,38 @@ using System.Collections.ObjectModel; using System.Linq; using Vintagestory.API.Common.Entities; +using Vintagestory.API.MathTools; namespace Automap { /// + /// Actual Physical Point in space - that is interesting. + /// + public struct EntityOfInterest + { + public string Notes; + public BlockPos Location; + public DateTimeOffset Timestamp; + public long EntityId; + } + + /// /// Entities of interest. /// /// Tracked by ID - these never leave. - public class EntitiesOfInterest + public class EntitiesOfInterest : KeyedCollection { - private Dictionary entitySet = new Dictionary(50); - - internal void Upsert(Entity something, string message = @"") + internal void AddReplace(EntityOfInterest entity) { - if (entitySet.ContainsKey(something.EntityId)) - { - var movingPOI = entitySet[something.EntityId]; - movingPOI.Location = something.Pos.AsBlockPos.Copy(); - movingPOI.Timestamp = DateTimeOffset.UtcNow; - } - else - { - PointOfInterest newPOI = new PointOfInterest(); - newPOI.EntityId = something.EntityId; - newPOI.Location = something.Pos.AsBlockPos.Copy(); - newPOI.Timestamp = DateTimeOffset.UtcNow; - newPOI.Notes = message; - entitySet.Add(something.EntityId, newPOI); - } - - } + if (Contains(entity.EntityId)) + Remove(entity.EntityId); - - public List PointsList - { - get { - return entitySet.Values.ToList(); - } + Add(entity); } + protected override long GetKeyForItem(EntityOfInterest item) + => item.EntityId; } } diff --git a/Automap/Data/EntityDesignator.cs b/Automap/Data/EntityDesignator.cs index 82b1e25..9939446 100644 --- a/Automap/Data/EntityDesignator.cs +++ b/Automap/Data/EntityDesignator.cs @@ -17,7 +17,7 @@ namespace Automap /// public class EntityDesignator { - public Color OverwriteColor; + public Color Color; public EntityDesignatonAction SpecialAction; public AssetLocation Pattern; public EnumEntityState? StateCheck;//Needed? @@ -28,27 +28,25 @@ namespace Automap throw new NotSupportedException(); } - public EntityDesignator(AssetLocation pattern, Color overwriteColor, EnumEntityState? state) + public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state) { - this.Pattern = pattern; - this.OverwriteColor = overwriteColor; - this.StateCheck = state; - this.Enabled = true; + Pattern = pattern; + Color = color; + StateCheck = state; + Enabled = true; } - public EntityDesignator(AssetLocation pattern, Color overwriteColor, EnumEntityState? state, EntityDesignatonAction specialAct) + public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state, EntityDesignatonAction specialAct) { - this.Pattern = pattern; - this.OverwriteColor = overwriteColor; - this.StateCheck = state; - this.SpecialAction = specialAct; - this.Enabled = true; + Pattern = pattern; + Color = color; + StateCheck = state; + SpecialAction = specialAct; + Enabled = true; } public override string ToString() - { - return Pattern.ToShortString() + "|" + OverwriteColor.Name + "|" + StateCheck ?? ""; - } + => Pattern.ToShortString() + "|" + Color.Name + "|" + StateCheck ?? ""; } } diff --git a/Automap/Data/PointOfInterest.cs b/Automap/Data/PointOfInterest.cs index f7bd258..b19335d 100644 --- a/Automap/Data/PointOfInterest.cs +++ b/Automap/Data/PointOfInterest.cs @@ -14,30 +14,21 @@ namespace Automap public string Notes; public BlockPos Location; public DateTimeOffset Timestamp; - public long? EntityId; } public class PointsOfInterest : KeyedCollection { protected override BlockPos GetKeyForItem(PointOfInterest item) - { - return item.Location; - } + => item.Location; internal void AddReplace(PointOfInterest poi) { - if (this.Contains(poi.Location)) - { - this.Remove(poi.Location); - this.Add(poi); - } - else - { - this.Add(poi); - } + if (Contains(poi.Location)) + Remove(poi.Location); - } - } + Add(poi); + } + } } diff --git a/Automap/Designators/DefaultDesignators.cs b/Automap/Designators/DefaultDesignators.cs index 19b448e..2329be1 100644 --- a/Automap/Designators/DefaultDesignators.cs +++ b/Automap/Designators/DefaultDesignators.cs @@ -133,13 +133,19 @@ namespace Automap { clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn); - var message = $"{entity.GetName()}"; var traderJoe = entity as EntityTrader; + var message = $"{entity.GetName()} Alive: {traderJoe.Alive}"; if (traderJoe.TradeProps != null) { - message = $"{traderJoe.GetName()} Alive:{traderJoe.Alive} - Gears: {traderJoe.TradeProps.Money}, "; + message += $" - Gears: {traderJoe.TradeProps.Money}, "; } - poi.Upsert(entity, message); + poi.AddReplace(new EntityOfInterest + { + Location = posn.Copy(), + Notes = message, + Timestamp = DateTimeOffset.UtcNow, + EntityId = entity.EntityId + }); } internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block) diff --git a/Automap/Subsystems/AutomapSystem.cs b/Automap/Subsystems/AutomapSystem.cs index 1606656..17a68e4 100644 --- a/Automap/Subsystems/AutomapSystem.cs +++ b/Automap/Subsystems/AutomapSystem.cs @@ -52,7 +52,7 @@ namespace Automap private readonly int chunkSize; private string path; - private IAsset stylesFile; + private IAsset staticMap; public static string AutomapStatusEventKey = @"AutomapStatus"; public static string AutomapCommandEventKey = @"AutomapCommand"; @@ -80,8 +80,13 @@ namespace Automap path = ClientAPI.GetOrCreateDataPath(_mapPath); path = ClientAPI.GetOrCreateDataPath(Path.Combine(path, "World_" + ClientAPI.World.Seed));//Add name of World too...'ServerApi.WorldManager.CurrentWorldName' - stylesFile = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap_format.css")); - Logger.VerboseDebug("CSS loaded: {0} size: {1}", stylesFile.IsLoaded(), stylesFile.ToText().Length); + + string mapFilename = Path.Combine(path, "automap.html"); + StreamWriter outputText = new StreamWriter(File.Open(mapFilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)); + + staticMap = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap.html")); + outputText.Write(staticMap.ToText()); + outputText.Flush(); Prefill_POI_Designators(); startChunkColumn = new Vec2i((ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.X / chunkSize), (ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Z / chunkSize)); @@ -200,7 +205,6 @@ namespace Automap { //What about chunk updates themselves; a update bitmap isn't kept... updatedChunksTotal += updatedChunks; - GenerateMapHTML(); GenerateJSONMetadata(); updatedChunks = 0; } @@ -284,208 +288,8 @@ namespace Automap } - - private void GenerateMapHTML() - { - string mapFilename = Path.Combine(path, "Automap.html"); - - int TopNorth = chunkTopMetadata.North_mostChunk; - int TopSouth = chunkTopMetadata.South_mostChunk; - int TopEast = chunkTopMetadata.East_mostChunk; - int TopWest = chunkTopMetadata.West_mostChunk; - - using (StreamWriter outputText = new StreamWriter(File.Open(mapFilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))) - { - using (HtmlTextWriter tableWriter = new HtmlTextWriter(outputText)) - { - tableWriter.BeginRender(); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Html); - - tableWriter.RenderBeginTag(HtmlTextWriterTag.Head); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Title); - tableWriter.WriteEncodedText("Generated Automap"); - tableWriter.RenderEndTag(); - //CSS style here - tableWriter.RenderBeginTag(HtmlTextWriterTag.Style); - tableWriter.Write(stylesFile.ToText()); - tableWriter.RenderEndTag();// - - tableWriter.RenderEndTag(); - - tableWriter.RenderBeginTag(HtmlTextWriterTag.Body); - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); - tableWriter.WriteEncodedText($"Created {DateTimeOffset.UtcNow.ToString("u")}"); - tableWriter.RenderEndTag(); - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); - tableWriter.WriteEncodedText($"W:{TopWest}, E: {TopEast}, N:{TopNorth}, S:{TopSouth} "); - tableWriter.RenderEndTag(); - tableWriter.WriteLine(); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Table); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Caption); - tableWriter.WriteEncodedText($"Start: {startChunkColumn}, Seed: {ClientAPI.World.Seed}\n"); - tableWriter.RenderEndTag(); - - //################ X-Axis ####################### - tableWriter.RenderBeginTag(HtmlTextWriterTag.Thead); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); - - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); - tableWriter.Write("N, W"); - tableWriter.RenderEndTag(); - - for (int xAxisT = TopWest; xAxisT <= TopEast; xAxisT++) - { - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); - tableWriter.Write(xAxisT); - tableWriter.RenderEndTag(); - } - - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); - tableWriter.Write("N, E"); - tableWriter.RenderEndTag(); - - tableWriter.RenderEndTag(); - tableWriter.RenderEndTag(); - //###### ################################ - - //###### - Chunk rows & Y-axis cols - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tbody); - - //######## for every vertical row - for (int yAxis = TopNorth; yAxis <= TopSouth; yAxis++) - { - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); - tableWriter.Write(yAxis);//legend: Y-axis - tableWriter.RenderEndTag(); - - for (int xAxis = TopWest; xAxis <= TopEast; xAxis++) - { - //###### #### for chunk shard - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); - var colLoc = new Vec2i(xAxis, yAxis); - if (chunkTopMetadata.Contains(colLoc)) - { - ColumnMeta meta = chunkTopMetadata[colLoc]; - //Tooltip first - tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltip"); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Div); - - tableWriter.AddAttribute(HtmlTextWriterAttribute.Src, $"{xAxis}_{yAxis}.png"); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Img); - tableWriter.RenderEndTag(); - // Tooltip text - tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltiptext"); - tableWriter.RenderBeginTag(HtmlTextWriterTag.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 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 - } - else - { - tableWriter.Write("?"); - } - - tableWriter.RenderEndTag(); - }//############ ########### - - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); - tableWriter.Write(yAxis);//legend: Y-axis - tableWriter.RenderEndTag(); - - tableWriter.RenderEndTag(); - - } - tableWriter.RenderEndTag(); - - //################ X-Axis ####################### - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tfoot); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); - - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); - tableWriter.Write("S, W"); - tableWriter.RenderEndTag(); - - for (int xAxisB = TopWest; xAxisB <= TopEast; xAxisB++) - { - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); - tableWriter.Write(xAxisB); - tableWriter.RenderEndTag(); - } - - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); - tableWriter.Write("S, E"); - tableWriter.RenderEndTag(); - - tableWriter.RenderEndTag(); - tableWriter.RenderEndTag(); - //###### ################################ - - - tableWriter.RenderEndTag();// - - //############## POI list ##################### - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); - tableWriter.WriteLine("Points of Interest"); - tableWriter.RenderEndTag(); - tableWriter.RenderBeginTag(HtmlTextWriterTag.Ul); - foreach (var poi in this.POIs) - { - tableWriter.RenderBeginTag(HtmlTextWriterTag.Li); - tableWriter.WriteEncodedText(poi.Location.PrettyCoords(this.ClientAPI) + "\t"); - tableWriter.WriteEncodedText(poi.Notes + "\t"); - tableWriter.WriteEncodedText(poi.Timestamp.ToString("u")); - tableWriter.RenderEndTag(); - } - - foreach (var eoi in this.EOIs.PointsList) - { - tableWriter.RenderBeginTag(HtmlTextWriterTag.Li); - tableWriter.WriteEncodedText(eoi.Location.PrettyCoords(this.ClientAPI) + "\t"); - tableWriter.WriteEncodedText(eoi.Notes + "\t"); - tableWriter.WriteEncodedText(eoi.Timestamp.ToString("u")); - tableWriter.RenderEndTag(); - } - - tableWriter.RenderEndTag(); - - - - - tableWriter.RenderEndTag();//### ### - - tableWriter.EndRender(); - tableWriter.Flush(); - } - outputText.Flush(); - } - - Logger.VerboseDebug("Generated HTML map"); - } - /// - /// Generates the JSON Metadata. (in MAP object format ) + /// Generates the JSON Metadata. (in Map object format ) /// private void GenerateJSONMetadata() { @@ -538,7 +342,7 @@ namespace Automap jsonWriter.Write("}],"); } - foreach (var poi in EOIs.PointsList) + foreach (var poi in EOIs) { jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Z); jsonWriter.Write("{"); diff --git a/Automap/assets/automap/config/automap.html b/Automap/assets/automap/config/automap.html new file mode 100644 index 0000000..ad5ec0b --- /dev/null +++ b/Automap/assets/automap/config/automap.html @@ -0,0 +1,143 @@ + + + + + + Automap + + + + +
+

Chunk Info

+
+
+ + + + \ No newline at end of file diff --git a/Automap/assets/automap/config/automap_format.css b/Automap/assets/automap/config/automap_format.css deleted file mode 100644 index 9fe8ce9..0000000 --- a/Automap/assets/automap/config/automap_format.css +++ /dev/null @@ -1,75 +0,0 @@ -table { -border: 1px solid black; -border-collapse: collapse; -} - -thead tr th { -max-width:32px; -margin: 0px; -padding: 0px; -overflow:hidden; -border-right: 1px solid black; -border-bottom: 1px solid black; -font-size:8pt; -font-weight:bold; -font-family: Monospace; -} - -tfoot tr td { -max-width: 32px; -padding: 0px; -overflow:hidden; -border-right: 1px solid black; -border-top: 1px solid black; -font-size:8pt; -font-weight:bold; -font-family: Monospace; -} - -tbody tr { -max-height:32px; -padding: 0px; -overflow:hidden; -} - -tbody td { -padding: 0px; -border: 0px none black; -max-width: 32px; -background-color: white; -width:32px; -font-size: 6pt; -} - -/* Tooltip container */ -.tooltip { -position: relative; -display: inline-block; -} - -/* Tooltip text */ -.tooltip .tooltiptext { -visibility: hidden; -background-color: black; -color: #fff; -text-align: center; -padding: 5px 0; -position: absolute; -z-index: 1; -} - -/* Show the tooltip text when you mouse over the tooltip container */ -.tooltip:hover .tooltiptext { -left: 33px; -top: 33px; -opacity: 0.75; -position: absolute; -visibility: visible; -min-width: 120px; -box-shadow: 5px 5px 8px 12px black; -} - -.tooltip img:hover { -outline: 1px dashed orange; -opacity: 0.9; -} -- 2.11.0