OSDN Git Service

Merge branch 'Split_renderers' into vgd
[automap/automap.git] / Automap / Data / BlockDesignator.cs
index df56415..56e33f0 100644 (file)
@@ -2,6 +2,9 @@
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Drawing;
+using System.Runtime.Serialization;
+
+using Newtonsoft.Json;
 
 using Vintagestory.API.Client;
 using Vintagestory.API.Common;
@@ -14,17 +17,30 @@ namespace Automap
        /// <summary>
        /// Point of Interest Rule Designator
        /// </summary>
+       [JsonObject(MemberSerialization.OptIn)]
        public class BlockDesignator
        {
+               [JsonProperty]
                public Color OverwriteColor;
-               public BlockDesignatorAction SpecialAction;
+
+               [JsonIgnore]
+               public BlockDesignatonAction SpecialAction;
+
+               [JsonProperty]
+               public string SpecialActionName;
+
+               [JsonProperty]
                public AssetLocation Pattern;
+
+               [JsonProperty]
                public EnumBlockMaterial? Material;
+
+               [JsonProperty]
                public bool Enabled { get; set; }
 
                private BlockDesignator()
                {
-                       throw new NotSupportedException();
+                       //throw new NotSupportedException();
                }
 
                public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material)
@@ -41,6 +57,7 @@ namespace Automap
                        this.OverwriteColor = overwriteColor;
                        this.Material = material;
                        this.SpecialAction = specialAct;
+                       this.SpecialActionName = specialAct.Method.Name;
                        this.Enabled = true;
                }
 
@@ -48,6 +65,30 @@ namespace Automap
                {
                        return Pattern.ToShortString() + "|" + OverwriteColor.Name + "|" + Material ?? "";
                }
+
+               [OnDeserialized]
+               public void RelinkDesignator(StreamingContext sCtx )
+               {
+                       //TODO: properly Via reflection - and support for external designators?
+                       if (SpecialAction == null && !String.IsNullOrEmpty(SpecialActionName)) {
+                               switch (SpecialActionName) {
+
+                                       case "DecodeSign":
+                                       SpecialAction = DefaultDesignators.DecodeSign;
+                                       break;
+                               
+                                       case "DecodePostSign":
+                                       SpecialAction = DefaultDesignators.DecodePostSign;
+                                       break;
+                               
+                                       case "DecodeTranslocator":
+                                       SpecialAction = DefaultDesignators.DecodeTranslocator;
+                                       break;
+
+                               }
+                       }
+
+               }
        }
 }