Skip to content

Commit 14a499c

Browse files
committed
wip(1.35): initial refactor and cleanup
1 parent 9239705 commit 14a499c

24 files changed

Lines changed: 629 additions & 584 deletions

MultiplayerCore.sln.DotSettings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=beatmap/@EntryIndexedValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Beatmaps/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

MultiplayerCore/Beatmaps/Abstractions/DifficultyColors.cs

Lines changed: 0 additions & 112 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using MultiplayerCore.Beatmaps.Serializable;
5+
using UnityEngine;
6+
using static SongCore.Data.ExtraSongData;
7+
8+
namespace MultiplayerCore.Beatmaps.Abstractions
9+
{
10+
/// <summary>
11+
/// Base class for Beatmap data that can be used in multiplayer.
12+
/// </summary>
13+
public abstract class MpBeatmap
14+
{
15+
/// <summary>
16+
/// The hash of the level. Should be the same on all clients.
17+
/// </summary>
18+
public abstract string LevelHash { get; protected set; }
19+
/// <summary>
20+
/// The local ID of the level. Can vary between clients.
21+
/// </summary>
22+
public string LevelID => $"custom_level_{LevelHash}";
23+
public abstract string SongName { get; }
24+
public abstract string SongSubName { get; }
25+
public abstract string SongAuthorName { get; }
26+
public abstract string LevelAuthorName { get; }
27+
public virtual float BeatsPerMinute { get; protected set; }
28+
public virtual float SongDuration { get; protected set; }
29+
public virtual Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> Requirements { get; protected set; } = new();
30+
public virtual Dictionary<string, Dictionary<BeatmapDifficulty, DifficultyColors>> DifficultyColors { get; protected set; } = new();
31+
public virtual Contributor[]? Contributors { get; protected set; } = null!;
32+
33+
public virtual Task<Sprite> TryGetCoverSpriteAsync(CancellationToken cancellationToken)
34+
=> Task.FromResult<Sprite>(null!);
35+
}
36+
}

MultiplayerCore/Beatmaps/Abstractions/MpBeatmapLevel.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

MultiplayerCore/Beatmaps/BeatSaverBeatmapLevel.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
using BeatSaverSharp.Models;
2-
using MultiplayerCore.Beatmaps.Abstractions;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.Linq;
64
using System.Threading;
75
using System.Threading.Tasks;
6+
using BeatSaverSharp.Models;
7+
using MultiplayerCore.Beatmaps.Abstractions;
88
using UnityEngine;
99
using static BeatSaverSharp.Models.BeatmapDifficulty;
1010
using static SongCore.Data.ExtraSongData;
1111

