OSDN Git Service

the previous way could return non english stuff, which is bad
[automap/automap.git] / Automap / Designators / DefaultDesignators.cs
index 19b448e..102de1b 100644 (file)
@@ -2,16 +2,19 @@
 using System.Collections.Generic;
 using System.Drawing;
 using System.Text;
+using System.Text.RegularExpressions;
+
 using Vintagestory.API.Client;
 using Vintagestory.API.Common;
 using Vintagestory.API.Common.Entities;
+using Vintagestory.API.Config;
 using Vintagestory.API.MathTools;
 using Vintagestory.GameContent;
 
 namespace Automap
 {
        public static class DefaultDesignators
-       {
+       {               
                public static BlockDesignator Roads =
                         new BlockDesignator(
                                new AssetLocation("game", "stonepath"),
@@ -81,6 +84,8 @@ namespace Automap
                };
                }
 
+               #region Designators
+
                internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
                {
 #if DEBUG
@@ -95,14 +100,14 @@ namespace Automap
                                poi.AddReplace(
                                                        new PointOfInterest
                                                        {
+                                                               Name = "Sign",
+                                                               PrettyLocation = posn.PrettyCoords(clientAPI),
                                                                Location = posn.Copy(),
                                                                Notes = signEntity.text,
-                                                               Timestamp = DateTimeOffset.UtcNow,
+                                                               Timestamp = DateTime.UtcNow,
                                                        }
                                                        );
-
                        }
-
                }
 
 
@@ -120,56 +125,106 @@ namespace Automap
                                poi.AddReplace(
                                                        new PointOfInterest
                                                        {
+                                                               Name = "Signpost",
+                                                               PrettyLocation = posn.PrettyCoords(clientAPI),
                                                                Location = posn.Copy(),
                                                                Notes = string.Join(",", signEntity.textByCardinalDirection),
-                                                               Timestamp = DateTimeOffset.UtcNow,
+                                                               Timestamp = DateTime.UtcNow,
                                                        }
                                                        );
-
                        }
                }
 
                internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
                {
-                       clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
+                       //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
 
-                       var message = $"{entity.GetName()}";
                        var traderJoe = entity as EntityTrader;
+                       var traderName = entity.GetBehavior<EntityBehaviorNameTag>()?.DisplayName;
+                       string code;
+                       // this makes me ill
+                       switch (entity.Code.Path) {
+                               case "humanoid-trader-artisan":
+                                       code = "{0} the artisan";
+                                       break;
+                               case "humanoid-trader-treasurehunter":
+                                       code = "{0} the treasure hunter";
+                                       break;
+                               case "humanoid-trader-buildmaterials":
+                                       code = "{0} the building materials trader";
+                                       break;
+                               case "humanoid-trader-clothing":
+                                       code = "{0} the clothing merchant";
+                                       break;
+                               case "humanoid-trader-commodities":
+                                       code = "{0} the commodities merchant";
+                                       break;
+                               case "humanoid-trader-foods":
+                                       code = "{0} the foods supplier";
+                                       break;
+                               case "humanoid-trader-furniture":
+                                       code = "{0} the furniture trader";
+                                       break;
+                               case "humanoid-trader-luxuries":
+                                       code = "{0} the luxuries merchant";
+                                       break;
+                               case "humanoid-trader-survivalgoods":
+                                       code = "{0} the survival goods supplier";
+                                       break;
+                               default:
+                                       code = "";
+                                       break;
+                       }
+                       var message = string.Format(code, traderName);
                        if (traderJoe.TradeProps != null)
                        {
-                               message = $"{traderJoe.GetName()} Alive:{traderJoe.Alive} - Gears: {traderJoe.TradeProps.Money}, ";
+                               message += $" - Gears: {traderJoe.TradeProps.Money}, ";
                        }
-                       poi.Upsert(entity, message);
+                       poi.AddReplace(new EntityOfInterest
+                       {
+                               Name = "Trader",
+                               PrettyLocation = posn.PrettyCoords(clientAPI),
+                               Location = posn.Copy(),
+                               Notes = message,
+                               Timestamp = DateTime.UtcNow,
+                               EntityId = entity.EntityId
+                       });
                }
 
                internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
                {
-                       clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
+               #if DEBUG
+               clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
+               #endif
                        //Where to? and from!
 
                        BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
 
                        if (te != null)
                        {
-
+                               //FIXME: Delayed rescan ?
                                StringBuilder textTarget = new StringBuilder();
                                //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
-
-                               textTarget.Append(te.Activated ? "Online " : "offline ");
-                               textTarget.Append(" Dest.: ");
-                               textTarget.Append(te.TargetLocation != null ? te.TargetLocation.PrettyCoords(clientAPI) : "???");//Or ABS coords?               
-
+                               textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
+                               textTarget.Append(te.Activated ? "Online, " : "Offline, ");
+                               textTarget.Append(" Target: [ ");
+                               textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?           
+                               textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
                                poi.AddReplace(
                                                        new PointOfInterest
                                                        {
+                                                               Name = "Translocator",
+                                                               PrettyLocation = posn.PrettyCoords(clientAPI),
                                                                Location = posn.Copy(),
                                                                Notes = textTarget.ToString(),
-                                                               Timestamp = DateTimeOffset.UtcNow,
+                                                               Timestamp = DateTime.UtcNow,
+                                                               Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy()) : null
                                                        }
                                                        );
-
                        }
                }
+
+               #endregion
        }
 }