• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Automap (client) [VS plugin mod]


コミットメタ情報

リビジョンe1fcf4409fb6624b7b90a242521f8e8ee2c118e7 (tree)
日時2020-03-02 09:59:12
作者melchior <melchior@user...>
コミッターmelchior

ログメッセージ

Pre-PR5: Now with better, mostly-standard-compliant JSON

変更サマリ

差分

--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -177,7 +177,7 @@ namespace Automap
177177 }
178178
179179 UpdateEntityMetadata();
180- ProcessChunkBlocks(mostActiveCol.Key, mapChunk, chunkMeta);
180+ ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta);
181181
182182 PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, chunkMeta);
183183 ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter, out updatedPixels);
@@ -248,7 +248,7 @@ namespace Automap
248248
249249 this.BlockID_Designators = new Dictionary<int, BlockDesignator>();
250250 this.Entity_Designators = new Dictionary<AssetLocation, EntityDesignator>();
251- this.RockIdCodes = Helpers.ArbitrarytBlockIdHunter(ClientAPI, new AssetLocation(GlobalConstants.DefaultDomain, "rock"), EnumBlockMaterial.Stone);
251+ this.RockIdCodes = Helpers.ArbitrarytBlockIdHunter(ClientAPI, new AssetLocation(GlobalConstants.DefaultDomain, "rock-"), EnumBlockMaterial.Stone);
252252
253253 //Add special marker types for BlockID's of "Interest", overwrite colour, and method
254254
@@ -290,6 +290,7 @@ namespace Automap
290290
291291 }
292292
293+ //TODO: Rewrite as Newtonsoft JsonTextWriter !!!
293294 /// <summary>
294295 /// Generates the JSON Metadata. (in Map object format )
295296 /// </summary>
@@ -297,67 +298,207 @@ namespace Automap
297298 {
298299 string jsonFilename = Path.Combine(path, "Metadata.js");
299300
300- StreamWriter jsonWriter = new StreamWriter(jsonFilename, false, Encoding.UTF8);
301+ StreamWriter stream = new StreamWriter(jsonFilename, false, Encoding.UTF8);
302+
303+ using (stream) {
304+ JsonTextWriter jsonWriter = new JsonTextWriter(stream);
305+
306+ jsonWriter.Formatting = Formatting.None;
307+ jsonWriter.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
308+ jsonWriter.Indentation = 0;
309+ //jsonWriter.AutoCompleteOnClose = true;
310+ jsonWriter.QuoteChar = '\'';
311+ jsonWriter.DateFormatHandling = DateFormatHandling.IsoDateFormat;
312+ jsonWriter.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
313+
301314 using (jsonWriter)
302315 {
303- jsonWriter.Write("ViewFrame.chunks={};");
304- jsonWriter.Write("ViewFrame.chunks.worldSeedNum={0};", ClientAPI.World.Seed);
305- jsonWriter.Write("ViewFrame.chunks.genTime=new Date('{0}');", DateTimeOffset.UtcNow.ToString("O"));
306- jsonWriter.Write("ViewFrame.chunks.startCoords=[{0},{1}];", startChunkColumn.X, startChunkColumn.Y);
307- jsonWriter.Write("ViewFrame.chunks.chunkSize={0};", chunkSize);
308- jsonWriter.Write("ViewFrame.chunks.northMostChunk={0};", chunkTopMetadata.North_mostChunk);
309- jsonWriter.Write("ViewFrame.chunks.southMostChunk={0};", chunkTopMetadata.South_mostChunk);
310- jsonWriter.Write("ViewFrame.chunks.eastMostChunk={0};", chunkTopMetadata.East_mostChunk);
311- jsonWriter.Write("ViewFrame.chunks.westMostChunk={0};", chunkTopMetadata.West_mostChunk);
316+ jsonWriter.WriteRaw("ViewFrame.chunks={};\n");
317+ jsonWriter.WriteRaw("ViewFrame.chunks.worldSeedNum=" );
318+ jsonWriter.WriteValue(ClientAPI.World.Seed);
319+ jsonWriter.WriteRaw(";\n");
320+
321+ jsonWriter.WriteRaw("ViewFrame.chunks.genTime=");
322+ jsonWriter.WriteValue(DateTimeOffset.UtcNow);
323+ jsonWriter.WriteRaw(";\n");
324+
325+ jsonWriter.WriteRaw("ViewFrame.chunks.startCoords=");
326+ jsonWriter.WriteStartArray( );
327+ jsonWriter.WriteValue(startChunkColumn.X);
328+ jsonWriter.WriteValue(startChunkColumn.Y);
329+ jsonWriter.WriteEndArray( );
330+ jsonWriter.WriteRaw(";\n");
331+
332+ jsonWriter.WriteRaw("ViewFrame.chunks.chunkSize=");
333+ jsonWriter.WriteValue(chunkSize);
334+ jsonWriter.WriteRaw(";\n");
335+
336+ jsonWriter.WriteRaw("ViewFrame.chunks.northMostChunk=");
337+ jsonWriter.WriteValue(chunkTopMetadata.North_mostChunk);
338+ jsonWriter.WriteRaw(";\n");
339+
340+ jsonWriter.WriteRaw("ViewFrame.chunks.southMostChunk=");
341+ jsonWriter.WriteValue(chunkTopMetadata.South_mostChunk);
342+ jsonWriter.WriteRaw(";\n");
343+
344+ jsonWriter.WriteRaw("ViewFrame.chunks.westMostChunk=");
345+ jsonWriter.WriteValue(chunkTopMetadata.West_mostChunk);
346+ jsonWriter.WriteRaw(";\n");
347+
348+ jsonWriter.WriteRaw("ViewFrame.chunks.eastMostChunk=");
349+ jsonWriter.WriteValue(chunkTopMetadata.East_mostChunk);
350+ jsonWriter.WriteRaw(";\n");
351+
352+
312353 //MAP object format - [key, value]: key is "x_y"
313- jsonWriter.Write("ViewFrame.chunks.chunkMetadata=new Map([");
354+ jsonWriter.WriteRaw("ViewFrame.chunks.chunkMetadata=");
355+ jsonWriter.WriteStartConstructor("Map");
356+ jsonWriter.WriteStartArray( );//An array of... 2-component arrays
357+
358+
314359 foreach (var shard in chunkTopMetadata)
315360 {
316- jsonWriter.Write("['{0}_{1}',", shard.Location.X, shard.Location.Y);
317- jsonWriter.Write("{");
318- jsonWriter.Write("prettyCoord:'{0}',", shard.Location.PrettyCoords(ClientAPI));
319- jsonWriter.Write("chunkAge:'{0}',", shard.ChunkAge.ToString("g"));//World age - relative? or last edit ??
320- jsonWriter.Write("temp:'{0}',", shard.Temperature.ToString("F1"));
321- jsonWriter.Write("YMax:'{0}',", shard.YMax);
322- jsonWriter.Write("fert:'{0}',", shard.Fertility.ToString("F1"));
323- jsonWriter.Write("forestDens:'{0}',", shard.ForestDensity.ToString("F1"));
324- jsonWriter.Write("rain:'{0}',", shard.Rainfall.ToString("F1"));
325- jsonWriter.Write("shrubDens:'{0}',", shard.ShrubDensity.ToString("F1"));
326- jsonWriter.Write("airBlocks:'{0}',", shard.AirBlocks);
327- jsonWriter.Write("nonAirBlocks:'{0}',", shard.NonAirBlocks);
328- //TODO: Heightmap
329- //TODO: Rock-ratio, also requires a BlockID => Name lookup table....elsewhere
330- jsonWriter.Write("}],");
361+ jsonWriter.WriteStartArray( );//Start tuple
362+ jsonWriter.WriteValue($"{shard.Location.X}_{shard.Location.Y}");//Key of Tuple
363+
364+ jsonWriter.WriteStartObject( );
365+ jsonWriter.WritePropertyName("prettyCoord");
366+ jsonWriter.WriteValue( shard.Location.PrettyCoords(ClientAPI));
367+
368+ jsonWriter.WritePropertyName("chunkAge");
369+ jsonWriter.WriteValue(shard.ChunkAge);
370+
371+ jsonWriter.WritePropertyName("temp");
372+ jsonWriter.WriteValue(shard.Temperature);
373+
374+ jsonWriter.WritePropertyName("YMax");
375+ jsonWriter.WriteValue(shard.YMax);
376+
377+ jsonWriter.WritePropertyName("fert");
378+ jsonWriter.WriteValue(shard.Fertility);
379+
380+ jsonWriter.WritePropertyName("forestDens");
381+ jsonWriter.WriteValue( shard.ForestDensity);
382+
383+ jsonWriter.WritePropertyName("rain");
384+ jsonWriter.WriteValue( shard.Rainfall);
385+
386+ jsonWriter.WritePropertyName("shrubDens");
387+ jsonWriter.WriteValue( shard.ShrubDensity);
388+
389+ jsonWriter.WritePropertyName("airBlocks");
390+ jsonWriter.WriteValue( shard.AirBlocks);
391+
392+ jsonWriter.WritePropertyName("nonAirBlocks");
393+ jsonWriter.WriteValue( shard.NonAirBlocks);
394+
395+ //TODO: Heightmap ?
396+ //Start rockMap ; FOR a Ratio....on tooltip GUI
397+ jsonWriter.WritePropertyName("rockRatio");
398+ jsonWriter.WriteStartConstructor("Map");
399+ jsonWriter.WriteStartArray( );
400+ foreach (var rockEntry in shard.RockRatio) {
401+ jsonWriter.WriteStartArray( );
402+ jsonWriter.WriteValue(rockEntry.Key);//BlockID
403+ jsonWriter.WriteValue(rockEntry.Value);//Total per chunk-column
404+ jsonWriter.WriteEndArray( );
405+ }
406+ jsonWriter.WriteEndArray( );
407+ jsonWriter.WriteEndConstructor( );//end rock-map
408+
409+ jsonWriter.WriteEndObject( );//end Map value: {Object}
410+ jsonWriter.WriteEndArray( );//end Tuple
331411 }
332- jsonWriter.Write("]);");
333412
413+ jsonWriter.WriteEndArray( );//Enclose tuples of chunkMetadata
414+ jsonWriter.WriteEndConstructor( );//Close constructor of Map (chunkMetadata)
415+ jsonWriter.WriteRaw(";\n");
416+
417+ jsonWriter.WriteRaw("ViewFrame.chunks.pointsOfInterest=");
418+ jsonWriter.WriteStartConstructor("Map");
419+ jsonWriter.WriteStartArray( );//An array of... 2-component arrays
334420
335- jsonWriter.Write("ViewFrame.chunks.pointsOfInterest = new Map([");
336421 foreach (var poi in POIs)
337422 {
338- jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Z);
339- jsonWriter.Write("{");
340- jsonWriter.Write("prettyCoord:'{0}',", poi.Location.PrettyCoords(ClientAPI));
341- jsonWriter.Write("notes:{0},", JsonConvert.ToString(poi.Notes, '\'', StringEscapeHandling.EscapeHtml));
342- jsonWriter.Write("time:new Date('{0}'),", poi.Timestamp.ToString("O"));
343- jsonWriter.Write("chunkPos:'{0}_{1}',", (poi.Location.X / chunkSize), (poi.Location.Z / chunkSize));
344- jsonWriter.Write("}],");
423+ jsonWriter.WriteStartArray( );
424+ jsonWriter.WriteValue($"{poi.Location.X}_{poi.Location.Z}");
425+
426+ jsonWriter.WriteStartObject();
427+ jsonWriter.WritePropertyName("prettyCoord");
428+ jsonWriter.WriteValue(poi.Location.PrettyCoords(ClientAPI) );
429+
430+ jsonWriter.WritePropertyName("notes");
431+ jsonWriter.WriteValue(poi.Notes);//Encoded to HTML Entities
432+
433+ jsonWriter.WritePropertyName("time");
434+ jsonWriter.WriteValue(poi.Timestamp);
435+
436+ jsonWriter.WritePropertyName("chunkPos");
437+ jsonWriter.WriteValue($"{(poi.Location.X / chunkSize)}_{(poi.Location.Z / chunkSize)}");
438+
439+ jsonWriter.WriteEndObject( );
440+ jsonWriter.WriteEndArray( );
345441 }
346442
347443 foreach (var poi in EOIs)
348444 {
349- jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Z);
350- jsonWriter.Write("{");
351- jsonWriter.Write("prettyCoord:'{0}',", poi.Location.PrettyCoords(ClientAPI));
352- jsonWriter.Write("notes:{0},", JsonConvert.ToString(poi.Notes, '\'', StringEscapeHandling.EscapeHtml));
353- jsonWriter.Write("time:new Date('{0}'),", poi.Timestamp.ToString("O"));
354- jsonWriter.Write("chunkPos:'{0}_{1}',", (poi.Location.X / chunkSize), (poi.Location.Z / chunkSize));
355- jsonWriter.Write("}],");
445+ jsonWriter.WriteStartArray( );
446+ jsonWriter.WriteValue($"{poi.Location.X}_{poi.Location.Z}");
447+
448+ jsonWriter.WriteStartObject( );
449+ jsonWriter.WritePropertyName("prettyCoord");
450+ jsonWriter.WriteValue(poi.Location.PrettyCoords(ClientAPI));
451+
452+ jsonWriter.WritePropertyName("notes");
453+ jsonWriter.WriteValue(poi.Notes);//Encoded to HTML Entities
454+
455+ jsonWriter.WritePropertyName("time");
456+ jsonWriter.WriteValue(poi.Timestamp);
457+
458+ jsonWriter.WritePropertyName("chunkPos");
459+ jsonWriter.WriteValue($"{(poi.Location.X / chunkSize)}_{(poi.Location.Z / chunkSize)}");
460+
461+ jsonWriter.WriteEndObject( );
462+ jsonWriter.WriteEndArray( );
356463 }
357- jsonWriter.Write("]);");
464+
465+ jsonWriter.WriteEndArray( );
466+ jsonWriter.WriteEndConstructor( );
467+ jsonWriter.WriteRaw(";\n");
468+
469+ jsonWriter.WriteWhitespace("\n");
470+ jsonWriter.WriteComment("============= BlockID's for Rockmap / Rock-ratios ===============");
471+ jsonWriter.WriteWhitespace("\n");
472+
473+ jsonWriter.WriteRaw("var rock_Lookup =");
474+ jsonWriter.WriteStartConstructor("Map");
475+ jsonWriter.WriteStartArray( );//An array of... 2-component arrays
476+
477+ foreach (var entry in RockIdCodes) {
478+ var block = ClientAPI.World.GetBlock(entry.Key);
479+
480+ jsonWriter.WriteStartArray( );
481+ jsonWriter.WriteValue(entry.Key);//BlockID
482+
483+ jsonWriter.WriteStartObject( );
484+ jsonWriter.WritePropertyName("assetCode");
485+ jsonWriter.WriteValue(entry.Value);
486+
487+ jsonWriter.WritePropertyName("name");
488+ jsonWriter.WriteValue(Lang.GetUnformatted(block.Code.Path));
489+ //Color?
490+
491+ jsonWriter.WriteEndObject( );
492+ jsonWriter.WriteEndArray( );
493+ }
494+ jsonWriter.WriteEndArray( );
495+ jsonWriter.WriteEndConstructor();
496+
497+ jsonWriter.WriteRaw(";\n");
358498
359499 jsonWriter.Flush();
360500 }
501+ }
361502
362503 }
363504
@@ -469,7 +610,7 @@ namespace Automap
469610 /// <param name="key">Chunk Coordinate</param>
470611 /// <param name="mapChunk">Map chunk.</param>
471612 /// <param name="chunkMeta">Chunk metadata</param>
472- private void ProcessChunkBlocks(Vec2i key, IMapChunk mapChunk, ColumnMeta chunkMeta)
613+ private void ProcessChunkBlocks(Vec2i key, IMapChunk mapChunk, ref ColumnMeta chunkMeta)
473614 {
474615
475616 int targetChunkY = mapChunk.YMax / chunkSize;//Surface ...