| | 1 | | using UnityEngine; |
| | 2 | | using System; |
| | 3 | | using Variables.RealmsInfo; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using Decentraland.Bff; |
| | 7 | |
|
| | 8 | | namespace DCL |
| | 9 | | { |
| | 10 | | public class RealmsInfoHandler |
| | 11 | | { |
| 0 | 12 | | private RealmsInfoModel model = new RealmsInfoModel(); |
| | 13 | |
|
| 1 | 14 | | public CurrentRealmVariable playerRealm => DataStore.i.realm.playerRealm; |
| 1 | 15 | | public BaseCollection<RealmModel> realmsInfo => DataStore.i.realm.realmsInfo; |
| 0 | 16 | | private BaseVariable<AboutResponse> playerRealmAbout => DataStore.i.realm.playerRealmAbout; |
| 4 | 17 | | private BaseVariable<string> realmName => DataStore.i.realm.realmName; |
| | 18 | |
|
| | 19 | | public void Set(string json) |
| | 20 | | { |
| 2 | 21 | | JsonUtility.FromJsonOverwrite(json, model); |
| 2 | 22 | | Set(model); |
| 2 | 23 | | } |
| | 24 | |
|
| | 25 | | public void Set(RealmsInfoModel newModel) |
| | 26 | | { |
| 5 | 27 | | model = newModel; |
| 5 | 28 | | if (!string.IsNullOrEmpty(model.current?.serverName)) |
| | 29 | | { |
| 4 | 30 | | DataStore.i.realm.playerRealm.Set(model.current.Clone()); |
| 4 | 31 | | realmName.Set(DataStore.i.realm.playerRealm.Get().serverName); |
| | 32 | | } |
| 5 | 33 | | DataStore.i.realm.realmsInfo.Set(newModel.realms != null ? newModel.realms.ToList() : new List<RealmModel>() |
| 5 | 34 | | } |
| | 35 | |
|
| | 36 | | public void SetAbout(string json) |
| | 37 | | { |
| 0 | 38 | | AboutResponse aboutResponse = AboutResponse.Parser.ParseJson(json); |
| 0 | 39 | | playerRealmAbout.Set(aboutResponse); |
| 0 | 40 | | realmName.Set(aboutResponse.Configurations.RealmName); |
| 0 | 41 | | } |
| | 42 | | } |
| | 43 | |
|
| | 44 | | [Serializable] |
| | 45 | | public class RealmsInfoModel |
| | 46 | | { |
| | 47 | | public CurrentRealmModel current; |
| | 48 | | public RealmModel[] realms; |
| | 49 | | } |
| | 50 | | } |