| | 1 | | using DCLServices.Lambdas; |
| | 2 | | using MainScripts.DCL.Controllers.HotScenes; |
| | 3 | | using Newtonsoft.Json; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Globalization; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace DCLServices.WorldsAPIService |
| | 10 | | { |
| | 11 | | public static class WorldsResponse |
| | 12 | | { |
| | 13 | | [Serializable] |
| | 14 | | public class WorldInfo : ISerializationCallbackReceiver |
| | 15 | | { |
| | 16 | | [Serializable] |
| | 17 | | public class Realm |
| | 18 | | { |
| | 19 | | public string serverName; |
| | 20 | | public string layer; |
| | 21 | | public string url; |
| | 22 | | public int usersCount; |
| | 23 | | public int maxUsers; |
| | 24 | | public Vector2Int[] userParcels; |
| | 25 | | } |
| | 26 | | public string id; |
| | 27 | | public string title; |
| | 28 | | public string description; |
| | 29 | | public string image; |
| | 30 | | public string owner; |
| | 31 | | public string[] tags; |
| | 32 | | [SerializeField] private string[] positions; |
| | 33 | | public string world_name; |
| | 34 | |
|
| | 35 | | public Vector2Int[] Positions; |
| | 36 | |
|
| | 37 | | public string base_position; |
| | 38 | | public string contact_name; |
| | 39 | | public string contact_email; |
| | 40 | | public string content_rating; |
| | 41 | | public bool disabled; |
| | 42 | | public string disabled_at; |
| | 43 | | public string created_at; |
| | 44 | | public string updated_at; |
| | 45 | | public string deployed_at; |
| | 46 | | public int favorites; |
| | 47 | | public int likes; |
| | 48 | | public int dislikes; |
| | 49 | | public string[] categories; |
| | 50 | | public bool highlighted; |
| | 51 | | public string highlighted_image; |
| | 52 | | public bool featured; |
| | 53 | | public string featured_image; |
| | 54 | | public bool user_favorite; |
| | 55 | | public bool user_like; |
| | 56 | | public bool user_dislike; |
| | 57 | | public int user_count; |
| | 58 | | public int user_visits; |
| | 59 | | public Realm[] realms_detail; |
| | 60 | |
|
| | 61 | | public string like_rate; |
| | 62 | |
|
| | 63 | | [JsonIgnore] |
| | 64 | | public float? like_rate_as_float |
| | 65 | | { |
| | 66 | | get |
| | 67 | | { |
| 1 | 68 | | if (string.IsNullOrEmpty(like_rate)) |
| 1 | 69 | | return null; |
| | 70 | |
|
| 0 | 71 | | if (float.TryParse(like_rate, NumberStyles.Float, CultureInfo.InvariantCulture, out float result)) |
| 0 | 72 | | return result; |
| | 73 | |
|
| 0 | 74 | | return null; |
| | 75 | | } |
| | 76 | | } |
| | 77 | |
|
| | 78 | | public void OnBeforeSerialize() |
| | 79 | | { |
| 0 | 80 | | if (Positions == null) |
| | 81 | | { |
| 0 | 82 | | positions = null; |
| 0 | 83 | | return; |
| | 84 | | } |
| | 85 | |
|
| 0 | 86 | | positions = new string[Positions.Length]; |
| 0 | 87 | | for (int i = 0; i < Positions.Length; i++) |
| 0 | 88 | | positions[i] = $"{Positions[i].x},{Positions[i].y}"; |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | public void OnAfterDeserialize() |
| | 92 | | { |
| 0 | 93 | | if (positions == null) |
| 0 | 94 | | return; |
| 0 | 95 | | Positions = new Vector2Int[positions.Length]; |
| 0 | 96 | | for (int i = 0; i < positions.Length; i++) |
| | 97 | | { |
| 0 | 98 | | string[] split = positions[i].Split(','); |
| 0 | 99 | | Positions[i] = new Vector2Int(int.Parse(split[0]), int.Parse(split[1])); |
| | 100 | | } |
| 0 | 101 | | } |
| | 102 | | } |
| | 103 | |
|
| | 104 | | [Serializable] |
| | 105 | | public class WorldsAPIResponse : PaginatedResponse |
| | 106 | | { |
| | 107 | | public bool ok; |
| | 108 | | public int total; |
| | 109 | | public List<WorldInfo> data; |
| | 110 | | } |
| | 111 | | } |
| | 112 | | } |