source: binary-improvements/MapRendering/API/GetStats.cs@ 498

Last change on this file since 498 was 455, checked in by alloc, 16 months ago

25_30_44

  • Got rid (mostly) of custom JSON serialization
  • Some code cleanup
File size: 1.5 KB
RevLine 
[251]1using AllocsFixes.LiveData;
[455]2using JetBrains.Annotations;
3using Utf8Json;
[454]4using Webserver;
5using Webserver.WebAPI;
[251]6
[454]7namespace AllocsFixes.WebAPIs {
[455]8 [UsedImplicitly]
[454]9 public class GetStats : AbsWebAPI {
[455]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
[454]16 public override void HandleRequest (RequestContext _context) {
[455]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);
[251]35 }
[279]36
37 public override int DefaultPermissionLevel () {
38 return 2000;
39 }
[251]40 }
[325]41}
Note: See TracBrowser for help on using the repository browser.