OSDN Git Service

Snapshots crash fix
[automap/automap.git] / Automap / Designators / DefaultDesignators.cs
index 4bdcaab..652b5c1 100644 (file)
@@ -3,7 +3,9 @@ using System.Collections.Generic;
 using System.Drawing;
 using System.Text;
 using System.Text.RegularExpressions;
+
 using HarmonyLib;
+
 using Vintagestory.API.Client;
 using Vintagestory.API.Common;
 using Vintagestory.API.Common.Entities;
@@ -72,6 +74,26 @@ namespace Automap
                                KeepTrackOfMerchant
                        );
 
+               public static BlockDesignator Wildbeehives =
+                        new BlockDesignator(
+                               new AssetLocation("game", "wildbeehive"),
+                               Color.Honeydew,
+                               EnumBlockMaterial.Other,
+                               NoteWildbeehive,
+                               false
+                       );
+
+               public static BlockDesignator PineResinLeaks =
+                        new BlockDesignator(
+                               new AssetLocation("game", "log-resin"),
+                               Color.DarkOrange,
+                               EnumBlockMaterial.Wood,
+                               NotePineResinLeak,
+                               false
+                       );
+
+
+
                /// <summary>
                /// Not just blocks, but block-entities as well!
                /// </summary>
@@ -87,6 +109,8 @@ namespace Automap
                                        DefaultDesignators.PostSigns,
                                        DefaultDesignators.Translocators,
                                        DefaultDesignators.Teleporters,
+                       DefaultDesignators.Wildbeehives,
+                       DefaultDesignators.PineResinLeaks,
                                        };
                        }
                }
@@ -101,6 +125,10 @@ namespace Automap
                        }
                }
 
+               internal static Encoding SaferUnicodeEncoding = Encoding.GetEncoding(Encoding.UTF8.WebName,
+               new EncoderReplacementFallback(@" "),
+               new DecoderReplacementFallback(@" "));
+
                #endregion
 
 
@@ -108,20 +136,22 @@ namespace Automap
 
                internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
                {
-#if DEBUG
+               #if DEBUG
                clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
-#endif
+               #endif
                //sign Text into a POI field...
                BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
 
                if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) {
 
+               var textTemp = SaferUnicodeEncoding.GetBytes(signEntity.text);
+
                poi.AddReplace(
                                        new PointOfInterest {
                                                Name = "Sign",
                                                PrettyLocation = posn.PrettyCoords(clientAPI),
                                                Location = posn.Copy( ),
-                                               Notes = signEntity.text,
+                                               Notes = SaferUnicodeEncoding.GetString(textTemp).Normalize(),
                                                Timestamp = DateTime.UtcNow,
                                        }
                                        );
@@ -139,12 +169,14 @@ namespace Automap
 
                if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) {
 
+               var textTemp = SaferUnicodeEncoding.GetBytes(string.Join(",", signEntity.textByCardinalDirection));
+
                poi.AddReplace(
                                        new PointOfInterest {
                                                Name = "Signpost",
                                                PrettyLocation = posn.PrettyCoords(clientAPI),
                                                Location = posn.Copy( ),
-                                               Notes = string.Join(",", signEntity.textByCardinalDirection),
+                                               Notes = SaferUnicodeEncoding.GetString(textTemp).Normalize(),
                                                Timestamp = DateTime.UtcNow,
                                        }
                                        );
@@ -207,9 +239,9 @@ namespace Automap
 
                internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
                {
-#if DEBUG
+               #if DEBUG
                clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
-#endif
+               #endif
                //Where to? and from!
 
                BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
@@ -217,9 +249,9 @@ namespace Automap
                if (te != null) {
                //FIXME: Delayed rescan ?
                StringBuilder textTarget = new StringBuilder( );
-               //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
+               
                textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
-               textTarget.Append(te.Activated ? "Online, " : "Offline, ");
+               textTarget.Append(te.Activated ? "Online, " : "Offline, ");//Property hardcoded TRUE ?!
                textTarget.Append(" Target: [ ");
                textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?           
                textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
@@ -271,6 +303,49 @@ namespace Automap
                }
                }
 
+               internal static void NoteWildbeehive(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
+               {
+               #if DEBUG
+               clientAPI.Logger.VerboseDebug("Wild bee hive Designator Invoked!");
+               #endif
+
+               BlockEntityBeehive bees = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityBeehive;
+
+               if (bees != null) {                             
+               EnumHivePopSize hiveSize = AccessTools.FieldRefAccess<BlockEntityBeehive, EnumHivePopSize>(bees, @"hivePopSize");
+
+               StringBuilder textTarget = new StringBuilder( );
+               textTarget.AppendLine($" Population: {(hiveSize != null? hiveSize.ToString() : "?")} ");                
+               
+               poi.AddReplace(
+                                       new PointOfInterest {
+                                               Name = "Wildbeehive",
+                                               PrettyLocation = posn.PrettyCoords(clientAPI),
+                                               Location = posn.Copy( ),
+                                               Notes = textTarget.ToString( ),
+                                               Timestamp = DateTime.UtcNow,
+                                       }
+                                       );              
+               }
+               }
+
+               internal static void NotePineResinLeak(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
+               {
+               #if DEBUG
+               clientAPI.Logger.VerboseDebug("Resin leaking Pine tree Designator Invoked!");
+               #endif
+               //Note:Due to how Block-Entities are handled...only Harvested resin is tracked....
+               poi.AddReplace(
+                                       new PointOfInterest {
+                                               Name = "PineResin",
+                                               PrettyLocation = posn.PrettyCoords(clientAPI),
+                                               Location = posn.Copy( ),
+                                               Notes = String.Empty,
+                                               Timestamp = DateTime.UtcNow,
+                                       }
+                                       );
+               }
+
                #endregion
        }
 }