Changeset 455 for binary-improvements/MapRendering/API/GetStats.cs
- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API/GetStats.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 GetStats : 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 8 16 public override void HandleRequest (RequestContext _context) { 9 JSONObject result = new JSONObject (); 10 11 JSONObject time = new JSONObject (); 12 time.Add ("days", new JSONNumber (GameUtils.WorldTimeToDays (GameManager.Instance.World.worldTime))); 13 time.Add ("hours", new JSONNumber (GameUtils.WorldTimeToHours (GameManager.Instance.World.worldTime))); 14 time.Add ("minutes", new JSONNumber (GameUtils.WorldTimeToMinutes (GameManager.Instance.World.worldTime))); 15 result.Add ("gametime", time); 16 17 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 18 result.Add ("hostiles", new JSONNumber (Hostiles.Instance.GetCount ())); 19 result.Add ("animals", new JSONNumber (Animals.Instance.GetCount ())); 20 21 LegacyApiHelper.WriteJSON (_context.Response, result); 17 JsonWriter writer = new JsonWriter (); 18 19 writer.WriteRaw (jsonKeyGameTime); 20 (int days, int hours, int minutes) = GameUtils.WorldTimeToElements (GameManager.Instance.World.worldTime); 21 JsonCommons.WriteGameTimeObject (ref writer, days, hours, minutes); 22 23 writer.WriteRaw (jsonKeyPlayers); 24 writer.WriteInt32 (GameManager.Instance.World.Players.Count); 25 26 writer.WriteRaw (jsonKeyHostiles); 27 writer.WriteInt32 (Hostiles.Instance.GetCount ()); 28 29 writer.WriteRaw (jsonKeyAnimals); 30 writer.WriteInt32 (Animals.Instance.GetCount ()); 31 32 writer.WriteEndObject (); 33 34 WebUtils.WriteJsonData (_context.Response, ref writer); 22 35 } 23 36
Note:
See TracChangeset
for help on using the changeset viewer.