OSDN Git Service

W.I.P. Changes for non-Seasonal color on map, default spawn coords
authormelchior <melchior@users.osdn.me>
Sun, 20 Sep 2020 20:23:03 +0000 (16:23 -0400)
committermelchior <melchior@users.osdn.me>
Sun, 20 Sep 2020 20:23:03 +0000 (16:23 -0400)
Automap/Automap.csproj
Automap/Data/PersistedConfiguration.cs
Automap/Renderers/AChunkRenderer.cs [new file with mode: 0644]
Automap/Renderers/AlternateRenderer.cs
Automap/Renderers/IChunkRenderer.cs [deleted file]
Automap/Renderers/StandardRenderer.cs
Automap/Subsystems/AutomapSystem.cs
Automap/Subsystems/JsonGenerator.cs

index 41857e1..34a3dca 100644 (file)
@@ -88,7 +88,7 @@
                <Compile Include="Designators\DefaultDesignators.cs" />
     <Compile Include="Subsystems\AutomapSystem.cs" />
     <Compile Include="Subsystems\AutomapGUIDialog.cs" />
-    <Compile Include="Renderers\IChunkRenderer.cs" />
+    <Compile Include="Renderers\AChunkRenderer.cs" />
     <Compile Include="Renderers\StandardRenderer.cs" />
     <Compile Include="Renderers\AlternateRenderer.cs" />
     <Compile Include="Data\StatusData.cs" />
index 4f4a35c..dca5f88 100644 (file)
@@ -14,6 +14,12 @@ namespace Automap
                /// <value>To autostart.</value>
                public bool Autostart { get; set; } = false;
 
+               /// <summary>
+               /// Use Same season effected colors as ingame-map.
+               /// </summary>
+               /// <value>The seasonal colors.</value>
+               public bool SeasonalColors { get; set; } = true;
+
                //public string ChosenRendererName { get; set; }
 
                //All - Designators, setup
diff --git a/Automap/Renderers/AChunkRenderer.cs b/Automap/Renderers/AChunkRenderer.cs
new file mode 100644 (file)
index 0000000..51c4f21
--- /dev/null
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+using Hjg.Pngcs;
+using Hjg.Pngcs.Chunks;
+
+using Vintagestory.API.Client;
+using Vintagestory.API.Common;
+using Vintagestory.API.MathTools;
+
+namespace Automap
+{
+    public abstract class AChunkRenderer
+    {          
+               protected readonly int chunkSize;
+
+        public virtual ICoreClientAPI ClientAPI { get; protected set; }
+        public virtual ILogger Logger { get; protected set; }
+        public virtual Dictionary<int, BlockDesignator> BlockID_Designators { get; set; }
+               public virtual bool SeasonalColors { get; }
+               //private PngWriter pngWriter;
+
+               protected AChunkRenderer(ICoreClientAPI clientAPI, ILogger logger, bool useSeasonColor = true)
+               {
+                       this.ClientAPI = clientAPI;
+                       this.Logger = logger;
+                       this.SeasonalColors = useSeasonColor;
+                       this.chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;
+
+               }
+
+        public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount);
+
+               public virtual PngWriter SetupPngImage(Vec2i coord, string path, string chunkPath, ref ColumnMeta metadata)
+               {
+               ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false);
+
+               string filename = $"{coord.X}_{coord.Y}.png";
+               filename = Path.Combine(path, chunkPath, filename);
+
+               PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true);
+               PngMetadata meta = pngWriter.GetMetadata( );
+               meta.SetTimeNow( );
+               meta.SetText("Chunk_X", coord.X.ToString("D"));
+               meta.SetText("Chunk_Y", coord.Y.ToString("D"));
+               meta.SetText("PxSz", "1");
+               //Setup specialized meta-data PNG chunks here...
+               PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo) {
+                       ChunkMetadata = metadata
+               };
+               pngWriter.GetChunksList( ).Queue(pngChunkMeta);
+               pngWriter.CompLevel = 5;// 9 is the maximum compression but thats too high for the small benefit it gives
+               pngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman;
+
+               return pngWriter;
+               }
+
+               protected virtual void ExtractBlockColor(BlockPos tmpPos, Block block, float slopeBoost,out int red, out int green, out int blue )
+               {
+               int avgCol, rndCol, col, packedFormat;
+
+               if (SeasonalColors) {
+               avgCol = block.GetColor(ClientAPI, tmpPos);
+               rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP);
+               col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f);
+               packedFormat = ColorUtil.ColorMultiply3Clamped(col, slopeBoost);
+
+               red = ColorUtil.ColorB(packedFormat);
+               green = ColorUtil.ColorG(packedFormat);
+               blue = ColorUtil.ColorR(packedFormat);
+               }
+               else {
+               col = block.GetColorWithoutTint(ClientAPI, tmpPos);
+               //How to set as Eternal-Summer???
+               //col = ClientAPI.World.ApplyColorMapOnRgba(block.ClimateColorMapForMap, block.SeasonColorMapForMap, col, tmpPos.X, tmpPos.Y, tmpPos.Z);
+
+               /*
+               int greenAmp = ColorUtil.ColorG(127);
+               col = ColorUtil.ColorOverlay(col, greenAmp, 0.125f);
+               */
+               packedFormat = ColorUtil.ColorMultiply3Clamped(col, slopeBoost);                
+
+               red = ColorUtil.ColorB(packedFormat);
+               green = ColorUtil.ColorG(packedFormat);
+               blue = ColorUtil.ColorR(packedFormat);
+               }
+               }
+    }
+}
+
index 69ff326..b88b0be 100644 (file)
@@ -9,11 +9,9 @@ using Vintagestory.API.MathTools;
 
 namespace Automap
 {
-       public class AlternateRenderer : IChunkRenderer
+       public class AlternateRenderer : AChunkRenderer
        {
-               private readonly int chunkSize;
-
-
+               
                /// <summary>
                /// V.G.D:'s Alternative renderer
                /// </summary>
@@ -21,7 +19,7 @@ namespace Automap
                /// <param name="logger">Logger.</param>
                public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger)
                {
-                       chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;
+                       
                }
 
                public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount)
