OSDN Git Service

Pre-PR5 Configurable Designators, Autostart, fix for Entity processing
[automap/automap.git] / Automap / Data / EntityDesignator.cs
index 9939446..77ffe00 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;
@@ -15,17 +18,30 @@ namespace Automap
        /// <summary>
        /// Point of Interest Rule Designator
        /// </summary>
+       [JsonObject(MemberSerialization.OptIn)]
        public class EntityDesignator
        {
+               [JsonProperty]
                public Color Color;
+
+               [JsonIgnore]
                public EntityDesignatonAction SpecialAction;
+
+               [JsonProperty]
+               public string SpecialActionName;
+
+               [JsonProperty]
                public AssetLocation Pattern;
+
+               [JsonProperty]
                public EnumEntityState? StateCheck;//Needed?
+
+               [JsonProperty]
                public bool Enabled { get; set; }
 
                private EntityDesignator()
                {
-                       throw new NotSupportedException();
+                       //throw new NotSupportedException();
                }
 
                public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state)
@@ -42,11 +58,29 @@ namespace Automap
                        Color = color;
                        StateCheck = state;
                        SpecialAction = specialAct;
+                       SpecialActionName = specialAct.Method.Name;
                        Enabled = true;
                }
 
                public override string ToString()
                        => Pattern.ToShortString() + "|" + Color.Name + "|" + StateCheck ?? "";
+
+               [OnDeserialized]
+               public void RelinkDesignator(StreamingContext sCtx)
+               {
+               //TODO: properly Via reflection - and support for external designators?
+               if (SpecialAction == null && !String.IsNullOrEmpty(SpecialActionName)) {
+               switch (SpecialActionName) {
+
+               case "KeepTrackOfMerchant":
+                       SpecialAction = DefaultDesignators.KeepTrackOfMerchant;
+                       break;
+
+               
+               }
+               }
+
+               }
        }
 }