using System; 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; using Vintagestory.API.MathTools; namespace Automap { public delegate void BlockDesignatorAction(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block); /// /// Point of Interest Rule Designator /// [JsonObject(MemberSerialization.OptIn)] public class BlockDesignator { [JsonProperty] public Color OverwriteColor; [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(); } public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material) { this.Pattern = pattern; this.OverwriteColor = overwriteColor; this.Material = material; this.Enabled = true; } public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material, BlockDesignatorAction specialAct) { this.Pattern = pattern; this.OverwriteColor = overwriteColor; this.Material = material; this.SpecialAction = specialAct; this.SpecialActionName = specialAct.Method.Name; this.Enabled = true; } public override string ToString() { 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; } } } } }