source: binary-improvements/MapRendering/Web/API/GetAnimalsLocation.cs@ 338

Last change on this file since 338 was 325, checked in by alloc, 6 years ago

Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)

File size: 1.3 KB
RevLine 
[325]1using System.Collections.Generic;
2using System.Net;
3using AllocsFixes.JSON;
[251]4using AllocsFixes.LiveData;
5
[325]6namespace AllocsFixes.NetConnections.Servers.Web.API {
7 internal class GetAnimalsLocation : WebAPI {
8 private readonly List<EntityAnimal> animals = new List<EntityAnimal> ();
[306]9
[325]10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
11 int permissionLevel) {
12 JSONArray animalsJsResult = new JSONArray ();
[251]13
[313]14 Animals.Instance.Get (animals);
[325]15 for (int i = 0; i < animals.Count; i++) {
[306]16 EntityAnimal entity = animals [i];
[325]17 Vector3i position = new Vector3i (entity.GetPosition ());
[251]18
[325]19 JSONObject jsonPOS = new JSONObject ();
20 jsonPOS.Add ("x", new JSONNumber (position.x));
21 jsonPOS.Add ("y", new JSONNumber (position.y));
22 jsonPOS.Add ("z", new JSONNumber (position.z));
[251]23
[325]24 JSONObject pJson = new JSONObject ();
25 pJson.Add ("id", new JSONNumber (entity.entityId));
[251]26
[325]27 if (!string.IsNullOrEmpty (entity.EntityName)) {
28 pJson.Add ("name", new JSONString (entity.EntityName));
29 } else {
30 pJson.Add ("name", new JSONString ("animal class #" + entity.entityClass));
31 }
[251]32
[325]33 pJson.Add ("position", jsonPOS);
[251]34
[325]35 animalsJsResult.Add (pJson);
36 }
37
38 WriteJSON (resp, animalsJsResult);
39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.