| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using DCLServices.Lambdas; |
| | 4 | | using Newtonsoft.Json; |
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Globalization; |
| | 8 | | using System.Threading; |
| | 9 | | using UnityEngine; |
| | 10 | |
|
| | 11 | | namespace MainScripts.DCL.Controllers.HotScenes |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Despite this service is called `HotScenesController` it is responsible to fetch users outside of comms region, |
| | 15 | | /// so it is essentially `ColdScenesController` |
| | 16 | | /// </summary> |
| | 17 | | public interface IHotScenesController : IService |
| | 18 | | { |
| | 19 | | UniTask<IReadOnlyList<HotSceneInfo>> GetHotScenesListAsync(CancellationToken cancellationToken); |
| | 20 | | UniTask<IReadOnlyList<HotWorldInfo.WorldInfo>> GetHotWorldsListAsync(CancellationToken cancellationToken); |
| | 21 | |
|
| | 22 | | [Serializable] |
| | 23 | | class HotSceneInfo |
| | 24 | | { |
| | 25 | | [Serializable] |
| | 26 | | public class Realm |
| | 27 | | { |
| | 28 | | public string serverName; |
| | 29 | | public string layer; |
| | 30 | | public int usersCount; |
| | 31 | | public int maxUsers; |
| | 32 | | public Vector2Int[] userParcels; |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public string id; |
| | 36 | | public string name; |
| | 37 | | public string creator; |
| | 38 | | public string description; |
| | 39 | | public string thumbnail; |
| | 40 | | public Vector2Int baseCoords; |
| | 41 | | public Vector2Int[] parcels; |
| | 42 | | public int usersTotalCount; |
| | 43 | | public Realm[] realms; |
| | 44 | | } |
| | 45 | |
|
| | 46 | | [Serializable] |
| | 47 | | class HotWorldInfo |
| | 48 | | { |
| | 49 | | [Serializable] |
| | 50 | | public class WorldInfo |
| | 51 | | { |
| | 52 | | public string worldName; |
| | 53 | | public int users; |
| | 54 | | } |
| | 55 | |
|
| | 56 | | [Serializable] |
| | 57 | | public class WorldData |
| | 58 | | { |
| | 59 | | public int totalUsers; |
| | 60 | | public WorldInfo[] perWorld; |
| | 61 | | } |
| | 62 | |
|
| | 63 | | public WorldData data; |
| | 64 | | public string lastUpdated; |
| | 65 | |
|
| | 66 | | } |
| | 67 | |
|
| | 68 | | // TODO: This class should be moved to the PlacesAPIService folder |
| | 69 | | [Serializable] |
| | 70 | | public class PlaceInfo : ISerializationCallbackReceiver |
| | 71 | | { |
| | 72 | | [Serializable] |
| | 73 | | public class Realm |
| | 74 | | { |
| | 75 | | public string serverName; |
| | 76 | | public string layer; |
| | 77 | | public string url; |
| | 78 | | public int usersCount; |
| | 79 | | public int maxUsers; |
| | 80 | | public Vector2Int[] userParcels; |
| | 81 | | } |
| | 82 | | public string id; |
| | 83 | | public string title; |
| | 84 | | public string description; |
| | 85 | | public string image; |
| | 86 | | public string owner; |
| | 87 | | public string[] tags; |
| | 88 | | [SerializeField] private string[] positions; |
| | 89 | | public string world_name; |
| | 90 | |
|
| | 91 | | public Vector2Int[] Positions; |
| | 92 | |
|
| | 93 | | public string base_position; |
| | 94 | | public string contact_name; |
| | 95 | | public string contact_email; |
| | 96 | | public string content_rating; |
| | 97 | | public bool disabled; |
| | 98 | | public string disabled_at; |
| | 99 | | public string created_at; |
| | 100 | | public string updated_at; |
| | 101 | | public string deployed_at; |
| | 102 | | public int favorites; |
| | 103 | | public int likes; |
| | 104 | | public int dislikes; |
| | 105 | | public string[] categories; |
| | 106 | | public bool highlighted; |
| | 107 | | public string highlighted_image; |
| | 108 | | public bool featured; |
| | 109 | | public string featured_image; |
| | 110 | | public bool user_favorite; |
| | 111 | | public bool user_like; |
| | 112 | | public bool user_dislike; |
| | 113 | | public int user_count; |
| | 114 | | public int user_visits; |
| | 115 | | public Realm[] realms_detail; |
| | 116 | |
|
| | 117 | | public string like_rate; |
| | 118 | |
|
| | 119 | | [JsonIgnore] |
| | 120 | | public float? like_rate_as_float |
| | 121 | | { |
| | 122 | | get |
| | 123 | | { |
| 1 | 124 | | if (string.IsNullOrEmpty(like_rate)) |
| 1 | 125 | | return null; |
| | 126 | |
|
| 0 | 127 | | if (float.TryParse(like_rate, NumberStyles.Float, CultureInfo.InvariantCulture, out float result)) |
| 0 | 128 | | return result; |
| | 129 | |
|
| 0 | 130 | | return null; |
| | 131 | | } |
| | 132 | | } |
| | 133 | |
|
| | 134 | | public void OnBeforeSerialize() |
| | 135 | | { |
| 2206 | 136 | | if (Positions == null) |
| | 137 | | { |
| 0 | 138 | | positions = null; |
| 0 | 139 | | return; |
| | 140 | | } |
| | 141 | |
|
| 2206 | 142 | | positions = new string[Positions.Length]; |
| 4412 | 143 | | for (int i = 0; i < Positions.Length; i++) |
| 0 | 144 | | positions[i] = $"{Positions[i].x},{Positions[i].y}"; |
| 2206 | 145 | | } |
| | 146 | |
|
| | 147 | | public void OnAfterDeserialize() |
| | 148 | | { |
| 2217 | 149 | | if (positions == null) |
| 0 | 150 | | return; |
| 2217 | 151 | | Positions = new Vector2Int[positions.Length]; |
| 4434 | 152 | | for (int i = 0; i < positions.Length; i++) |
| | 153 | | { |
| 0 | 154 | | string[] split = positions[i].Split(','); |
| 0 | 155 | | Positions[i] = new Vector2Int(int.Parse(split[0]), int.Parse(split[1])); |
| | 156 | | } |
| 2217 | 157 | | } |
| | 158 | | } |
| | 159 | |
|
| | 160 | | // TODO: This class should be moved to the PlacesAPIService folder |
| | 161 | | [Serializable] |
| | 162 | | public class PlacesAPIResponse : PaginatedResponse |
| | 163 | | { |
| | 164 | | public bool ok; |
| | 165 | | public int total; |
| | 166 | | public List<PlaceInfo> data; |
| | 167 | | } |
| | 168 | |
|
| | 169 | | // TODO: This class should be moved to the PlacesAPIService folder |
| | 170 | | [Serializable] |
| | 171 | | public class PlacesAPIGetParcelResponse |
| | 172 | | { |
| | 173 | | public bool ok; |
| | 174 | | public PlaceInfo data; |
| | 175 | | } |
| | 176 | | } |
| | 177 | | } |