Automap (client) [VS plugin mod]
Révision | a5cf48106e5ad88de4153de6393b122c5096c3fb (tree) |
---|---|
l'heure | 2021-08-27 05:14:57 |
Auteur | melchior <melchior@user...> |
Commiter | melchior |
Assorted fixes
Unicode fix (normalization), extra-constructor for S.P. use
@@ -118,6 +118,26 @@ namespace Automap | ||
118 | 118 | ColumnPresense = new BitArray(maxChunkHeight, false);//TODO: get real chunk height MAX |
119 | 119 | } |
120 | 120 | |
121 | + public ColumnMeta(Vec2i loc, byte chunkSize = 32, int maxChunkHeight = 16) | |
122 | + { | |
123 | + Location = loc; | |
124 | + PrettyLocation = string.Empty; | |
125 | + ChunkAge = TimeSpan.Zero; | |
126 | + Temperature = 0f; | |
127 | + YMax = 0; | |
128 | + RockRatio = new Dictionary<int, uint>(10); | |
129 | + Fertility = 0f; | |
130 | + ForestDensity = 0f; | |
131 | + Rainfall = 0f; | |
132 | + ShrubDensity = 0f; | |
133 | + AirBlocks = 0; | |
134 | + NonAirBlocks = 0; | |
135 | + ChunkSize = chunkSize; | |
136 | + HeightMap = new ushort[ChunkSize, ChunkSize]; | |
137 | + _flattened_HeightMap = null; | |
138 | + ColumnPresense = new BitArray(maxChunkHeight, false); | |
139 | + } | |
140 | + | |
121 | 141 | internal void UpdateFieldsFrom(ClimateCondition climate, IMapChunk mapChunk, TimeSpan chunkAge) |
122 | 142 | { |
123 | 143 | this.ChunkAge = chunkAge; |
@@ -3,7 +3,9 @@ using System.Collections.Generic; | ||
3 | 3 | using System.Drawing; |
4 | 4 | using System.Text; |
5 | 5 | using System.Text.RegularExpressions; |
6 | + | |
6 | 7 | using HarmonyLib; |
8 | + | |
7 | 9 | using Vintagestory.API.Client; |
8 | 10 | using Vintagestory.API.Common; |
9 | 11 | using Vintagestory.API.Common.Entities; |
@@ -123,6 +125,10 @@ namespace Automap | ||
123 | 125 | } |
124 | 126 | } |
125 | 127 | |
128 | + internal static Encoding SaferUnicodeEncoding = Encoding.GetEncoding(Encoding.UTF8.WebName, | |
129 | + new EncoderReplacementFallback(@" "), | |
130 | + new DecoderReplacementFallback(@" ")); | |
131 | + | |
126 | 132 | #endregion |
127 | 133 | |
128 | 134 |
@@ -130,20 +136,22 @@ namespace Automap | ||
130 | 136 | |
131 | 137 | internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block) |
132 | 138 | { |
133 | -#if DEBUG | |
139 | + #if DEBUG | |
134 | 140 | clientAPI.Logger.VerboseDebug("Sign Designator Invoked!"); |
135 | -#endif | |
141 | + #endif | |
136 | 142 | //sign Text into a POI field... |
137 | 143 | BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign; |
138 | 144 | |
139 | 145 | if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) { |
140 | 146 | |
147 | + var textTemp = SaferUnicodeEncoding.GetBytes(signEntity.text); | |
148 | + | |
141 | 149 | poi.AddReplace( |
142 | 150 | new PointOfInterest { |
143 | 151 | Name = "Sign", |
144 | 152 | PrettyLocation = posn.PrettyCoords(clientAPI), |
145 | 153 | Location = posn.Copy( ), |
146 | - Notes = signEntity.text, | |
154 | + Notes = SaferUnicodeEncoding.GetString(textTemp).Normalize(), | |
147 | 155 | Timestamp = DateTime.UtcNow, |
148 | 156 | } |
149 | 157 | ); |
@@ -161,12 +169,14 @@ namespace Automap | ||
161 | 169 | |
162 | 170 | if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) { |
163 | 171 | |
172 | + var textTemp = SaferUnicodeEncoding.GetBytes(string.Join(",", signEntity.textByCardinalDirection)); | |
173 | + | |
164 | 174 | poi.AddReplace( |
165 | 175 | new PointOfInterest { |
166 | 176 | Name = "Signpost", |
167 | 177 | PrettyLocation = posn.PrettyCoords(clientAPI), |
168 | 178 | Location = posn.Copy( ), |
169 | - Notes = string.Join(",", signEntity.textByCardinalDirection), | |
179 | + Notes = SaferUnicodeEncoding.GetString(textTemp).Normalize(), | |
170 | 180 | Timestamp = DateTime.UtcNow, |
171 | 181 | } |
172 | 182 | ); |
@@ -204,7 +204,9 @@ namespace Automap | ||
204 | 204 | if (mapChunk == null) |
205 | 205 | { |
206 | 206 | //TODO: REVISIT THIS CHUNK! |
207 | + #if DEBUG | |
207 | 208 | Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key); |
209 | + #endif | |
208 | 210 | nullMapCount++; |
209 | 211 | columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem); |
210 | 212 | continue; |
@@ -400,17 +402,19 @@ namespace Automap | ||
400 | 402 | |
401 | 403 | if (this.POIs.Count > 0) |
402 | 404 | { |
403 | - using (var poiFile = File.Open(poiPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) | |
405 | + using (var poiFile = File.Open(poiPath, FileMode.Create, FileAccess.Write, FileShare.None)) | |
404 | 406 | { |
405 | 407 | Serializer.Serialize<PointsOfInterest>(poiFile, this.POIs); |
408 | + poiFile.Flush(true); | |
406 | 409 | } |
407 | 410 | } |
408 | 411 | |
409 | 412 | if (this.EOIs.Count > 0) |
410 | 413 | { |
411 | - using (var eoiFile = File.Open(eoiPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) | |
414 | + using (var eoiFile = File.Open(eoiPath, FileMode.Create, FileAccess.Write, FileShare.None)) | |
412 | 415 | { |
413 | 416 | Serializer.Serialize<EntitiesOfInterest>(eoiFile, this.EOIs); |
417 | + eoiFile.Flush(true); | |
414 | 418 | } |
415 | 419 | } |
416 | 420 |