using System.Collections.Generic; using AllocsFixes.JSON; using AllocsFixes.LiveData; using Webserver; using Webserver.WebAPI; namespace AllocsFixes.WebAPIs { internal class GetAnimalsLocation : AbsWebAPI { private readonly List animals = new List (); public override void HandleRequest (RequestContext _context) { JSONArray animalsJsResult = new JSONArray (); Animals.Instance.Get (animals); for (int i = 0; i < animals.Count; i++) { EntityAnimal entity = animals [i]; Vector3i position = new Vector3i (entity.GetPosition ()); JSONObject jsonPOS = new JSONObject (); jsonPOS.Add ("x", new JSONNumber (position.x)); jsonPOS.Add ("y", new JSONNumber (position.y)); jsonPOS.Add ("z", new JSONNumber (position.z)); JSONObject pJson = new JSONObject (); pJson.Add ("id", new JSONNumber (entity.entityId)); if (!string.IsNullOrEmpty (entity.EntityName)) { pJson.Add ("name", new JSONString (entity.EntityName)); } else { pJson.Add ("name", new JSONString ("animal class #" + entity.entityClass)); } pJson.Add ("position", jsonPOS); animalsJsResult.Add (pJson); } LegacyApiHelper.WriteJSON (_context.Response, animalsJsResult); } } }