Automap (client) [VS plugin mod]
Revision | edc76b96b63c2ed2affd067281ebbe37bfcdcd6a (tree) |
---|---|
Time | 2020-09-21 05:23:03 |
Author | ![]() |
Commiter | melchior |
W.I.P. Changes for non-Seasonal color on map, default spawn coords
@@ -88,7 +88,7 @@ | ||
88 | 88 | <Compile Include="Designators\DefaultDesignators.cs" /> |
89 | 89 | <Compile Include="Subsystems\AutomapSystem.cs" /> |
90 | 90 | <Compile Include="Subsystems\AutomapGUIDialog.cs" /> |
91 | - <Compile Include="Renderers\IChunkRenderer.cs" /> | |
91 | + <Compile Include="Renderers\AChunkRenderer.cs" /> | |
92 | 92 | <Compile Include="Renderers\StandardRenderer.cs" /> |
93 | 93 | <Compile Include="Renderers\AlternateRenderer.cs" /> |
94 | 94 | <Compile Include="Data\StatusData.cs" /> |
@@ -14,6 +14,12 @@ namespace Automap | ||
14 | 14 | /// <value>To autostart.</value> |
15 | 15 | public bool Autostart { get; set; } = false; |
16 | 16 | |
17 | + /// <summary> | |
18 | + /// Use Same season effected colors as ingame-map. | |
19 | + /// </summary> | |
20 | + /// <value>The seasonal colors.</value> | |
21 | + public bool SeasonalColors { get; set; } = true; | |
22 | + | |
17 | 23 | //public string ChosenRendererName { get; set; } |
18 | 24 | |
19 | 25 | //All - Designators, setup |
@@ -0,0 +1,91 @@ | ||
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.IO; | |
4 | + | |
5 | +using Hjg.Pngcs; | |
6 | +using Hjg.Pngcs.Chunks; | |
7 | + | |
8 | +using Vintagestory.API.Client; | |
9 | +using Vintagestory.API.Common; | |
10 | +using Vintagestory.API.MathTools; | |
11 | + | |
12 | +namespace Automap | |
13 | +{ | |
14 | + public abstract class AChunkRenderer | |
15 | + { | |
16 | + protected readonly int chunkSize; | |
17 | + | |
18 | + public virtual ICoreClientAPI ClientAPI { get; protected set; } | |
19 | + public virtual ILogger Logger { get; protected set; } | |
20 | + public virtual Dictionary<int, BlockDesignator> BlockID_Designators { get; set; } | |
21 | + public virtual bool SeasonalColors { get; } | |
22 | + //private PngWriter pngWriter; | |
23 | + | |
24 | + protected AChunkRenderer(ICoreClientAPI clientAPI, ILogger logger, bool useSeasonColor = true) | |
25 | + { | |
26 | + this.ClientAPI = clientAPI; | |
27 | + this.Logger = logger; | |
28 | + this.SeasonalColors = useSeasonColor; | |
29 | + this.chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
30 | + | |
31 | + } | |
32 | + | |
33 | + public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount); | |
34 | + | |
35 | + public virtual PngWriter SetupPngImage(Vec2i coord, string path, string chunkPath, ref ColumnMeta metadata) | |
36 | + { | |
37 | + ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false); | |
38 | + | |
39 | + string filename = $"{coord.X}_{coord.Y}.png"; | |
40 | + filename = Path.Combine(path, chunkPath, filename); | |
41 | + | |
42 | + PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true); | |
43 | + PngMetadata meta = pngWriter.GetMetadata( ); | |
44 | + meta.SetTimeNow( ); | |
45 | + meta.SetText("Chunk_X", coord.X.ToString("D")); | |
46 | + meta.SetText("Chunk_Y", coord.Y.ToString("D")); | |
47 | + meta.SetText("PxSz", "1"); | |
48 | + //Setup specialized meta-data PNG chunks here... | |
49 | + PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo) { | |
50 | + ChunkMetadata = metadata | |
51 | + }; | |
52 | + pngWriter.GetChunksList( ).Queue(pngChunkMeta); | |
53 | + pngWriter.CompLevel = 5;// 9 is the maximum compression but thats too high for the small benefit it gives | |
54 | + pngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman; | |
55 | + | |
56 | + return pngWriter; | |
57 | + } | |
58 | + | |
59 | + protected virtual void ExtractBlockColor(BlockPos tmpPos, Block block, float slopeBoost,out int red, out int green, out int blue ) | |
60 | + { | |
61 | + int avgCol, rndCol, col, packedFormat; | |
62 | + | |
63 | + if (SeasonalColors) { | |
64 | + avgCol = block.GetColor(ClientAPI, tmpPos); | |
65 | + rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP); | |
66 | + col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f); | |
67 | + packedFormat = ColorUtil.ColorMultiply3Clamped(col, slopeBoost); | |
68 | + | |
69 | + red = ColorUtil.ColorB(packedFormat); | |
70 | + green = ColorUtil.ColorG(packedFormat); | |
71 | + blue = ColorUtil.ColorR(packedFormat); | |
72 | + } | |
73 | + else { | |
74 | + col = block.GetColorWithoutTint(ClientAPI, tmpPos); | |
75 | + //How to set as Eternal-Summer??? | |
76 | + //col = ClientAPI.World.ApplyColorMapOnRgba(block.ClimateColorMapForMap, block.SeasonColorMapForMap, col, tmpPos.X, tmpPos.Y, tmpPos.Z); | |
77 | + | |
78 | + /* | |
79 | + int greenAmp = ColorUtil.ColorG(127); | |
80 | + col = ColorUtil.ColorOverlay(col, greenAmp, 0.125f); | |
81 | + */ | |
82 | + packedFormat = ColorUtil.ColorMultiply3Clamped(col, slopeBoost); | |
83 | + | |
84 | + red = ColorUtil.ColorB(packedFormat); | |
85 | + green = ColorUtil.ColorG(packedFormat); | |
86 | + blue = ColorUtil.ColorR(packedFormat); | |
87 | + } | |
88 | + } | |
89 | + } | |
90 | +} | |
91 | + |
@@ -9,11 +9,9 @@ using Vintagestory.API.MathTools; | ||
9 | 9 | |
10 | 10 | namespace Automap |
11 | 11 | { |
12 | - public class AlternateRenderer : IChunkRenderer | |
12 | + public class AlternateRenderer : AChunkRenderer | |
13 | 13 | { |
14 | - private readonly int chunkSize; | |
15 | - | |
16 | - | |
14 | + | |
17 | 15 | /// <summary> |
18 | 16 | /// V.G.D:'s Alternative renderer |
19 | 17 | /// </summary> |
@@ -21,7 +19,7 @@ namespace Automap | ||
21 | 19 | /// <param name="logger">Logger.</param> |
22 | 20 | public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger) |
23 | 21 | { |
24 | - chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
22 | + | |
25 | 23 | } |
26 | 24 | |
27 | 25 | public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount) |
@@ -1,27 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Collections.Generic; | |
3 | - | |
4 | -using Hjg.Pngcs; | |
5 | - | |
6 | -using Vintagestory.API.Client; | |
7 | -using Vintagestory.API.Common; | |
8 | -using Vintagestory.API.MathTools; | |
9 | - | |
10 | -namespace Automap | |
11 | -{ | |
12 | - public abstract class IChunkRenderer | |
13 | - { | |
14 | - public virtual ICoreClientAPI ClientAPI { get; protected set; } | |
15 | - public virtual ILogger Logger { get; protected set; } | |
16 | - public virtual Dictionary<int, BlockDesignator> BlockID_Designators { get; set; } | |
17 | - | |
18 | - protected IChunkRenderer(ICoreClientAPI clientAPI, ILogger logger) | |
19 | - { | |
20 | - this.ClientAPI = clientAPI; | |
21 | - this.Logger = logger; | |
22 | - } | |
23 | - | |
24 | - public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount); | |
25 | - } | |
26 | -} | |
27 | - |
@@ -9,9 +9,9 @@ using Vintagestory.API.MathTools; | ||
9 | 9 | |
10 | 10 | namespace Automap |
11 | 11 | { |
12 | - public class StandardRenderer : IChunkRenderer | |
12 | + public class StandardRenderer : AChunkRenderer | |
13 | 13 | { |
14 | - private readonly int chunkSize; | |
14 | + | |
15 | 15 | |
16 | 16 | |
17 | 17 | /// <summary> |
@@ -19,9 +19,9 @@ namespace Automap | ||
19 | 19 | /// </summary> |
20 | 20 | /// <param name="clientAPI">Client API.</param> |
21 | 21 | /// <param name="logger">Logger.</param> |
22 | - public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger) | |
22 | + public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger, seasonalColor) | |
23 | 23 | { |
24 | - chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
24 | + | |
25 | 25 | } |
26 | 26 | |
27 | 27 | public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount) |
@@ -61,7 +61,7 @@ namespace Automap | ||
61 | 61 | int localX = localpos.X; |
62 | 62 | int localZ = localpos.Y; |
63 | 63 | |
64 | - float b = 1; | |
64 | + float slopeBoost = 1; | |
65 | 65 | int leftTop, rightTop, leftBot; |
66 | 66 | |
67 | 67 | IMapChunk leftTopMapChunk = mc; |
@@ -102,10 +102,10 @@ namespace Automap | ||
102 | 102 | |
103 | 103 | float slopeness = (leftTop + rightTop + leftBot); |
104 | 104 | |
105 | - if (slopeness > 0) b = 1.2f; | |
106 | - if (slopeness < 0) b = 0.8f; | |
105 | + if (slopeness > 0) slopeBoost = 1.2f; | |
106 | + if (slopeness < 0) slopeBoost = 0.8f; | |
107 | 107 | |
108 | - b -= 0.15f; //Slope boost value | |
108 | + slopeBoost -= 0.15f; //Slope boost value | |
109 | 109 | |
110 | 110 | if (chunksColumn[localChunkY] == null) |
111 | 111 | { |
@@ -120,15 +120,9 @@ namespace Automap | ||
120 | 120 | |
121 | 121 | tmpPos.Set(chunkSize * chunkPos.X + localpos.X, mapY, chunkSize * chunkPos.Y + localpos.Y); |
122 | 122 | |
123 | - int avgCol = block.GetColor(ClientAPI, tmpPos); | |
124 | - int rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP); | |
125 | - int col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f); | |
126 | - var packedFormat = ColorUtil.ColorMultiply3Clamped(col, b); | |
127 | - | |
128 | - int red = ColorUtil.ColorB(packedFormat); | |
129 | - int green = ColorUtil.ColorG(packedFormat); | |
130 | - int blue = ColorUtil.ColorR(packedFormat); | |
123 | + int red, green, blue; | |
131 | 124 | |
125 | + ExtractBlockColor(tmpPos, block, slopeBoost, out red, out green, out blue); | |
132 | 126 | |
133 | 127 | //============ POI Population ================= |
134 | 128 | if (BlockID_Designators.ContainsKey(blockId)) |
@@ -28,7 +28,7 @@ namespace Automap | ||
28 | 28 | private Snapshotter snapshot; |
29 | 29 | private ICoreClientAPI ClientAPI { get; set; } |
30 | 30 | private ILogger Logger { get; set; } |
31 | - private IChunkRenderer ChunkRenderer { get; set; } | |
31 | + private AChunkRenderer ChunkRenderer { get; set; } | |
32 | 32 | private JsonGenerator JsonGenerator { get; set; } |
33 | 33 | |
34 | 34 | internal const string _mapPath = @"Maps"; |
@@ -72,7 +72,7 @@ namespace Automap | ||
72 | 72 | configuration = config; |
73 | 73 | |
74 | 74 | //TODO:Choose which one from GUI |
75 | - this.ChunkRenderer = new StandardRenderer(clientAPI, logger); | |
75 | + this.ChunkRenderer = new StandardRenderer(clientAPI, logger, this.configuration.SeasonalColors); | |
76 | 76 | |
77 | 77 | //Listen on bus for commands |
78 | 78 | ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey); |
@@ -218,7 +218,7 @@ namespace Automap | ||
218 | 218 | } |
219 | 219 | ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta); |
220 | 220 | |
221 | - PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, ref chunkMeta); | |
221 | + PngWriter pngWriter = ChunkRenderer.SetupPngImage(mostActiveCol.Key, path, _chunkPath, ref chunkMeta); | |
222 | 222 | ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter, out updatedPixels); |
223 | 223 | |
224 | 224 | if (updatedPixels > 0) |
@@ -526,29 +526,7 @@ namespace Automap | ||
526 | 526 | |
527 | 527 | } |
528 | 528 | |
529 | - private PngWriter SetupPngImage(Vec2i coord, ref ColumnMeta metadata) | |
530 | - { | |
531 | - ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false); | |
532 | - | |
533 | - string filename = $"{coord.X}_{coord.Y}.png"; | |
534 | - filename = Path.Combine(path, _chunkPath ,filename); | |
535 | - | |
536 | - PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true); | |
537 | - PngMetadata meta = pngWriter.GetMetadata(); | |
538 | - meta.SetTimeNow(); | |
539 | - meta.SetText("Chunk_X", coord.X.ToString("D")); | |
540 | - meta.SetText("Chunk_Y", coord.Y.ToString("D")); | |
541 | - //Setup specialized meta-data PNG chunks here... | |
542 | - PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo) | |
543 | - { | |
544 | - ChunkMetadata = metadata | |
545 | - }; | |
546 | - pngWriter.GetChunksList().Queue(pngChunkMeta); | |
547 | - pngWriter.CompLevel = 5;// 9 is the maximum compression but thats too high for the small benefit it gives | |
548 | - pngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman; | |
549 | 529 | |
550 | - return pngWriter; | |
551 | - } | |
552 | 530 | |
553 | 531 | /// <summary> |
554 | 532 | /// Does the heavy lifting of Scanning columns of chunks - scans for BlockEntity, creates Heightmap and stats... |
@@ -77,7 +77,7 @@ namespace Automap | ||
77 | 77 | jsonWriter.WriteKeyValue("genTime", DateTimeOffset.UtcNow); |
78 | 78 | |
79 | 79 | jsonWriter.WriteKeyRawValue("startCoords", $"[{startChunkColumn.X},{startChunkColumn.Y}]"); |
80 | - | |
80 | + jsonWriter.WriteKeyRawValue("defaultSpawnPos", $"[{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.X},{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.Y},{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.Z}]" ); | |
81 | 81 | jsonWriter.WriteKeyValue("chunkSize", chunkSize); |
82 | 82 | |
83 | 83 | jsonWriter.WriteArray("edges", new int[]{ |