diff --git a/Automap/Renderers/IChunkRenderer.cs b/Automap/Renderers/IChunkRenderer.cs
deleted file mode 100644 (file)
index f9ec576..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-using Hjg.Pngcs;
-
-using Vintagestory.API.Client;
-using Vintagestory.API.Common;
-using Vintagestory.API.MathTools;
-
-namespace Automap
-{
-    public abstract class IChunkRenderer
-    {
-        public virtual ICoreClientAPI ClientAPI { get; protected set; }
-        public virtual ILogger Logger { get; protected set; }
-        public virtual Dictionary<int, BlockDesignator> BlockID_Designators { get; set; }
-
-               protected IChunkRenderer(ICoreClientAPI clientAPI, ILogger logger)
-               {
-                       this.ClientAPI = clientAPI;
-                       this.Logger = logger;
-               }
-
-        public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount);
-    }
-}
-
index 3ee4c7f..538e7ff 100644 (file)
@@ -9,9 +9,9 @@ using Vintagestory.API.MathTools;
 
 namespace Automap
 {
-       public class StandardRenderer : IChunkRenderer
+       public class StandardRenderer : AChunkRenderer
        {
-               private readonly int chunkSize;
+               
 
 
                /// <summary>
@@ -19,9 +19,9 @@ namespace Automap
                /// </summary>
                /// <param name="clientAPI">Client API.</param>
                /// <param name="logger">Logger.</param>
-               public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger)
+               public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger, seasonalColor)
                {
-                       chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;
+                       
                }
 
                public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount)
@@ -61,7 +61,7 @@ namespace Automap
                                int localX = localpos.X;
                                int localZ = localpos.Y;
 
-                               float b = 1;
+                               float slopeBoost = 1;
                                int leftTop, rightTop, leftBot;
 
                                IMapChunk leftTopMapChunk = mc;
@@ -102,10 +102,10 @@ namespace Automap
 
                                float slopeness = (leftTop + rightTop + leftBot);
 
-                               if (slopeness > 0) b = 1.2f;
-                               if (slopeness < 0) b = 0.8f;
+                               if (slopeness > 0) slopeBoost = 1.2f;
+                               if (slopeness < 0) slopeBoost = 0.8f;
 
