Skip to content

Commit

Permalink
Merge pull request #137 from Goobwabber/1.16.3
Browse files Browse the repository at this point in the history
1.18 Update
  • Loading branch information
Goobwabber authored Nov 14, 2021
2 parents d047e8d + fed2450 commit e70690a
Show file tree
Hide file tree
Showing 51 changed files with 1,259 additions and 1,609 deletions.
13 changes: 6 additions & 7 deletions MultiplayerExtensions/Beatmaps/PreviewBeatmapStub.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BeatSaverSharp;
using BeatSaverSharp.Models;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -23,7 +23,7 @@ public Task<bool> isDownloadable

if (_downloadableTask == null)
{
_downloadableTask = Plugin.BeatSaver.Hash(levelHash).ContinueWith<bool>(r => r.Exception == null && r.Result is Beatmap);
_downloadableTask = Plugin.BeatSaver.BeatmapByHash(levelHash).ContinueWith<bool>(r => r.Exception == null && r.Result is Beatmap);
_downloadableTask.ContinueWith(r => _downloadable = r.Result ? DownloadableState.True : DownloadableState.False);
}

Expand Down Expand Up @@ -85,14 +85,14 @@ public PreviewBeatmapStub(PreviewBeatmapPacket packet)
this.songDuration = packet.songDuration;
}

public PreviewBeatmapStub(string levelID, Beatmap bm)
public PreviewBeatmapStub(string levelID, string hash, Beatmap bm)
{
this._beatmap = bm;
this._downloadable = DownloadableState.True;
this.isDownloaded = false;

this.levelID = levelID;
this.levelHash = bm.Hash;
this.levelHash = hash;

this.songName = bm.Metadata.SongName;
this.songSubName = bm.Metadata.SongSubName;
Expand All @@ -113,17 +113,16 @@ public async Task<Sprite> GetCoverImageAsync(CancellationToken cancellationToken
{
try
{
Sprite? cover = Utilities.Sprites.GetSprite(await _beatmap.CoverImageBytes());
Sprite? cover = Utilities.Sprites.GetSprite(await _beatmap.Versions[0].DownloadCoverImage());
if (cover != null)
return cover;
}
catch(Exception ex)
{
Plugin.Log?.Warn($"Failed to fetch beatmap cover: {ex.Message}");
}

}

return Sprite.Create(Texture2D.blackTexture, new Rect(0, 0, 2, 2), new Vector2(0, 0), 100.0f);
}

Expand Down
25 changes: 11 additions & 14 deletions MultiplayerExtensions/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using System.Threading.Tasks;
using MultiplayerExtensions.Utilities;
using System.Collections.Concurrent;
using BeatSaverSharp;
using System.Diagnostics;
using BeatSaverSharp.Models;
using System.Linq;
#nullable enable

namespace MultiplayerExtensions
Expand All @@ -25,14 +26,14 @@ public static bool TryGetDownload(string levelId, out Task<IPreviewBeatmapLevel?

private static async Task<IPreviewBeatmapLevel?> DownloadSong(string hash, CancellationToken cancellationToken)
{
Beatmap? bm = await Plugin.BeatSaver.Hash(hash);
Beatmap? bm = await Plugin.BeatSaver.BeatmapByHash(hash);

if (bm == null)
{
Plugin.Log?.Warn($"Could not find song '{hash}' on Beat Saver.");
return null;
}
Plugin.Log.Info($"Attempting to download song '({bm.Key}) {bm.Name ?? hash}'");
Plugin.Log.Info($"Attempting to download song '({bm.ID}) {bm.Name ?? hash}'");
#if DEBUG
if((Plugin.Config.DebugConfig?.FailDownloads ?? false))
{
Expand All @@ -43,16 +44,12 @@ public static bool TryGetDownload(string levelId, out Task<IPreviewBeatmapLevel?
#endif
Stopwatch sw = new Stopwatch();
sw.Start();
byte[] beatmapBytes = await bm.ZipBytes(false, new StandardRequestOptions()
{
Progress = new Progress<double>(d =>
{
#if DEBUG
Plugin.Log.Debug($"Downloading '{hash}': {d}");
#endif
DownloadProgressChanged?.Invoke(hash, d);
})
});

Plugin.Log?.Info($"Target hash: '{hash}'");
byte[]? beatmapBytes = await bm.Versions.ToList().Find(version => {
Plugin.Log?.Info($"Version: '{version.Key}' '{version.Hash}'");
return version.Hash.ToUpper() == hash;
}).DownloadZIP(progress: UI.CenterScreenLoadingPanel.Instance);
#if DEBUG
TimeSpan delay = TimeSpan.FromSeconds(Plugin.Config.DebugConfig?.MinDownloadTime ?? 0) - TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
if (delay > TimeSpan.Zero)
Expand All @@ -62,7 +59,7 @@ public static bool TryGetDownload(string levelId, out Task<IPreviewBeatmapLevel?
Plugin.Log.Debug($"Delay finished.");
}
#endif
string folderPath = Utils.GetSongDirectoryName(bm.Key, bm.Metadata.SongName, bm.Metadata.LevelAuthorName);
string folderPath = Utils.GetSongDirectoryName(bm.LatestVersion.Key, bm.Metadata.SongName, bm.Metadata.LevelAuthorName);
folderPath = Path.Combine(CustomLevelsFolder, folderPath);
using (var ms = new MemoryStream(beatmapBytes))
{
Expand Down
14 changes: 6 additions & 8 deletions MultiplayerExtensions/Environments/LobbyAvatarManager.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
using System;
using System.Collections.Generic;
using IPA.Utilities;
using MultiplayerExtensions.Sessions;
using MultiplayerExtensions.Extensions;
using UnityEngine;
using Zenject;

namespace MultiplayerExtensions.Environments
{
public class LobbyAvatarManager : IInitializable, IDisposable
{
protected readonly IMultiplayerSessionManager _sessionManager;
protected readonly ExtendedPlayerManager _playerManager;
protected readonly ExtendedSessionManager _sessionManager;
protected readonly MultiplayerLobbyAvatarManager _avatarManager;

protected Dictionary<string, MultiplayerLobbyAvatarController>? _refPlayerIdToAvatarMap;

private Dictionary<string, ExtendedPlayer> _extendedPlayers;

internal LobbyAvatarManager(IMultiplayerSessionManager sessionManager, ExtendedPlayerManager playerManager, MultiplayerLobbyAvatarManager avatarManager)
internal LobbyAvatarManager(IMultiplayerSessionManager sessionManager, MultiplayerLobbyAvatarManager avatarManager)
{
_sessionManager = sessionManager;
_playerManager = playerManager;
_sessionManager = (sessionManager as ExtendedSessionManager)!;
_avatarManager = avatarManager;

_refPlayerIdToAvatarMap = null;
Expand All @@ -32,14 +30,14 @@ public void Initialize()
{
MPEvents.LobbyAvatarCreated += HandleLobbyAvatarCreated;
_sessionManager.playerDisconnectedEvent += HandlePlayerDisconnected;
_playerManager.extendedPlayerConnectedEvent += HandleExtendedPlayerConnected;
_sessionManager.extendedPlayerConnectedEvent += HandleExtendedPlayerConnected;
}

public void Dispose()
{
MPEvents.LobbyAvatarCreated -= HandleLobbyAvatarCreated;
_sessionManager.playerDisconnectedEvent -= HandlePlayerDisconnected;
_playerManager.extendedPlayerConnectedEvent -= HandleExtendedPlayerConnected;
_sessionManager.extendedPlayerConnectedEvent -= HandleExtendedPlayerConnected;
}

#region Events
Expand Down
2 changes: 1 addition & 1 deletion MultiplayerExtensions/Environments/LobbyAvatarNameTag.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using HMUI;
using MultiplayerExtensions.Sessions;
using MultiplayerExtensions.Extensions;
using MultiplayerExtensions.Utilities;
using UnityEngine;
using UnityEngine.UI;
Expand Down
19 changes: 8 additions & 11 deletions MultiplayerExtensions/Environments/LobbyEnvironmentManager.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
using System;
using IPA.Utilities;
using MultiplayerExtensions.Sessions;
using System;
using MultiplayerExtensions.Extensions;
using UnityEngine;
using Zenject;

namespace MultiplayerExtensions.Environments
{
public class LobbyEnvironmentManager : IInitializable, IDisposable
{
protected readonly IMultiplayerSessionManager _sessionManager;
protected readonly ExtendedSessionManager _sessionManager;
protected readonly ILobbyStateDataModel _lobbyStateDataModel;
protected readonly MenuEnvironmentManager _menuEnvironmentManager;
protected readonly MultiplayerLobbyAvatarPlaceManager _placeManager;
protected readonly MultiplayerLobbyCenterStageManager _stageManager;
protected readonly ExtendedPlayerManager _playerManager;

private LobbyAvatarPlaceLighting[] _avatarPlaces = Array.Empty<LobbyAvatarPlaceLighting>();
private float _innerCircleRadius;
private float _minOuterCircleRadius;
private float _angleBetweenPlayersWithEvenAdjustment;
private float _outerCircleRadius;

internal LobbyEnvironmentManager(IMultiplayerSessionManager sessionManager, ILobbyStateDataModel lobbyStateDataModel, MenuEnvironmentManager menuEnvironmentManager, MultiplayerLobbyAvatarPlaceManager placeManager, MultiplayerLobbyCenterStageManager stageManager, ExtendedPlayerManager playerManager)
internal LobbyEnvironmentManager(IMultiplayerSessionManager sessionManager, ILobbyStateDataModel lobbyStateDataModel, MenuEnvironmentManager menuEnvironmentManager, MultiplayerLobbyAvatarPlaceManager placeManager, MultiplayerLobbyCenterStageManager stageManager)
{
_sessionManager = sessionManager;
_sessionManager = (sessionManager as ExtendedSessionManager)!;
_lobbyStateDataModel = lobbyStateDataModel;
_menuEnvironmentManager = menuEnvironmentManager;
_placeManager = placeManager;
_stageManager = stageManager;
_playerManager = playerManager;
}

public void Initialize()
{
MPEvents.LobbyEnvironmentLoaded += HandleLobbyEnvironmentLoaded;
_playerManager.extendedPlayerConnectedEvent += HandleExtendedPlayerConnected;
_sessionManager.extendedPlayerConnectedEvent += HandleExtendedPlayerConnected;
_sessionManager.playerConnectedEvent += HandlePlayerConnected;
_sessionManager.playerDisconnectedEvent += HandlePlayerDisconnected;
}

public void Dispose()
{
MPEvents.LobbyEnvironmentLoaded -= HandleLobbyEnvironmentLoaded;
_playerManager.extendedPlayerConnectedEvent -= HandleExtendedPlayerConnected;
_sessionManager.extendedPlayerConnectedEvent -= HandleExtendedPlayerConnected;
_sessionManager.playerConnectedEvent -= HandlePlayerConnected;
_sessionManager.playerDisconnectedEvent -= HandlePlayerDisconnected;
}
Expand Down Expand Up @@ -81,12 +78,12 @@ private void HandleLobbyEnvironmentLoaded(object sender, System.EventArgs e)
public void SetDefaultPlayerPlaceColors()
{
SetAllPlayerPlaceColors(Color.black, true);
SetPlayerPlaceColor(_sessionManager.localPlayer, ExtendedPlayerManager.localColor, true);
SetPlayerPlaceColor(_sessionManager.localPlayer, ExtendedSessionManager.localExtendedPlayer.playerColor, true);

foreach (var player in _sessionManager.connectedPlayers)
SetPlayerPlaceColor(player, ExtendedPlayer.DefaultColor, false);

foreach (var extendedPlayer in _playerManager.players.Values)
foreach (var extendedPlayer in _sessionManager.extendedPlayers.Values)
SetPlayerPlaceColor(extendedPlayer, extendedPlayer.playerColor, true);
}

Expand Down
16 changes: 10 additions & 6 deletions MultiplayerExtensions/Environments/MultiplayerActivePlayer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MultiplayerExtensions.Sessions;
using MultiplayerExtensions.Extensions;
using UnityEngine;
using Zenject;

Expand All @@ -8,28 +8,32 @@ public class MultiplayerActivePlayer : MonoBehaviour
{
protected IConnectedPlayer _connectedPlayer = null!;
protected MultiplayerController _multiplayerController = null!;
protected ExtendedPlayerManager _extendedPlayerManager = null!;
protected ExtendedSessionManager _sessionManager = null!;
protected IScoreSyncStateManager _scoreProvider = null!;
protected MultiplayerLeadPlayerProvider _leadPlayerProvider = null!;

[Inject]
internal void Inject(IConnectedPlayer connectedPlayer, MultiplayerController multiplayerController, ExtendedPlayerManager extendedPlayerManager, IScoreSyncStateManager scoreProvider, MultiplayerLeadPlayerProvider leadPlayerProvider)
internal void Inject(IConnectedPlayer connectedPlayer, MultiplayerController multiplayerController, IMultiplayerSessionManager sessionManager, IScoreSyncStateManager scoreProvider, MultiplayerLeadPlayerProvider leadPlayerProvider)
{
_connectedPlayer = connectedPlayer;
_multiplayerController = multiplayerController;
_extendedPlayerManager = extendedPlayerManager;
_sessionManager = (sessionManager as ExtendedSessionManager)!;
_scoreProvider = scoreProvider;
_leadPlayerProvider = leadPlayerProvider;
}

protected void Awake()
{
MultiplayerGameplayAnimator gameplayAnimator = transform.GetComponentInChildren<MultiplayerGameplayAnimator>();

if (Plugin.Config.MissLighting)
{
MultiplayerGameplayAnimator gameplayAnimator = transform.GetComponentInChildren<MultiplayerGameplayAnimator>();
MultiplayerGameplayLighting gameplayLighting = gameplayAnimator.gameObject.AddComponent<MultiplayerGameplayLighting>();
gameplayLighting.Construct(_connectedPlayer, _multiplayerController, _scoreProvider, _leadPlayerProvider, gameplayAnimator, _extendedPlayerManager);
gameplayLighting.Construct(_connectedPlayer, _multiplayerController, _scoreProvider, _leadPlayerProvider, gameplayAnimator, _sessionManager);
}

MultiplayerGameplayHud gameplayHud = gameplayAnimator.gameObject.AddComponent<MultiplayerGameplayHud>();
gameplayHud.Construct(_connectedPlayer, gameplayAnimator);
}
}
}
81 changes: 81 additions & 0 deletions MultiplayerExtensions/Environments/MultiplayerGameplayHud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using HMUI;
using IPA.Utilities;
using UnityEngine;

namespace MultiplayerExtensions.Environments
{
class MultiplayerGameplayHud : MonoBehaviour
{
protected IConnectedPlayer _connectedPlayer = null!;
protected MultiplayerGameplayAnimator _gameplayAnimator = null!;

protected CoreGameHUDController _coreGameHUDController = null!;
protected GameObject _songProgressPanelGO = null!;
protected GameObject _energyPanelGO = null!;

internal void Construct(IConnectedPlayer connectedPlayer, MultiplayerGameplayAnimator gameplayAnimator)
{
_connectedPlayer = connectedPlayer;
_gameplayAnimator = gameplayAnimator;

if (gameplayAnimator is MultiplayerLocalActivePlayerGameplayAnimator localGameplayAnimator)
{
_coreGameHUDController = localGameplayAnimator.GetField<CoreGameHUDController, MultiplayerLocalActivePlayerGameplayAnimator>("_coreGameHUDController");

_songProgressPanelGO = _coreGameHUDController.GetField<GameObject, CoreGameHUDController>("_songProgressPanelGO");
_energyPanelGO = _coreGameHUDController.GetField<GameObject, CoreGameHUDController>("_energyPanelGO");
}
}

internal void Start()
{
if (Plugin.Config.SingleplayerHUD && _coreGameHUDController != null)
{
Plugin.Log?.Debug("Setting up multiplayer HUD");

_coreGameHUDController.transform.position = new Vector3(0f, 0f, 10f);
_coreGameHUDController.transform.eulerAngles = new Vector3(270f, 0f, 0f);

_energyPanelGO.transform.localPosition = new Vector3(0f, 4f, 0f);
_energyPanelGO.transform.localEulerAngles = new Vector3(90f, 0f, 0f);

if (!_coreGameHUDController.transform.Find("LeftPanel"))
{
Transform comboPanel = _coreGameHUDController.transform.Find("ComboPanel");
Transform scoreCanvas = _coreGameHUDController.transform.Find("ScoreCanvas");
Transform multiplierCanvas = _coreGameHUDController.transform.Find("MultiplierCanvas");

GameObject leftPanel = new GameObject();
GameObject rightPanel = new GameObject();
leftPanel.name = "LeftPanel";
rightPanel.name = "RightPanel";
leftPanel.transform.parent = _coreGameHUDController.transform;
rightPanel.transform.parent = _coreGameHUDController.transform;
leftPanel.transform.localPosition = new Vector3(-2.5f, 0f, 1f);
rightPanel.transform.localPosition = new Vector3(2.5f, 0f, 1f);

_songProgressPanelGO.transform.SetParent(rightPanel.transform, true);
_songProgressPanelGO.transform.localPosition = new Vector3(0f, -1.1f, 0f);
_songProgressPanelGO.transform.SetParent(_coreGameHUDController.transform, true);

multiplierCanvas.transform.SetParent(rightPanel.transform, true);
multiplierCanvas.transform.localPosition = new Vector3(0f, 0f, 0f);
multiplierCanvas.transform.SetParent(_coreGameHUDController.transform, true);

comboPanel.transform.SetParent(leftPanel.transform, true);
comboPanel.transform.localPosition = new Vector3(0f, 0f, 0f);
comboPanel.transform.SetParent(_coreGameHUDController.transform, true);

scoreCanvas.transform.SetParent(leftPanel.transform, true);
scoreCanvas.transform.localPosition = new Vector3(0f, -1.1f, 0f);
scoreCanvas.transform.SetParent(_coreGameHUDController.transform, true);

foreach (CurvedTextMeshPro panel in scoreCanvas.GetComponentsInChildren<CurvedTextMeshPro>())
{
panel.enabled = true;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using IPA.Utilities;
using MultiplayerExtensions.Sessions;
using MultiplayerExtensions.Extensions;
using UnityEngine;

namespace MultiplayerExtensions.Environments
Expand All @@ -11,7 +11,7 @@ class MultiplayerGameplayLighting : MonoBehaviour
protected IScoreSyncStateManager _scoreProvider = null!;
protected MultiplayerLeadPlayerProvider _leadPlayerProvider = null!;
protected MultiplayerGameplayAnimator _gameplayAnimator = null!;
protected ExtendedPlayerManager _extendedPlayerManager = null!;
protected ExtendedSessionManager _sessionManager = null!;

protected LightsAnimator[] _allLights = null!;
protected LightsAnimator[] _gameplayLights = null!;
Expand All @@ -26,14 +26,14 @@ class MultiplayerGameplayLighting : MonoBehaviour

protected MultiplayerSyncState<StandardScoreSyncState, StandardScoreSyncState.Score, int> _syncState = null!;

internal void Construct(IConnectedPlayer connectedPlayer, MultiplayerController multiplayerController, IScoreSyncStateManager scoreProvider, MultiplayerLeadPlayerProvider leadPlayerProvider, MultiplayerGameplayAnimator gameplayAnimator, ExtendedPlayerManager extendedPlayerManager)
internal void Construct(IConnectedPlayer connectedPlayer, MultiplayerController multiplayerController, IScoreSyncStateManager scoreProvider, MultiplayerLeadPlayerProvider leadPlayerProvider, MultiplayerGameplayAnimator gameplayAnimator, ExtendedSessionManager sessionManager)
{
_connectedPlayer = connectedPlayer;
_multiplayerController = multiplayerController;
_scoreProvider = scoreProvider;
_leadPlayerProvider = leadPlayerProvider;
_gameplayAnimator = gameplayAnimator;
_extendedPlayerManager = extendedPlayerManager;
_sessionManager = sessionManager;

_allLights = gameplayAnimator.GetField<LightsAnimator[], MultiplayerGameplayAnimator>("_allLightsAnimators");
_gameplayLights = gameplayAnimator.GetField<LightsAnimator[], MultiplayerGameplayAnimator>("_gameplayLightsAnimators");
Expand Down
Loading

0 comments on commit e70690a

Please sign in to comment.