| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using DCL; |
| | 4 | | using Decentraland.Bff; |
| | 5 | | using UnityEngine; |
| | 6 | | using Variables.RealmsInfo; |
| | 7 | |
|
| | 8 | | namespace DCLPlugins.RealmsPlugin |
| | 9 | | { |
| | 10 | | public class RealmsPlugin : IPlugin |
| | 11 | | { |
| 24 | 12 | | private BaseCollection<RealmModel> realmsList => DataStore.i.realm.realmsInfo; |
| 8 | 13 | | private BaseVariable<AboutResponse> realmAboutConfiguration => DataStore.i.realm.playerRealmAbout; |
| | 14 | | private AboutResponse currentConfiguration; |
| | 15 | |
|
| | 16 | | internal List<IRealmsModifier> realmsModifiers; |
| | 17 | |
|
| 4 | 18 | | public RealmsPlugin() |
| | 19 | | { |
| 4 | 20 | | realmsModifiers = new List<IRealmsModifier>() { new RealmsBlockerModifier() }; |
| | 21 | |
|
| 4 | 22 | | realmAboutConfiguration.OnChange += RealmChanged; |
| 4 | 23 | | realmsList.OnSet += RealmListSet; |
| 4 | 24 | | } |
| | 25 | |
|
| | 26 | | private void RealmListSet(IEnumerable<RealmModel> _) |
| | 27 | | { |
| 4 | 28 | | if (currentConfiguration != null) |
| 0 | 29 | | SetRealmModifiers(); |
| 4 | 30 | | } |
| | 31 | |
|
| | 32 | | private void RealmChanged(AboutResponse current, AboutResponse _) |
| | 33 | | { |
| 8 | 34 | | currentConfiguration = current; |
| 8 | 35 | | if (realmsList.Count().Equals(0)) |
| 0 | 36 | | return; |
| | 37 | |
|
| 8 | 38 | | SetRealmModifiers(); |
| 8 | 39 | | } |
| | 40 | |
|
| | 41 | | private void SetRealmModifiers() |
| | 42 | | { |
| 8 | 43 | | List<RealmModel> currentRealmsList = realmsList.Get().ToList(); |
| 16 | 44 | | bool isCatalyst = currentRealmsList.FirstOrDefault(r => r.serverName == currentConfiguration.Configurations. |
| 24 | 45 | | realmsModifiers.ForEach(e => e.OnEnteredRealm(isCatalyst, currentConfiguration)); |
| 8 | 46 | | } |
| | 47 | |
|
| | 48 | | public void Dispose() |
| | 49 | | { |
| 12 | 50 | | realmsModifiers.ForEach(e => e.Dispose()); |
| | 51 | |
|
| 4 | 52 | | realmAboutConfiguration.OnChange -= RealmChanged; |
| 4 | 53 | | realmsList.OnSet -= RealmListSet; |
| 4 | 54 | | } |
| | 55 | | } |
| | 56 | | } |