OSDN Git Service

Bodged in Translocator Coordinates
authormelchior <melchior@users.osdn.me>
Fri, 5 Jun 2020 04:33:35 +0000 (00:33 -0400)
committermelchior <melchior@users.osdn.me>
Fri, 5 Jun 2020 04:33:35 +0000 (00:33 -0400)
Automap/Automap.csproj
Automap/Data/JSON/BlockPosJson.cs [new file with mode: 0644]
Automap/Data/PointOfInterest.cs
Automap/Designators/DefaultDesignators.cs
Automap/Subsystems/JsonGenerator.cs

index 159cbab..41857e1 100644 (file)
@@ -98,6 +98,7 @@
     <Compile Include="Data\DisplayNameAttribute.cs" />
     <Compile Include="Subsystems\JsonGenerator.cs" />
        <Compile Include="Subsystems\Snapshot.cs" />
+       <Compile Include="Data\JSON\BlockPosJson.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="VS_libs\" />
     <Folder Include="Libs\" />
     <Folder Include="Subsystems\" />
     <Folder Include="Renderers\" />
+    <Folder Include="Data\JSON\" />
   </ItemGroup>
   <ItemGroup>
     <None Include="modinfo.json">
diff --git a/Automap/Data/JSON/BlockPosJson.cs b/Automap/Data/JSON/BlockPosJson.cs
new file mode 100644 (file)
index 0000000..f1879d6
--- /dev/null
@@ -0,0 +1,61 @@
+using System;
+
+using Newtonsoft.Json;
+
+using ProtoBuf;
+
+using Vintagestory.API.MathTools;
+
+namespace Automap
+{
+       [JsonConverter(typeof(BlockPosConverter))]
+       [ProtoContract]
+       public class BlockPosJson : BlockPos
+       {
+               public BlockPosJson(BlockPos orig) : base(x: orig.X, y: orig.Y, z: orig.Z)
+               {
+               }
+
+
+       }
+
+       /// <summary>
+       /// How JSON object conversion should be done for special formatting
+       /// </summary>
+       public class BlockPosConverter : JsonConverter 
+       {
+               public override bool CanConvert(Type objectType)
+               {
+               return objectType == typeof(BlockPosJson);
+               }
+
+               public override bool CanRead {
+                       get
+                       {
+                       return false;
+                       }
+               }
+
+               public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+               {
+               throw new NotImplementedException( );
+               }
+
+               public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+               {
+               if (value != null) {
+               BlockPosJson bpj = value as BlockPosJson;
+
+               writer.WriteStartArray( );
+               writer.WriteValue(bpj.X);
+               writer.WriteValue(bpj.Y);
+               writer.WriteValue(bpj.Z);
+               writer.WriteEndArray( );
+               }
+               else writer.WriteNull( );
+
+               }
+
+       }
+}
+
index 3ad779b..28bf5d8 100644 (file)
@@ -37,6 +37,11 @@ namespace Automap
                public DateTime Timestamp;
 
 
+               [DisplayName(4, "Dest")]
+               [ProtoMember(5)]
+               public BlockPosJson Destination;
+
+
        }
 
        public class PointsOfInterest : KeyedCollection<BlockPos, PointOfInterest>
index 948f6b8..7637cb2 100644 (file)
@@ -158,7 +158,9 @@ namespace Automap
 
                internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
                {
-                       clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
+               #if DEBUG
+               clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
+               #endif
                        //Where to? and from!
 
                        BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
@@ -181,6 +183,7 @@ namespace Automap
                                                                Location = posn.Copy(),
                                                                Notes = textTarget.ToString(),
                                                                Timestamp = DateTime.UtcNow,
+                                                               Destination = new BlockPosJson(te.TargetLocation)
                                                        }
                                                        );
 
index 285dbd6..3d0a01a 100644 (file)
@@ -119,7 +119,10 @@ namespace Automap
                                                jsonWriter.WriteMapTupleForeach(
                                                        $"{poi.Location.X}_{poi.Location.Z}",
                                                        PointsOfInterest_Vals,
-                                                       (mem) => jsonWriter.WriteValue(GetValue(mem, poi))
+                                                       (mem) => {
+                                                               var dasField = GetValue(mem, poi);
+                                                               jsonWriter.WriteRawValue(JsonConvert.SerializeObject(dasField));
+                                                       }
                                                );
                                        });
 #if DEBUG