OSDN Git Service

Pre-PR: Point Metadata persistence, GUI work
[automap/automap.git] / Automap / Data / EntityDesignator.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Drawing;
5 using System.Runtime.Serialization;
6
7 using Newtonsoft.Json;
8
9 using Vintagestory.API.Client;
10 using Vintagestory.API.Common;
11 using Vintagestory.API.Common.Entities;
12 using Vintagestory.API.MathTools;
13
14 namespace Automap
15 {
16         public delegate void EntityDesignatonAction(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity);
17
18         /// <summary>
19         /// Point of Interest Rule Designator
20         /// </summary>
21         [JsonObject(MemberSerialization.OptIn)]
22         public class EntityDesignator
23         {
24                 [JsonProperty]
25                 public Color Color;
26
27                 [JsonIgnore]
28                 public EntityDesignatonAction SpecialAction;
29
30                 [JsonProperty]
31                 public string SpecialActionName;
32
33                 [JsonProperty]
34                 public AssetLocation Pattern;
35
36                 [JsonProperty]
37                 public EnumEntityState? StateCheck;//Needed?
38
39                 [JsonProperty]
40                 public bool Enabled { get; set; }
41
42                 private EntityDesignator()
43                 {
44                         //throw new NotSupportedException();
45                 }
46
47                 public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state)
48                 {
49                         Pattern = pattern;
50                         Color = color;
51                         StateCheck = state;
52                         Enabled = true;
53                 }
54
55                 public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state, EntityDesignatonAction specialAct)
56                 {
57                         Pattern = pattern;
58                         Color = color;
59                         StateCheck = state;
60                         SpecialAction = specialAct;
61                         SpecialActionName = specialAct.Method.Name;
62                         Enabled = true;
63                 }
64
65                 public override string ToString()
66                         => Pattern.ToShortString() + "|" + Color.Name + "|" + StateCheck ?? "";
67
68                 [OnDeserialized]
69                 public void RelinkDesignator(StreamingContext sCtx)
70                 {
71                 //TODO: properly Via reflection - and support for external designators?
72                 if (SpecialAction == null && !String.IsNullOrEmpty(SpecialActionName)) {
73                 switch (SpecialActionName) {
74
75                 case "KeepTrackOfMerchant":
76                         SpecialAction = DefaultDesignators.KeepTrackOfMerchant;
77                         break;
78
79                 
80                 }
81                 }
82
83                 }
84         }
85 }
86