• R/O
  • HTTP
  • SSH
  • HTTPS

automap: Commit

Automap (OSS) GIT software repository


Commit MetaInfo

Revision0d9295b369e57cad2d4b2a6bfbb1b000fe7c57d0 (tree)
Time2020-06-05 13:33:35
Authormelchior <melchior@user...>
Commitermelchior

Log Message

Bodged in Translocator Coordinates

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,61 @@
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+ public BlockPosJson(BlockPos orig) : base(x: orig.X, y: orig.Y, z: orig.Z)
16+ {
17+ }
18+
19+
20+ }
21+
22+ /// <summary>
23+ /// How JSON object conversion should be done for special formatting
24+ /// </summary>
25+ public class BlockPosConverter : JsonConverter
26+ {
27+ public override bool CanConvert(Type objectType)
28+ {
29+ return objectType == typeof(BlockPosJson);
30+ }
31+
32+ public override bool CanRead {
33+ get
34+ {
35+ return false;
36+ }
37+ }
38+
39+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
40+ {
41+ throw new NotImplementedException( );
42+ }
43+
44+ public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
45+ {
46+ if (value != null) {
47+ BlockPosJson bpj = value as BlockPosJson;
48+
49+ writer.WriteStartArray( );
50+ writer.WriteValue(bpj.X);
51+ writer.WriteValue(bpj.Y);
52+ writer.WriteValue(bpj.Z);
53+ writer.WriteEndArray( );
54+ }
55+ else writer.WriteNull( );
56+
57+ }
58+
59+ }
60+}
61+
--- 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