Automap (client) [VS plugin mod]
Revision | 8bde879f2fb8ad66dbafc2b4e4e246e2ab66856b (tree) |
---|---|
Time | 2020-02-27 03:51:20 |
Author | The Grand Dog <alex.h@me.c...> |
Commiter | The Grand Dog |
bug fix with international use, simplification
@@ -1,21 +1,17 @@ | ||
1 | 1 | using System; |
2 | 2 | using System.Collections.Concurrent; |
3 | 3 | using System.Collections.Generic; |
4 | -using System.Collections.ObjectModel; | |
5 | - | |
6 | 4 | using System.IO; |
7 | 5 | using System.Linq; |
8 | 6 | using System.Text; |
9 | 7 | using System.Text.RegularExpressions; |
10 | 8 | using System.Threading; |
11 | -using System.Web.UI; | |
12 | 9 | |
13 | 10 | using Hjg.Pngcs; |
14 | 11 | using Hjg.Pngcs.Chunks; |
15 | 12 | |
16 | 13 | using Vintagestory.API.Client; |
17 | 14 | using Vintagestory.API.Common; |
18 | -using Vintagestory.API.Common.Entities; | |
19 | 15 | using Vintagestory.API.Config; |
20 | 16 | using Vintagestory.API.Datastructures; |
21 | 17 | using Vintagestory.API.MathTools; |
@@ -176,9 +172,8 @@ namespace Automap | ||
176 | 172 | UpdateEntityMetadata(); |
177 | 173 | ProcessChunkBlocks(mostActiveCol.Key, mapChunk, chunkMeta); |
178 | 174 | |
179 | - uint updatedPixels = 0; | |
180 | 175 | |
181 | - ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter, out updatedPixels); | |
176 | + ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter, out uint updatedPixels); | |
182 | 177 | |
183 | 178 | if (updatedPixels > 0) |
184 | 179 | { |
@@ -315,14 +310,14 @@ namespace Automap | ||
315 | 310 | jsonWriter.Write("{"); |
316 | 311 | jsonWriter.Write("prettyCoord:'{0}',", shard.Location.PrettyCoords(ClientAPI)); |
317 | 312 | jsonWriter.Write("chunkAge:'{0}',", shard.ChunkAge.ToString("g"));//World age - relative? or last edit ?? |
318 | - jsonWriter.Write("temp:{0},", shard.Temperature.ToString("F1")); | |
319 | - jsonWriter.Write("YMax:{0},", shard.YMax); | |
320 | - jsonWriter.Write("fert:{0},", shard.Fertility.ToString("F1")); | |
321 | - jsonWriter.Write("forestDens:{0},", shard.ForestDensity.ToString("F1")); | |
322 | - jsonWriter.Write("rain:{0},", shard.Rainfall.ToString("F1")); | |
323 | - jsonWriter.Write("shrubDens:{0},", shard.ShrubDensity.ToString("F1")); | |
324 | - jsonWriter.Write("airBlocks:{0},", shard.AirBlocks); | |
325 | - jsonWriter.Write("nonAirBlocks:{0},", shard.NonAirBlocks); | |
313 | + jsonWriter.Write("temp:'{0}',", shard.Temperature.ToString("F1")); | |
314 | + jsonWriter.Write("YMax:'{0}',", shard.YMax); | |
315 | + jsonWriter.Write("fert:'{0}',", shard.Fertility.ToString("F1")); | |
316 | + jsonWriter.Write("forestDens:'{0}',", shard.ForestDensity.ToString("F1")); | |
317 | + jsonWriter.Write("rain:'{0}',", shard.Rainfall.ToString("F1")); | |
318 | + jsonWriter.Write("shrubDens:'{0}',", shard.ShrubDensity.ToString("F1")); | |
319 | + jsonWriter.Write("airBlocks:'{0}',", shard.AirBlocks); | |
320 | + jsonWriter.Write("nonAirBlocks:'{0}',", shard.NonAirBlocks); | |
326 | 321 | //TODO: Heightmap |
327 | 322 | //TODO: Rock-ratio |
328 | 323 | jsonWriter.Write("}],"); |
@@ -405,17 +400,15 @@ namespace Automap | ||
405 | 400 | int Z_chunk_pos = int.Parse(result.Groups["Z"].Value); |
406 | 401 | |
407 | 402 | //Parse PNG chunks for METADATA in shard |
408 | - using (var fileStream = shardFile.OpenRead()) | |
409 | - { | |
410 | - //TODO: Add corrupted PNG Exception handing HERE ! | |
411 | - PngReader pngRead = new PngReader(fileStream); | |
412 | - pngRead.ReadSkippingAllRows(); | |
413 | - pngRead.End(); | |
403 | + using var fileStream = shardFile.OpenRead(); | |
404 | + //TODO: Add corrupted PNG Exception handing HERE ! | |
405 | + PngReader pngRead = new PngReader(fileStream); | |
406 | + pngRead.ReadSkippingAllRows(); | |
407 | + pngRead.End(); | |
414 | 408 | |
415 | - PngMetadataChunk metadataFromPng = pngRead.GetChunksList().GetById1(PngMetadataChunk.ID) as PngMetadataChunk; | |
409 | + PngMetadataChunk metadataFromPng = pngRead.GetChunksList().GetById1(PngMetadataChunk.ID) as PngMetadataChunk; | |
416 | 410 | |
417 | - chunkTopMetadata.Add(metadataFromPng.ChunkMetadata); | |
418 | - } | |
411 | + chunkTopMetadata.Add(metadataFromPng.ChunkMetadata); | |
419 | 412 | |
420 | 413 | } |
421 | 414 | } |
@@ -446,8 +439,10 @@ namespace Automap | ||
446 | 439 | meta.SetText("Chunk_X", coord.X.ToString("D")); |
447 | 440 | meta.SetText("Chunk_Y", coord.Y.ToString("D")); |
448 | 441 | //Setup specialized meta-data PNG chunks here... |
449 | - PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo); | |
450 | - pngChunkMeta.ChunkMetadata = metadata; | |
442 | + PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo) | |
443 | + { | |
444 | + ChunkMetadata = metadata | |
445 | + }; | |
451 | 446 | pngWriter.GetChunksList().Queue(pngChunkMeta); |
452 | 447 | |
453 | 448 | return pngWriter; |
@@ -465,9 +460,7 @@ namespace Automap | ||
465 | 460 | int targetChunkY = mapChunk.YMax / chunkSize;//Surface ... |
466 | 461 | for (; targetChunkY > 0; targetChunkY--) |
467 | 462 | { |
468 | - WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk; | |
469 | - | |
470 | - if (chunkData == null || chunkData.BlockEntities == null) | |
463 | + if (!(ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) is WorldChunk chunkData) || chunkData.BlockEntities == null) | |
471 | 464 | { |
472 | 465 | #if DEBUG |
473 | 466 | Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y); |