- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API/GetAnimalsLocation.cs
r454 r455 1 using System.Collections.Generic; 2 using AllocsFixes.JSON; 3 using AllocsFixes.LiveData; 4 using Webserver; 5 using Webserver.WebAPI; 1 using AllocsFixes.LiveData; 2 using JetBrains.Annotations; 6 3 7 4 namespace AllocsFixes.WebAPIs { 8 internal class GetAnimalsLocation : AbsWebAPI { 9 private readonly List<EntityAnimal> animals = new List<EntityAnimal> (); 10 11 public override void HandleRequest (RequestContext _context) { 12 JSONArray animalsJsResult = new JSONArray (); 13 14 Animals.Instance.Get (animals); 15 for (int i = 0; i < animals.Count; i++) { 16 EntityAnimal entity = animals [i]; 17 Vector3i position = new Vector3i (entity.GetPosition ()); 18 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)); 23 24 JSONObject pJson = new JSONObject (); 25 pJson.Add ("id", new JSONNumber (entity.entityId)); 26 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 } 32 33 pJson.Add ("position", jsonPOS); 34 35 animalsJsResult.Add (pJson); 36 } 37 38 LegacyApiHelper.WriteJSON (_context.Response, animalsJsResult); 5 [UsedImplicitly] 6 internal class GetAnimalsLocation : GetEntityListAbs<EntityAnimal> { 7 public GetAnimalsLocation () : base (Animals.Instance.Get) { 39 8 } 40 9 }
Note:
See TracChangeset
for help on using the changeset viewer.