-                               b -= 0.15f; //Slope boost value 
+                               slopeBoost -= 0.15f; //Slope boost value 
 
                                if (chunksColumn[localChunkY] == null)
                                {
@@ -120,15 +120,9 @@ namespace Automap
 
                                tmpPos.Set(chunkSize * chunkPos.X + localpos.X, mapY, chunkSize * chunkPos.Y + localpos.Y);
 
-                               int avgCol = block.GetColor(ClientAPI, tmpPos);
-                               int rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP);
-                               int col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f);
-                               var packedFormat = ColorUtil.ColorMultiply3Clamped(col, b);
-
-                               int red = ColorUtil.ColorB(packedFormat);
-                               int green = ColorUtil.ColorG(packedFormat);
-                               int blue = ColorUtil.ColorR(packedFormat);
+                               int red, green, blue;
 
+                               ExtractBlockColor(tmpPos, block, slopeBoost, out red, out green, out blue);
 
                                //============ POI Population =================
                                if (BlockID_Designators.ContainsKey(blockId))
index 0a85be3..910b11f 100644 (file)
@@ -28,7 +28,7 @@ namespace Automap
                private Snapshotter snapshot;
                private ICoreClientAPI ClientAPI { get; set; }
                private ILogger Logger { get; set; }
-               private IChunkRenderer ChunkRenderer { get; set; }
+               private AChunkRenderer ChunkRenderer { get; set; }
                private JsonGenerator JsonGenerator { get; set; }
 
                internal const string _mapPath = @"Maps";
@@ -72,7 +72,7 @@ namespace Automap
                        configuration = config;
 
                        //TODO:Choose which one from GUI 
-                       this.ChunkRenderer = new StandardRenderer(clientAPI, logger);
+                       this.ChunkRenderer = new StandardRenderer(clientAPI, logger, this.configuration.SeasonalColors);
 
                        //Listen on bus for commands
                        ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey);
@@ -218,7 +218,7 @@ namespace Automap
                                                }
                                                ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta);
 
-                                               PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, ref chunkMeta);
+                                               PngWriter pngWriter = ChunkRenderer.SetupPngImage(mostActiveCol.Key, path, _chunkPath, ref chunkMeta);
                                                ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter, out updatedPixels);
 
                                                if (updatedPixels > 0)
@@ -526,29 +526,7 @@ namespace Automap
 
                }
 
-               private PngWriter SetupPngImage(Vec2i coord, ref ColumnMeta metadata)
-               {
-                       ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false);
-
-                       string filename = $"{coord.X}_{coord.Y}.png";
-                       filename = Path.Combine(path, _chunkPath ,filename);
-
-                       PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true);
-                       PngMetadata meta = pngWriter.GetMetadata();
-                       meta.SetTimeNow();
-                       meta.SetText("Chunk_X", coord.X.ToString("D"));
-                       meta.SetText("Chunk_Y", coord.Y.ToString("D"));
-                       //Setup specialized meta-data PNG chunks here...
-                       PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo)
-                       {
-                               ChunkMetadata = metadata
-                       };
-                       pngWriter.GetChunksList().Queue(pngChunkMeta);
-                       pngWriter.CompLevel = 5;// 9 is the maximum compression but thats too high for the small benefit it gives
-                       pngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman;
 
-                       return pngWriter;
-               }
 
                /// <summary>
                /// Does the heavy lifting of Scanning columns of chunks - scans for BlockEntity, creates Heightmap and stats...
index 3d0a01a..f215979 100644 (file)
@@ -77,7 +77,7 @@ namespace Automap
                                        jsonWriter.WriteKeyValue("genTime", DateTimeOffset.UtcNow);
 
                                        jsonWriter.WriteKeyRawValue("startCoords", $"[{startChunkColumn.X},{startChunkColumn.Y}]");
-
+                                       jsonWriter.WriteKeyRawValue("defaultSpawnPos", $"[{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.X},{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.Y},{ClientAPI.World.DefaultSpawnPosition.AsBlockPos.Z}]" );
                                        jsonWriter.WriteKeyValue("chunkSize", chunkSize);
 
                                        jsonWriter.WriteArray("edges", new int[]{