OSDN Git Service

Assorted fixes
authormelchior <melchior@users.osdn.me>
Thu, 26 Aug 2021 20:14:57 +0000 (16:14 -0400)
committermelchior <melchior@users.osdn.me>
Thu, 26 Aug 2021 20:14:57 +0000 (16:14 -0400)
Unicode fix (normalization), extra-constructor for S.P. use

Automap/Data/ColumnMeta.cs
Automap/Designators/DefaultDesignators.cs
Automap/Subsystems/AutomapSystem.cs

index 2f8233f..b266a9d 100644 (file)
@@ -118,6 +118,26 @@ namespace Automap
                        ColumnPresense = new BitArray(maxChunkHeight, false);//TODO: get real chunk height MAX
                }
 
+               public ColumnMeta(Vec2i loc, byte chunkSize = 32, int maxChunkHeight = 16)
+               {
+               Location = loc;
+               PrettyLocation = string.Empty;
+               ChunkAge = TimeSpan.Zero;
+               Temperature = 0f;
+               YMax = 0;
+               RockRatio = new Dictionary<int, uint>(10);
+               Fertility = 0f;
+               ForestDensity = 0f;
+               Rainfall = 0f;
+               ShrubDensity = 0f;
+               AirBlocks = 0;
+               NonAirBlocks = 0;
+               ChunkSize = chunkSize;
+               HeightMap = new ushort[ChunkSize, ChunkSize];
+               _flattened_HeightMap = null;
+               ColumnPresense = new BitArray(maxChunkHeight, false);
+               }
+
                internal void UpdateFieldsFrom(ClimateCondition climate, IMapChunk mapChunk, TimeSpan chunkAge)
                {
                        this.ChunkAge = chunkAge;
index 5c9aee2..33b499a 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;
@@ -123,6 +125,10 @@ namespace Automap
                        }
                }
 
+               internal static Encoding SaferUnicodeEncoding = Encoding.GetEncoding(Encoding.UTF8.WebName,
+               new EncoderReplacementFallback(@" "),
+               new DecoderReplacementFallback(@" "));
+
                #endregion
 
 
@@ -130,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,
                                        }
                                        );
@@ -161,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,
                                        }
                                        );
index c041803..abbfc44 100644 (file)
@@ -204,7 +204,9 @@ namespace Automap
                                                if (mapChunk == null)
                                                {
                                                        //TODO: REVISIT THIS CHUNK!
+                                                       #if DEBUG
                                                        Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key);
+                                                       #endif
                                                        nullMapCount++;
                                                        columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
                                                        continue;
@@ -400,17 +402,19 @@ namespace Automap
 
                        if (this.POIs.Count > 0)
                        {
-                               using (var poiFile = File.Open(poiPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
+                               using (var poiFile = File.Open(poiPath, FileMode.Create, FileAccess.Write, FileShare.None))
                                {
                                        Serializer.Serialize<PointsOfInterest>(poiFile, this.POIs);
+                                       poiFile.Flush(true);
                                }
                        }
 
                        if (this.EOIs.Count > 0)
                        {
-                               using (var eoiFile = File.Open(eoiPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
+                               using (var eoiFile = File.Open(eoiPath, FileMode.Create, FileAccess.Write, FileShare.None))
                                {
                                        Serializer.Serialize<EntitiesOfInterest>(eoiFile, this.EOIs);
+                                       eoiFile.Flush(true);
                                }
                        }