1212
namespace MultiplayerCore.Beatmaps
1313
{
1414
/// <summary>
15-
/// An <see cref="IPreviewBeatmapLevel"/> created from data from BeatSaver.
15+
/// Beatmap level data that was loaded remotely from the BeatSaver API.
1616
/// </summary>
17-
public class BeatSaverBeatmapLevel : MpBeatmapLevel
17+
public class BeatSaverBeatmapLevel : MpBeatmap
1818
{
19-
public override string levelHash { get; protected set; }
19+
public override string LevelHash { get; protected set; }
2020

21-
public override string songName => _beatmap.Metadata.SongName;
22-
public override string songSubName => _beatmap.Metadata.SongSubName;
23-
public override string songAuthorName => _beatmap.Metadata.SongAuthorName;
24-
public override string levelAuthorName => _beatmap.Metadata.LevelAuthorName;
25-
public override float beatsPerMinute => _beatmap.Metadata.BPM;
26-
public override float songDuration => _beatmap.Metadata.Duration;
21+
public override string SongName => _beatmap.Metadata.SongName;
22+
public override string SongSubName => _beatmap.Metadata.SongSubName;
23+
public override string SongAuthorName => _beatmap.Metadata.SongAuthorName;
24+
public override string LevelAuthorName => _beatmap.Metadata.LevelAuthorName;
25+
public override float BeatsPerMinute => _beatmap.Metadata.BPM;
26+
public override float SongDuration => _beatmap.Metadata.Duration;
2727

28-
public override Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> requirements
28+
public override Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> Requirements
2929
{
3030
get
3131
{
@@ -58,7 +58,7 @@ public override Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> requ
5858
}
5959
}
6060

61-
public override Contributor[] contributors => new Contributor[] { new Contributor
61+
public override Contributor[] Contributors => new Contributor[] { new Contributor
6262
{
6363
_role = "Uploader",
6464
_name = _beatmap.Uploader.Name,
@@ -69,11 +69,11 @@ public override Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> requ
6969

7070
public BeatSaverBeatmapLevel(string hash, Beatmap beatmap)
7171
{
72-
levelHash = hash;
72+
LevelHash = hash;
7373
_beatmap = beatmap;
7474
}
7575

76-
public override async Task<Sprite> GetCoverImageAsync(CancellationToken cancellationToken)
76+
public override async Task<Sprite> TryGetCoverSpriteAsync(CancellationToken cancellationToken)
7777
{
7878
byte[]? coverBytes = await _beatmap.LatestVersion.DownloadCoverImage(cancellationToken);
7979
if (coverBytes == null || coverBytes.Length == 0)
Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
1-
using MultiplayerCore.Beatmaps.Abstractions;
2-
using SongCore.Data;
3-
using System.Collections.Generic;
4-
using System.Linq;
1+
using System.Collections.Generic;
52
using System.Threading;
63
using System.Threading.Tasks;
4+
using MultiplayerCore.Beatmaps.Abstractions;
5+
using MultiplayerCore.Beatmaps.Serializable;
76
using UnityEngine;
87
using static SongCore.Data.ExtraSongData;
98

109
namespace MultiplayerCore.Beatmaps
1110
{
1211
/// <summary>
13-
/// An <see cref="IPreviewBeatmapLevel"/> created from a local preview.
12+
/// Beatmap level data that was loaded locally by SongCore.
1413
/// </summary>
15-
public class LocalBeatmapLevel : MpBeatmapLevel
14+
public class LocalBeatmapLevel : MpBeatmap
1615
{
17-
public override string levelHash { get; protected set; }
16+
public override string LevelHash { get; protected set; }
1817

19-
public override string songName => _preview.songName;
20-
public override string songSubName => _preview.songSubName;
21-
public override string songAuthorName => _preview.songAuthorName;
22-
public override string levelAuthorName => _preview.levelAuthorName;
18+
public override string SongName => _localBeatmapLevel.songName;
19+
public override string SongSubName => _localBeatmapLevel.songSubName;
20+
public override string SongAuthorName => _localBeatmapLevel.songAuthorName;
21+
public override string LevelAuthorName => string.Join(", ", _localBeatmapLevel.allMappers);
2322

24-
public override float beatsPerMinute => _preview.beatsPerMinute;
25-
public override float songDuration => _preview.songDuration;
26-
public override float previewStartTime => _preview.previewStartTime;
27-
public override float previewDuration => _preview.previewDuration;
28-
public override EnvironmentInfoSO[] environmentInfos => _preview.environmentInfos;
29-
public override IReadOnlyList<PreviewDifficultyBeatmapSet>? previewDifficultyBeatmapSets => _preview.previewDifficultyBeatmapSets;
30-
31-
public override Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> requirements
23+
public override float BeatsPerMinute => _localBeatmapLevel.beatsPerMinute;
24+
public override float SongDuration => _localBeatmapLevel.songDuration;
25+
26+
public override Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> Requirements
3227
{
3328
get
3429
{
3530
Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> reqs = new();
36-
var difficulties = SongCore.Collections.RetrieveExtraSongData(levelHash)?._difficulties;
31+
var difficulties = SongCore.Collections.RetrieveExtraSongData(LevelHash)?._difficulties;
3732
if (difficulties == null)
3833
return new();
3934
foreach (var difficulty in difficulties)
@@ -46,12 +41,12 @@ public override Dictionary<string, Dictionary<BeatmapDifficulty, string[]>> requ
4641
}
4742
}
4843

49-
public override Dictionary<string, Dictionary<BeatmapDifficulty, DifficultyColors>> difficultyColors
44+
public override Dictionary<string, Dictionary<BeatmapDifficulty, DifficultyColors>> DifficultyColors
5045
{
5146
get
5247
{
5348
Dictionary<string, Dictionary<BeatmapDifficulty, DifficultyColors>> colors = new();
54-
var difficulties = SongCore.Collections.RetrieveExtraSongData(levelHash)?._difficulties;
49+
var difficulties = SongCore.Collections.RetrieveExtraSongData(LevelHash)?._difficulties;
5550
if (difficulties == null)
5651
return new();
5752
foreach (var difficulty in difficulties)
@@ -65,17 +60,17 @@ public override Dictionary<string, Dictionary<BeatmapDifficulty, DifficultyColor
6560
}
6661
}
6762

68-
public override Contributor[] contributors => SongCore.Collections.RetrieveExtraSongData(levelHash)?.contributors ?? new Contributor[0];
63+
public override Contributor[] Contributors => SongCore.Collections.RetrieveExtraSongData(LevelHash)?.contributors ?? new Contributor[0];
6964

70-
private readonly IPreviewBeatmapLevel _preview;
65+
private readonly BeatmapLevel _localBeatmapLevel;
7166

72-
public LocalBeatmapLevel(string hash, IPreviewBeatmapLevel preview)
67+
public LocalBeatmapLevel(string hash, BeatmapLevel localBeatmapLevel)
7368
{
74-
levelHash = hash;
75-
_preview = preview;
69+
LevelHash = hash;
70+
_localBeatmapLevel = localBeatmapLevel;
7671
}
7772

78-
public override Task<Sprite> GetCoverImageAsync(CancellationToken cancellationToken)
79-
=> _preview.GetCoverImageAsync(cancellationToken);
73+
public override Task<Sprite> TryGetCoverSpriteAsync(CancellationToken cancellationToken)
74+
=> _localBeatmapLevel.previewMediaData.GetCoverSpriteAsync(cancellationToken);
8075
}
8176
}

0 commit comments

Comments
 (0)