Automap (client) [VS plugin mod]
修訂 | 62212ee5fcf9e7b00bba51bab1a1351b22515648 (tree) |
---|---|
時間 | 2020-02-27 01:36:45 |
作者 | The Grand Dog <alex.h@me.c...> |
Commiter | The Grand Dog |
replaced the static static map with dynamic static map :)
@@ -5,46 +5,38 @@ using System.Collections.ObjectModel; | ||
5 | 5 | using System.Linq; |
6 | 6 | |
7 | 7 | using Vintagestory.API.Common.Entities; |
8 | +using Vintagestory.API.MathTools; | |
8 | 9 | |
9 | 10 | namespace Automap |
10 | 11 | { |
11 | 12 | /// <summary> |
13 | + /// Actual Physical Point in space - that is interesting. | |
14 | + /// </summary> | |
15 | + public struct EntityOfInterest | |
16 | + { | |
17 | + public string Notes; | |
18 | + public BlockPos Location; | |
19 | + public DateTimeOffset Timestamp; | |
20 | + public long EntityId; | |
21 | + } | |
22 | + | |
23 | + /// <summary> | |
12 | 24 | /// Entities of interest. |
13 | 25 | /// </summary> |
14 | 26 | /// <remarks>Tracked by ID - these never leave.</remarks> |
15 | - public class EntitiesOfInterest | |
27 | + public class EntitiesOfInterest : KeyedCollection<long, EntityOfInterest> | |
16 | 28 | { |
17 | - private Dictionary<long, PointOfInterest> entitySet = new Dictionary<long, PointOfInterest>(50); | |
18 | 29 | |
19 | - | |
20 | - internal void Upsert(Entity something, string message = @"") | |
30 | + internal void AddReplace(EntityOfInterest entity) | |
21 | 31 | { |
22 | - if (entitySet.ContainsKey(something.EntityId)) | |
23 | - { | |
24 | - var movingPOI = entitySet[something.EntityId]; | |
25 | - movingPOI.Location = something.Pos.AsBlockPos.Copy(); | |
26 | - movingPOI.Timestamp = DateTimeOffset.UtcNow; | |
27 | - } | |
28 | - else | |
29 | - { | |
30 | - PointOfInterest newPOI = new PointOfInterest(); | |
31 | - newPOI.EntityId = something.EntityId; | |
32 | - newPOI.Location = something.Pos.AsBlockPos.Copy(); | |
33 | - newPOI.Timestamp = DateTimeOffset.UtcNow; | |
34 | - newPOI.Notes = message; | |
35 | - entitySet.Add(something.EntityId, newPOI); | |
36 | - } | |
37 | - | |
38 | - } | |
32 | + if (Contains(entity.EntityId)) | |
33 | + Remove(entity.EntityId); | |
39 | 34 | |
40 | - | |
41 | - public List<PointOfInterest> PointsList | |
42 | - { | |
43 | - get { | |
44 | - return entitySet.Values.ToList(); | |
45 | - } | |
35 | + Add(entity); | |
46 | 36 | } |
47 | 37 | |
38 | + protected override long GetKeyForItem(EntityOfInterest item) | |
39 | + => item.EntityId; | |
48 | 40 | } |
49 | 41 | } |
50 | 42 |
@@ -17,7 +17,7 @@ namespace Automap | ||
17 | 17 | /// </summary> |
18 | 18 | public class EntityDesignator |
19 | 19 | { |
20 | - public Color OverwriteColor; | |
20 | + public Color Color; | |
21 | 21 | public EntityDesignatonAction SpecialAction; |
22 | 22 | public AssetLocation Pattern; |
23 | 23 | public EnumEntityState? StateCheck;//Needed? |
@@ -28,27 +28,25 @@ namespace Automap | ||
28 | 28 | throw new NotSupportedException(); |
29 | 29 | } |
30 | 30 | |
31 | - public EntityDesignator(AssetLocation pattern, Color overwriteColor, EnumEntityState? state) | |
31 | + public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state) | |
32 | 32 | { |
33 | - this.Pattern = pattern; | |
34 | - this.OverwriteColor = overwriteColor; | |
35 | - this.StateCheck = state; | |
36 | - this.Enabled = true; | |
33 | + Pattern = pattern; | |
34 | + Color = color; | |
35 | + StateCheck = state; | |
36 | + Enabled = true; | |
37 | 37 | } |
38 | 38 | |
39 | - public EntityDesignator(AssetLocation pattern, Color overwriteColor, EnumEntityState? state, EntityDesignatonAction specialAct) | |
39 | + public EntityDesignator(AssetLocation pattern, Color color, EnumEntityState? state, EntityDesignatonAction specialAct) | |
40 | 40 | { |
41 | - this.Pattern = pattern; | |
42 | - this.OverwriteColor = overwriteColor; | |
43 | - this.StateCheck = state; | |
44 | - this.SpecialAction = specialAct; | |
45 | - this.Enabled = true; | |
41 | + Pattern = pattern; | |
42 | + Color = color; | |
43 | + StateCheck = state; | |
44 | + SpecialAction = specialAct; | |
45 | + Enabled = true; | |
46 | 46 | } |
47 | 47 | |
48 | 48 | public override string ToString() |
49 | - { | |
50 | - return Pattern.ToShortString() + "|" + OverwriteColor.Name + "|" + StateCheck ?? ""; | |
51 | - } | |
49 | + => Pattern.ToShortString() + "|" + Color.Name + "|" + StateCheck ?? ""; | |
52 | 50 | } |
53 | 51 | } |
54 | 52 |
@@ -14,30 +14,21 @@ namespace Automap | ||
14 | 14 | public string Notes; |
15 | 15 | public BlockPos Location; |
16 | 16 | public DateTimeOffset Timestamp; |
17 | - public long? EntityId; | |
18 | 17 | } |
19 | 18 | |
20 | 19 | public class PointsOfInterest : KeyedCollection<BlockPos, PointOfInterest> |
21 | 20 | { |
22 | 21 | protected override BlockPos GetKeyForItem(PointOfInterest item) |
23 | - { | |
24 | - return item.Location; | |
25 | - } | |
22 | + => item.Location; | |
26 | 23 | |
27 | 24 | internal void AddReplace(PointOfInterest poi) |
28 | 25 | { |
29 | - if (this.Contains(poi.Location)) | |
30 | - { | |
31 | - this.Remove(poi.Location); | |
32 | - this.Add(poi); | |
33 | - } | |
34 | - else | |
35 | - { | |
36 | - this.Add(poi); | |
37 | - } | |
26 | + if (Contains(poi.Location)) | |
27 | + Remove(poi.Location); | |
38 | 28 | |
39 | - } | |
40 | - } | |
29 | + Add(poi); | |
30 | + } | |
31 | + } | |
41 | 32 | |
42 | 33 | } |
43 | 34 |
@@ -133,13 +133,19 @@ namespace Automap | ||
133 | 133 | { |
134 | 134 | clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn); |
135 | 135 | |
136 | - var message = $"{entity.GetName()}"; | |
137 | 136 | var traderJoe = entity as EntityTrader; |
137 | + var message = $"{entity.GetName()} Alive: {traderJoe.Alive}"; | |
138 | 138 | if (traderJoe.TradeProps != null) |
139 | 139 | { |
140 | - message = $"{traderJoe.GetName()} Alive:{traderJoe.Alive} - Gears: {traderJoe.TradeProps.Money}, "; | |
140 | + message += $" - Gears: {traderJoe.TradeProps.Money}, "; | |
141 | 141 | } |
142 | - poi.Upsert(entity, message); | |
142 | + poi.AddReplace(new EntityOfInterest | |
143 | + { | |
144 | + Location = posn.Copy(), | |
145 | + Notes = message, | |
146 | + Timestamp = DateTimeOffset.UtcNow, | |
147 | + EntityId = entity.EntityId | |
148 | + }); | |
143 | 149 | } |
144 | 150 | |
145 | 151 | internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block) |
@@ -52,7 +52,7 @@ namespace Automap | ||
52 | 52 | |
53 | 53 | private readonly int chunkSize; |
54 | 54 | private string path; |
55 | - private IAsset stylesFile; | |
55 | + private IAsset staticMap; | |
56 | 56 | |
57 | 57 | public static string AutomapStatusEventKey = @"AutomapStatus"; |
58 | 58 | public static string AutomapCommandEventKey = @"AutomapCommand"; |
@@ -80,8 +80,13 @@ namespace Automap | ||
80 | 80 | path = ClientAPI.GetOrCreateDataPath(_mapPath); |
81 | 81 | path = ClientAPI.GetOrCreateDataPath(Path.Combine(path, "World_" + ClientAPI.World.Seed));//Add name of World too...'ServerApi.WorldManager.CurrentWorldName' |
82 | 82 | |
83 | - stylesFile = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap_format.css")); | |
84 | - Logger.VerboseDebug("CSS loaded: {0} size: {1}", stylesFile.IsLoaded(), stylesFile.ToText().Length); | |
83 | + | |
84 | + string mapFilename = Path.Combine(path, "automap.html"); | |
85 | + StreamWriter outputText = new StreamWriter(File.Open(mapFilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)); | |
86 | + | |
87 | + staticMap = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap.html")); | |
88 | + outputText.Write(staticMap.ToText()); | |
89 | + outputText.Flush(); | |
85 | 90 | |
86 | 91 | Prefill_POI_Designators(); |
87 | 92 | startChunkColumn = new Vec2i((ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.X / chunkSize), (ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Z / chunkSize)); |
@@ -200,7 +205,6 @@ namespace Automap | ||
200 | 205 | { |
201 | 206 | //What about chunk updates themselves; a update bitmap isn't kept... |
202 | 207 | updatedChunksTotal += updatedChunks; |
203 | - GenerateMapHTML(); | |
204 | 208 | GenerateJSONMetadata(); |
205 | 209 | updatedChunks = 0; |
206 | 210 | } |
@@ -284,208 +288,8 @@ namespace Automap | ||
284 | 288 | |
285 | 289 | } |
286 | 290 | |
287 | - | |
288 | - private void GenerateMapHTML() | |
289 | - { | |
290 | - string mapFilename = Path.Combine(path, "Automap.html"); | |
291 | - | |
292 | - int TopNorth = chunkTopMetadata.North_mostChunk; | |
293 | - int TopSouth = chunkTopMetadata.South_mostChunk; | |
294 | - int TopEast = chunkTopMetadata.East_mostChunk; | |
295 | - int TopWest = chunkTopMetadata.West_mostChunk; | |
296 | - | |
297 | - using (StreamWriter outputText = new StreamWriter(File.Open(mapFilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))) | |
298 | - { | |
299 | - using (HtmlTextWriter tableWriter = new HtmlTextWriter(outputText)) | |
300 | - { | |
301 | - tableWriter.BeginRender(); | |
302 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Html); | |
303 | - | |
304 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Head); | |
305 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Title); | |
306 | - tableWriter.WriteEncodedText("Generated Automap"); | |
307 | - tableWriter.RenderEndTag(); | |
308 | - //CSS style here | |
309 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Style); | |
310 | - tableWriter.Write(stylesFile.ToText()); | |
311 | - tableWriter.RenderEndTag();//</style> | |
312 | - | |
313 | - tableWriter.RenderEndTag(); | |
314 | - | |
315 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Body); | |
316 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
317 | - tableWriter.WriteEncodedText($"Created {DateTimeOffset.UtcNow.ToString("u")}"); | |
318 | - tableWriter.RenderEndTag(); | |
319 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
320 | - tableWriter.WriteEncodedText($"W:{TopWest}, E: {TopEast}, N:{TopNorth}, S:{TopSouth} "); | |
321 | - tableWriter.RenderEndTag(); | |
322 | - tableWriter.WriteLine(); | |
323 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Table); | |
324 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Caption); | |
325 | - tableWriter.WriteEncodedText($"Start: {startChunkColumn}, Seed: {ClientAPI.World.Seed}\n"); | |
326 | - tableWriter.RenderEndTag(); | |
327 | - | |
328 | - //################ X-Axis <thead> ####################### | |
329 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Thead); | |
330 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
331 | - | |
332 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
333 | - tableWriter.Write("N, W"); | |
334 | - tableWriter.RenderEndTag(); | |
335 | - | |
336 | - for (int xAxisT = TopWest; xAxisT <= TopEast; xAxisT++) | |
337 | - { | |
338 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
339 | - tableWriter.Write(xAxisT); | |
340 | - tableWriter.RenderEndTag(); | |
341 | - } | |
342 | - | |
343 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
344 | - tableWriter.Write("N, E"); | |
345 | - tableWriter.RenderEndTag(); | |
346 | - | |
347 | - tableWriter.RenderEndTag(); | |
348 | - tableWriter.RenderEndTag(); | |
349 | - //###### </thead> ################################ | |
350 | - | |
351 | - //###### <tbody> - Chunk rows & Y-axis cols | |
352 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tbody); | |
353 | - | |
354 | - //######## <tr> for every vertical row | |
355 | - for (int yAxis = TopNorth; yAxis <= TopSouth; yAxis++) | |
356 | - { | |
357 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
358 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
359 | - tableWriter.Write(yAxis);//legend: Y-axis | |
360 | - tableWriter.RenderEndTag(); | |
361 | - | |
362 | - for (int xAxis = TopWest; xAxis <= TopEast; xAxis++) | |
363 | - { | |
364 | - //###### <td> #### for chunk shard | |
365 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
366 | - var colLoc = new Vec2i(xAxis, yAxis); | |
367 | - if (chunkTopMetadata.Contains(colLoc)) | |
368 | - { | |
369 | - ColumnMeta meta = chunkTopMetadata[colLoc]; | |
370 | - //Tooltip first | |
371 | - tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltip"); | |
372 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Div); | |
373 | - | |
374 | - tableWriter.AddAttribute(HtmlTextWriterAttribute.Src, $"{xAxis}_{yAxis}.png"); | |
375 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Img); | |
376 | - tableWriter.RenderEndTag(); | |
377 | - // <span class="tooltiptext">Tooltip text | |
378 | - tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltiptext"); | |
379 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Span); | |
380 | - | |
381 | - StringBuilder tooltipText = new StringBuilder(); | |
382 | - tooltipText.Append($"{meta.Location.PrettyCoords(ClientAPI)} "); | |
383 | - tooltipText.Append($" Max-Height: {meta.YMax}, Temp: {meta.Temperature.ToString("F1")} "); | |
384 | - tooltipText.Append($" Rainfall: {meta.Rainfall.ToString("F1")}, "); | |
385 | - tooltipText.Append($" Shrubs: {meta.ShrubDensity.ToString("F1")}, "); | |
386 | - tooltipText.Append($" Forest: {meta.ForestDensity.ToString("F1")}, "); | |
387 | - tooltipText.Append($" Fertility: {meta.Fertility.ToString("F1")}, "); | |
388 | - | |
389 | - if (meta.RockRatio != null) | |
390 | - { | |
391 | - foreach (KeyValuePair<int, uint> blockID in meta.RockRatio) | |
392 | - { | |
393 | - var block = ClientAPI.World.GetBlock(blockID.Key); | |
394 | - tooltipText.AppendFormat(" {0} × {1},\t", block.Code.GetName(), meta.RockRatio[blockID.Key]); | |
395 | - } | |
396 | - } | |
397 | - | |
398 | - tableWriter.WriteEncodedText(tooltipText.ToString()); | |
399 | - | |
400 | - tableWriter.RenderEndTag();//</span> | |
401 | - | |
402 | - | |
403 | - tableWriter.RenderEndTag();//</div> --tooltip enclosure | |
404 | - } | |
405 | - else | |
406 | - { | |
407 | - tableWriter.Write("?"); | |
408 | - } | |
409 | - | |
410 | - tableWriter.RenderEndTag(); | |
411 | - }//############ </td> ########### | |
412 | - | |
413 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
414 | - tableWriter.Write(yAxis);//legend: Y-axis | |
415 | - tableWriter.RenderEndTag(); | |
416 | - | |
417 | - tableWriter.RenderEndTag(); | |
418 | - | |
419 | - } | |
420 | - tableWriter.RenderEndTag(); | |
421 | - | |
422 | - //################ X-Axis <tfoot> ####################### | |
423 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tfoot); | |
424 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
425 | - | |
426 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
427 | - tableWriter.Write("S, W"); | |
428 | - tableWriter.RenderEndTag(); | |
429 | - | |
430 | - for (int xAxisB = TopWest; xAxisB <= TopEast; xAxisB++) | |
431 | - { | |
432 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
433 | - tableWriter.Write(xAxisB); | |
434 | - tableWriter.RenderEndTag(); | |
435 | - } | |
436 | - | |
437 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
438 | - tableWriter.Write("S, E"); | |
439 | - tableWriter.RenderEndTag(); | |
440 | - | |
441 | - tableWriter.RenderEndTag(); | |
442 | - tableWriter.RenderEndTag(); | |
443 | - //###### </tfoot> ################################ | |
444 | - | |
445 | - | |
446 | - tableWriter.RenderEndTag();//</table> | |
447 | - | |
448 | - //############## POI list ##################### | |
449 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
450 | - tableWriter.WriteLine("Points of Interest"); | |
451 | - tableWriter.RenderEndTag(); | |
452 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Ul); | |
453 | - foreach (var poi in this.POIs) | |
454 | - { | |
455 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Li); | |
456 | - tableWriter.WriteEncodedText(poi.Location.PrettyCoords(this.ClientAPI) + "\t"); | |
457 | - tableWriter.WriteEncodedText(poi.Notes + "\t"); | |
458 | - tableWriter.WriteEncodedText(poi.Timestamp.ToString("u")); | |
459 | - tableWriter.RenderEndTag(); | |
460 | - } | |
461 | - | |
462 | - foreach (var eoi in this.EOIs.PointsList) | |
463 | - { | |
464 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Li); | |
465 | - tableWriter.WriteEncodedText(eoi.Location.PrettyCoords(this.ClientAPI) + "\t"); | |
466 | - tableWriter.WriteEncodedText(eoi.Notes + "\t"); | |
467 | - tableWriter.WriteEncodedText(eoi.Timestamp.ToString("u")); | |
468 | - tableWriter.RenderEndTag(); | |
469 | - } | |
470 | - | |
471 | - tableWriter.RenderEndTag(); | |
472 | - | |
473 | - | |
474 | - | |
475 | - | |
476 | - tableWriter.RenderEndTag();//### </BODY> ### | |
477 | - | |
478 | - tableWriter.EndRender(); | |
479 | - tableWriter.Flush(); | |
480 | - } | |
481 | - outputText.Flush(); | |
482 | - } | |
483 | - | |
484 | - Logger.VerboseDebug("Generated HTML map"); | |
485 | - } | |
486 | - | |
487 | 291 | /// <summary> |
488 | - /// Generates the JSON Metadata. (in MAP object format ) | |
292 | + /// Generates the JSON Metadata. (in Map object format ) | |
489 | 293 | /// </summary> |
490 | 294 | private void GenerateJSONMetadata() |
491 | 295 | { |
@@ -538,7 +342,7 @@ namespace Automap | ||
538 | 342 | jsonWriter.Write("}],"); |
539 | 343 | } |
540 | 344 | |
541 | - foreach (var poi in EOIs.PointsList) | |
345 | + foreach (var poi in EOIs) | |
542 | 346 | { |
543 | 347 | jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Z); |
544 | 348 | jsonWriter.Write("{"); |
@@ -0,0 +1,143 @@ | ||
1 | +<!DOCTYPE html> | |
2 | +<html lang="en" dir="ltr"> | |
3 | + | |
4 | +<head> | |
5 | + <meta charset="utf-8"> | |
6 | + <title>Automap</title> | |
7 | + <style media="screen">.m,body,html{width:100%;height:100%;margin:0;outline:1px dotted #000}.m img{position:absolute;image-rendering:pixelated}.i{width:15em;background-color:rgba(200,200,200,.5);left:0;top:0;font-family:sans-serif;position:absolute;z-index:1}h1{font-size:22px;margin:.6em 1em;text-align:center}.t{margin:.3em auto;width:90%;outline:1px solid #333}.t th{width:30%}.t td{text-align:right}</style> | |
8 | +</head> | |
9 | + | |
10 | +<body> | |
11 | + <div class="i"> | |
12 | + <h1>Chunk Info</h1> | |
13 | + <table class="t"></table> | |
14 | + </div> | |
15 | + <script type="text/javascript"> | |
16 | + function ViewFrame() { | |
17 | + this.map = document.createElement("div"), this.map.className = "m", this.infobox = document.getElementsByClassName("t")[0], this.infoboxSlots = new Map, ViewFrame.initInfobox(this.infobox, this.infoboxSlots), document.getElementsByTagName("body")[ | |
18 | + 0].append(this.map), this.loadedChunksByName = new Map, this.loadedChunksByCoords = new Map, this.availableChunks = null, this.chunkScript = null, this.renderOnReload = !0, this.dirty = !1, this.rendering = !1, this.x = null, this.y = null, | |
19 | + this._zoom = 32, this.updateEdges() | |
20 | + } | |
21 | + | |
22 | + function decode(t, e) { | |
23 | + t.decode().then(() => { | |
24 | + e(t) | |
25 | + }).catch(() => {}) | |
26 | + } | |
27 | + ViewFrame.prototype.reloadChunkList = function() { | |
28 | + console.log("Reloading chunks!"), this.chunkScript && (this.chunkScript.remove(), delete this.chunkScript), this.chunkScript = document.createElement("script"), this.chunkScript.type = "text/javascript", this.chunkScript.src = "Metadata.js", | |
29 | + document.getElementsByTagName("body")[0].append(this.chunkScript), this.chunkScript.onload = (() => { | |
30 | + this.availableChunks = ViewFrame.chunks.chunkMetadata, null !== this.x && null !== this.y || (this.x = ViewFrame.chunks.startCoords[0], this.y = ViewFrame.chunks.startCoords[1]), this.renderOnReload && this.render() | |
31 | + }), this.dirty = !0 | |
32 | + }, ViewFrame.prototype.render = function() { | |
33 | + if (!this.availableChunks) return; | |
34 | + if (this.rendering) return; | |
35 | + this.rendering = !0, this.dirty && this.updateEdges(), this.loadedChunksByCoords.forEach((t, e) => { | |
36 | + if (e[0] < this.eastChunk && e[0] >= this.westChunk && e[1] <= this.northChunk && e[1] >= this.southChunk) { | |
37 | + let [s, i] = this.chunkToScreen(e[0], e[1]); | |
38 | + t.style.left = s + "px", t.style.top = i + "px"; | |
39 | + const n = this.zoom / 32; | |
40 | + 1 != n && (t.style.transform = `scale(${n})`) | |
41 | + } else this.loadedChunksByCoords.delete(e), this.loadedChunksByName.delete(e.join("_")), t.remove() | |
42 | + }); | |
43 | + const t = new Set; | |
44 | + for (var e = this.westChunk; e < this.eastChunk; e++) | |
45 | + for (var s = this.southChunk; s < this.northChunk; s++) { | |
46 | + const i = [e, s], | |
47 | + n = i.join("_"); | |
48 | + this.availableChunks.has(n) && !this.loadedChunksByName.has(n) && t.add(i) | |
49 | + } | |
50 | + const i = t.values(); | |
51 | + let n = setInterval(() => { | |
52 | + let t = i.next(); | |
53 | + if (t.done) clearInterval(n), this.rendering = !1; | |
54 | + else { | |
55 | + const e = new Image(32, 32), | |
56 | + s = t.value.join("_"); | |
57 | + e.src = s + ".png", e.alt = s, decode(e, e => { | |
58 | + let [s, i] = this.chunkToScreen(t.value[0], t.value[1]); | |
59 | + e.style.left = s + "px", e.style.top = i + "px"; | |
60 | + const n = this.zoom / 32; | |
61 | + 1 != n && (chunk.style.transform = `scale(${n})`), this.map.append(e) | |
62 | + }), this.loadedChunksByName.set(s, e), this.loadedChunksByCoords.set(t.value, e) | |
63 | + } | |
64 | + }, 4) | |
65 | + }, ViewFrame.prototype.updateInfobox = function(t) { | |
66 | + const e = this.availableChunks.get(t); | |
67 | + this.infoboxSlots.forEach((t, s) => { | |
68 | + t.innerText = e[s] | |
69 | + }) | |
70 | + }, ViewFrame.initInfobox = function(t, e) { | |
71 | + ["prettyCoord:Loc.", "chunkAge:Age", "temp:Temp.", "YMax:Y Max", "fert:Fert.", "forestDens:Forest", "rain:Rain", "shrubDens:Shrub", "airBlocks:Air", "nonAirBlocks:Non-Air"].map(t => t.split(":")).forEach(s => { | |
72 | + const i = s[0], | |
73 | + n = s[1], | |
74 | + h = document.createElement("tr"), | |
75 | + o = document.createElement("th"); | |
76 | + o.innerText = n; | |
77 | + const r = document.createElement("td"); | |
78 | + r.innerText = "0", e.set(i, r), h.append(o, r), t.append(h) | |
79 | + }) | |
80 | + }, ViewFrame.prototype.screenToChunk = function(t, e) { | |
81 | + return [(t - this.width / 2) / this.zoom, (e - this.height / 2) / this.zoom] | |
82 | + }, ViewFrame.prototype.chunkToScreen = function(t, e) { | |
83 | + return [(t - this.west) * this.zoom, (e - this.south) * this.zoom] | |
84 | + }, ViewFrame.prototype.updateEdges = function() { | |
85 | + if (!this.dirty) return; | |
86 | + const t = Math.ceil(this.width / this.zoom), | |
87 | + e = Math.ceil(this.height / this.zoom); | |
88 | + this.east = this.x + t / 2, this.eastChunk = Math.ceil(this.east), this.west = this.x - t / 2, this.westChunk = Math.floor(this.west), this.north = this.y + e / 2, this.northChunk = Math.ceil(this.north), this.south = this.y - e / 2, this.southChunk = | |
89 | + Math.floor(this.south), this.dirty = !1 | |
90 | + }, ViewFrame.prototype.moveCenter = function(t, e) { | |
91 | + let [s, i] = this.screenToChunk(t, e); | |
92 | + this.x += s, this.y += i, this.dirty = !0 | |
93 | + }, ViewFrame.prototype.clear = function() { | |
94 | + this.loadedChunksByName.clear(), this.loadedChunksByCoords.clear(), this.chunkScript && this.chunkScript.remove(), delete this.chunkScript, delete ViewFrame.chunks, this.map.innerHTML = "" | |
95 | + }, Object.defineProperties(ViewFrame.prototype, { | |
96 | + width: { | |
97 | + get() { | |
98 | + return this.map.clientWidth | |
99 | + } | |
100 | + }, | |
101 | + height: { | |
102 | + get() { | |
103 | + return this.map.clientHeight | |
104 | + } | |
105 | + }, | |
106 | + zoom: { | |
107 | + get() { | |
108 | + return this._zoom | |
109 | + }, | |
110 | + set(t) { | |
111 | + this._zoom = t, this.dirty = !0 | |
112 | + } | |
113 | + } | |
114 | + }); | |
115 | + const vf = new ViewFrame; | |
116 | + vf.reloadChunkList(), | |
117 | + function() { | |
118 | + var t; | |
119 | + window.addEventListener("resize", () => { | |
120 | + clearTimeout(t), vf.clear(), t = setTimeout(() => { | |
121 | + vf.updateEdges(), vf.render() | |
122 | + }, 500) | |
123 | + }) | |
124 | + }(), vf.map.addEventListener("mousedown", t => { | |
125 | + vf.moveCenter(t.x, t.y), setTimeout(() => { | |
126 | + vf.render() | |
127 | + }, 250) | |
128 | + }), | |
129 | + function() { | |
130 | + var t; | |
131 | + vf.map.addEventListener("mousemove", e => { | |
132 | + e.target instanceof HTMLImageElement && t !== e.target && (t = e.target, vf.updateInfobox(e.target.alt)) | |
133 | + }) | |
134 | + }(); | |
135 | + (function() { | |
136 | + setInterval(() => { | |
137 | + vf.reloadChunkList(); | |
138 | + }, 6000); | |
139 | + }()); | |
140 | + </script> | |
141 | +</body> | |
142 | + | |
143 | +</html> | |
\ No newline at end of file |
@@ -1,75 +0,0 @@ | ||
1 | -table { | |
2 | -border: 1px solid black; | |
3 | -border-collapse: collapse; | |
4 | -} | |
5 | - | |
6 | -thead tr th { | |
7 | -max-width:32px; | |
8 | -margin: 0px; | |
9 | -padding: 0px; | |
10 | -overflow:hidden; | |
11 | -border-right: 1px solid black; | |
12 | -border-bottom: 1px solid black; | |
13 | -font-size:8pt; | |
14 | -font-weight:bold; | |
15 | -font-family: Monospace; | |
16 | -} | |
17 | - | |
18 | -tfoot tr td { | |
19 | -max-width: 32px; | |
20 | -padding: 0px; | |
21 | -overflow:hidden; | |
22 | -border-right: 1px solid black; | |
23 | -border-top: 1px solid black; | |
24 | -font-size:8pt; | |
25 | -font-weight:bold; | |
26 | -font-family: Monospace; | |
27 | -} | |
28 | - | |
29 | -tbody tr { | |
30 | -max-height:32px; | |
31 | -padding: 0px; | |
32 | -overflow:hidden; | |
33 | -} | |
34 | - | |
35 | -tbody td { | |
36 | -padding: 0px; | |
37 | -border: 0px none black; | |
38 | -max-width: 32px; | |
39 | -background-color: white; | |
40 | -width:32px; | |
41 | -font-size: 6pt; | |
42 | -} | |
43 | - | |
44 | -/* Tooltip container */ | |
45 | -.tooltip { | |
46 | -position: relative; | |
47 | -display: inline-block; | |
48 | -} | |
49 | - | |
50 | -/* Tooltip text */ | |
51 | -.tooltip .tooltiptext { | |
52 | -visibility: hidden; | |
53 | -background-color: black; | |
54 | -color: #fff; | |
55 | -text-align: center; | |
56 | -padding: 5px 0; | |
57 | -position: absolute; | |
58 | -z-index: 1; | |
59 | -} | |
60 | - | |
61 | -/* Show the tooltip text when you mouse over the tooltip container */ | |
62 | -.tooltip:hover .tooltiptext { | |
63 | -left: 33px; | |
64 | -top: 33px; | |
65 | -opacity: 0.75; | |
66 | -position: absolute; | |
67 | -visibility: visible; | |
68 | -min-width: 120px; | |
69 | -box-shadow: 5px 5px 8px 12px black; | |
70 | -} | |
71 | - | |
72 | -.tooltip img:hover { | |
73 | -outline: 1px dashed orange; | |
74 | -opacity: 0.9; | |
75 | -} |