OSDN Git Service

48769572434baf7968c46d43803fe96b944793e6
[automap/automap.git] / Automap / Data / PointOfInterest.cs
1 using System;
2 using System.Collections.ObjectModel;
3 using System.IO;
4 using Vintagestory.API.Client;
5 using Vintagestory.API.Common;
6 using Vintagestory.API.MathTools;
7
8 namespace Automap
9 {
10         /// <summary>
11         /// Actual Physical Point in space - that is interesting.
12         /// </summary>
13         public struct PointOfInterest
14         {
15                 [DisplayName(1, "Notes")]
16                 public string Notes;
17                 [DisplayName(0, "Loc.")]
18                 public BlockPos Location;
19                 [DisplayName(2, "Time")]
20                 public DateTimeOffset Timestamp;
21                 public void Write(StreamWriter stream, ICoreClientAPI ClientApi)
22                 {
23                         // this is gross i hate this
24                         stream.Write("['{0}_{1}',[",
25                                 Location.X,
26                                 Location.Y
27                                 );
28                         stream.Write("'{0}',", Location.PrettyCoords(ClientApi));
29                         stream.Write("'{0}',", System.Web.HttpUtility.HtmlEncode(Notes).Replace("\n", "&#13;&#10;").Replace("\\","\\\\"));
30                         stream.Write("'{0}',", Timestamp);
31                         stream.Write("]]");
32                 }
33         }
34
35         public class PointsOfInterest : KeyedCollection<BlockPos, PointOfInterest>
36         {
37                 protected override BlockPos GetKeyForItem(PointOfInterest item)
38                         => item.Location;
39
40                 internal void AddReplace(PointOfInterest poi)
41                 {
42                         if (Contains(poi.Location))
43                                 Remove(poi.Location);
44
45                         Add(poi);
46                 }
47         }
48
49 }
50