Automap (client) [VS plugin mod]
リビジョン | 8e4c042fed0bcb8e5de35d1cec15c458206e0e0f (tree) |
---|---|
日時 | 2020-06-04 08:04:24 |
作者 | melchior <melchior@user...> |
コミッター | melchior |
Working (W.I.P.) snapshots!
@@ -75,6 +75,10 @@ namespace Automap | ||
75 | 75 | txtNoteArea.fixedHeight = 24; |
76 | 76 | txtNoteArea.fixedWidth = 256; |
77 | 77 | |
78 | + ElementBounds btnSnapshotArea = btnNoteArea.CopyOffsetedSibling(0, 64, 2, 5); | |
79 | + btnNoteArea.fixedHeight = 24; | |
80 | + btnNoteArea.fixedWidth = 20; | |
81 | + | |
78 | 82 | |
79 | 83 | this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds) |
80 | 84 | .AddShadedDialogBG(bgBounds) |
@@ -86,6 +90,7 @@ namespace Automap | ||
86 | 90 | .AddDynamicText("Idle.", CairoFont.WhiteSmallText().WithFontSize(12), EnumTextOrientation.Left, txtStatusBounds, _statusTextKey) |
87 | 91 | .AddTextInput(txtNoteArea, null, CairoFont.WhiteMediumText().WithFontSize(16), _noteTextKey) |
88 | 92 | .AddButton("Note:", CreateNote, btnNoteArea, CairoFont.ButtonText()) |
93 | + .AddButton("Snapshot!", TriggerSnapshot, btnSnapshotArea, CairoFont.ButtonText( )) | |
89 | 94 | .Compose(); |
90 | 95 | |
91 | 96 | //Controls for ALL Block & Entity Designators (Enable/Disable) <-- block edits while in 'Run' state |
@@ -147,6 +152,15 @@ namespace Automap | ||
147 | 152 | return true;//FINDOUT: What does this DO? |
148 | 153 | } |
149 | 154 | |
155 | + private bool TriggerSnapshot( ) | |
156 | + { | |
157 | + var snappyCmd = new CommandData(CommandType.Snapshot); | |
158 | + | |
159 | + capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, snappyCmd); | |
160 | + | |
161 | + return true;//FINDOUT: What does this DO? | |
162 | + } | |
163 | + | |
150 | 164 | private void AutostartChange(bool startValue) |
151 | 165 | { |
152 | 166 | configuration.Autostart = startValue; |
@@ -34,8 +34,8 @@ namespace Automap | ||
34 | 34 | private IChunkRenderer ChunkRenderer { get; set; } |
35 | 35 | private JsonGenerator JsonGenerator { get; set; } |
36 | 36 | |
37 | - private const string _mapPath = @"Maps"; | |
38 | - private const string _chunkPath = @"Chunks"; | |
37 | + internal const string _mapPath = @"Maps"; | |
38 | + internal const string _chunkPath = @"Chunks"; | |
39 | 39 | private const string _domain = @"automap"; |
40 | 40 | private const string chunkFile_filter = @"*_*.png"; |
41 | 41 | private const string poiFileName = @"poi_binary"; |
@@ -79,7 +79,7 @@ namespace Automap | ||
79 | 79 | |
80 | 80 | //Listen on bus for commands |
81 | 81 | ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey); |
82 | - | |
82 | + //TODO: recreate as GUI button! | |
83 | 83 | ClientAPI.RegisterCommand("snapshot", "", "", (id, args) => CurrentState = CommandType.Snapshot); |
84 | 84 | |
85 | 85 | if (configuration.Autostart) |
@@ -122,7 +122,7 @@ namespace Automap | ||
122 | 122 | IsBackground = true |
123 | 123 | }; |
124 | 124 | |
125 | - snapshot = new Snapshotter(path, _chunkPath, chunkTopMetadata, chunkSize); | |
125 | + snapshot = new Snapshotter(path, chunkTopMetadata, chunkSize,ClientAPI.World.Seed ); | |
126 | 126 | snapshotThread = new Thread(Snap) |
127 | 127 | { |
128 | 128 | Name = "Snapshot", |
@@ -5,6 +5,7 @@ using System.IO; | ||
5 | 5 | using System.Linq; |
6 | 6 | using System.Threading; |
7 | 7 | using System.Threading.Tasks; |
8 | + | |
8 | 9 | using Hjg.Pngcs; |
9 | 10 | using Hjg.Pngcs.Chunks; |
10 | 11 |
@@ -12,19 +13,21 @@ namespace Automap | ||
12 | 13 | { |
13 | 14 | public class Snapshotter |
14 | 15 | { |
15 | - public string path; | |
16 | + public readonly int chunkSize; | |
17 | + public string fileName; | |
16 | 18 | public string chunkPath; |
17 | 19 | public ColumnsMetadata cols; |
18 | - public int chunkSize; | |
20 | + //TODO: Refactor - so Edges are set at construction time, as ColumnsMetadata is async updating in real time! | |
19 | 21 | public int NorthEdge => cols.North_mostChunk; |
20 | 22 | public int WestEdge => cols.West_mostChunk; |
21 | 23 | public int Width => (cols.East_mostChunk - WestEdge + 1); |
22 | 24 | public int Height => (cols.South_mostChunk - NorthEdge + 1); |
23 | 25 | |
24 | - public Snapshotter(string path, string chunkPath, ColumnsMetadata cols, int chunkSize) | |
26 | + | |
27 | + public Snapshotter(string path, ColumnsMetadata cols, int chunkSize, int worldSeed) | |
25 | 28 | { |
26 | - this.path = Path.Combine(path, "snapshot.png"); | |
27 | - this.chunkPath = Path.Combine(path, chunkPath); | |
29 | + this.fileName = Path.Combine(path, $"snapshot_{worldSeed}_{DateTime.UtcNow:s}.png"); | |
30 | + this.chunkPath = Path.Combine(path, AutomapSystem._chunkPath); | |
28 | 31 | this.cols = cols; |
29 | 32 | this.chunkSize = chunkSize; |
30 | 33 | } |
@@ -40,16 +43,19 @@ namespace Automap | ||
40 | 43 | { |
41 | 44 | var t = new Stopwatch(); |
42 | 45 | t.Start(); |
46 | + | |
43 | 47 | Console.WriteLine("snapshot started"); |
44 | 48 | |
45 | 49 | ImageInfo info = new ImageInfo(Width * chunkSize, Height * chunkSize, 8, false); |
46 | - PngWriter snapWriter = FileHelper.CreatePngWriter(path, info, true); | |
50 | + PngWriter snapWriter = FileHelper.CreatePngWriter(fileName, info, true); | |
47 | 51 | PngMetadata meta = snapWriter.GetMetadata( ); |
48 | 52 | meta.SetTimeNow( ); |
49 | 53 | var transparencyChunk = meta.CreateTRNSChunk( ); |
50 | - transparencyChunk.SetRGB(0, 0, 0); | |
51 | - //meta.SetText("Center_X", coord.X.ToString("D")); | |
52 | - //meta.SetText("Center_Y", coord.Y.ToString("D")); | |
54 | + transparencyChunk.SetRGB(0, 0, 0);//CHECK: This is pure black. | |
55 | + meta.SetText("Northmost", NorthEdge.ToString("D")); | |
56 | + meta.SetText("Eastmost", WestEdge.ToString("D")); | |
57 | + meta.SetText("Width", Width.ToString("D")); | |
58 | + meta.SetText("Height", Height.ToString("D")); | |
53 | 59 | |
54 | 60 | |
55 | 61 |