OSDN Git Service

fully implement the most advanced version of the map so far
[automap/automap.git] / Automap / Data / PointOfInterest.cs
index 15fdda8..4876957 100644 (file)
@@ -1,5 +1,7 @@
 using System;
-
+using System.Collections.ObjectModel;
+using System.IO;
+using Vintagestory.API.Client;
 using Vintagestory.API.Common;
 using Vintagestory.API.MathTools;
 
@@ -10,10 +12,38 @@ namespace Automap
        /// </summary>
        public struct PointOfInterest
        {
-               CollectibleObject Thing;
-               string Notes;
-               BlockPos Location;
-               DateTimeOffset Timestamp;
+               [DisplayName(1, "Notes")]
+               public string Notes;
+               [DisplayName(0, "Loc.")]
+               public BlockPos Location;
+               [DisplayName(2, "Time")]
+               public DateTimeOffset Timestamp;
+               public void Write(StreamWriter stream, ICoreClientAPI ClientApi)
+               {
+                       // this is gross i hate this
+                       stream.Write("['{0}_{1}',[",
+                               Location.X,
+                               Location.Y
+                               );
+                       stream.Write("'{0}',", Location.PrettyCoords(ClientApi));
+                       stream.Write("'{0}',", System.Web.HttpUtility.HtmlEncode(Notes).Replace("\n", "&#13;&#10;").Replace("\\","\\\\"));
+                       stream.Write("'{0}',", Timestamp);
+                       stream.Write("]]");
+               }
+       }
+
+       public class PointsOfInterest : KeyedCollection<BlockPos, PointOfInterest>
+       {
+               protected override BlockPos GetKeyForItem(PointOfInterest item)
+                       => item.Location;
+
+               internal void AddReplace(PointOfInterest poi)
+               {
+                       if (Contains(poi.Location))
+                               Remove(poi.Location);
+
+                       Add(poi);
+               }
        }
 
 }