Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }