Skip to content

Commit

Permalink
Fix Multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
affederaffe committed Sep 25, 2021
1 parent fdcd2a6 commit 0e14ee0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 48 deletions.
9 changes: 3 additions & 6 deletions Plugin/CustomFloorPlugin/AssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,13 @@ public void Construct(IBeatmapObjectCallbackController beatmapObjectCallbackCont
public void PlatformEnabled(DiContainer container)
{
container.Inject(this);

gameObject.SetActive(false);
List<ILightWithId>?[] lights = _lightWithIdManager.GetField<List<ILightWithId>?[], LightWithIdManager>("_lights");

if (_lightSwitchEventEffects is null)
{
Color normalColor = new(1f, 1f, 1f, 0.7490196f);
Color boostColor = new(1f, 1f, 1f, 0.8f);
Color highlightColor = new(1f, 1f, 1f, 1f);

_lightSwitchEventEffects = new LightSwitchEventEffect[5];
for (int i = 0; i < _lightSwitchEventEffects.Length; i++)
{
Expand All @@ -238,11 +236,9 @@ public void PlatformEnabled(DiContainer container)
foreach (LightSwitchEventEffect lse in _lightSwitchEventEffects)
{
lights[lse.lightsId] ??= new List<ILightWithId>();
lse.SetField("_initialized", false);
lse.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController);
lse.SetField("_lightManager", _lightWithIdManager);
lse.SetColor(Color.clear);
gameObject.SetActive(true);
lse.Start();
}
}
Expand All @@ -255,13 +251,14 @@ public void PlatformEnabled(DiContainer container)
_simpleLightColor1Boost.SetColor(_colorScheme.environmentColor1Boost);
_simpleHighlightColor0Boost.SetColor(_colorScheme.environmentColor0Boost);
_simpleHighlightColor1Boost.SetColor(_colorScheme.environmentColor1Boost);
gameObject.SetActive(true);
}

public void PlatformDisabled()
{
if (_lightSwitchEventEffects is null) return;
foreach (LightSwitchEventEffect lse in _lightSwitchEventEffects)
lse.OnDestroy();
_beatmapObjectCallbackController.beatmapEventDidTriggerEvent -= lse.HandleBeatmapObjectCallbackControllerBeatmapEventDidTrigger;
gameObject.SetActive(false);
}

Expand Down
11 changes: 3 additions & 8 deletions Plugin/CustomFloorPlugin/PlatformManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ public PlatformManager(SiraLog siraLog,

public async void Initialize()
{
try
{
await LoadPlatformsAsync();
}
catch (System.OperationCanceledException) { }
await LoadPlatformsAsync();
}

/// <summary>
Expand Down Expand Up @@ -142,10 +138,9 @@ private async Task LoadPlatformsAsync()
}

// Load all remaining platforms, or all if no cache file is found
foreach (string path in Directory.EnumerateFiles(DirectoryPath, "*.plat"))
foreach (string path in Directory.EnumerateFiles(DirectoryPath, "*.plat").Where(x => AllPlatforms.All(y => y.fullPath != x)))
{
cancellationToken.ThrowIfCancellationRequested();
if (AllPlatforms.Any(x => x.fullPath == path)) continue;
if (cancellationToken.IsCancellationRequested) return;
CustomPlatform? platform = await CreatePlatformAsync(path);
if (platform is null) continue;
AllPlatforms.AddSorted(1, AllPlatforms.Count - 1, platform);
Expand Down
57 changes: 24 additions & 33 deletions Plugin/CustomFloorPlugin/PlatformSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,44 +154,35 @@ private void OnMultiplayerGameStateModelDidChange(MultiplayerGameState multiplay
/// <param name="platform">The <see cref="CustomPlatform"/> to change to</param>
public async Task ChangeToPlatformAsync(CustomPlatform platform)
{
try
{
if (platform == _platformManager.ActivePlatform) return;
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = _cancellationTokenSource.Token;
if (platform == _platformManager.ActivePlatform) return;
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = _cancellationTokenSource.Token;

DestroyCustomObjects();
_platformManager.ActivePlatform.gameObject.SetActive(false);
_platformManager.ActivePlatform = platform;
DestroyCustomObjects();
_platformManager.ActivePlatform.gameObject.SetActive(false);
_platformManager.ActivePlatform = platform;

if (platform.isDescriptor)
if (platform.isDescriptor)
{
CustomPlatform? newPlatform = await _platformManager.CreatePlatformAsync(platform.fullPath);
if (newPlatform is null)
{
CustomPlatform? newPlatform = await _platformManager.CreatePlatformAsync(platform.fullPath);
if (newPlatform is not null)
{
_platformManager.AllPlatforms.Replace(platform, newPlatform);
UnityEngine.Object.Destroy(platform.gameObject);
}

cancellationToken.ThrowIfCancellationRequested();

if (newPlatform is null)
{
_ = ChangeToPlatformAsync(_platformManager.DefaultPlatform);
return;
}

_platformManager.ActivePlatform = newPlatform;
_ = ChangeToPlatformAsync(_platformManager.DefaultPlatform);
return;
}

_siraLog.Info($"Switching to {_platformManager.ActivePlatform.name}");
_environmentHider.HideObjectsForPlatform(_platformManager.ActivePlatform);
_platformManager.ActivePlatform.gameObject.SetActive(true);
SpawnCustomObjects();
_platformManager.AllPlatforms.Replace(platform, newPlatform);
UnityEngine.Object.Destroy(platform.gameObject);
if (cancellationToken.IsCancellationRequested) return;
_platformManager.ActivePlatform = newPlatform;
}
catch (OperationCanceledException) { }

_siraLog.Info($"Switching to {_platformManager.ActivePlatform.name}");
_environmentHider.HideObjectsForPlatform(_platformManager.ActivePlatform);
_platformManager.ActivePlatform.gameObject.SetActive(true);
SpawnCustomObjects();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Plugin/CustomFloorPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "Custom Platforms",
"name": "Custom Platforms",
"author": "Rolo",
"version": "6.1.8",
"version": "6.1.9",
"description": "A plugin to support custom platforms and environments",
"gameVersion": "1.18.0",
"dependsOn": {
Expand Down

0 comments on commit 0e14ee0

Please sign in to comment.