public static StarSystem CreateFromDTO(StarSystemResponse response) { StarSystemType GetType() { return(StarSystemType.Double); } StarSystemSize GetSize() { return(StarSystemSize.Medium); } StarSystem system = new StarSystem() { PublicName = response.publicName ?? response.name, Owner = response.owner, DiscoveredBy = response.discovered_by, Speed = response.speed, DiscoveredAt = response.discovered_at, Id = response.id, Seed = response.seed, Sector = response.sector, CreatedAt = response.created_at, Name = response.name, Location = new Vector2(response.position_x, response.position_y), Type = GetType(), Size = GetSize() }; return(system); }
public static void Get(int id, Action <Model.StarSystem> callback, Action <Exception> error) { Request <StarSystemGetRequest> request = new Request <StarSystemGetRequest>(GetMethod, new StarSystemGetRequest(id)); request.Then(json => { StarSystemResponse response = JsonUtility.FromJson <StarSystemResponse>(json); Model.StarSystem system = Model.StarSystem.CreateFromDTO(response); callback.Invoke(system); }).Catch(error.Invoke); }
public static void Create(int sector, Action <StarSystem> callback, Action <Exception> error) { StarSystem starSystem = StarSystemGenerator.Generate(sector); Request <StarSystemCreateRequest> request = new Request <StarSystemCreateRequest>(CreateMethod, StarSystemCreateRequest.FromModel(starSystem)); request.Then(json => { StarSystemResponse response = JsonUtility.FromJson <StarSystemResponse>(json); StarSystem system = StarSystem.CreateFromDTO(response); callback.Invoke(system); }).Catch(error.Invoke); }