Automap (client) [VS plugin mod]
Revisão | c46988f0b9e821ef654f7334608b0abc4966e57f (tree) |
---|---|
Hora | 2020-03-11 22:22:18 |
Autor | The Grand Dog <alex.h@me.c...> |
Commiter | The Grand Dog |
change the way the metadata is exported, typos
instead of having a map of objects, a map of arrays with a seperate array of names is used, this makes a smaller file
@@ -9,7 +9,7 @@ using Vintagestory.API.MathTools; | ||
9 | 9 | |
10 | 10 | namespace Automap |
11 | 11 | { |
12 | - public delegate void BlockDesignatonAction(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block); | |
12 | + public delegate void BlockDesignatorAction(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block); | |
13 | 13 | |
14 | 14 | /// <summary> |
15 | 15 | /// Point of Interest Rule Designator |
@@ -17,7 +17,7 @@ namespace Automap | ||
17 | 17 | public class BlockDesignator |
18 | 18 | { |
19 | 19 | public Color OverwriteColor; |
20 | - public BlockDesignatonAction SpecialAction; | |
20 | + public BlockDesignatorAction SpecialAction; | |
21 | 21 | public AssetLocation Pattern; |
22 | 22 | public EnumBlockMaterial? Material; |
23 | 23 | public bool Enabled { get; set; } |
@@ -35,7 +35,7 @@ namespace Automap | ||
35 | 35 | this.Enabled = true; |
36 | 36 | } |
37 | 37 | |
38 | - public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material, BlockDesignatonAction specialAct) | |
38 | + public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material, BlockDesignatorAction specialAct) | |
39 | 39 | { |
40 | 40 | this.Pattern = pattern; |
41 | 41 | this.OverwriteColor = overwriteColor; |
@@ -10,7 +10,7 @@ using Vintagestory.API.MathTools; | ||
10 | 10 | namespace Automap |
11 | 11 | { |
12 | 12 | /// <summary> |
13 | - /// Actual Physical Point in space - that is interesting. | |
13 | + /// Basically the same as a POI but for an entity | |
14 | 14 | /// </summary> |
15 | 15 | public struct EntityOfInterest |
16 | 16 | { |
@@ -26,6 +26,8 @@ namespace Automap | ||
26 | 26 | /// <remarks>Tracked by ID - these never leave.</remarks> |
27 | 27 | public class EntitiesOfInterest : KeyedCollection<long, EntityOfInterest> |
28 | 28 | { |
29 | + protected override long GetKeyForItem(EntityOfInterest item) | |
30 | + => item.EntityId; | |
29 | 31 | |
30 | 32 | internal void AddReplace(EntityOfInterest entity) |
31 | 33 | { |
@@ -35,8 +37,6 @@ namespace Automap | ||
35 | 37 | Add(entity); |
36 | 38 | } |
37 | 39 | |
38 | - protected override long GetKeyForItem(EntityOfInterest item) | |
39 | - => item.EntityId; | |
40 | 40 | } |
41 | 41 | } |
42 | 42 |
@@ -10,7 +10,7 @@ using Vintagestory.API.MathTools; | ||
10 | 10 | |
11 | 11 | namespace Automap |
12 | 12 | { |
13 | - public delegate void EntityDesignatonAction(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity); | |
13 | + public delegate void EntityDesignatorAction(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity); | |
14 | 14 | |
15 | 15 | /// <summary> |
16 | 16 | /// Point of Interest Rule Designator |
@@ -18,7 +18,7 @@ namespace Automap | ||
18 | 18 | public class EntityDesignator |
19 | 19 | { |
20 | 20 | public Color Color; |
21 | - public EntityDesignatonAction SpecialAction; | |
21 | + public EntityDesignatorAction SpecialAction; | |
22 | 22 | public AssetLocation Pattern; |
23 | 23 | public EnumEntityState? StateCheck;//Needed? |
24 | 24 | public bool Enabled { get; set; } |
@@ -36,7 +36,7 @@ namespace Automap | ||
36 | 36 | Enabled = true; |
37 | 37 | } |
38 | 38 | |
39 | - public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state, EntityDesignatonAction specialAct) | |
39 | + public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state, EntityDesignatorAction specialAct) | |
40 | 40 | { |
41 | 41 | Pattern = pattern; |
42 | 42 | Color = color; |
@@ -131,7 +131,7 @@ namespace Automap | ||
131 | 131 | |
132 | 132 | internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity) |
133 | 133 | { |
134 | - clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn); | |
134 | + //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn); | |
135 | 135 | |
136 | 136 | var traderJoe = entity as EntityTrader; |
137 | 137 | var message = $"{entity.GetName()} Alive: {traderJoe.Alive}"; |
@@ -169,11 +169,13 @@ namespace Automap | ||
169 | 169 | } |
170 | 170 | |
171 | 171 | ColumnMeta chunkMeta; |
172 | - if (chunkTopMetadata.Contains(mostActiveCol.Key)) { | |
173 | - chunkMeta = chunkTopMetadata[mostActiveCol.Key]; | |
172 | + if (chunkTopMetadata.Contains(mostActiveCol.Key)) | |
173 | + { | |
174 | + chunkMeta = chunkTopMetadata[mostActiveCol.Key]; | |
174 | 175 | } |
175 | - else { | |
176 | - chunkMeta = CreateColumnMetadata(mostActiveCol, mapChunk); | |
176 | + else | |
177 | + { | |
178 | + chunkMeta = CreateColumnMetadata(mostActiveCol, mapChunk); | |
177 | 179 | } |
178 | 180 | |
179 | 181 | UpdateEntityMetadata(); |
@@ -309,33 +311,40 @@ namespace Automap | ||
309 | 311 | jsonWriter.Write("ViewFrame.chunks.southMostChunk={0};", chunkTopMetadata.South_mostChunk); |
310 | 312 | jsonWriter.Write("ViewFrame.chunks.eastMostChunk={0};", chunkTopMetadata.East_mostChunk); |
311 | 313 | jsonWriter.Write("ViewFrame.chunks.westMostChunk={0};", chunkTopMetadata.West_mostChunk); |
314 | + // this is so that the tool tip doesnt need to be hard coded in the map | |
315 | + jsonWriter.Write("ViewFrame.chunks.chunkMetaNames=["); | |
316 | + // there are 10 (TEN) (ten) things | |
317 | + jsonWriter.Write("'Loc.','Age','Temp.','Y Max','Fert.','Forest','Rain','Shrub','Air','Non-Air'"); | |
318 | + jsonWriter.Write("];"); | |
312 | 319 | //MAP object format - [key, value]: key is "x_y" |
313 | 320 | jsonWriter.Write("ViewFrame.chunks.chunkMetadata=new Map(["); |
314 | 321 | foreach (var shard in chunkTopMetadata) |
315 | 322 | { |
316 | 323 | jsonWriter.Write("['{0}_{1}',", shard.Location.X, shard.Location.Y); |
317 | - jsonWriter.Write("{"); | |
318 | - jsonWriter.Write("prettyCoord:'{0}',", shard.Location.PrettyCoords(ClientAPI)); | |
319 | - jsonWriter.Write("chunkAge:'{0}',", shard.ChunkAge.ToString("g"));//World age - relative? or last edit ?? | |
320 | - jsonWriter.Write("temp:'{0}',", shard.Temperature.ToString("F1")); | |
321 | - jsonWriter.Write("YMax:'{0}',", shard.YMax); | |
322 | - jsonWriter.Write("fert:'{0}',", shard.Fertility.ToString("F1")); | |
323 | - jsonWriter.Write("forestDens:'{0}',", shard.ForestDensity.ToString("F1")); | |
324 | - jsonWriter.Write("rain:'{0}',", shard.Rainfall.ToString("F1")); | |
325 | - jsonWriter.Write("shrubDens:'{0}',", shard.ShrubDensity.ToString("F1")); | |
326 | - jsonWriter.Write("airBlocks:'{0}',", shard.AirBlocks); | |
327 | - jsonWriter.Write("nonAirBlocks:'{0}',", shard.NonAirBlocks); | |
328 | - //TODO: Heightmap | |
324 | + jsonWriter.Write("["); | |
325 | + // 10 things but 0 indexed so NINE (9) | |
326 | + jsonWriter.Write("'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}'", | |
327 | + shard.Location.PrettyCoords(ClientAPI), | |
328 | + shard.ChunkAge.ToString("g"),//World age - relative? or last edit ?? | |
329 | + shard.Temperature.ToString("F1"), | |
330 | + shard.YMax, | |
331 | + shard.Fertility.ToString("F1"), | |
332 | + shard.ForestDensity.ToString("F1"), | |
333 | + shard.Rainfall.ToString("F1"), | |
334 | + shard.ShrubDensity.ToString("F1"), | |
335 | + shard.AirBlocks, | |
336 | + shard.NonAirBlocks | |
337 | + ); | |
329 | 338 | //TODO: Rock-ratio, also requires a BlockID => Name lookup table....elsewhere |
330 | - jsonWriter.Write("}],"); | |
339 | + jsonWriter.Write("]],"); | |
331 | 340 | } |
332 | 341 | jsonWriter.Write("]);"); |
333 | 342 | |
334 | 343 | |
335 | - jsonWriter.Write("ViewFrame.chunks.pointsOfInterest = new Map(["); | |
344 | + jsonWriter.Write("ViewFrame.chunks.pointsOfInterest=new Map(["); | |
336 | 345 | foreach (var poi in POIs) |
337 | 346 | { |
338 | - jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Z); | |
347 | + jsonWriter.Write("['{0}_{1}',", (float) poi.Location.X / chunkSize, (float) poi.Location.Z / chunkSize); | |
339 | 348 | jsonWriter.Write("{"); |
340 | 349 | jsonWriter.Write("prettyCoord:'{0}',", poi.Location.PrettyCoords(ClientAPI)); |
341 | 350 | jsonWriter.Write("notes:{0},", JsonConvert.ToString(poi.Notes, '\'', StringEscapeHandling.EscapeHtml)); |
@@ -343,15 +352,18 @@ namespace Automap | ||
343 | 352 | jsonWriter.Write("chunkPos:'{0}_{1}',", (poi.Location.X / chunkSize), (poi.Location.Z / chunkSize)); |
344 | 353 | jsonWriter.Write("}],"); |
345 | 354 | } |
355 | + jsonWriter.Write("]);"); | |
346 | 356 | |
347 | - foreach (var poi in EOIs) | |
357 | + jsonWriter.Write("ViewFrame.chunks.entitiesOfInterest=new Map(["); | |
358 | + foreach (var eoi in EOIs) | |
348 | 359 | { |
349 | - jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Z); | |
360 | + jsonWriter.Write("['{0}_{1}',", (float) eoi.Location.X / chunkSize, (float) eoi.Location.Z / chunkSize); | |
350 | 361 | jsonWriter.Write("{"); |
351 | - jsonWriter.Write("prettyCoord:'{0}',", poi.Location.PrettyCoords(ClientAPI)); | |
352 | - jsonWriter.Write("notes:{0},", JsonConvert.ToString(poi.Notes, '\'', StringEscapeHandling.EscapeHtml)); | |
353 | - jsonWriter.Write("time:new Date('{0}'),", poi.Timestamp.ToString("O")); | |
354 | - jsonWriter.Write("chunkPos:'{0}_{1}',", (poi.Location.X / chunkSize), (poi.Location.Z / chunkSize)); | |
362 | + jsonWriter.Write("prettyCoord:'{0}',", eoi.Location.PrettyCoords(ClientAPI)); | |
363 | + jsonWriter.Write("notes:{0},", JsonConvert.ToString(eoi.Notes, '\'', StringEscapeHandling.EscapeHtml)); | |
364 | + jsonWriter.Write("time:new Date('{0}'),", eoi.Timestamp.ToString("O")); | |
365 | + jsonWriter.Write("chunkPos:'{0}_{1}',", (eoi.Location.X / chunkSize), (eoi.Location.Z / chunkSize)); | |
366 | + jsonWriter.Write("entityId:'{0}'", eoi.EntityId); | |
355 | 367 | jsonWriter.Write("}],"); |
356 | 368 | } |
357 | 369 | jsonWriter.Write("]);"); |
@@ -364,7 +376,7 @@ namespace Automap | ||
364 | 376 | |
365 | 377 | private ColumnMeta CreateColumnMetadata(KeyValuePair<Vec2i, uint> mostActiveCol, IMapChunk mapChunk) |
366 | 378 | { |
367 | - ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), ( byte )chunkSize); | |
379 | + ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), (byte) chunkSize); | |
368 | 380 | BlockPos equivBP = new BlockPos(mostActiveCol.Key.X * chunkSize, |
369 | 381 | mapChunk.YMax, |
370 | 382 | mostActiveCol.Key.Y * chunkSize); |
@@ -390,38 +402,41 @@ namespace Automap | ||
390 | 402 | |
391 | 403 | if (files.Length > 0) |
392 | 404 | { |
393 | - #if DEBUG | |
405 | +#if DEBUG | |
394 | 406 | Logger.VerboseDebug("{0} Existing world chunk shards", files.Length); |
395 | - #endif | |
396 | - | |
397 | - foreach (var shardFile in files) { | |
407 | +#endif | |
398 | 408 | |
399 | - if (shardFile.Length < 1024) continue; | |
400 | - var result = chunkShardRegex.Match(shardFile.Name); | |
401 | - if (result.Success) { | |
402 | - int X_chunk_pos = int.Parse(result.Groups["X"].Value); | |
403 | - int Z_chunk_pos = int.Parse(result.Groups["Z"].Value); | |
409 | + foreach (var shardFile in files) | |
410 | + { | |
404 | 411 | |
405 | - try | |
412 | + if (shardFile.Length < 1024) continue; | |
413 | + var result = chunkShardRegex.Match(shardFile.Name); | |
414 | + if (result.Success) | |
406 | 415 | { |
407 | - using (var fileStream = shardFile.OpenRead( )) { | |
416 | + int X_chunk_pos = int.Parse(result.Groups["X"].Value); | |
417 | + int Z_chunk_pos = int.Parse(result.Groups["Z"].Value); | |
408 | 418 | |
409 | - PngReader pngRead = new PngReader(fileStream); | |
410 | - pngRead.ReadSkippingAllRows( ); | |
411 | - pngRead.End( ); | |
412 | - //Parse PNG chunks for METADATA in shard | |
413 | - PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk; | |
419 | + try | |
420 | + { | |
421 | + using (var fileStream = shardFile.OpenRead()) | |
422 | + { | |
414 | 423 | |
415 | - chunkTopMetadata.Add(metadataFromPng.ChunkMetadata); | |
416 | - } | |
424 | + PngReader pngRead = new PngReader(fileStream); | |
425 | + pngRead.ReadSkippingAllRows(); | |
426 | + pngRead.End(); | |
427 | + //Parse PNG chunks for METADATA in shard | |
428 | + PngMetadataChunk metadataFromPng = pngRead.GetChunksList().GetById1(PngMetadataChunk.ID) as PngMetadataChunk; | |
417 | 429 | |
430 | + chunkTopMetadata.Add(metadataFromPng.ChunkMetadata); | |
431 | + } | |
432 | + | |
433 | + } | |
434 | + catch (PngjException someEx) | |
435 | + { | |
436 | + Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx); | |
437 | + continue; | |
438 | + } | |
418 | 439 | } |
419 | - catch (PngjException someEx) | |
420 | - { | |
421 | - Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx); | |
422 | - continue; | |
423 | - } | |
424 | - } | |
425 | 440 | |
426 | 441 | } |
427 | 442 | } |
@@ -475,21 +490,21 @@ namespace Automap | ||
475 | 490 | int targetChunkY = mapChunk.YMax / chunkSize;//Surface ... |
476 | 491 | for (; targetChunkY > 0; targetChunkY--) |
477 | 492 | { |
478 | - WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk; | |
479 | - | |
480 | - if (chunkData == null || chunkData.BlockEntities == null) { | |
481 | - #if DEBUG | |
482 | - Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y); | |
483 | - #endif | |
484 | - continue; | |
485 | - } | |
493 | + WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk; | |
494 | + if (chunkData == null || chunkData.BlockEntities == null) | |
495 | + { | |
496 | +#if DEBUG | |
497 | + Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y); | |
498 | +#endif | |
499 | + continue; | |
500 | + } | |
486 | 501 | |
487 | 502 | /*************** Chunk Entities Scanning *********************/ |
488 | 503 | if (chunkData.BlockEntities != null && chunkData.BlockEntities.Length > 0) |
489 | 504 | { |
490 | - #if DEBUG | |
505 | +#if DEBUG | |
491 | 506 | Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, chunkData.BlockEntities.Length); |
492 | - #endif | |
507 | +#endif | |
493 | 508 | |
494 | 509 | foreach (var blockEnt in chunkData.BlockEntities) |
495 | 510 | { |
@@ -534,10 +549,12 @@ namespace Automap | ||
534 | 549 | |
535 | 550 | chunkMeta.NonAirBlocks++; |
536 | 551 | |
537 | - //Heightmap | |
538 | - if (chunkMeta.HeightMap[X_index, Z_index] == 0) | |
539 | - { chunkMeta.HeightMap[X_index, Z_index] = (ushort) (Y_index + (targetChunkY * chunkSize)); } | |
540 | - | |
552 | + ////Heightmap | |
553 | + //if (chunkMeta.HeightMap[X_index, Z_index] == 0) | |
554 | + //{ | |
555 | + // chunkMeta.HeightMap[X_index, Z_index] | |
556 | + // = (ushort) (Y_index + (targetChunkY * chunkSize)); | |
557 | + //} | |
541 | 558 | } |
542 | 559 | while (X_index++ < (chunkSize - 1)); |
543 | 560 | X_index = 0; |
@@ -564,6 +581,7 @@ namespace Automap | ||
564 | 581 | var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code)); |
565 | 582 | if (dMatch.Value != null) |
566 | 583 | { |
584 | + Logger.Chat("Entity designator hit!"); | |
567 | 585 | dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.LocalPos.AsBlockPos.Copy(), loadedEntity.Value); |
568 | 586 | } |
569 | 587 |