• R/O
  • HTTP
  • SSH
  • HTTPS

automap: Commit

Automap (OSS) GIT software repository


Commit MetaInfo

Revisionb61b39f4fb6186af709f0ccff4f80141a86732e1 (tree)
Time2020-06-19 01:48:22
AuthorThe Grand Dog <alex.h@me.c...>
CommiterThe Grand Dog

Log Message

Merge branch 'snapshots_m' into vgd

Change Summary

Incremental Difference

--- a/Automap/Automap.csproj
+++ b/Automap/Automap.csproj
@@ -98,6 +98,7 @@
9898 <Compile Include="Data\DisplayNameAttribute.cs" />
9999 <Compile Include="Subsystems\JsonGenerator.cs" />
100100 <Compile Include="Subsystems\Snapshot.cs" />
101+ <Compile Include="Data\JSON\BlockPosJson.cs" />
101102 </ItemGroup>
102103 <ItemGroup>
103104 <Folder Include="VS_libs\" />
@@ -108,6 +109,7 @@
108109 <Folder Include="Libs\" />
109110 <Folder Include="Subsystems\" />
110111 <Folder Include="Renderers\" />
112+ <Folder Include="Data\JSON\" />
111113 </ItemGroup>
112114 <ItemGroup>
113115 <None Include="modinfo.json">
--- /dev/null
+++ b/Automap/Data/JSON/BlockPosJson.cs
@@ -0,0 +1,65 @@
1+using System;
2+
3+using Newtonsoft.Json;
4+
5+using ProtoBuf;
6+
7+using Vintagestory.API.MathTools;
8+
9+namespace Automap
10+{
11+ [JsonConverter(typeof(BlockPosConverter))]
12+ [ProtoContract]
13+ public class BlockPosJson : BlockPos
14+ {
15+
16+ public BlockPosJson( )
17+ {
18+
19+ }
20+
21+ public BlockPosJson(BlockPos orig) : base(x: orig.X, y: orig.Y, z: orig.Z)
22+ {
23+ }
24+ }
25+
26+ /// <summary>
27+ /// How JSON object conversion should be done for special formatting
28+ /// </summary>
29+ public class BlockPosConverter : JsonConverter
30+ {
31+ public override bool CanConvert(Type objectType)
32+ {
33+ return objectType == typeof(BlockPosJson);
34+ }
35+
36+ public override bool CanRead {
37+ get
38+ {
39+ return false;
40+ }
41+ }
42+
43+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
44+ {
45+ throw new NotImplementedException( );
46+ }
47+
48+ public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
49+ {
50+ if (value != null) {
51+ BlockPosJson bpj = value as BlockPosJson;
52+
53+ writer.WriteStartArray( );
54+ writer.WriteValue(bpj.X);
55+ writer.WriteValue(bpj.Y);
56+ writer.WriteValue(bpj.Z);
57+ writer.WriteEndArray( );
58+ }
59+ else writer.WriteNull( );
60+
61+ }
62+
63+ }
64+}
65+
--- a/Automap/Data/PointOfInterest.cs
+++ b/Automap/Data/PointOfInterest.cs
@@ -37,6 +37,11 @@ namespace Automap
3737 public DateTime Timestamp;
3838
3939
40+ [DisplayName(4, "Dest")]
41+ [ProtoMember(5)]
42+ public BlockPosJson Destination;
43+
44+
4045 }
4146
4247 public class PointsOfInterest : KeyedCollection<BlockPos, PointOfInterest>
--- a/Automap/Designators/DefaultDesignators.cs
+++ b/Automap/Designators/DefaultDesignators.cs
@@ -158,7 +158,9 @@ namespace Automap
158158
159159 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
160160 {
161- clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
161+ #if DEBUG
162+ clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
163+ #endif
162164 //Where to? and from!
163165
164166 BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
@@ -181,6 +183,7 @@ namespace Automap
181183 Location = posn.Copy(),
182184 Notes = textTarget.ToString(),
183185 Timestamp = DateTime.UtcNow,
186+ Destination = new BlockPosJson(te.TargetLocation)
184187 }
185188 );
186189
--- a/Automap/Subsystems/JsonGenerator.cs
+++ b/Automap/Subsystems/JsonGenerator.cs
@@ -119,7 +119,10 @@ namespace Automap
119119 jsonWriter.WriteMapTupleForeach(
120120 $"{poi.Location.X}_{poi.Location.Z}",
121121 PointsOfInterest_Vals,
122- (mem) => jsonWriter.WriteValue(GetValue(mem, poi))
122+ (mem) => {
123+ var dasField = GetValue(mem, poi);
124+ jsonWriter.WriteRawValue(JsonConvert.SerializeObject(dasField));
125+ }
123126 );
124127 });
125128 #if DEBUG
Show on old repository browser