Automap (client) [VS plugin mod]
修訂 | f2daf9ef05f9f97f40f18a56be811851c4cbe3c0 (tree) |
---|---|
時間 | 2020-11-26 12:11:50 |
作者 | melchior <melchior@user...> |
Commiter | melchior |
Added configurability for Renderer choice,
*New* Flat Renderer added
@@ -100,6 +100,7 @@ | ||
100 | 100 | <Compile Include="Subsystems\Snapshot.cs" /> |
101 | 101 | <Compile Include="Data\JSON\BlockPosJson.cs" /> |
102 | 102 | <Compile Include="Data\ColumnCounter.cs" /> |
103 | + <Compile Include="Renderers\FlatRenderer.cs" /> | |
103 | 104 | </ItemGroup> |
104 | 105 | <ItemGroup> |
105 | 106 | <Folder Include="VS_libs\" /> |
@@ -20,7 +20,11 @@ namespace Automap | ||
20 | 20 | /// <value>The seasonal colors.</value> |
21 | 21 | public bool SeasonalColors { get; set; } = true; |
22 | 22 | |
23 | - //public string ChosenRendererName { get; set; } | |
23 | + /// <summary> | |
24 | + /// Which appearance 'theme' should shards have? | |
25 | + /// </summary> | |
26 | + /// <value>'Standard' / 'Alternate' / 'Flat'</value> | |
27 | + public string RendererName { get; set; } = @"Standard"; | |
24 | 28 | |
25 | 29 | //All - Designators, setup |
26 | 30 | public List<BlockDesignator> BlockDesignators { get; set; } |
@@ -11,13 +11,14 @@ namespace Automap | ||
11 | 11 | { |
12 | 12 | public class AlternateRenderer : AChunkRenderer |
13 | 13 | { |
14 | - | |
14 | + public const string Name = @"Alternate"; | |
15 | + | |
15 | 16 | /// <summary> |
16 | 17 | /// V.G.D:'s Alternative renderer |
17 | 18 | /// </summary> |
18 | 19 | /// <param name="clientAPI">Client API.</param> |
19 | 20 | /// <param name="logger">Logger.</param> |
20 | - public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger) | |
21 | + public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger) | |
21 | 22 | { |
22 | 23 | |
23 | 24 | } |
@@ -0,0 +1,95 @@ | ||
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.Linq; | |
4 | + | |
5 | +using Hjg.Pngcs; | |
6 | + | |
7 | +using Vintagestory.API.Client; | |
8 | +using Vintagestory.API.Common; | |
9 | +using Vintagestory.API.MathTools; | |
10 | +using Vintagestory.Common; | |
11 | + | |
12 | +namespace Automap | |
13 | +{ | |
14 | + public class FlatRenderer : AChunkRenderer | |
15 | + { | |
16 | + public const string Name = @"Flat"; | |
17 | + | |
18 | + /// <summary> | |
19 | + /// Renders shards similar to the OLD VS (1.8) version, plus P.O.I. markings. | |
20 | + /// </summary> | |
21 | + /// <param name="clientAPI">Client API.</param> | |
22 | + /// <param name="logger">Logger.</param> | |
23 | + public FlatRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger, seasonalColor) | |
24 | + { | |
25 | + | |
26 | + } | |
27 | + | |
28 | + public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount) | |
29 | + { | |
30 | + pixelCount = 0; | |
31 | + BlockPos tmpPos = new BlockPos( ); | |
32 | + Vec2i localpos = new Vec2i( ); | |
33 | + | |
34 | + var chunksColumn = new IWorldChunk[ClientAPI.World.BlockAccessor.MapSizeY / chunkSize]; | |
35 | + | |
36 | + //pre-create PNG line slices... | |
37 | + ImageLine[ ] lines = Enumerable.Repeat(new object( ), chunkSize).Select(l => new ImageLine(this.PngWriter.ImgInfo)).ToArray( ); | |
38 | + | |
39 | + int topChunkY = targetColMeta.YMax / chunkSize; | |
40 | + | |
41 | + for (int chunkY = 0; chunkY <= topChunkY; chunkY++) { | |
42 | + chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y); | |
43 | + WorldChunk ownChunk = chunksColumn[chunkY] as WorldChunk; | |
44 | + if (ownChunk != null) { | |
45 | + if (ownChunk.IsPacked( )) ownChunk.Unpack( );//Gah - probably done already by chunk processor | |
46 | + } | |
47 | + else { | |
48 | + Logger.Warning("CHUNK A.W.O.L. : X{0} Y{1} Z{2} - Missing slice FOR COLUMN", chunkPos.X, chunkY, chunkPos.Y); | |
49 | + //return; | |
50 | + } | |
51 | + } | |
52 | + | |
53 | + for (int pixelIndex = 0; pixelIndex < (chunkSize * chunkSize); pixelIndex++) { | |
54 | + MapUtil.PosInt2d(pixelIndex, chunkSize, localpos); | |
55 | + int localX = localpos.X; | |
56 | + int localZ = localpos.Y; | |
57 | + ushort localY = targetColMeta.HeightMap[localX, localZ]; | |
58 | + | |
59 | + int localChunkY = localY / chunkSize; | |
60 | + if (localChunkY >= (chunksColumn.Length)) continue;//Out of range! | |
61 | + if (chunksColumn[localChunkY] == null) continue;//BIG Gaps! | |
62 | + | |
63 | + int blockId = chunksColumn[localChunkY].MaybeBlocks[MapUtil.Index3d(localX, (localY % chunkSize), localZ, chunkSize, chunkSize)]; | |
64 | + | |
65 | + Block block = ClientAPI.World.Blocks[blockId]; | |
66 | + | |
67 | + tmpPos.Set(chunkSize * chunkPos.X + localpos.X, localY, chunkSize * chunkPos.Y + localpos.Y); | |
68 | + | |
69 | + int red = 0, green = 0, blue = 0; | |
70 | + | |
71 | + ExtractBlockColor(tmpPos, block, 1.0f, out red, out green, out blue); | |
72 | + | |
73 | + //============ POI Population ================= | |
74 | + if (BlockID_Designators.ContainsKey(blockId)) { | |
75 | + var desig = BlockID_Designators[blockId]; | |
76 | + | |
77 | + if (desig.Enabled) { | |
78 | + red = desig.OverwriteColor.R; | |
79 | + green = desig.OverwriteColor.G; | |
80 | + blue = desig.OverwriteColor.B; | |
81 | + } | |
82 | + } | |
83 | + | |
84 | + ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue); | |
85 | + pixelCount++; | |
86 | + } | |
87 | + | |
88 | + for (int row = 0; row < this.PngWriter.ImgInfo.Rows; row++) { | |
89 | + this.PngWriter.WriteRow(lines[row], row); | |
90 | + } | |
91 | + | |
92 | + this.PngWriter.End( ); | |
93 | + } | |
94 | + } | |
95 | +} | |
\ No newline at end of file |
@@ -13,6 +13,7 @@ namespace Automap | ||
13 | 13 | { |
14 | 14 | public class StandardRenderer : AChunkRenderer |
15 | 15 | { |
16 | + public const string Name = @"Standard"; | |
16 | 17 | |
17 | 18 | /// <summary> |
18 | 19 | /// Renders shards similar to the Default VS version, plus P.O.I. markings. |
@@ -21,7 +22,7 @@ namespace Automap | ||
21 | 22 | /// <param name="logger">Logger.</param> |
22 | 23 | public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger, bool seasonalColor) : base(clientAPI, logger, seasonalColor) |
23 | 24 | { |
24 | - | |
25 | + | |
25 | 26 | } |
26 | 27 | |
27 | 28 | public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount) |
@@ -73,8 +73,7 @@ namespace Automap | ||
73 | 73 | ClientAPI.Event.LevelFinalize += EngageAutomap; |
74 | 74 | configuration = config; |
75 | 75 | |
76 | - //TODO:Choose which one from GUI | |
77 | - this.ChunkRenderer = new StandardRenderer(clientAPI, logger, this.configuration.SeasonalColors); | |
76 | + this.ChunkRenderer = InstantiateChosenRenderer(config.RendererName); | |
78 | 77 | |
79 | 78 | //Listen on bus for commands |
80 | 79 | ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey); |
@@ -723,12 +722,32 @@ namespace Automap | ||
723 | 722 | AddNote(cmdData.Notation); |
724 | 723 | break; |
725 | 724 | } |
726 | -#if DEBUG | |
725 | + #if DEBUG | |
727 | 726 | ClientAPI.TriggerChatMessage($"Automap commanded to: {cmdData.State} "); |
728 | -#endif | |
727 | + #endif | |
729 | 728 | } |
730 | 729 | #endregion |
731 | 730 | |
731 | + private AChunkRenderer InstantiateChosenRenderer(string rendererName ) | |
732 | + { | |
733 | + Logger.VerboseDebug("Using '{0}' style Shard Renderer", rendererName); | |
734 | + switch (rendererName) | |
735 | + { | |
736 | + case StandardRenderer.Name: | |
737 | + return new StandardRenderer(ClientAPI, Logger, this.configuration.SeasonalColors); | |
738 | + | |
739 | + case AlternateRenderer.Name: | |
740 | + return new AlternateRenderer(ClientAPI, Logger, this.configuration.SeasonalColors); | |
741 | + | |
742 | + case FlatRenderer.Name: | |
743 | + return new FlatRenderer(ClientAPI, Logger, this.configuration.SeasonalColors); | |
744 | + | |
745 | + default: | |
746 | + throw new ArgumentOutOfRangeException("rendererName",rendererName,"That value isn't supported or known..."); | |
747 | + } | |
748 | + | |
749 | + return null; | |
750 | + } | |
732 | 751 | } |
733 | 752 | |
734 | 753 | } |