| | 1 | | using DCL; |
| | 2 | | using DCL.SettingsCommon; |
| | 3 | | using DCLPlugins.RealmPlugin; |
| | 4 | | using static Decentraland.Bff.AboutResponse.Types; |
| | 5 | |
|
| | 6 | | namespace DCLPlugins.RealmsPlugin |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Align skybox with the realm skybox settings. It allows the world creator to force specific skybox state. |
| | 10 | | /// </summary> |
| | 11 | | public class RealmsSkyboxModifier : IRealmModifier |
| | 12 | | { |
| | 13 | | private readonly DataStore_SkyboxConfig skyboxConfig; |
| | 14 | |
|
| | 15 | | private bool hasCached; |
| | 16 | |
|
| | 17 | | private SkyboxMode cachedMode; |
| | 18 | | private float cachedFixedTime; |
| | 19 | |
|
| 7 | 20 | | public RealmsSkyboxModifier(DataStore_SkyboxConfig skyboxConfig) |
| | 21 | | { |
| 7 | 22 | | this.skyboxConfig = skyboxConfig; |
| 7 | 23 | | } |
| | 24 | |
|
| 0 | 25 | | public void Dispose() { } |
| | 26 | |
|
| | 27 | | public void OnEnteredRealm(bool _, AboutConfiguration realmConfiguration) |
| | 28 | | { |
| 11 | 29 | | if (realmConfiguration.Skybox is { HasFixedHour: true }) |
| | 30 | | { |
| 6 | 31 | | if (!hasCached) |
| 6 | 32 | | CacheCurrentSkyboxSettings(); |
| | 33 | |
|
| 6 | 34 | | CommonSettingsScriptableObjects.SkyboxControlledByRealm.Set(true); |
| 6 | 35 | | skyboxConfig.UseFixedTimeFromSeconds(realmConfiguration.Skybox!.FixedHour, SkyboxMode.HoursFixedByWorld) |
| | 36 | | } |
| 5 | 37 | | else if (hasCached) |
| 5 | 38 | | ResetToCached(); |
| 5 | 39 | | } |
| | 40 | |
|
| | 41 | | private void ResetToCached() |
| | 42 | | { |
| 5 | 43 | | skyboxConfig.UseFixedTimeFromHours(cachedFixedTime, cachedMode); |
| 5 | 44 | | hasCached = false; |
| | 45 | |
|
| 5 | 46 | | CommonSettingsScriptableObjects.SkyboxControlledByRealm.Set(false); |
| 5 | 47 | | } |
| | 48 | |
|
| | 49 | | private void CacheCurrentSkyboxSettings() |
| | 50 | | { |
| 6 | 51 | | cachedMode = skyboxConfig.mode.Get(); |
| 6 | 52 | | cachedFixedTime = skyboxConfig.fixedTime.Get(); |
| | 53 | |
|
| 6 | 54 | | hasCached = true; |
| 6 | 55 | | } |
| | 56 | | } |
| | 57 | | } |