source: binary-improvements2/MapRendering/Web/API/GetHostileLocation.cs@ 389

Last change on this file since 389 was 387, checked in by alloc, 2 years ago

Big refactoring in Web to pass around a Context instead of a bunch of individual arguments all the time

File size: 1.2 KB
RevLine 
[325]1using System.Collections.Generic;
2using AllocsFixes.JSON;
[251]3using AllocsFixes.LiveData;
4
[325]5namespace AllocsFixes.NetConnections.Servers.Web.API {
[387]6 internal class GetHostileLocation : AbsWebAPI {
[325]7 private readonly List<EntityEnemy> enemies = new List<EntityEnemy> ();
[306]8
[387]9 public override void HandleRequest (RequestContext _context) {
[325]10 JSONArray hostilesJsResult = new JSONArray ();
[251]11
[313]12 Hostiles.Instance.Get (enemies);
[325]13 for (int i = 0; i < enemies.Count; i++) {
[306]14 EntityEnemy entity = enemies [i];
[325]15 Vector3i position = new Vector3i (entity.GetPosition ());
[251]16
[325]17 JSONObject jsonPOS = new JSONObject ();
18 jsonPOS.Add ("x", new JSONNumber (position.x));
19 jsonPOS.Add ("y", new JSONNumber (position.y));
20 jsonPOS.Add ("z", new JSONNumber (position.z));
[251]21
[325]22 JSONObject pJson = new JSONObject ();
23 pJson.Add ("id", new JSONNumber (entity.entityId));
[251]24
[325]25 if (!string.IsNullOrEmpty (entity.EntityName)) {
26 pJson.Add ("name", new JSONString (entity.EntityName));
27 } else {
28 pJson.Add ("name", new JSONString ("enemy class #" + entity.entityClass));
29 }
[251]30
[325]31 pJson.Add ("position", jsonPOS);
[251]32
[325]33 hostilesJsResult.Add (pJson);
34 }
[251]35
[387]36 WebUtils.WriteJson (_context.Response, hostilesJsResult);
[325]37 }
38 }
39}
Note: See TracBrowser for help on using the repository browser.