Changeset 455 for binary-improvements/MapRendering/API/GetWebUIUpdates.cs
- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API/GetWebUIUpdates.cs
r454 r455 1 using AllocsFixes.JSON;2 1 using AllocsFixes.LiveData; 2 using JetBrains.Annotations; 3 using Utf8Json; 3 4 using Webserver; 4 5 using Webserver.WebAPI; 5 6 6 7 namespace AllocsFixes.WebAPIs { 8 [UsedImplicitly] 7 9 public class GetWebUIUpdates : AbsWebAPI { 10 private static readonly byte[] jsonKeyGameTime = JsonWriter.GetEncodedPropertyNameWithBeginObject ("gametime"); 11 12 private static readonly byte[] jsonKeyPlayers = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("players"); 13 private static readonly byte[] jsonKeyHostiles = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("hostiles"); 14 private static readonly byte[] jsonKeyAnimals = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("animals"); 15 private static readonly byte[] jsonKeyNewLogs = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("newlogs"); 16 8 17 public override void HandleRequest (RequestContext _context) { 9 18 int latestLine; … … 13 22 } 14 23 15 J SONObject result = new JSONObject();24 JsonWriter writer = new JsonWriter (); 16 25 17 JSONObject time = new JSONObject (); 18 time.Add ("days", new JSONNumber (GameUtils.WorldTimeToDays (GameManager.Instance.World.worldTime))); 19 time.Add ("hours", new JSONNumber (GameUtils.WorldTimeToHours (GameManager.Instance.World.worldTime))); 20 time.Add ("minutes", new JSONNumber (GameUtils.WorldTimeToMinutes (GameManager.Instance.World.worldTime))); 21 result.Add ("gametime", time); 22 23 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 24 result.Add ("hostiles", new JSONNumber (Hostiles.Instance.GetCount ())); 25 result.Add ("animals", new JSONNumber (Animals.Instance.GetCount ())); 26 27 result.Add ("newlogs", new JSONNumber (LogBuffer.Instance.LatestLine - latestLine)); 28 29 LegacyApiHelper.WriteJSON (_context.Response, result); 26 writer.WriteRaw (jsonKeyGameTime); 27 (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime); 28 JsonCommons.WriteGameTimeObject (ref writer, days, hours, minutes); 29 30 writer.WriteRaw (jsonKeyPlayers); 31 writer.WriteInt32 (GameManager.Instance.World.Players.Count); 32 33 writer.WriteRaw (jsonKeyHostiles); 34 writer.WriteInt32 (Hostiles.Instance.GetCount ()); 35 36 writer.WriteRaw (jsonKeyAnimals); 37 writer.WriteInt32 (Animals.Instance.GetCount ()); 38 39 writer.WriteRaw (jsonKeyNewLogs); 40 writer.WriteInt32 (LogBuffer.Instance.LatestLine - latestLine); 41 42 writer.WriteEndObject (); 43 44 WebUtils.WriteJsonData (_context.Response, ref writer); 30 45 } 31 46
Note:
See TracChangeset
for help on using the changeset viewer.