mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 05:03:02 +08:00
Merge remote-tracking branch 'ppy/master' into aim-refactor-base
This commit is contained in:
commit
cec063206e
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@ -1 +1,2 @@
|
||||
github: ppy
|
||||
custom: https://osu.ppy.sh/home/support
|
||||
|
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@ -79,9 +79,14 @@ jobs:
|
||||
run: |
|
||||
# TODO: Add ignore filters and GitHub Workflow Command Reporting in CFS. That way we don't have to do this workaround.
|
||||
# FIXME: Suppress warnings from templates project
|
||||
dotnet codefilesanity | while read -r line; do
|
||||
echo "::warning::$line"
|
||||
done
|
||||
exit_code=0
|
||||
while read -r line; do
|
||||
if [[ ! -z "$line" ]]; then
|
||||
echo "::error::$line"
|
||||
exit_code=1
|
||||
fi
|
||||
done <<< $(dotnet codefilesanity)
|
||||
exit $exit_code
|
||||
|
||||
# Temporarily disabled due to test failures, but it won't work anyway until the tool is upgraded.
|
||||
# - name: .NET Format (Dry Run)
|
||||
|
@ -52,7 +52,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1004.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.1004.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.1013.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Transitive Dependencies">
|
||||
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->
|
||||
|
@ -45,8 +45,8 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
|
||||
{
|
||||
new Spinner
|
||||
{
|
||||
Duration = 2000,
|
||||
Position = OsuPlayfield.BASE_SIZE / 2
|
||||
Duration = 6000,
|
||||
Position = OsuPlayfield.BASE_SIZE / 2,
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -30,6 +30,9 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
public class TestSceneSpinnerRotation : TestSceneOsuPlayer
|
||||
{
|
||||
private const double spinner_start_time = 100;
|
||||
private const double spinner_duration = 6000;
|
||||
|
||||
[Resolved]
|
||||
private AudioManager audioManager { get; set; }
|
||||
|
||||
@ -77,7 +80,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
double finalTrackerRotation = 0, trackerRotationTolerance = 0;
|
||||
double finalSpinnerSymbolRotation = 0, spinnerSymbolRotationTolerance = 0;
|
||||
|
||||
addSeekStep(5000);
|
||||
addSeekStep(spinner_start_time + 5000);
|
||||
AddStep("retrieve disc rotation", () =>
|
||||
{
|
||||
finalTrackerRotation = drawableSpinner.RotationTracker.Rotation;
|
||||
@ -90,7 +93,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
});
|
||||
AddStep("retrieve cumulative disc rotation", () => finalCumulativeTrackerRotation = drawableSpinner.Result.RateAdjustedRotation);
|
||||
|
||||
addSeekStep(2500);
|
||||
addSeekStep(spinner_start_time + 2500);
|
||||
AddAssert("disc rotation rewound",
|
||||
// we want to make sure that the rotation at time 2500 is in the same direction as at time 5000, but about half-way in.
|
||||
// due to the exponential damping applied we're allowing a larger margin of error of about 10%
|
||||
@ -102,7 +105,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
// cumulative rotation is not damped, so we're treating it as the "ground truth" and allowing a comparatively smaller margin of error.
|
||||
() => Precision.AlmostEquals(drawableSpinner.Result.RateAdjustedRotation, finalCumulativeTrackerRotation / 2, 100));
|
||||
|
||||
addSeekStep(5000);
|
||||
addSeekStep(spinner_start_time + 5000);
|
||||
AddAssert("is disc rotation almost same",
|
||||
() => Precision.AlmostEquals(drawableSpinner.RotationTracker.Rotation, finalTrackerRotation, trackerRotationTolerance));
|
||||
AddAssert("is symbol rotation almost same",
|
||||
@ -140,7 +143,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
[Test]
|
||||
public void TestSpinnerNormalBonusRewinding()
|
||||
{
|
||||
addSeekStep(1000);
|
||||
addSeekStep(spinner_start_time + 1000);
|
||||
|
||||
AddAssert("player score matching expected bonus score", () =>
|
||||
{
|
||||
@ -201,24 +204,9 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
AddAssert("spm almost same", () => Precision.AlmostEquals(expectedSpm, drawableSpinner.SpinsPerMinute.Value, 2.0));
|
||||
}
|
||||
|
||||
private Replay applyRateAdjustment(Replay scoreReplay, double rate) => new Replay
|
||||
{
|
||||
Frames = scoreReplay
|
||||
.Frames
|
||||
.Cast<OsuReplayFrame>()
|
||||
.Select(replayFrame =>
|
||||
{
|
||||
var adjustedTime = replayFrame.Time * rate;
|
||||
return new OsuReplayFrame(adjustedTime, replayFrame.Position, replayFrame.Actions.ToArray());
|
||||
})
|
||||
.Cast<ReplayFrame>()
|
||||
.ToList()
|
||||
};
|
||||
|
||||
private void addSeekStep(double time)
|
||||
{
|
||||
AddStep($"seek to {time}", () => Player.GameplayClockContainer.Seek(time));
|
||||
|
||||
AddUntilStep("wait for seek to finish", () => Precision.AlmostEquals(time, Player.DrawableRuleset.FrameStableClock.CurrentTime, 100));
|
||||
}
|
||||
|
||||
@ -241,7 +229,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
new Spinner
|
||||
{
|
||||
Position = new Vector2(256, 192),
|
||||
EndTime = 6000,
|
||||
StartTime = spinner_start_time,
|
||||
Duration = spinner_duration
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@ -509,5 +509,17 @@ namespace osu.Game.Tests.Chat
|
||||
Assert.AreEqual(LinkAction.External, result.Action);
|
||||
Assert.AreEqual("/relative", result.Argument);
|
||||
}
|
||||
|
||||
[TestCase("https://dev.ppy.sh/home/changelog", "")]
|
||||
[TestCase("https://dev.ppy.sh/home/changelog/lazer/2021.1012", "lazer/2021.1012")]
|
||||
public void TestChangelogLinks(string link, string expectedArg)
|
||||
{
|
||||
MessageFormatter.WebsiteRootUrl = "dev.ppy.sh";
|
||||
|
||||
LinkDetails result = MessageFormatter.GetLinkDetails(link);
|
||||
|
||||
Assert.AreEqual(LinkAction.OpenChangelog, result.Action);
|
||||
Assert.AreEqual(expectedArg, result.Argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
114
osu.Game.Tests/Database/FileStoreTests.cs
Normal file
114
osu.Game.Tests/Database/FileStoreTests.cs
Normal file
@ -0,0 +1,114 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Models;
|
||||
using osu.Game.Stores;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Tests.Database
|
||||
{
|
||||
public class FileStoreTests : RealmTest
|
||||
{
|
||||
[Test]
|
||||
public void TestImportFile()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
var files = new RealmFileStore(realmFactory, storage);
|
||||
|
||||
var testData = new MemoryStream(new byte[] { 0, 1, 2, 3 });
|
||||
|
||||
realm.Write(() => files.Add(testData, realm));
|
||||
|
||||
Assert.True(files.Storage.Exists("0/05/054edec1d0211f624fed0cbca9d4f9400b0e491c43742af2c5b0abebf0c990d8"));
|
||||
Assert.True(files.Storage.Exists(realm.All<RealmFile>().First().StoragePath));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestImportSameFileTwice()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
var files = new RealmFileStore(realmFactory, storage);
|
||||
|
||||
var testData = new MemoryStream(new byte[] { 0, 1, 2, 3 });
|
||||
|
||||
realm.Write(() => files.Add(testData, realm));
|
||||
realm.Write(() => files.Add(testData, realm));
|
||||
|
||||
Assert.AreEqual(1, realm.All<RealmFile>().Count());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDontPurgeReferenced()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
var files = new RealmFileStore(realmFactory, storage);
|
||||
|
||||
var file = realm.Write(() => files.Add(new MemoryStream(new byte[] { 0, 1, 2, 3 }), realm));
|
||||
|
||||
var timer = new Stopwatch();
|
||||
timer.Start();
|
||||
|
||||
realm.Write(() =>
|
||||
{
|
||||
// attach the file to an arbitrary beatmap
|
||||
var beatmapSet = CreateBeatmapSet(CreateRuleset());
|
||||
|
||||
beatmapSet.Files.Add(new RealmNamedFileUsage(file, "arbitrary.resource"));
|
||||
|
||||
realm.Add(beatmapSet);
|
||||
});
|
||||
|
||||
Logger.Log($"Import complete at {timer.ElapsedMilliseconds}");
|
||||
|
||||
string path = file.StoragePath;
|
||||
|
||||
Assert.True(realm.All<RealmFile>().Any());
|
||||
Assert.True(files.Storage.Exists(path));
|
||||
|
||||
files.Cleanup();
|
||||
Logger.Log($"Cleanup complete at {timer.ElapsedMilliseconds}");
|
||||
|
||||
Assert.True(realm.All<RealmFile>().Any());
|
||||
Assert.True(file.IsValid);
|
||||
Assert.True(files.Storage.Exists(path));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPurgeUnreferenced()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
var files = new RealmFileStore(realmFactory, storage);
|
||||
|
||||
var file = realm.Write(() => files.Add(new MemoryStream(new byte[] { 0, 1, 2, 3 }), realm));
|
||||
|
||||
string path = file.StoragePath;
|
||||
|
||||
Assert.True(realm.All<RealmFile>().Any());
|
||||
Assert.True(files.Storage.Exists(path));
|
||||
|
||||
files.Cleanup();
|
||||
|
||||
Assert.False(realm.All<RealmFile>().Any());
|
||||
Assert.False(file.IsValid);
|
||||
Assert.False(files.Storage.Exists(path));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
213
osu.Game.Tests/Database/RealmLiveTests.cs
Normal file
213
osu.Game.Tests/Database/RealmLiveTests.cs
Normal file
@ -0,0 +1,213 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Models;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Tests.Database
|
||||
{
|
||||
public class RealmLiveTests : RealmTest
|
||||
{
|
||||
[Test]
|
||||
public void TestLiveCastability()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
{
|
||||
RealmLive<RealmBeatmap> beatmap = realmFactory.CreateContext().Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))).ToLive();
|
||||
|
||||
ILive<IBeatmapInfo> iBeatmap = beatmap;
|
||||
|
||||
Assert.AreEqual(0, iBeatmap.Value.Length);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestValueAccessWithOpenContext()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
{
|
||||
RealmLive<RealmBeatmap>? liveBeatmap = null;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
using (var threadContext = realmFactory.CreateContext())
|
||||
{
|
||||
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive();
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
|
||||
Debug.Assert(liveBeatmap != null);
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
using (realmFactory.CreateContext())
|
||||
{
|
||||
var resolved = liveBeatmap.Value;
|
||||
|
||||
Assert.IsTrue(resolved.Realm.IsClosed);
|
||||
Assert.IsTrue(resolved.IsValid);
|
||||
|
||||
// can access properties without a crash.
|
||||
Assert.IsFalse(resolved.Hidden);
|
||||
}
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScopedReadWithoutContext()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
{
|
||||
RealmLive<RealmBeatmap>? liveBeatmap = null;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
using (var threadContext = realmFactory.CreateContext())
|
||||
{
|
||||
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive();
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
|
||||
Debug.Assert(liveBeatmap != null);
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
liveBeatmap.PerformRead(beatmap =>
|
||||
{
|
||||
Assert.IsTrue(beatmap.IsValid);
|
||||
Assert.IsFalse(beatmap.Hidden);
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScopedWriteWithoutContext()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
{
|
||||
RealmLive<RealmBeatmap>? liveBeatmap = null;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
using (var threadContext = realmFactory.CreateContext())
|
||||
{
|
||||
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive();
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
|
||||
Debug.Assert(liveBeatmap != null);
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
liveBeatmap.PerformWrite(beatmap => { beatmap.Hidden = true; });
|
||||
liveBeatmap.PerformRead(beatmap => { Assert.IsTrue(beatmap.Hidden); });
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestValueAccessWithoutOpenContextFails()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
{
|
||||
RealmLive<RealmBeatmap>? liveBeatmap = null;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
using (var threadContext = realmFactory.CreateContext())
|
||||
{
|
||||
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive();
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
|
||||
Debug.Assert(liveBeatmap != null);
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
var unused = liveBeatmap.Value;
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLiveAssumptions()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
{
|
||||
int changesTriggered = 0;
|
||||
|
||||
using (var updateThreadContext = realmFactory.CreateContext())
|
||||
{
|
||||
updateThreadContext.All<RealmBeatmap>().SubscribeForNotifications(gotChange);
|
||||
RealmLive<RealmBeatmap>? liveBeatmap = null;
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
using (var threadContext = realmFactory.CreateContext())
|
||||
{
|
||||
var ruleset = CreateRuleset();
|
||||
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
||||
|
||||
// add a second beatmap to ensure that a full refresh occurs below.
|
||||
// not just a refresh from the resolved Live.
|
||||
threadContext.Write(r => r.Add(new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive();
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||
|
||||
Debug.Assert(liveBeatmap != null);
|
||||
|
||||
// not yet seen by main context
|
||||
Assert.AreEqual(0, updateThreadContext.All<RealmBeatmap>().Count());
|
||||
Assert.AreEqual(0, changesTriggered);
|
||||
|
||||
var resolved = liveBeatmap.Value;
|
||||
|
||||
// retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point.
|
||||
Assert.AreEqual(2, updateThreadContext.All<RealmBeatmap>().Count());
|
||||
Assert.AreEqual(1, changesTriggered);
|
||||
|
||||
// even though the realm that this instance was resolved for was closed, it's still valid.
|
||||
Assert.IsTrue(resolved.Realm.IsClosed);
|
||||
Assert.IsTrue(resolved.IsValid);
|
||||
|
||||
// can access properties without a crash.
|
||||
Assert.IsFalse(resolved.Hidden);
|
||||
|
||||
updateThreadContext.Write(r =>
|
||||
{
|
||||
// can use with the main context.
|
||||
r.Remove(resolved);
|
||||
});
|
||||
}
|
||||
|
||||
void gotChange(IRealmCollection<RealmBeatmap> sender, ChangeSet changes, Exception error)
|
||||
{
|
||||
changesTriggered++;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -4,12 +4,13 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Nito.AsyncEx;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Models;
|
||||
|
||||
#nullable enable
|
||||
|
||||
@ -28,42 +29,109 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
protected void RunTestWithRealm(Action<RealmContextFactory, Storage> testAction, [CallerMemberName] string caller = "")
|
||||
{
|
||||
AsyncContext.Run(() =>
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(caller))
|
||||
{
|
||||
var testStorage = storage.GetStorageForDirectory(caller);
|
||||
|
||||
using (var realmFactory = new RealmContextFactory(testStorage, caller))
|
||||
host.Run(new RealmTestGame(() =>
|
||||
{
|
||||
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
|
||||
testAction(realmFactory, testStorage);
|
||||
var testStorage = storage.GetStorageForDirectory(caller);
|
||||
|
||||
realmFactory.Dispose();
|
||||
using (var realmFactory = new RealmContextFactory(testStorage, caller))
|
||||
{
|
||||
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
|
||||
testAction(realmFactory, testStorage);
|
||||
|
||||
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
|
||||
realmFactory.Compact();
|
||||
Logger.Log($"Final database size after compact: {getFileSize(testStorage, realmFactory)}");
|
||||
}
|
||||
});
|
||||
realmFactory.Dispose();
|
||||
|
||||
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
|
||||
realmFactory.Compact();
|
||||
Logger.Log($"Final database size after compact: {getFileSize(testStorage, realmFactory)}");
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
protected void RunTestWithRealmAsync(Func<RealmContextFactory, Storage, Task> testAction, [CallerMemberName] string caller = "")
|
||||
{
|
||||
AsyncContext.Run(async () =>
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(caller))
|
||||
{
|
||||
var testStorage = storage.GetStorageForDirectory(caller);
|
||||
|
||||
using (var realmFactory = new RealmContextFactory(testStorage, caller))
|
||||
host.Run(new RealmTestGame(async () =>
|
||||
{
|
||||
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
|
||||
await testAction(realmFactory, testStorage);
|
||||
var testStorage = storage.GetStorageForDirectory(caller);
|
||||
|
||||
realmFactory.Dispose();
|
||||
using (var realmFactory = new RealmContextFactory(testStorage, caller))
|
||||
{
|
||||
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
|
||||
await testAction(realmFactory, testStorage);
|
||||
|
||||
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
|
||||
realmFactory.Compact();
|
||||
Logger.Log($"Final database size after compact: {getFileSize(testStorage, realmFactory)}");
|
||||
realmFactory.Dispose();
|
||||
|
||||
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
|
||||
realmFactory.Compact();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
protected static RealmBeatmapSet CreateBeatmapSet(RealmRuleset ruleset)
|
||||
{
|
||||
RealmFile createRealmFile() => new RealmFile { Hash = Guid.NewGuid().ToString().ComputeSHA2Hash() };
|
||||
|
||||
var metadata = new RealmBeatmapMetadata
|
||||
{
|
||||
Title = "My Love",
|
||||
Artist = "Kuba Oms"
|
||||
};
|
||||
|
||||
var beatmapSet = new RealmBeatmapSet
|
||||
{
|
||||
Beatmaps =
|
||||
{
|
||||
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Easy", },
|
||||
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Normal", },
|
||||
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Hard", },
|
||||
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) { DifficultyName = "Insane", }
|
||||
},
|
||||
Files =
|
||||
{
|
||||
new RealmNamedFileUsage(createRealmFile(), "test [easy].osu"),
|
||||
new RealmNamedFileUsage(createRealmFile(), "test [normal].osu"),
|
||||
new RealmNamedFileUsage(createRealmFile(), "test [hard].osu"),
|
||||
new RealmNamedFileUsage(createRealmFile(), "test [insane].osu"),
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
beatmapSet.Files.Add(new RealmNamedFileUsage(createRealmFile(), $"hitsound{i}.mp3"));
|
||||
|
||||
foreach (var b in beatmapSet.Beatmaps)
|
||||
b.BeatmapSet = beatmapSet;
|
||||
|
||||
return beatmapSet;
|
||||
}
|
||||
|
||||
protected static RealmRuleset CreateRuleset() =>
|
||||
new RealmRuleset(0, "osu!", "osu", true);
|
||||
|
||||
private class RealmTestGame : Framework.Game
|
||||
{
|
||||
public RealmTestGame(Func<Task> work)
|
||||
{
|
||||
// ReSharper disable once AsyncVoidLambda
|
||||
Scheduler.Add(async () =>
|
||||
{
|
||||
await work().ConfigureAwait(true);
|
||||
Exit();
|
||||
});
|
||||
}
|
||||
|
||||
public RealmTestGame(Action work)
|
||||
{
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
work();
|
||||
Exit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static long getFileSize(Storage testStorage, RealmContextFactory realmFactory)
|
||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Tests
|
||||
protected virtual TestOsuGameBase LoadOsuIntoHost(GameHost host, bool withBeatmap = false)
|
||||
{
|
||||
var osu = new TestOsuGameBase(withBeatmap);
|
||||
Task.Run(() => host.Run(osu))
|
||||
Task.Factory.StartNew(() => host.Run(osu), TaskCreationOptions.LongRunning)
|
||||
.ContinueWith(t => Assert.Fail($"Host threw exception {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
|
||||
|
||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||
|
@ -168,14 +168,14 @@ namespace osu.Game.Tests.Online
|
||||
return new TestBeatmapModelManager(this, storage, contextFactory, rulesets, api, host);
|
||||
}
|
||||
|
||||
protected override BeatmapModelDownloader CreateBeatmapModelDownloader(BeatmapModelManager modelManager, IAPIProvider api, GameHost host)
|
||||
protected override BeatmapModelDownloader CreateBeatmapModelDownloader(IBeatmapModelManager manager, IAPIProvider api, GameHost host)
|
||||
{
|
||||
return new TestBeatmapModelDownloader(modelManager, api, host);
|
||||
return new TestBeatmapModelDownloader(manager, api, host);
|
||||
}
|
||||
|
||||
internal class TestBeatmapModelDownloader : BeatmapModelDownloader
|
||||
{
|
||||
public TestBeatmapModelDownloader(BeatmapModelManager modelManager, IAPIProvider apiProvider, GameHost gameHost)
|
||||
public TestBeatmapModelDownloader(IBeatmapModelManager modelManager, IAPIProvider apiProvider, GameHost gameHost)
|
||||
: base(modelManager, apiProvider, gameHost)
|
||||
{
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.OpenGL.Textures;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
@ -65,10 +64,9 @@ namespace osu.Game.Tests.Skins
|
||||
|
||||
public new void TriggerSourceChanged() => base.TriggerSourceChanged();
|
||||
|
||||
protected override void OnSourceChanged()
|
||||
protected override void RefreshSources()
|
||||
{
|
||||
ResetSources();
|
||||
sources.ForEach(AddSource);
|
||||
SetSources(sources);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
@ -18,16 +19,19 @@ namespace osu.Game.Tests.Visual.Audio
|
||||
{
|
||||
public class TestSceneAudioFilter : OsuTestScene
|
||||
{
|
||||
private OsuSpriteText lowpassText;
|
||||
private AudioFilter lowpassFilter;
|
||||
private OsuSpriteText lowPassText;
|
||||
private AudioFilter lowPassFilter;
|
||||
|
||||
private OsuSpriteText highpassText;
|
||||
private AudioFilter highpassFilter;
|
||||
private OsuSpriteText highPassText;
|
||||
private AudioFilter highPassFilter;
|
||||
|
||||
private Track track;
|
||||
|
||||
private WaveformTestBeatmap beatmap;
|
||||
|
||||
private OsuSliderBar<int> lowPassSlider;
|
||||
private OsuSliderBar<int> highPassSlider;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
@ -38,53 +42,89 @@ namespace osu.Game.Tests.Visual.Audio
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
lowpassFilter = new AudioFilter(audio.TrackMixer),
|
||||
highpassFilter = new AudioFilter(audio.TrackMixer, BQFType.HighPass),
|
||||
lowpassText = new OsuSpriteText
|
||||
lowPassFilter = new AudioFilter(audio.TrackMixer),
|
||||
highPassFilter = new AudioFilter(audio.TrackMixer, BQFType.HighPass),
|
||||
lowPassText = new OsuSpriteText
|
||||
{
|
||||
Padding = new MarginPadding(20),
|
||||
Text = $"Low Pass: {lowpassFilter.Cutoff.Value}hz",
|
||||
Text = $"Low Pass: {lowPassFilter.Cutoff}hz",
|
||||
Font = new FontUsage(size: 40)
|
||||
},
|
||||
new OsuSliderBar<int>
|
||||
lowPassSlider = new OsuSliderBar<int>
|
||||
{
|
||||
Width = 500,
|
||||
Height = 50,
|
||||
Padding = new MarginPadding(20),
|
||||
Current = { BindTarget = lowpassFilter.Cutoff }
|
||||
Current = new BindableInt
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = AudioFilter.MAX_LOWPASS_CUTOFF,
|
||||
}
|
||||
},
|
||||
highpassText = new OsuSpriteText
|
||||
highPassText = new OsuSpriteText
|
||||
{
|
||||
Padding = new MarginPadding(20),
|
||||
Text = $"High Pass: {highpassFilter.Cutoff.Value}hz",
|
||||
Text = $"High Pass: {highPassFilter.Cutoff}hz",
|
||||
Font = new FontUsage(size: 40)
|
||||
},
|
||||
new OsuSliderBar<int>
|
||||
highPassSlider = new OsuSliderBar<int>
|
||||
{
|
||||
Width = 500,
|
||||
Height = 50,
|
||||
Padding = new MarginPadding(20),
|
||||
Current = { BindTarget = highpassFilter.Cutoff }
|
||||
Current = new BindableInt
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = AudioFilter.MAX_LOWPASS_CUTOFF,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
lowpassFilter.Cutoff.ValueChanged += e => lowpassText.Text = $"Low Pass: {e.NewValue}hz";
|
||||
highpassFilter.Cutoff.ValueChanged += e => highpassText.Text = $"High Pass: {e.NewValue}hz";
|
||||
|
||||
lowPassSlider.Current.ValueChanged += e =>
|
||||
{
|
||||
lowPassText.Text = $"Low Pass: {e.NewValue}hz";
|
||||
lowPassFilter.Cutoff = e.NewValue;
|
||||
};
|
||||
|
||||
highPassSlider.Current.ValueChanged += e =>
|
||||
{
|
||||
highPassText.Text = $"High Pass: {e.NewValue}hz";
|
||||
highPassFilter.Cutoff = e.NewValue;
|
||||
};
|
||||
}
|
||||
|
||||
#region Overrides of Drawable
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
highPassSlider.Current.Value = highPassFilter.Cutoff;
|
||||
lowPassSlider.Current.Value = lowPassFilter.Cutoff;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("Play Track", () => track.Start());
|
||||
|
||||
AddStep("Reset filters", () =>
|
||||
{
|
||||
lowPassFilter.Cutoff = AudioFilter.MAX_LOWPASS_CUTOFF;
|
||||
highPassFilter.Cutoff = 0;
|
||||
});
|
||||
|
||||
waitTrackPlay();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLowPass()
|
||||
public void TestLowPassSweep()
|
||||
{
|
||||
AddStep("Filter Sweep", () =>
|
||||
{
|
||||
lowpassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF).Then()
|
||||
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF).Then()
|
||||
.CutoffTo(0, 2000, Easing.OutCubic);
|
||||
});
|
||||
|
||||
@ -92,7 +132,7 @@ namespace osu.Game.Tests.Visual.Audio
|
||||
|
||||
AddStep("Filter Sweep (reverse)", () =>
|
||||
{
|
||||
lowpassFilter.CutoffTo(0).Then()
|
||||
lowPassFilter.CutoffTo(0).Then()
|
||||
.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, 2000, Easing.InCubic);
|
||||
});
|
||||
|
||||
@ -101,11 +141,11 @@ namespace osu.Game.Tests.Visual.Audio
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestHighPass()
|
||||
public void TestHighPassSweep()
|
||||
{
|
||||
AddStep("Filter Sweep", () =>
|
||||
{
|
||||
highpassFilter.CutoffTo(0).Then()
|
||||
highPassFilter.CutoffTo(0).Then()
|
||||
.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, 2000, Easing.InCubic);
|
||||
});
|
||||
|
||||
@ -113,7 +153,7 @@ namespace osu.Game.Tests.Visual.Audio
|
||||
|
||||
AddStep("Filter Sweep (reverse)", () =>
|
||||
{
|
||||
highpassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF).Then()
|
||||
highPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF).Then()
|
||||
.CutoffTo(0, 2000, Easing.OutCubic);
|
||||
});
|
||||
|
||||
|
@ -32,6 +32,8 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
AddUntilStep("wait for editor load", () => editor != null);
|
||||
|
||||
AddStep("Set overall difficulty", () => editorBeatmap.Difficulty.OverallDifficulty = 7);
|
||||
|
||||
AddStep("Add timing point", () => editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint()));
|
||||
|
||||
AddStep("Enter compose mode", () => InputManager.Key(Key.F1));
|
||||
@ -41,11 +43,11 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
AddStep("Move to playfield", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.Centre));
|
||||
AddStep("Place single hitcircle", () => InputManager.Click(MouseButton.Left));
|
||||
|
||||
AddStep("Save and exit", () =>
|
||||
{
|
||||
InputManager.Keys(PlatformAction.Save);
|
||||
InputManager.Key(Key.Escape);
|
||||
});
|
||||
AddAssert("Beatmap contains single hitcircle", () => editorBeatmap.HitObjects.Count == 1);
|
||||
|
||||
AddStep("Save", () => InputManager.Keys(PlatformAction.Save));
|
||||
|
||||
AddStep("Exit", () => InputManager.Key(Key.Escape));
|
||||
|
||||
AddUntilStep("Wait for main menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
|
||||
|
||||
@ -57,6 +59,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
AddUntilStep("Wait for editor load", () => editor != null);
|
||||
AddAssert("Beatmap contains single hitcircle", () => editorBeatmap.HitObjects.Count == 1);
|
||||
AddAssert("Beatmap has correct overall difficulty", () => editorBeatmap.Difficulty.OverallDifficulty == 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,6 +103,30 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
checkFrameCount(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRatePreservedWhenTimeNotProgressing()
|
||||
{
|
||||
AddStep("set manual clock rate", () => manualClock.Rate = 1);
|
||||
seekManualTo(5000);
|
||||
createStabilityContainer();
|
||||
checkRate(1);
|
||||
|
||||
seekManualTo(10000);
|
||||
checkRate(1);
|
||||
|
||||
AddWaitStep("wait some", 3);
|
||||
checkRate(1);
|
||||
|
||||
seekManualTo(5000);
|
||||
checkRate(-1);
|
||||
|
||||
AddWaitStep("wait some", 3);
|
||||
checkRate(-1);
|
||||
|
||||
seekManualTo(10000);
|
||||
checkRate(1);
|
||||
}
|
||||
|
||||
private const int max_frames_catchup = 50;
|
||||
|
||||
private void createStabilityContainer(double gameplayStartTime = double.MinValue) => AddStep("create container", () =>
|
||||
@ -116,6 +140,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
private void checkFrameCount(int frames) =>
|
||||
AddAssert($"elapsed frames is {frames}", () => consumer.ElapsedFrames == frames);
|
||||
|
||||
private void checkRate(double rate) =>
|
||||
AddAssert($"clock rate is {rate}", () => consumer.Clock.Rate == rate);
|
||||
|
||||
public class ClockConsumingChild : CompositeDrawable
|
||||
{
|
||||
private readonly OsuSpriteText text;
|
||||
|
@ -90,8 +90,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
CreateTest(() =>
|
||||
{
|
||||
AddStep("fail on first judgement", () => currentFailConditions = (_, __) => true);
|
||||
AddStep("set storyboard duration to 1.3s", () => currentStoryboardDuration = 1300);
|
||||
|
||||
// Fail occurs at 164ms with the provided beatmap.
|
||||
// Fail animation runs for 2.5s realtime but the gameplay time change is *variable* due to the frequency transform being applied, so we need a bit of lenience.
|
||||
AddStep("set storyboard duration to 0.6s", () => currentStoryboardDuration = 600);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for fail", () => Player.HasFailed);
|
||||
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.GameplayClock.CurrentTime >= currentStoryboardDuration);
|
||||
AddUntilStep("wait for fail overlay", () => Player.FailOverlay.State.Value == Visibility.Visible);
|
||||
|
31
osu.Game.Tests/Visual/Navigation/TestSceneStartupImport.cs
Normal file
31
osu.Game.Tests/Visual/Navigation/TestSceneStartupImport.cs
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
public class TestSceneStartupImport : OsuGameTestScene
|
||||
{
|
||||
private string importFilename;
|
||||
|
||||
protected override TestOsuGame CreateTestGame() => new TestOsuGame(LocalStorage, API, new[] { importFilename });
|
||||
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
AddStep("Prepare import beatmap", () => importFilename = TestResources.GetTestBeatmapForImport());
|
||||
|
||||
base.SetUpSteps();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestImportCreatedNotification()
|
||||
{
|
||||
AddUntilStep("Import notification was presented", () => Game.Notifications.ChildrenOfType<ImportProgressNotification>().Count() == 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -32,12 +32,14 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
private TestResultsScreen resultsScreen;
|
||||
private int currentScoreId;
|
||||
private bool requestComplete;
|
||||
private int totalCount;
|
||||
|
||||
[SetUp]
|
||||
public void Setup() => Schedule(() =>
|
||||
{
|
||||
currentScoreId = 0;
|
||||
requestComplete = false;
|
||||
totalCount = 0;
|
||||
bindHandler();
|
||||
});
|
||||
|
||||
@ -53,7 +55,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
});
|
||||
|
||||
createResults(() => userScore);
|
||||
waitForDisplay();
|
||||
|
||||
AddAssert("user score selected", () => this.ChildrenOfType<ScorePanel>().Single(p => p.Score.OnlineScoreID == userScore.OnlineScoreID).State == PanelState.Expanded);
|
||||
}
|
||||
@ -62,7 +63,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
public void TestShowNullUserScore()
|
||||
{
|
||||
createResults();
|
||||
waitForDisplay();
|
||||
|
||||
AddAssert("top score selected", () => this.ChildrenOfType<ScorePanel>().OrderByDescending(p => p.Score.TotalScore).First().State == PanelState.Expanded);
|
||||
}
|
||||
@ -79,7 +79,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
});
|
||||
|
||||
createResults(() => userScore);
|
||||
waitForDisplay();
|
||||
|
||||
AddAssert("more than 1 panel displayed", () => this.ChildrenOfType<ScorePanel>().Count() > 1);
|
||||
AddAssert("user score selected", () => this.ChildrenOfType<ScorePanel>().Single(p => p.Score.OnlineScoreID == userScore.OnlineScoreID).State == PanelState.Expanded);
|
||||
@ -91,7 +90,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
AddStep("bind delayed handler", () => bindHandler(true));
|
||||
|
||||
createResults();
|
||||
waitForDisplay();
|
||||
|
||||
AddAssert("top score selected", () => this.ChildrenOfType<ScorePanel>().OrderByDescending(p => p.Score.TotalScore).First().State == PanelState.Expanded);
|
||||
}
|
||||
@ -100,7 +98,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
public void TestFetchWhenScrolledToTheRight()
|
||||
{
|
||||
createResults();
|
||||
waitForDisplay();
|
||||
|
||||
AddStep("bind delayed handler", () => bindHandler(true));
|
||||
|
||||
@ -131,7 +128,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
});
|
||||
|
||||
createResults(() => userScore);
|
||||
waitForDisplay();
|
||||
|
||||
AddStep("bind delayed handler", () => bindHandler(true));
|
||||
|
||||
@ -161,13 +157,15 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
}));
|
||||
});
|
||||
|
||||
AddUntilStep("wait for load", () => resultsScreen.ChildrenOfType<ScorePanelList>().FirstOrDefault()?.AllPanelsVisible == true);
|
||||
waitForDisplay();
|
||||
}
|
||||
|
||||
private void waitForDisplay()
|
||||
{
|
||||
AddUntilStep("wait for request to complete", () => requestComplete);
|
||||
AddUntilStep("wait for panels to be visible", () => resultsScreen.ChildrenOfType<ScorePanelList>().FirstOrDefault()?.AllPanelsVisible == true);
|
||||
AddUntilStep("wait for load to complete", () =>
|
||||
requestComplete
|
||||
&& resultsScreen.ScorePanelList.GetScorePanels().Count() == totalCount
|
||||
&& resultsScreen.ScorePanelList.AllPanelsVisible);
|
||||
AddWaitStep("wait for display", 5);
|
||||
}
|
||||
|
||||
@ -203,6 +201,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
triggerFail(s);
|
||||
else
|
||||
triggerSuccess(s, createUserResponse(userScore));
|
||||
|
||||
break;
|
||||
|
||||
case IndexPlaylistScoresRequest i:
|
||||
@ -248,6 +247,8 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
}
|
||||
};
|
||||
|
||||
totalCount++;
|
||||
|
||||
for (int i = 1; i <= scores_per_result; i++)
|
||||
{
|
||||
multiplayerUserScore.ScoresAround.Lower.Scores.Add(new MultiplayerScore
|
||||
@ -285,6 +286,8 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
},
|
||||
Statistics = userScore.Statistics
|
||||
});
|
||||
|
||||
totalCount += 2;
|
||||
}
|
||||
|
||||
addCursor(multiplayerUserScore.ScoresAround.Lower);
|
||||
@ -325,6 +328,8 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
{ HitResult.Great, 300 }
|
||||
}
|
||||
});
|
||||
|
||||
totalCount++;
|
||||
}
|
||||
|
||||
addCursor(result);
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Handlers.Tablet;
|
||||
@ -21,6 +22,9 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
private TestTabletHandler tabletHandler;
|
||||
private TabletSettings settings;
|
||||
|
||||
[Cached]
|
||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
|
@ -142,6 +142,8 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
|
||||
AddStep("store selected beatmap", () => selected = Beatmap.Value);
|
||||
|
||||
AddUntilStep("wait for beatmaps to load", () => songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmap>().Any());
|
||||
|
||||
AddStep("select next and enter", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmap>()
|
||||
@ -599,10 +601,10 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
});
|
||||
|
||||
FilterableDifficultyIcon difficultyIcon = null;
|
||||
AddStep("Find an icon", () =>
|
||||
AddUntilStep("Find an icon", () =>
|
||||
{
|
||||
difficultyIcon = set.ChildrenOfType<FilterableDifficultyIcon>()
|
||||
.First(icon => getDifficultyIconIndex(set, icon) != getCurrentBeatmapIndex());
|
||||
return (difficultyIcon = set.ChildrenOfType<FilterableDifficultyIcon>()
|
||||
.FirstOrDefault(icon => getDifficultyIconIndex(set, icon) != getCurrentBeatmapIndex())) != null;
|
||||
});
|
||||
|
||||
AddStep("Click on a difficulty", () =>
|
||||
@ -765,10 +767,10 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
});
|
||||
|
||||
FilterableGroupedDifficultyIcon groupIcon = null;
|
||||
AddStep("Find group icon for different ruleset", () =>
|
||||
AddUntilStep("Find group icon for different ruleset", () =>
|
||||
{
|
||||
groupIcon = set.ChildrenOfType<FilterableGroupedDifficultyIcon>()
|
||||
.First(icon => icon.Items.First().BeatmapInfo.Ruleset.ID == 3);
|
||||
return (groupIcon = set.ChildrenOfType<FilterableGroupedDifficultyIcon>()
|
||||
.FirstOrDefault(icon => icon.Items.First().BeatmapInfo.Ruleset.ID == 3)) != null;
|
||||
});
|
||||
|
||||
AddAssert("Check ruleset is osu!", () => Ruleset.Value.ID == 0);
|
||||
|
@ -163,7 +163,6 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
});
|
||||
|
||||
AddUntilStep("wait for fetch", () => leaderboard.Scores != null);
|
||||
|
||||
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != scoreBeingDeleted.OnlineScoreID));
|
||||
}
|
||||
|
||||
@ -171,6 +170,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
public void TestDeleteViaDatabase()
|
||||
{
|
||||
AddStep("delete top score", () => scoreManager.Delete(importedScores[0]));
|
||||
AddUntilStep("wait for fetch", () => leaderboard.Scores != null);
|
||||
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != importedScores[0].OnlineScoreID));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneRoundedButton : OsuTestScene
|
||||
{
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
RoundedButton button = null;
|
||||
|
||||
AddStep("create button", () => Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Colour4.DarkGray
|
||||
},
|
||||
button = new RoundedButton
|
||||
{
|
||||
Width = 400,
|
||||
Text = "Test button",
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Action = () => { }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AddToggleStep("toggle disabled", disabled => button.Action = disabled ? (Action)null : () => { });
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
|
||||
public static TournamentGameBase LoadTournament(GameHost host, TournamentGameBase tournament = null)
|
||||
{
|
||||
tournament ??= new TournamentGameBase();
|
||||
Task.Run(() => host.Run(tournament))
|
||||
Task.Factory.StartNew(() => host.Run(tournament), TaskCreationOptions.LongRunning)
|
||||
.ContinueWith(t => Assert.Fail($"Host threw exception {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
|
||||
WaitForOrAssert(() => tournament.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||
return tournament;
|
||||
|
@ -127,7 +127,7 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
|
||||
score2Text.X = Math.Max(5 + score2Text.DrawWidth / 2, score2Bar.DrawWidth);
|
||||
}
|
||||
|
||||
private class MatchScoreCounter : ScoreCounter
|
||||
private class MatchScoreCounter : CommaSeparatedScoreCounter
|
||||
{
|
||||
private OsuSpriteText displayedSpriteText;
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
using System.Diagnostics;
|
||||
using ManagedBass.Fx;
|
||||
using osu.Framework.Audio.Mixing;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Audio.Effects
|
||||
@ -21,10 +20,25 @@ namespace osu.Game.Audio.Effects
|
||||
private readonly BQFParameters filter;
|
||||
private readonly BQFType type;
|
||||
|
||||
private bool isAttached;
|
||||
|
||||
private int cutoff;
|
||||
|
||||
/// <summary>
|
||||
/// The current cutoff of this filter.
|
||||
/// The cutoff frequency of this filter.
|
||||
/// </summary>
|
||||
public BindableNumber<int> Cutoff { get; }
|
||||
public int Cutoff
|
||||
{
|
||||
get => cutoff;
|
||||
set
|
||||
{
|
||||
if (value == cutoff)
|
||||
return;
|
||||
|
||||
cutoff = value;
|
||||
updateFilter(cutoff);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A Component that implements a BASS FX BiQuad Filter Effect.
|
||||
@ -36,102 +50,96 @@ namespace osu.Game.Audio.Effects
|
||||
this.mixer = mixer;
|
||||
this.type = type;
|
||||
|
||||
int initialCutoff;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case BQFType.HighPass:
|
||||
initialCutoff = 1;
|
||||
break;
|
||||
|
||||
case BQFType.LowPass:
|
||||
initialCutoff = MAX_LOWPASS_CUTOFF;
|
||||
break;
|
||||
|
||||
default:
|
||||
initialCutoff = 500; // A default that should ensure audio remains audible for other filters.
|
||||
break;
|
||||
}
|
||||
|
||||
Cutoff = new BindableNumber<int>(initialCutoff)
|
||||
{
|
||||
MinValue = 1,
|
||||
MaxValue = MAX_LOWPASS_CUTOFF
|
||||
};
|
||||
|
||||
filter = new BQFParameters
|
||||
{
|
||||
lFilter = type,
|
||||
fCenter = initialCutoff,
|
||||
fBandwidth = 0,
|
||||
fQ = 0.7f // This allows fCenter to go up to 22049hz (nyquist - 1hz) without overflowing and causing weird filter behaviour (see: https://www.un4seen.com/forum/?topic=19542.0)
|
||||
// This allows fCenter to go up to 22049hz (nyquist - 1hz) without overflowing and causing weird filter behaviour (see: https://www.un4seen.com/forum/?topic=19542.0)
|
||||
fQ = 0.7f
|
||||
};
|
||||
|
||||
// Don't start attached if this is low-pass or high-pass filter (as they have special auto-attach/detach logic)
|
||||
if (type != BQFType.LowPass && type != BQFType.HighPass)
|
||||
attachFilter();
|
||||
|
||||
Cutoff.ValueChanged += updateFilter;
|
||||
Cutoff = getInitialCutoff(type);
|
||||
}
|
||||
|
||||
private void attachFilter()
|
||||
private int getInitialCutoff(BQFType type)
|
||||
{
|
||||
Debug.Assert(!mixer.Effects.Contains(filter));
|
||||
mixer.Effects.Add(filter);
|
||||
}
|
||||
|
||||
private void detachFilter()
|
||||
{
|
||||
Debug.Assert(mixer.Effects.Contains(filter));
|
||||
mixer.Effects.Remove(filter);
|
||||
}
|
||||
|
||||
private void updateFilter(ValueChangedEvent<int> cutoff)
|
||||
{
|
||||
// Workaround for weird behaviour when rapidly setting fCenter of a low-pass filter to nyquist - 1hz.
|
||||
if (type == BQFType.LowPass)
|
||||
switch (type)
|
||||
{
|
||||
if (cutoff.NewValue >= MAX_LOWPASS_CUTOFF)
|
||||
{
|
||||
detachFilter();
|
||||
return;
|
||||
}
|
||||
case BQFType.HighPass:
|
||||
return 1;
|
||||
|
||||
if (cutoff.OldValue >= MAX_LOWPASS_CUTOFF && cutoff.NewValue < MAX_LOWPASS_CUTOFF)
|
||||
attachFilter();
|
||||
case BQFType.LowPass:
|
||||
return MAX_LOWPASS_CUTOFF;
|
||||
|
||||
default:
|
||||
return 500; // A default that should ensure audio remains audible for other filters.
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFilter(int newValue)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case BQFType.LowPass:
|
||||
// Workaround for weird behaviour when rapidly setting fCenter of a low-pass filter to nyquist - 1hz.
|
||||
if (newValue >= MAX_LOWPASS_CUTOFF)
|
||||
{
|
||||
ensureDetached();
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Workaround for weird behaviour when rapidly setting fCenter of a high-pass filter to 1hz.
|
||||
case BQFType.HighPass:
|
||||
if (newValue <= 1)
|
||||
{
|
||||
ensureDetached();
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Workaround for weird behaviour when rapidly setting fCenter of a high-pass filter to 1hz.
|
||||
if (type == BQFType.HighPass)
|
||||
{
|
||||
if (cutoff.NewValue <= 1)
|
||||
{
|
||||
detachFilter();
|
||||
return;
|
||||
}
|
||||
|
||||
if (cutoff.OldValue <= 1 && cutoff.NewValue > 1)
|
||||
attachFilter();
|
||||
}
|
||||
ensureAttached();
|
||||
|
||||
var filterIndex = mixer.Effects.IndexOf(filter);
|
||||
|
||||
if (filterIndex < 0) return;
|
||||
|
||||
if (mixer.Effects[filterIndex] is BQFParameters existingFilter)
|
||||
{
|
||||
existingFilter.fCenter = cutoff.NewValue;
|
||||
existingFilter.fCenter = newValue;
|
||||
|
||||
// required to update effect with new parameters.
|
||||
mixer.Effects[filterIndex] = existingFilter;
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureAttached()
|
||||
{
|
||||
if (isAttached)
|
||||
return;
|
||||
|
||||
Debug.Assert(!mixer.Effects.Contains(filter));
|
||||
mixer.Effects.Add(filter);
|
||||
isAttached = true;
|
||||
}
|
||||
|
||||
private void ensureDetached()
|
||||
{
|
||||
if (!isAttached)
|
||||
return;
|
||||
|
||||
Debug.Assert(mixer.Effects.Contains(filter));
|
||||
mixer.Effects.Remove(filter);
|
||||
isAttached = false;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (mixer.Effects.Contains(filter))
|
||||
detachFilter();
|
||||
ensureDetached();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Transforms;
|
||||
|
||||
@ -12,7 +11,7 @@ namespace osu.Game.Audio.Effects
|
||||
/// <summary>
|
||||
/// The filter cutoff.
|
||||
/// </summary>
|
||||
BindableNumber<int> Cutoff { get; }
|
||||
int Cutoff { get; set; }
|
||||
}
|
||||
|
||||
public static class FilterableAudioComponentExtensions
|
||||
@ -40,7 +39,7 @@ namespace osu.Game.Audio.Effects
|
||||
public static TransformSequence<T> CutoffTo<T, TEasing>(this T component, int newCutoff, double duration, TEasing easing)
|
||||
where T : class, ITransformableFilter, IDrawable
|
||||
where TEasing : IEasingFunction
|
||||
=> component.TransformBindableTo(component.Cutoff, newCutoff, duration, easing);
|
||||
=> component.TransformTo(nameof(component.Cutoff), newCutoff, duration, easing);
|
||||
|
||||
/// <summary>
|
||||
/// Smoothly adjusts filter cutoff over time.
|
||||
@ -49,6 +48,6 @@ namespace osu.Game.Audio.Effects
|
||||
public static TransformSequence<T> CutoffTo<T, TEasing>(this TransformSequence<T> sequence, int newCutoff, double duration, TEasing easing)
|
||||
where T : class, ITransformableFilter, IDrawable
|
||||
where TEasing : IEasingFunction
|
||||
=> sequence.Append(o => o.TransformBindableTo(o.Cutoff, newCutoff, duration, easing));
|
||||
=> sequence.Append(o => o.TransformTo(nameof(o.Cutoff), newCutoff, duration, easing));
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,13 @@ namespace osu.Game.Beatmaps
|
||||
public IBeatmap Convert(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// We always operate on a clone of the original beatmap, to not modify it game-wide
|
||||
return ConvertBeatmap(Beatmap.Clone(), cancellationToken);
|
||||
var original = Beatmap.Clone();
|
||||
|
||||
// Shallow clone isn't enough to ensure we don't mutate beatmap info unexpectedly.
|
||||
// Can potentially be removed after `Beatmap.Difficulty` doesn't save back to `Beatmap.BeatmapInfo`.
|
||||
original.BeatmapInfo = original.BeatmapInfo.Clone();
|
||||
|
||||
return ConvertBeatmap(original, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual BeatmapModelDownloader CreateBeatmapModelDownloader(BeatmapModelManager modelManager, IAPIProvider api, GameHost host)
|
||||
protected virtual BeatmapModelDownloader CreateBeatmapModelDownloader(IBeatmapModelManager modelManager, IAPIProvider api, GameHost host)
|
||||
{
|
||||
return new BeatmapModelDownloader(modelManager, api, host);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace osu.Game.Beatmaps
|
||||
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) =>
|
||||
new DownloadBeatmapSetRequest(set, minimiseDownloadSize);
|
||||
|
||||
public BeatmapModelDownloader(BeatmapModelManager beatmapModelManager, IAPIProvider api, GameHost host = null)
|
||||
public BeatmapModelDownloader(IBeatmapModelManager beatmapModelManager, IAPIProvider api, GameHost host = null)
|
||||
: base(beatmapModelManager, api, host)
|
||||
{
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace osu.Game.Configuration
|
||||
[Description("Never repeat")]
|
||||
RandomPermutation,
|
||||
|
||||
[Description("Random")]
|
||||
[Description("True Random")]
|
||||
Random
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ namespace osu.Game.Database
|
||||
/// <param name="paths">One or more archive locations on disk.</param>
|
||||
public Task Import(params string[] paths)
|
||||
{
|
||||
var notification = new ProgressNotification { State = ProgressNotificationState.Active };
|
||||
var notification = new ImportProgressNotification();
|
||||
|
||||
PostNotification?.Invoke(notification);
|
||||
|
||||
@ -125,7 +125,7 @@ namespace osu.Game.Database
|
||||
|
||||
public Task Import(params ImportTask[] tasks)
|
||||
{
|
||||
var notification = new ProgressNotification { State = ProgressNotificationState.Active };
|
||||
var notification = new ImportProgressNotification();
|
||||
|
||||
PostNotification?.Invoke(notification);
|
||||
|
||||
|
20
osu.Game/Database/IHasRealmFiles.cs
Normal file
20
osu.Game/Database/IHasRealmFiles.cs
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Models;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
/// <summary>
|
||||
/// A model that contains a list of files it is responsible for.
|
||||
/// </summary>
|
||||
public interface IHasRealmFiles
|
||||
{
|
||||
IList<RealmNamedFileUsage> Files { get; }
|
||||
|
||||
string Hash { get; set; }
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ using osu.Game.Overlays.Notifications;
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
/// <summary>
|
||||
/// A class which handles importing of asociated models to the game store.
|
||||
/// A class which handles importing of associated models to the game store.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The model type.</typeparam>
|
||||
public interface IModelImporter<TModel> : IPostNotifications
|
||||
|
19
osu.Game/Database/INamedFile.cs
Normal file
19
osu.Game/Database/INamedFile.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Game.Models;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a join model which gives a filename and scope to a <see cref="File"/>.
|
||||
/// </summary>
|
||||
public interface INamedFile
|
||||
{
|
||||
string Filename { get; set; }
|
||||
|
||||
RealmFile File { get; set; }
|
||||
}
|
||||
}
|
15
osu.Game/Database/ImportProgressNotification.cs
Normal file
15
osu.Game/Database/ImportProgressNotification.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Game.Overlays.Notifications;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public class ImportProgressNotification : ProgressNotification
|
||||
{
|
||||
public ImportProgressNotification()
|
||||
{
|
||||
State = ProgressNotificationState.Active;
|
||||
}
|
||||
}
|
||||
}
|
@ -135,9 +135,8 @@ namespace osu.Game.Database
|
||||
if (IsDisposed)
|
||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||
|
||||
// TODO: this can be added for safety once we figure how to bypass in test
|
||||
// if (!ThreadSafety.IsUpdateThread)
|
||||
// throw new InvalidOperationException($"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException($"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||
|
||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||
|
||||
|
111
osu.Game/Database/RealmLive.cs
Normal file
111
osu.Game/Database/RealmLive.cs
Normal file
@ -0,0 +1,111 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a method of working with realm objects over longer application lifetimes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The underlying object type.</typeparam>
|
||||
public class RealmLive<T> : ILive<T> where T : RealmObject, IHasGuidPrimaryKey
|
||||
{
|
||||
public Guid ID { get; }
|
||||
|
||||
private readonly SynchronizationContext? fetchedContext;
|
||||
private readonly int fetchedThreadId;
|
||||
|
||||
/// <summary>
|
||||
/// The original live data used to create this instance.
|
||||
/// </summary>
|
||||
private readonly T data;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new instance of live realm data.
|
||||
/// </summary>
|
||||
/// <param name="data">The realm data.</param>
|
||||
public RealmLive(T data)
|
||||
{
|
||||
this.data = data;
|
||||
|
||||
fetchedContext = SynchronizationContext.Current;
|
||||
fetchedThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
ID = data.ID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a read operation on this live object.
|
||||
/// </summary>
|
||||
/// <param name="perform">The action to perform.</param>
|
||||
public void PerformRead(Action<T> perform)
|
||||
{
|
||||
if (originalDataValid)
|
||||
{
|
||||
perform(data);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var realm = Realm.GetInstance(data.Realm.Config))
|
||||
perform(realm.Find<T>(ID));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a read operation on this live object.
|
||||
/// </summary>
|
||||
/// <param name="perform">The action to perform.</param>
|
||||
public TReturn PerformRead<TReturn>(Func<T, TReturn> perform)
|
||||
{
|
||||
if (typeof(RealmObjectBase).IsAssignableFrom(typeof(TReturn)))
|
||||
throw new InvalidOperationException($"Realm live objects should not exit the scope of {nameof(PerformRead)}.");
|
||||
|
||||
if (originalDataValid)
|
||||
return perform(data);
|
||||
|
||||
using (var realm = Realm.GetInstance(data.Realm.Config))
|
||||
return perform(realm.Find<T>(ID));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a write operation on this live object.
|
||||
/// </summary>
|
||||
/// <param name="perform">The action to perform.</param>
|
||||
public void PerformWrite(Action<T> perform) =>
|
||||
PerformRead(t =>
|
||||
{
|
||||
var transaction = t.Realm.BeginWrite();
|
||||
perform(t);
|
||||
transaction.Commit();
|
||||
});
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (originalDataValid)
|
||||
return data;
|
||||
|
||||
T retrieved;
|
||||
|
||||
using (var realm = Realm.GetInstance(data.Realm.Config))
|
||||
retrieved = realm.Find<T>(ID);
|
||||
|
||||
if (!retrieved.IsValid)
|
||||
throw new InvalidOperationException("Attempted to access value without an open context");
|
||||
|
||||
return retrieved;
|
||||
}
|
||||
}
|
||||
|
||||
private bool originalDataValid => isCorrectThread && data.IsValid;
|
||||
|
||||
// this matches realm's internal thread validation (see https://github.com/realm/realm-dotnet/blob/903b4d0b304f887e37e2d905384fb572a6496e70/Realm/Realm/Native/SynchronizationContextScheduler.cs#L72)
|
||||
private bool isCorrectThread
|
||||
=> (fetchedContext != null && SynchronizationContext.Current == fetchedContext) || fetchedThreadId == Thread.CurrentThread.ManagedThreadId;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using osu.Game.Input.Bindings;
|
||||
using Realms;
|
||||
@ -47,5 +48,17 @@ namespace osu.Game.Database
|
||||
|
||||
return mapper.Map<T>(item);
|
||||
}
|
||||
|
||||
public static List<RealmLive<T>> ToLive<T>(this IEnumerable<T> realmList)
|
||||
where T : RealmObject, IHasGuidPrimaryKey
|
||||
{
|
||||
return realmList.Select(l => new RealmLive<T>(l)).ToList();
|
||||
}
|
||||
|
||||
public static RealmLive<T> ToLive<T>(this T realmObject)
|
||||
where T : RealmObject, IHasGuidPrimaryKey
|
||||
{
|
||||
return new RealmLive<T>(realmObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,6 +225,16 @@ namespace osu.Game.Graphics
|
||||
public readonly Color4 GrayE = Color4Extensions.FromHex(@"eee");
|
||||
public readonly Color4 GrayF = Color4Extensions.FromHex(@"fff");
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="OverlayColourProvider.Pink"/>'s <see cref="OverlayColourProvider.Colour3"/>.
|
||||
/// </summary>
|
||||
public readonly Color4 Pink3 = Color4Extensions.FromHex(@"cc3378");
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="OverlayColourProvider.Blue"/>'s <see cref="OverlayColourProvider.Colour3"/>.
|
||||
/// </summary>
|
||||
public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc");
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour1"/>.
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,24 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public abstract class CommaSeparatedScoreCounter : RollingCounter<double>
|
||||
{
|
||||
protected override double RollingDuration => 1000;
|
||||
protected override Easing RollingEasing => Easing.Out;
|
||||
|
||||
protected override double GetProportionalDuration(double currentValue, double newValue) =>
|
||||
currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||
|
||||
protected override LocalisableString FormatCount(double count) => ((long)count).ToLocalisableString(@"N0");
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
@ -13,43 +14,30 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected override double RollingDuration => 1000;
|
||||
protected override Easing RollingEasing => Easing.Out;
|
||||
|
||||
/// <summary>
|
||||
/// Whether comma separators should be displayed.
|
||||
/// </summary>
|
||||
public bool UseCommaSeparator { get; }
|
||||
|
||||
public Bindable<int> RequiredDisplayDigits { get; } = new Bindable<int>();
|
||||
|
||||
private string formatString;
|
||||
|
||||
/// <summary>
|
||||
/// Displays score.
|
||||
/// </summary>
|
||||
/// <param name="leading">How many leading zeroes the counter will have.</param>
|
||||
/// <param name="useCommaSeparator">Whether comma separators should be displayed.</param>
|
||||
protected ScoreCounter(int leading = 0, bool useCommaSeparator = false)
|
||||
protected ScoreCounter(int leading = 0)
|
||||
{
|
||||
UseCommaSeparator = useCommaSeparator;
|
||||
|
||||
RequiredDisplayDigits.Value = leading;
|
||||
RequiredDisplayDigits.BindValueChanged(_ => UpdateDisplay());
|
||||
RequiredDisplayDigits.BindValueChanged(displayDigitsChanged, true);
|
||||
}
|
||||
|
||||
protected override double GetProportionalDuration(double currentValue, double newValue)
|
||||
private void displayDigitsChanged(ValueChangedEvent<int> _)
|
||||
{
|
||||
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||
formatString = new string('0', RequiredDisplayDigits.Value);
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
protected override LocalisableString FormatCount(double count)
|
||||
{
|
||||
string format = new string('0', RequiredDisplayDigits.Value);
|
||||
protected override double GetProportionalDuration(double currentValue, double newValue) =>
|
||||
currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||
|
||||
if (UseCommaSeparator)
|
||||
{
|
||||
for (int i = format.Length - 3; i > 0; i -= 3)
|
||||
format = format.Insert(i, @",");
|
||||
}
|
||||
|
||||
return ((long)count).ToString(format);
|
||||
}
|
||||
protected override LocalisableString FormatCount(double count) => ((long)count).ToLocalisableString(formatString);
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true));
|
||||
|
49
osu.Game/Graphics/UserInterfaceV2/RoundedButton.cs
Normal file
49
osu.Game/Graphics/UserInterfaceV2/RoundedButton.cs
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
public class RoundedButton : OsuButton, IFilterable
|
||||
{
|
||||
public override float Height
|
||||
{
|
||||
get => base.Height;
|
||||
set
|
||||
{
|
||||
base.Height = value;
|
||||
|
||||
if (IsLoaded)
|
||||
updateCornerRadius();
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BackgroundColour = colours.Blue3;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
updateCornerRadius();
|
||||
}
|
||||
|
||||
private void updateCornerRadius() => Content.CornerRadius = DrawHeight / 2;
|
||||
|
||||
public virtual IEnumerable<string> FilterTerms => new[] { Text.ToString() };
|
||||
|
||||
public bool MatchingFilter
|
||||
{
|
||||
set => this.FadeTo(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public bool FilteringActive { get; set; }
|
||||
}
|
||||
}
|
@ -24,6 +24,11 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString VolumeHeader => new TranslatableString(getKey(@"volume_header"), @"Volume");
|
||||
|
||||
/// <summary>
|
||||
/// "Output device"
|
||||
/// </summary>
|
||||
public static LocalisableString OutputDevice => new TranslatableString(getKey(@"output_device"), @"Output device");
|
||||
|
||||
/// <summary>
|
||||
/// "Master"
|
||||
/// </summary>
|
||||
|
@ -14,11 +14,36 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString GameplaySectionHeader => new TranslatableString(getKey(@"gameplay_section_header"), @"Gameplay");
|
||||
|
||||
/// <summary>
|
||||
/// "Beatmap"
|
||||
/// </summary>
|
||||
public static LocalisableString BeatmapHeader => new TranslatableString(getKey(@"beatmap_header"), @"Beatmap");
|
||||
|
||||
/// <summary>
|
||||
/// "General"
|
||||
/// </summary>
|
||||
public static LocalisableString GeneralHeader => new TranslatableString(getKey(@"general_header"), @"General");
|
||||
|
||||
/// <summary>
|
||||
/// "Audio"
|
||||
/// </summary>
|
||||
public static LocalisableString AudioHeader => new TranslatableString(getKey(@"audio"), @"Audio");
|
||||
|
||||
/// <summary>
|
||||
/// "HUD"
|
||||
/// </summary>
|
||||
public static LocalisableString HUDHeader => new TranslatableString(getKey(@"h_u_d"), @"HUD");
|
||||
|
||||
/// <summary>
|
||||
/// "Input"
|
||||
/// </summary>
|
||||
public static LocalisableString InputHeader => new TranslatableString(getKey(@"input"), @"Input");
|
||||
|
||||
/// <summary>
|
||||
/// "Background"
|
||||
/// </summary>
|
||||
public static LocalisableString BackgroundHeader => new TranslatableString(getKey(@"background"), @"Background");
|
||||
|
||||
/// <summary>
|
||||
/// "Background dim"
|
||||
/// </summary>
|
||||
|
@ -104,6 +104,11 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString HitLighting => new TranslatableString(getKey(@"hit_lighting"), @"Hit lighting");
|
||||
|
||||
/// <summary>
|
||||
/// "Screenshots"
|
||||
/// </summary>
|
||||
public static LocalisableString Screenshots => new TranslatableString(getKey(@"screenshots"), @"Screenshots");
|
||||
|
||||
/// <summary>
|
||||
/// "Screenshot format"
|
||||
/// </summary>
|
||||
|
19
osu.Game/Localisation/RulesetSettingsStrings.cs
Normal file
19
osu.Game/Localisation/RulesetSettingsStrings.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Localisation;
|
||||
|
||||
namespace osu.Game.Localisation
|
||||
{
|
||||
public static class RulesetSettingsStrings
|
||||
{
|
||||
private const string prefix = @"osu.Game.Resources.Localisation.RulesetSettings";
|
||||
|
||||
/// <summary>
|
||||
/// "Rulesets"
|
||||
/// </summary>
|
||||
public static LocalisableString Rulesets => new TranslatableString(getKey(@"rulesets"), @"Rulesets");
|
||||
|
||||
private static string getKey(string key) => $@"{prefix}:{key}";
|
||||
}
|
||||
}
|
@ -14,6 +14,11 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString SkinSectionHeader => new TranslatableString(getKey(@"skin_section_header"), @"Skin");
|
||||
|
||||
/// <summary>
|
||||
/// "Current skin"
|
||||
/// </summary>
|
||||
public static LocalisableString CurrentSkin => new TranslatableString(getKey(@"current_skin"), @"Current skin");
|
||||
|
||||
/// <summary>
|
||||
/// "Skin layout editor"
|
||||
/// </summary>
|
||||
|
117
osu.Game/Models/RealmBeatmap.cs
Normal file
117
osu.Game/Models/RealmBeatmap.cs
Normal file
@ -0,0 +1,117 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Rulesets;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A single beatmap difficulty.
|
||||
/// </summary>
|
||||
[ExcludeFromDynamicCompile]
|
||||
[Serializable]
|
||||
[MapTo("Beatmap")]
|
||||
public class RealmBeatmap : RealmObject, IHasGuidPrimaryKey, IBeatmapInfo
|
||||
{
|
||||
[PrimaryKey]
|
||||
public Guid ID { get; set; } = Guid.NewGuid();
|
||||
|
||||
public string DifficultyName { get; set; } = string.Empty;
|
||||
|
||||
public RealmRuleset Ruleset { get; set; } = null!;
|
||||
|
||||
public RealmBeatmapDifficulty Difficulty { get; set; } = null!;
|
||||
|
||||
public RealmBeatmapMetadata Metadata { get; set; } = null!;
|
||||
|
||||
public RealmBeatmapSet? BeatmapSet { get; set; }
|
||||
|
||||
public BeatmapSetOnlineStatus Status
|
||||
{
|
||||
get => (BeatmapSetOnlineStatus)StatusInt;
|
||||
set => StatusInt = (int)value;
|
||||
}
|
||||
|
||||
[MapTo(nameof(Status))]
|
||||
public int StatusInt { get; set; }
|
||||
|
||||
public int? OnlineID { get; set; }
|
||||
|
||||
public double Length { get; set; }
|
||||
|
||||
public double BPM { get; set; }
|
||||
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
public double StarRating { get; set; }
|
||||
|
||||
public string MD5Hash { get; set; } = string.Empty;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool Hidden { get; set; }
|
||||
|
||||
public RealmBeatmap(RealmRuleset ruleset, RealmBeatmapDifficulty difficulty, RealmBeatmapMetadata metadata)
|
||||
{
|
||||
Ruleset = ruleset;
|
||||
Difficulty = difficulty;
|
||||
Metadata = metadata;
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private RealmBeatmap()
|
||||
{
|
||||
}
|
||||
|
||||
#region Properties we may not want persisted (but also maybe no harm?)
|
||||
|
||||
public double AudioLeadIn { get; set; }
|
||||
|
||||
public float StackLeniency { get; set; } = 0.7f;
|
||||
|
||||
public bool SpecialStyle { get; set; }
|
||||
|
||||
public bool LetterboxInBreaks { get; set; }
|
||||
|
||||
public bool WidescreenStoryboard { get; set; }
|
||||
|
||||
public bool EpilepsyWarning { get; set; }
|
||||
|
||||
public bool SamplesMatchPlaybackRate { get; set; }
|
||||
|
||||
public double DistanceSpacing { get; set; }
|
||||
|
||||
public int BeatDivisor { get; set; }
|
||||
|
||||
public int GridSize { get; set; }
|
||||
|
||||
public double TimelineZoom { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public bool AudioEquals(RealmBeatmap? other) => other != null
|
||||
&& BeatmapSet != null
|
||||
&& other.BeatmapSet != null
|
||||
&& BeatmapSet.Hash == other.BeatmapSet.Hash
|
||||
&& Metadata.AudioFile == other.Metadata.AudioFile;
|
||||
|
||||
public bool BackgroundEquals(RealmBeatmap? other) => other != null
|
||||
&& BeatmapSet != null
|
||||
&& other.BeatmapSet != null
|
||||
&& BeatmapSet.Hash == other.BeatmapSet.Hash
|
||||
&& Metadata.BackgroundFile == other.Metadata.BackgroundFile;
|
||||
|
||||
IBeatmapMetadataInfo IBeatmapInfo.Metadata => Metadata;
|
||||
IBeatmapSetInfo? IBeatmapInfo.BeatmapSet => BeatmapSet;
|
||||
IRulesetInfo IBeatmapInfo.Ruleset => Ruleset;
|
||||
IBeatmapDifficultyInfo IBeatmapInfo.Difficulty => Difficulty;
|
||||
}
|
||||
}
|
45
osu.Game/Models/RealmBeatmapDifficulty.cs
Normal file
45
osu.Game/Models/RealmBeatmapDifficulty.cs
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Models
|
||||
{
|
||||
[ExcludeFromDynamicCompile]
|
||||
[MapTo("BeatmapDifficulty")]
|
||||
public class RealmBeatmapDifficulty : EmbeddedObject, IBeatmapDifficultyInfo
|
||||
{
|
||||
public float DrainRate { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY;
|
||||
public float CircleSize { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY;
|
||||
public float OverallDifficulty { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY;
|
||||
public float ApproachRate { get; set; } = IBeatmapDifficultyInfo.DEFAULT_DIFFICULTY;
|
||||
|
||||
public double SliderMultiplier { get; set; } = 1;
|
||||
public double SliderTickRate { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a shallow-clone of this <see cref="RealmBeatmapDifficulty"/>.
|
||||
/// </summary>
|
||||
public RealmBeatmapDifficulty Clone()
|
||||
{
|
||||
var diff = new RealmBeatmapDifficulty();
|
||||
CopyTo(diff);
|
||||
return diff;
|
||||
}
|
||||
|
||||
public void CopyTo(RealmBeatmapDifficulty difficulty)
|
||||
{
|
||||
difficulty.ApproachRate = ApproachRate;
|
||||
difficulty.DrainRate = DrainRate;
|
||||
difficulty.CircleSize = CircleSize;
|
||||
difficulty.OverallDifficulty = OverallDifficulty;
|
||||
|
||||
difficulty.SliderMultiplier = SliderMultiplier;
|
||||
difficulty.SliderTickRate = SliderTickRate;
|
||||
}
|
||||
}
|
||||
}
|
45
osu.Game/Models/RealmBeatmapMetadata.cs
Normal file
45
osu.Game/Models/RealmBeatmapMetadata.cs
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Models
|
||||
{
|
||||
[ExcludeFromDynamicCompile]
|
||||
[Serializable]
|
||||
[MapTo("BeatmapMetadata")]
|
||||
public class RealmBeatmapMetadata : RealmObject, IBeatmapMetadataInfo
|
||||
{
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("title_unicode")]
|
||||
public string TitleUnicode { get; set; } = string.Empty;
|
||||
|
||||
public string Artist { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("artist_unicode")]
|
||||
public string ArtistUnicode { get; set; } = string.Empty;
|
||||
|
||||
public string Author { get; set; } = string.Empty; // eventually should be linked to a persisted User.
|
||||
|
||||
public string Source { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty(@"tags")]
|
||||
public string Tags { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The time in milliseconds to begin playing the track for preview purposes.
|
||||
/// If -1, the track should begin playing at 40% of its length.
|
||||
/// </summary>
|
||||
public int PreviewTime { get; set; }
|
||||
|
||||
public string AudioFile { get; set; } = string.Empty;
|
||||
public string BackgroundFile { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
78
osu.Game/Models/RealmBeatmapSet.cs
Normal file
78
osu.Game/Models/RealmBeatmapSet.cs
Normal file
@ -0,0 +1,78 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Models
|
||||
{
|
||||
[ExcludeFromDynamicCompile]
|
||||
[MapTo("BeatmapSet")]
|
||||
public class RealmBeatmapSet : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<RealmBeatmapSet>, IBeatmapSetInfo
|
||||
{
|
||||
[PrimaryKey]
|
||||
public Guid ID { get; set; } = Guid.NewGuid();
|
||||
|
||||
public int? OnlineID { get; set; }
|
||||
|
||||
public DateTimeOffset DateAdded { get; set; }
|
||||
|
||||
public IBeatmapMetadataInfo? Metadata => Beatmaps.FirstOrDefault()?.Metadata;
|
||||
|
||||
public IList<RealmBeatmap> Beatmaps { get; } = null!;
|
||||
|
||||
public IList<RealmNamedFileUsage> Files { get; } = null!;
|
||||
|
||||
public bool DeletePending { get; set; }
|
||||
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Whether deleting this beatmap set should be prohibited (due to it being a system requirement to be present).
|
||||
/// </summary>
|
||||
public bool Protected { get; set; }
|
||||
|
||||
public double MaxStarDifficulty => Beatmaps.Max(b => b.StarRating);
|
||||
|
||||
public double MaxLength => Beatmaps.Max(b => b.Length);
|
||||
|
||||
public double MaxBPM => Beatmaps.Max(b => b.BPM);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null.
|
||||
/// The path returned is relative to the user file storage.
|
||||
/// </summary>
|
||||
/// <param name="filename">The name of the file to get the storage path of.</param>
|
||||
public string? GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.File.StoragePath;
|
||||
|
||||
public override string ToString() => Metadata?.ToString() ?? base.ToString();
|
||||
|
||||
public bool Equals(RealmBeatmapSet? other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
if (IsManaged && other.IsManaged)
|
||||
return ID == other.ID;
|
||||
|
||||
if (OnlineID.HasValue && other.OnlineID.HasValue)
|
||||
return OnlineID == other.OnlineID;
|
||||
|
||||
if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash))
|
||||
return Hash == other.Hash;
|
||||
|
||||
return ReferenceEquals(this, other);
|
||||
}
|
||||
|
||||
IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;
|
||||
|
||||
IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files;
|
||||
}
|
||||
}
|
22
osu.Game/Models/RealmFile.cs
Normal file
22
osu.Game/Models/RealmFile.cs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.IO;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.IO;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Models
|
||||
{
|
||||
[ExcludeFromDynamicCompile]
|
||||
[MapTo("File")]
|
||||
public class RealmFile : RealmObject, IFileInfo
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
public string StoragePath => Path.Combine(Hash.Remove(1), Hash.Remove(2), Hash);
|
||||
}
|
||||
}
|
34
osu.Game/Models/RealmNamedFileUsage.cs
Normal file
34
osu.Game/Models/RealmNamedFileUsage.cs
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Models
|
||||
{
|
||||
[ExcludeFromDynamicCompile]
|
||||
public class RealmNamedFileUsage : EmbeddedObject, INamedFile, INamedFileUsage
|
||||
{
|
||||
public RealmFile File { get; set; } = null!;
|
||||
|
||||
public string Filename { get; set; } = null!;
|
||||
|
||||
public RealmNamedFileUsage(RealmFile file, string filename)
|
||||
{
|
||||
File = file;
|
||||
Filename = filename;
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private RealmNamedFileUsage()
|
||||
{
|
||||
}
|
||||
|
||||
IFileInfo INamedFileUsage.File => File;
|
||||
}
|
||||
}
|
63
osu.Game/Models/RealmRuleset.cs
Normal file
63
osu.Game/Models/RealmRuleset.cs
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Rulesets;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Models
|
||||
{
|
||||
[ExcludeFromDynamicCompile]
|
||||
[MapTo("Ruleset")]
|
||||
public class RealmRuleset : RealmObject, IEquatable<RealmRuleset>, IRulesetInfo
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string ShortName { get; set; } = string.Empty;
|
||||
|
||||
public int? OnlineID { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string InstantiationInfo { get; set; } = string.Empty;
|
||||
|
||||
public RealmRuleset(string shortName, string name, string instantiationInfo, int? onlineID = null)
|
||||
{
|
||||
ShortName = shortName;
|
||||
Name = name;
|
||||
InstantiationInfo = instantiationInfo;
|
||||
OnlineID = onlineID;
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private RealmRuleset()
|
||||
{
|
||||
}
|
||||
|
||||
public RealmRuleset(int? onlineID, string name, string shortName, bool available)
|
||||
{
|
||||
OnlineID = onlineID;
|
||||
Name = name;
|
||||
ShortName = shortName;
|
||||
Available = available;
|
||||
}
|
||||
|
||||
public bool Available { get; set; }
|
||||
|
||||
public bool Equals(RealmRuleset? other) => other != null && OnlineID == other.OnlineID && Available == other.Available && Name == other.Name && InstantiationInfo == other.InstantiationInfo;
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
public RealmRuleset Clone() => new RealmRuleset
|
||||
{
|
||||
OnlineID = OnlineID,
|
||||
Name = Name,
|
||||
ShortName = ShortName,
|
||||
InstantiationInfo = InstantiationInfo,
|
||||
Available = Available
|
||||
};
|
||||
}
|
||||
}
|
@ -177,6 +177,24 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
case "wiki":
|
||||
return new LinkDetails(LinkAction.OpenWiki, string.Join('/', args.Skip(3)));
|
||||
|
||||
case "home":
|
||||
if (mainArg != "changelog")
|
||||
// handle link other than changelog as external for now
|
||||
return new LinkDetails(LinkAction.External, url);
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 4:
|
||||
// https://osu.ppy.sh/home/changelog
|
||||
return new LinkDetails(LinkAction.OpenChangelog, string.Empty);
|
||||
|
||||
case 6:
|
||||
// https://osu.ppy.sh/home/changelog/lazer/2021.1006
|
||||
return new LinkDetails(LinkAction.OpenChangelog, $"{args[4]}/{args[5]}");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,6 +342,7 @@ namespace osu.Game.Online.Chat
|
||||
SearchBeatmapSet,
|
||||
OpenWiki,
|
||||
Custom,
|
||||
OpenChangelog,
|
||||
}
|
||||
|
||||
public class Link : IComparable<Link>
|
||||
|
@ -130,12 +130,6 @@ namespace osu.Game.Online.Rooms
|
||||
set => MaxAttempts.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The position of this <see cref="Room"/> in the list. This is not read from or written to the API.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public readonly Bindable<long> Position = new Bindable<long>(-1); // Todo: This does not need to exist.
|
||||
|
||||
public Room()
|
||||
{
|
||||
Password.BindValueChanged(p => HasPassword.Value = !string.IsNullOrEmpty(p.NewValue));
|
||||
@ -192,8 +186,6 @@ namespace osu.Game.Online.Rooms
|
||||
RecentParticipants.Clear();
|
||||
RecentParticipants.AddRange(other.RecentParticipants);
|
||||
}
|
||||
|
||||
Position.Value = other.Position.Value;
|
||||
}
|
||||
|
||||
public void RemoveExpiredPlaylistItems()
|
||||
|
@ -90,6 +90,8 @@ namespace osu.Game
|
||||
|
||||
private WikiOverlay wikiOverlay;
|
||||
|
||||
private ChangelogOverlay changelogOverlay;
|
||||
|
||||
private SkinEditorOverlay skinEditor;
|
||||
|
||||
private Container overlayContent;
|
||||
@ -209,13 +211,6 @@ namespace osu.Game
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
if (args?.Length > 0)
|
||||
{
|
||||
var paths = args.Where(a => !a.StartsWith('-')).ToArray();
|
||||
if (paths.Length > 0)
|
||||
Task.Run(() => Import(paths));
|
||||
}
|
||||
|
||||
dependencies.CacheAs(this);
|
||||
|
||||
dependencies.Cache(SentryLogger);
|
||||
@ -336,6 +331,17 @@ namespace osu.Game
|
||||
ShowWiki(link.Argument);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenChangelog:
|
||||
if (string.IsNullOrEmpty(link.Argument))
|
||||
ShowChangelogListing();
|
||||
else
|
||||
{
|
||||
var changelogArgs = link.Argument.Split("/");
|
||||
ShowChangelogBuild(changelogArgs[0], changelogArgs[1]);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException($"This {nameof(LinkAction)} ({link.Action.ToString()}) is missing an associated action.");
|
||||
}
|
||||
@ -401,6 +407,18 @@ namespace osu.Game
|
||||
/// <param name="path">The wiki page to show</param>
|
||||
public void ShowWiki(string path) => waitForReady(() => wikiOverlay, _ => wikiOverlay.ShowPage(path));
|
||||
|
||||
/// <summary>
|
||||
/// Show changelog listing overlay
|
||||
/// </summary>
|
||||
public void ShowChangelogListing() => waitForReady(() => changelogOverlay, _ => changelogOverlay.ShowListing());
|
||||
|
||||
/// <summary>
|
||||
/// Show changelog's build as an overlay
|
||||
/// </summary>
|
||||
/// <param name="updateStream">The update stream name</param>
|
||||
/// <param name="version">The build version of the update stream</param>
|
||||
public void ShowChangelogBuild(string updateStream, string version) => waitForReady(() => changelogOverlay, _ => changelogOverlay.ShowBuild(updateStream, version));
|
||||
|
||||
/// <summary>
|
||||
/// Present a beatmap at song select immediately.
|
||||
/// The user should have already requested this interactively.
|
||||
@ -769,7 +787,7 @@ namespace osu.Game
|
||||
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(new MessageNotifier(), AddInternal, true);
|
||||
loadComponentSingleFile(Settings = new SettingsOverlay(), leftFloatingOverlayContent.Add, true);
|
||||
var changelogOverlay = loadComponentSingleFile(new ChangelogOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(changelogOverlay = new ChangelogOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(wikiOverlay = new WikiOverlay(), overlayContent.Add, true);
|
||||
@ -842,6 +860,19 @@ namespace osu.Game
|
||||
{
|
||||
if (mode.NewValue != OverlayActivation.All) CloseAllOverlays();
|
||||
};
|
||||
|
||||
// Importantly, this should be run after binding PostNotification to the import handlers so they can present the import after game startup.
|
||||
handleStartupImport();
|
||||
}
|
||||
|
||||
private void handleStartupImport()
|
||||
{
|
||||
if (args?.Length > 0)
|
||||
{
|
||||
var paths = args.Where(a => !a.StartsWith('-')).ToArray();
|
||||
if (paths.Length > 0)
|
||||
Task.Run(() => Import(paths));
|
||||
}
|
||||
}
|
||||
|
||||
private void showOverlayAboveOthers(OverlayContainer overlay, OverlayContainer[] otherOverlays)
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
@ -410,11 +411,28 @@ namespace osu.Game
|
||||
{
|
||||
Logger.Log($@"Migrating osu! data from ""{Storage.GetFullPath(string.Empty)}"" to ""{path}""...");
|
||||
|
||||
using (realmFactory.BlockAllOperations())
|
||||
IDisposable realmBlocker = null;
|
||||
|
||||
try
|
||||
{
|
||||
contextFactory.FlushConnections();
|
||||
ManualResetEventSlim readyToRun = new ManualResetEventSlim();
|
||||
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
realmBlocker = realmFactory.BlockAllOperations();
|
||||
contextFactory.FlushConnections();
|
||||
|
||||
readyToRun.Set();
|
||||
}, false);
|
||||
|
||||
readyToRun.Wait();
|
||||
|
||||
(Storage as OsuStorage)?.Migrate(Host.GetStorage(path));
|
||||
}
|
||||
finally
|
||||
{
|
||||
realmBlocker?.Dispose();
|
||||
}
|
||||
|
||||
Logger.Log(@"Migration complete!");
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace osu.Game.Overlays.OSD
|
||||
private Sample sampleChange;
|
||||
|
||||
public TrackedSettingToast(SettingDescription description)
|
||||
: base(description.Name, description.Value, description.Shortcut)
|
||||
: base(description.Name.ToString(), description.Value.ToString(), description.Shortcut.ToString())
|
||||
{
|
||||
FillFlowContainer<OptionLight> optionLights;
|
||||
|
||||
|
@ -14,10 +14,7 @@ namespace osu.Game.Overlays.Settings
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BackgroundColour = colours.Pink;
|
||||
|
||||
Triangles.ColourDark = colours.PinkDark;
|
||||
Triangles.ColourLight = colours.PinkLight;
|
||||
BackgroundColour = colours.Pink3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
|
||||
{
|
||||
dropdown = new AudioDeviceSettingsDropdown
|
||||
{
|
||||
LabelText = AudioSettingsStrings.OutputDevice,
|
||||
Keywords = new[] { "speaker", "headphone", "output" }
|
||||
}
|
||||
};
|
||||
|
@ -0,0 +1,34 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.Gameplay
|
||||
{
|
||||
public class AudioSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => GameplaySettingsStrings.AudioHeader;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.PositionalHitsounds,
|
||||
Current = config.GetBindable<bool>(OsuSetting.PositionalHitSounds)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.AlwaysPlayFirstComboBreak,
|
||||
Current = config.GetBindable<bool>(OsuSetting.AlwaysPlayFirstComboBreak)
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.Gameplay
|
||||
{
|
||||
public class BackgroundSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => GameplaySettingsStrings.BackgroundHeader;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsSlider<double>
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.BackgroundDim,
|
||||
Current = config.GetBindable<double>(OsuSetting.DimLevel),
|
||||
KeyboardStep = 0.01f,
|
||||
DisplayAsPercentage = true
|
||||
},
|
||||
new SettingsSlider<double>
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.BackgroundBlur,
|
||||
Current = config.GetBindable<double>(OsuSetting.BlurLevel),
|
||||
KeyboardStep = 0.01f,
|
||||
DisplayAsPercentage = true
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.LightenDuringBreaks,
|
||||
Current = config.GetBindable<bool>(OsuSetting.LightenDuringBreaks)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.FadePlayfieldWhenHealthLow,
|
||||
Current = config.GetBindable<bool>(OsuSetting.FadePlayfieldWhenHealthLow),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.Gameplay
|
||||
{
|
||||
public class BeatmapSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => GameplaySettingsStrings.BeatmapHeader;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = SkinSettingsStrings.BeatmapSkins,
|
||||
Current = config.GetBindable<bool>(OsuSetting.BeatmapSkins)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = SkinSettingsStrings.BeatmapColours,
|
||||
Current = config.GetBindable<bool>(OsuSetting.BeatmapColours)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = SkinSettingsStrings.BeatmapHitsounds,
|
||||
Current = config.GetBindable<bool>(OsuSetting.BeatmapHitsounds)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GraphicsSettingsStrings.StoryboardVideo,
|
||||
Current = config.GetBindable<bool>(OsuSetting.ShowStoryboard)
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
@ -20,77 +19,18 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsSlider<double>
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.BackgroundDim,
|
||||
Current = config.GetBindable<double>(OsuSetting.DimLevel),
|
||||
KeyboardStep = 0.01f,
|
||||
DisplayAsPercentage = true
|
||||
},
|
||||
new SettingsSlider<double>
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.BackgroundBlur,
|
||||
Current = config.GetBindable<double>(OsuSetting.BlurLevel),
|
||||
KeyboardStep = 0.01f,
|
||||
DisplayAsPercentage = true
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.LightenDuringBreaks,
|
||||
Current = config.GetBindable<bool>(OsuSetting.LightenDuringBreaks)
|
||||
},
|
||||
new SettingsEnumDropdown<HUDVisibilityMode>
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.HUDVisibilityMode,
|
||||
Current = config.GetBindable<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.ShowDifficultyGraph,
|
||||
Current = config.GetBindable<bool>(OsuSetting.ShowProgressGraph)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.ShowHealthDisplayWhenCantFail,
|
||||
Current = config.GetBindable<bool>(OsuSetting.ShowHealthDisplayWhenCantFail),
|
||||
Keywords = new[] { "hp", "bar" }
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.FadePlayfieldWhenHealthLow,
|
||||
Current = config.GetBindable<bool>(OsuSetting.FadePlayfieldWhenHealthLow),
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.AlwaysShowKeyOverlay,
|
||||
Current = config.GetBindable<bool>(OsuSetting.KeyOverlay)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.PositionalHitsounds,
|
||||
Current = config.GetBindable<bool>(OsuSetting.PositionalHitSounds)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.AlwaysPlayFirstComboBreak,
|
||||
Current = config.GetBindable<bool>(OsuSetting.AlwaysPlayFirstComboBreak)
|
||||
},
|
||||
new SettingsEnumDropdown<ScoringMode>
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.ScoreDisplayMode,
|
||||
Current = config.GetBindable<ScoringMode>(OsuSetting.ScoreDisplayMode),
|
||||
Keywords = new[] { "scoring" }
|
||||
},
|
||||
};
|
||||
|
||||
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
||||
{
|
||||
Add(new SettingsCheckbox
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.DisableWinKey,
|
||||
Current = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey)
|
||||
});
|
||||
}
|
||||
LabelText = GraphicsSettingsStrings.HitLighting,
|
||||
Current = config.GetBindable<bool>(OsuSetting.HitLighting)
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
osu.Game/Overlays/Settings/Sections/Gameplay/HUDSettings.cs
Normal file
45
osu.Game/Overlays/Settings/Sections/Gameplay/HUDSettings.cs
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.Gameplay
|
||||
{
|
||||
public class HUDSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => GameplaySettingsStrings.HUDHeader;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsEnumDropdown<HUDVisibilityMode>
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.HUDVisibilityMode,
|
||||
Current = config.GetBindable<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.ShowDifficultyGraph,
|
||||
Current = config.GetBindable<bool>(OsuSetting.ShowProgressGraph)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.ShowHealthDisplayWhenCantFail,
|
||||
Current = config.GetBindable<bool>(OsuSetting.ShowHealthDisplayWhenCantFail),
|
||||
Keywords = new[] { "hp", "bar" }
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.AlwaysShowKeyOverlay,
|
||||
Current = config.GetBindable<bool>(OsuSetting.KeyOverlay)
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.Gameplay
|
||||
{
|
||||
public class InputSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => GameplaySettingsStrings.InputHeader;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsSlider<float, SizeSlider>
|
||||
{
|
||||
LabelText = SkinSettingsStrings.GameplayCursorSize,
|
||||
Current = config.GetBindable<float>(OsuSetting.GameplayCursorSize),
|
||||
KeyboardStep = 0.01f
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = SkinSettingsStrings.AutoCursorSize,
|
||||
Current = config.GetBindable<bool>(OsuSetting.AutoCursorSize)
|
||||
},
|
||||
};
|
||||
|
||||
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
||||
{
|
||||
Add(new SettingsCheckbox
|
||||
{
|
||||
LabelText = GameplaySettingsStrings.DisableWinKey,
|
||||
Current = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,11 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Overlays.Settings.Sections.Gameplay;
|
||||
using osu.Game.Rulesets;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Overlays.Settings.Sections.Gameplay;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections
|
||||
{
|
||||
@ -20,7 +15,7 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
|
||||
public override Drawable CreateIcon() => new SpriteIcon
|
||||
{
|
||||
Icon = FontAwesome.Regular.Circle
|
||||
Icon = FontAwesome.Regular.DotCircle
|
||||
};
|
||||
|
||||
public GameplaySection()
|
||||
@ -28,27 +23,13 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new GeneralSettings(),
|
||||
new AudioSettings(),
|
||||
new BeatmapSettings(),
|
||||
new BackgroundSettings(),
|
||||
new HUDSettings(),
|
||||
new InputSettings(),
|
||||
new ModsSettings(),
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(RulesetStore rulesets)
|
||||
{
|
||||
foreach (Ruleset ruleset in rulesets.AvailableRulesets.Select(info => info.CreateInstance()))
|
||||
{
|
||||
try
|
||||
{
|
||||
SettingsSubsection section = ruleset.CreateSettings();
|
||||
|
||||
if (section != null)
|
||||
Add(section);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, "Failed to load ruleset settings");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,25 +9,15 @@ using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||
{
|
||||
public class DetailSettings : SettingsSubsection
|
||||
public class ScreenshotSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => GraphicsSettingsStrings.DetailSettingsHeader;
|
||||
protected override LocalisableString Header => GraphicsSettingsStrings.Screenshots;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GraphicsSettingsStrings.StoryboardVideo,
|
||||
Current = config.GetBindable<bool>(OsuSetting.ShowStoryboard)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GraphicsSettingsStrings.HitLighting,
|
||||
Current = config.GetBindable<bool>(OsuSetting.HitLighting)
|
||||
},
|
||||
new SettingsEnumDropdown<ScreenshotFormat>
|
||||
{
|
||||
LabelText = GraphicsSettingsStrings.ScreenshotFormat,
|
@ -22,9 +22,9 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new RendererSettings(),
|
||||
new LayoutSettings(),
|
||||
new DetailSettings(),
|
||||
new RendererSettings(),
|
||||
new ScreenshotSettings(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Localisation;
|
||||
@ -59,7 +58,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
}
|
||||
}
|
||||
|
||||
public class ResetButton : DangerousTriangleButton
|
||||
public class ResetButton : DangerousSettingsButton
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -8,16 +9,24 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Handlers.Tablet;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
{
|
||||
internal class RotationPresetButtons : FillFlowContainer
|
||||
internal class RotationPresetButtons : CompositeDrawable
|
||||
{
|
||||
public new MarginPadding Padding
|
||||
{
|
||||
get => base.Padding;
|
||||
set => base.Padding = value;
|
||||
}
|
||||
|
||||
private readonly ITabletHandler tabletHandler;
|
||||
|
||||
private Bindable<float> rotation;
|
||||
private readonly RotationButton[] rotationPresets = new RotationButton[preset_count];
|
||||
|
||||
private const int preset_count = 4;
|
||||
private const int height = 50;
|
||||
|
||||
public RotationPresetButtons(ITabletHandler tabletHandler)
|
||||
@ -27,18 +36,39 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = height;
|
||||
|
||||
for (int i = 0; i < 360; i += 90)
|
||||
IEnumerable<Dimension> createColumns(int count)
|
||||
{
|
||||
var presetRotation = i;
|
||||
|
||||
Add(new RotationButton(i)
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = height,
|
||||
Width = 0.25f,
|
||||
Text = $@"{presetRotation}º",
|
||||
Action = () => tabletHandler.Rotation.Value = presetRotation,
|
||||
});
|
||||
if (i > 0)
|
||||
yield return new Dimension(GridSizeMode.Absolute, 10);
|
||||
|
||||
yield return new Dimension();
|
||||
}
|
||||
}
|
||||
|
||||
GridContainer grid;
|
||||
|
||||
InternalChild = grid = new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ColumnDimensions = createColumns(preset_count).ToArray()
|
||||
};
|
||||
|
||||
grid.Content = new[] { new Drawable[preset_count * 2 - 1] };
|
||||
|
||||
for (int i = 0; i < preset_count; i++)
|
||||
{
|
||||
var rotationValue = i * 90;
|
||||
|
||||
var rotationPreset = new RotationButton(rotationValue)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Height = 1,
|
||||
Text = $@"{rotationValue}º",
|
||||
Action = () => tabletHandler.Rotation.Value = rotationValue,
|
||||
};
|
||||
grid.Content[0][2 * i] = rotationPresets[i] = rotationPreset;
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,16 +79,19 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
rotation = tabletHandler.Rotation.GetBoundCopy();
|
||||
rotation.BindValueChanged(val =>
|
||||
{
|
||||
foreach (var b in Children.OfType<RotationButton>())
|
||||
foreach (var b in rotationPresets)
|
||||
b.IsSelected = b.Preset == val.NewValue;
|
||||
}, true);
|
||||
}
|
||||
|
||||
public class RotationButton : TriangleButton
|
||||
public class RotationButton : RoundedButton
|
||||
{
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OverlayColourProvider colourProvider { get; set; }
|
||||
|
||||
public readonly int Preset;
|
||||
|
||||
public RotationButton(int preset)
|
||||
@ -91,18 +124,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
|
||||
private void updateColour()
|
||||
{
|
||||
if (isSelected)
|
||||
{
|
||||
BackgroundColour = colours.BlueDark;
|
||||
Triangles.ColourDark = colours.BlueDarker;
|
||||
Triangles.ColourLight = colours.Blue;
|
||||
}
|
||||
else
|
||||
{
|
||||
BackgroundColour = colours.Gray4;
|
||||
Triangles.ColourDark = colours.Gray5;
|
||||
Triangles.ColourLight = colours.Gray6;
|
||||
}
|
||||
BackgroundColour = isSelected ? colours.Blue3 : colourProvider.Background3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Skinning;
|
||||
@ -21,15 +20,15 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||
{
|
||||
protected override LocalisableString Header => "General";
|
||||
|
||||
private TriangleButton importBeatmapsButton;
|
||||
private TriangleButton importScoresButton;
|
||||
private TriangleButton importSkinsButton;
|
||||
private TriangleButton importCollectionsButton;
|
||||
private TriangleButton deleteBeatmapsButton;
|
||||
private TriangleButton deleteScoresButton;
|
||||
private TriangleButton deleteSkinsButton;
|
||||
private TriangleButton restoreButton;
|
||||
private TriangleButton undeleteButton;
|
||||
private SettingsButton importBeatmapsButton;
|
||||
private SettingsButton importScoresButton;
|
||||
private SettingsButton importSkinsButton;
|
||||
private SettingsButton importCollectionsButton;
|
||||
private SettingsButton deleteBeatmapsButton;
|
||||
private SettingsButton deleteScoresButton;
|
||||
private SettingsButton deleteSkinsButton;
|
||||
private SettingsButton restoreButton;
|
||||
private SettingsButton undeleteButton;
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, [CanBeNull] CollectionManager collectionManager, [CanBeNull] StableImportManager stableImportManager, DialogOverlay dialogOverlay)
|
||||
|
44
osu.Game/Overlays/Settings/Sections/RulesetSection.cs
Normal file
44
osu.Game/Overlays/Settings/Sections/RulesetSection.cs
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections
|
||||
{
|
||||
public class RulesetSection : SettingsSection
|
||||
{
|
||||
public override LocalisableString Header => RulesetSettingsStrings.Rulesets;
|
||||
|
||||
public override Drawable CreateIcon() => new SpriteIcon
|
||||
{
|
||||
Icon = FontAwesome.Solid.Chess
|
||||
};
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(RulesetStore rulesets)
|
||||
{
|
||||
foreach (Ruleset ruleset in rulesets.AvailableRulesets.Select(info => info.CreateInstance()))
|
||||
{
|
||||
try
|
||||
{
|
||||
SettingsSubsection section = ruleset.CreateSettings();
|
||||
|
||||
if (section != null)
|
||||
Add(section);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, "Failed to load ruleset settings");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -64,39 +64,16 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
skinDropdown = new SkinSettingsDropdown(),
|
||||
skinDropdown = new SkinSettingsDropdown
|
||||
{
|
||||
LabelText = SkinSettingsStrings.CurrentSkin
|
||||
},
|
||||
new SettingsButton
|
||||
{
|
||||
Text = SkinSettingsStrings.SkinLayoutEditor,
|
||||
Action = () => skinEditor?.Toggle(),
|
||||
},
|
||||
new ExportSkinButton(),
|
||||
new SettingsSlider<float, SizeSlider>
|
||||
{
|
||||
LabelText = SkinSettingsStrings.GameplayCursorSize,
|
||||
Current = config.GetBindable<float>(OsuSetting.GameplayCursorSize),
|
||||
KeyboardStep = 0.01f
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = SkinSettingsStrings.AutoCursorSize,
|
||||
Current = config.GetBindable<bool>(OsuSetting.AutoCursorSize)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = SkinSettingsStrings.BeatmapSkins,
|
||||
Current = config.GetBindable<bool>(OsuSetting.BeatmapSkins)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = SkinSettingsStrings.BeatmapColours,
|
||||
Current = config.GetBindable<bool>(OsuSetting.BeatmapColours)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = SkinSettingsStrings.BeatmapHitsounds,
|
||||
Current = config.GetBindable<bool>(OsuSetting.BeatmapHitsounds)
|
||||
},
|
||||
};
|
||||
|
||||
managerUpdated = skins.ItemUpdated.GetBoundCopy();
|
||||
|
@ -6,11 +6,11 @@ using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
|
||||
namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
public class SettingsButton : TriangleButton, IHasTooltip
|
||||
public class SettingsButton : RoundedButton, IHasTooltip
|
||||
{
|
||||
public SettingsButton()
|
||||
{
|
||||
|
@ -24,12 +24,13 @@ namespace osu.Game.Overlays
|
||||
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
|
||||
{
|
||||
new GeneralSection(),
|
||||
new GraphicsSection(),
|
||||
new AudioSection(),
|
||||
new SkinSection(),
|
||||
new InputSection(createSubPanel(new KeyBindingPanel())),
|
||||
new UserInterfaceSection(),
|
||||
new GameplaySection(),
|
||||
new SkinSection(),
|
||||
new RulesetSection(),
|
||||
new AudioSection(),
|
||||
new GraphicsSection(),
|
||||
new OnlineSection(),
|
||||
new MaintenanceSection(),
|
||||
new DebugSection(),
|
||||
|
@ -55,7 +55,10 @@ namespace osu.Game.Rulesets.UI
|
||||
/// <summary>
|
||||
/// The current direction of playback to be exposed to frame stable children.
|
||||
/// </summary>
|
||||
private int direction;
|
||||
/// <remarks>
|
||||
/// Initially it is presumed that playback will proceed in the forward direction.
|
||||
/// </remarks>
|
||||
private int direction = 1;
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(GameplayClock clock, ISamplePlaybackDisabler sampleDisabler)
|
||||
@ -139,7 +142,9 @@ namespace osu.Game.Rulesets.UI
|
||||
state = PlaybackState.NotValid;
|
||||
}
|
||||
|
||||
if (state == PlaybackState.Valid)
|
||||
// if the proposed time is the same as the current time, assume that the clock will continue progressing in the same direction as previously.
|
||||
// this avoids spurious flips in direction from -1 to 1 during rewinds.
|
||||
if (state == PlaybackState.Valid && proposedTime != manualClock.CurrentTime)
|
||||
direction = proposedTime >= manualClock.CurrentTime ? 1 : -1;
|
||||
|
||||
double timeBehind = Math.Abs(proposedTime - parentGameplayClock.CurrentTime);
|
||||
|
@ -72,9 +72,12 @@ namespace osu.Game.Scoring
|
||||
}
|
||||
}
|
||||
|
||||
// We're calling .Result, but this should not be a blocking call due to the above GetDifficultyAsync() calls.
|
||||
return scores.OrderByDescending(s => GetTotalScoreAsync(s, cancellationToken: cancellationToken).Result)
|
||||
.ThenBy(s => s.OnlineScoreID)
|
||||
var totalScores = await Task.WhenAll(scores.Select(s => GetTotalScoreAsync(s, cancellationToken: cancellationToken))).ConfigureAwait(false);
|
||||
|
||||
return scores.Select((score, index) => (score, totalScore: totalScores[index]))
|
||||
.OrderByDescending(g => g.totalScore)
|
||||
.ThenBy(g => g.score.OnlineScoreID)
|
||||
.Select(g => g.score)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
@ -116,8 +116,6 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
if (ignoredRooms.Contains(room.RoomID.Value.Value))
|
||||
return;
|
||||
|
||||
room.Position.Value = -room.RoomID.Value.Value;
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var pi in room.Playlist)
|
||||
|
@ -129,7 +129,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
private void updateSorting()
|
||||
{
|
||||
foreach (var room in roomFlow)
|
||||
roomFlow.SetLayoutPosition(room, room.Room.Position.Value);
|
||||
roomFlow.SetLayoutPosition(room, -(room.Room.RoomID.Value ?? 0));
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
/// <summary>
|
||||
/// Manage the animation to be applied when a player fails.
|
||||
/// Single file; automatically disposed after use.
|
||||
/// Single use and automatically disposed after use.
|
||||
/// </summary>
|
||||
public class FailAnimation : CompositeDrawable
|
||||
{
|
||||
|
@ -11,7 +11,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
public class DefaultScoreCounter : GameplayScoreCounter, ISkinnableDrawable
|
||||
{
|
||||
public DefaultScoreCounter()
|
||||
: base(6)
|
||||
{
|
||||
Anchor = Anchor.TopCentre;
|
||||
Origin = Anchor.TopCentre;
|
||||
|
@ -14,8 +14,8 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
private Bindable<ScoringMode> scoreDisplayMode;
|
||||
|
||||
protected GameplayScoreCounter(int leading = 0, bool useCommaSeparator = false)
|
||||
: base(leading, useCommaSeparator)
|
||||
protected GameplayScoreCounter()
|
||||
: base(6)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,9 @@
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -148,7 +146,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
Score2Text.X = Math.Max(5 + Score2Text.DrawWidth / 2, score2Bar.DrawWidth);
|
||||
}
|
||||
|
||||
protected class MatchScoreCounter : ScoreCounter
|
||||
protected class MatchScoreCounter : CommaSeparatedScoreCounter
|
||||
{
|
||||
private OsuSpriteText displayedSpriteText;
|
||||
|
||||
@ -173,8 +171,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
=> displayedSpriteText.Font = winning
|
||||
? OsuFont.Torus.With(weight: FontWeight.Bold, size: font_size, fixedWidth: true)
|
||||
: OsuFont.Torus.With(weight: FontWeight.Regular, size: font_size * 0.8f, fixedWidth: true);
|
||||
|
||||
protected override LocalisableString FormatCount(double count) => count.ToLocalisableString(@"N0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -947,7 +947,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public override void OnSuspending(IScreen next)
|
||||
{
|
||||
screenSuspension?.Expire();
|
||||
screenSuspension?.RemoveAndDisposeImmediately();
|
||||
|
||||
fadeOut();
|
||||
base.OnSuspending(next);
|
||||
@ -955,7 +955,8 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
screenSuspension?.Expire();
|
||||
screenSuspension?.RemoveAndDisposeImmediately();
|
||||
failAnimation?.RemoveAndDisposeImmediately();
|
||||
|
||||
// if arriving here and the results screen preparation task hasn't run, it's safe to say the user has not completed the beatmap.
|
||||
if (prepareScoreForDisplayTask == null)
|
||||
|
@ -35,6 +35,8 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
protected const float BACKGROUND_BLUR = 15;
|
||||
|
||||
private const double content_out_duration = 300;
|
||||
|
||||
public override bool HideOverlaysOnEnter => hideOverlays;
|
||||
|
||||
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
||||
@ -135,36 +137,39 @@ namespace osu.Game.Screens.Play
|
||||
muteWarningShownOnce = sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce);
|
||||
batteryWarningShownOnce = sessionStatics.GetBindable<bool>(Static.LowBatteryNotificationShownOnce);
|
||||
|
||||
InternalChild = (content = new LogoTrackingContainer
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}).WithChildren(new Drawable[]
|
||||
{
|
||||
MetadataInfo = new BeatmapMetadataDisplay(Beatmap.Value, Mods, content.LogoFacade)
|
||||
(content = new LogoTrackingContainer
|
||||
{
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
},
|
||||
PlayerSettings = new FillFlowContainer<PlayerSettingsGroup>
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}).WithChildren(new Drawable[]
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 20),
|
||||
Margin = new MarginPadding(25),
|
||||
Children = new PlayerSettingsGroup[]
|
||||
MetadataInfo = new BeatmapMetadataDisplay(Beatmap.Value, Mods, content.LogoFacade)
|
||||
{
|
||||
VisualSettings = new VisualSettings(),
|
||||
new InputSettings()
|
||||
}
|
||||
},
|
||||
idleTracker = new IdleTracker(750),
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
},
|
||||
PlayerSettings = new FillFlowContainer<PlayerSettingsGroup>
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 20),
|
||||
Margin = new MarginPadding(25),
|
||||
Children = new PlayerSettingsGroup[]
|
||||
{
|
||||
VisualSettings = new VisualSettings(),
|
||||
new InputSettings()
|
||||
}
|
||||
},
|
||||
idleTracker = new IdleTracker(750),
|
||||
}),
|
||||
lowPassFilter = new AudioFilter(audio.TrackMixer)
|
||||
});
|
||||
};
|
||||
|
||||
if (Beatmap.Value.BeatmapInfo.EpilepsyWarning)
|
||||
{
|
||||
@ -195,7 +200,6 @@ namespace osu.Game.Screens.Play
|
||||
epilepsyWarning.DimmableBackground = b;
|
||||
});
|
||||
|
||||
lowPassFilter.CutoffTo(500, 100, Easing.OutCubic);
|
||||
Beatmap.Value.Track.AddAdjustment(AdjustableProperty.Volume, volumeAdjustment);
|
||||
|
||||
content.ScaleTo(0.7f);
|
||||
@ -240,15 +244,15 @@ namespace osu.Game.Screens.Play
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
cancelLoad();
|
||||
contentOut();
|
||||
|
||||
content.ScaleTo(0.7f, 150, Easing.InQuint);
|
||||
this.FadeOut(150);
|
||||
// Ensure the screen doesn't expire until all the outwards fade operations have completed.
|
||||
this.Delay(content_out_duration).FadeOut();
|
||||
|
||||
ApplyToBackground(b => b.IgnoreUserSettings.Value = true);
|
||||
|
||||
BackgroundBrightnessReduction = false;
|
||||
Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment);
|
||||
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, 100, Easing.InCubic);
|
||||
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
@ -344,6 +348,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
content.FadeInFromZero(400);
|
||||
content.ScaleTo(1, 650, Easing.OutQuint).Then().Schedule(prepareNewPlayer);
|
||||
lowPassFilter.CutoffTo(1000, 650, Easing.OutQuint);
|
||||
|
||||
ApplyToBackground(b => b?.FadeColour(Color4.White, 800, Easing.OutQuint));
|
||||
}
|
||||
@ -353,8 +358,9 @@ namespace osu.Game.Screens.Play
|
||||
// Ensure the logo is no longer tracking before we scale the content
|
||||
content.StopTracking();
|
||||
|
||||
content.ScaleTo(0.7f, 300, Easing.InQuint);
|
||||
content.FadeOut(250);
|
||||
content.ScaleTo(0.7f, content_out_duration * 2, Easing.OutQuint);
|
||||
content.FadeOut(content_out_duration, Easing.OutQuint);
|
||||
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, content_out_duration);
|
||||
}
|
||||
|
||||
private void pushWhenLoaded()
|
||||
@ -381,7 +387,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
contentOut();
|
||||
|
||||
TransformSequence<PlayerLoader> pushSequence = this.Delay(250);
|
||||
TransformSequence<PlayerLoader> pushSequence = this.Delay(content_out_duration);
|
||||
|
||||
// only show if the warning was created (i.e. the beatmap needs it)
|
||||
// and this is not a restart of the map (the warning expires after first load).
|
||||
@ -400,6 +406,11 @@ namespace osu.Game.Screens.Play
|
||||
})
|
||||
.Delay(EpilepsyWarning.FADE_DURATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This goes hand-in-hand with the restoration of low pass filter in contentOut().
|
||||
this.TransformBindableTo(volumeAdjustment, 0, content_out_duration, Easing.OutCubic);
|
||||
}
|
||||
|
||||
pushSequence.Schedule(() =>
|
||||
{
|
||||
|
@ -12,6 +12,9 @@ namespace osu.Game.Skinning
|
||||
/// </summary>
|
||||
public interface ISkinSource : ISkin
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired whenever a source change occurs, signalling that consumers should re-query as required.
|
||||
/// </summary>
|
||||
event Action SourceChanged;
|
||||
|
||||
/// <summary>
|
||||
|
@ -16,7 +16,6 @@ namespace osu.Game.Skinning
|
||||
public bool UsesFixedAnchor { get; set; }
|
||||
|
||||
public LegacyScoreCounter()
|
||||
: base(6)
|
||||
{
|
||||
Anchor = Anchor.TopRight;
|
||||
Origin = Anchor.TopRight;
|
||||
|
@ -58,10 +58,8 @@ namespace osu.Game.Skinning
|
||||
return base.CreateChildDependencies(parent);
|
||||
}
|
||||
|
||||
protected override void OnSourceChanged()
|
||||
protected override void RefreshSources()
|
||||
{
|
||||
ResetSources();
|
||||
|
||||
// Populate a local list first so we can adjust the returned order as we go.
|
||||
var sources = new List<ISkin>();
|
||||
|
||||
@ -91,8 +89,7 @@ namespace osu.Game.Skinning
|
||||
else
|
||||
sources.Add(rulesetResourcesSkin);
|
||||
|
||||
foreach (var skin in sources)
|
||||
AddSource(skin);
|
||||
SetSources(sources);
|
||||
}
|
||||
|
||||
protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio.Sample;
|
||||
@ -40,10 +41,12 @@ namespace osu.Game.Skinning
|
||||
|
||||
protected virtual bool AllowColourLookup => true;
|
||||
|
||||
private readonly object sourceSetLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// A dictionary mapping each <see cref="ISkin"/> source to a wrapper which handles lookup allowances.
|
||||
/// </summary>
|
||||
private readonly List<(ISkin skin, DisableableSkinSource wrapped)> skinSources = new List<(ISkin, DisableableSkinSource)>();
|
||||
private (ISkin skin, DisableableSkinSource wrapped)[] skinSources = Array.Empty<(ISkin skin, DisableableSkinSource wrapped)>();
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="SkinProvidingContainer"/> initialised with a single skin source.
|
||||
@ -52,7 +55,7 @@ namespace osu.Game.Skinning
|
||||
: this()
|
||||
{
|
||||
if (skin != null)
|
||||
AddSource(skin);
|
||||
SetSources(new[] { skin });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -168,49 +171,42 @@ namespace osu.Game.Skinning
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new skin to this provider. Will be added to the end of the lookup order precedence.
|
||||
/// Replace the sources used for lookups in this container.
|
||||
/// </summary>
|
||||
/// <param name="skin">The skin to add.</param>
|
||||
protected void AddSource(ISkin skin)
|
||||
/// <remarks>
|
||||
/// This does not implicitly fire a <see cref="SourceChanged"/> event. Consider calling <see cref="TriggerSourceChanged"/> if required.
|
||||
/// </remarks>
|
||||
/// <param name="sources">The new sources.</param>
|
||||
protected void SetSources(IEnumerable<ISkin> sources)
|
||||
{
|
||||
skinSources.Add((skin, new DisableableSkinSource(skin, this)));
|
||||
lock (sourceSetLock)
|
||||
{
|
||||
foreach (var skin in skinSources)
|
||||
{
|
||||
if (skin.skin is ISkinSource source)
|
||||
source.SourceChanged -= TriggerSourceChanged;
|
||||
}
|
||||
|
||||
if (skin is ISkinSource source)
|
||||
source.SourceChanged += TriggerSourceChanged;
|
||||
skinSources = sources.Select(skin => (skin, new DisableableSkinSource(skin, this))).ToArray();
|
||||
|
||||
foreach (var skin in skinSources)
|
||||
{
|
||||
if (skin.skin is ISkinSource source)
|
||||
source.SourceChanged += TriggerSourceChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a skin from this provider.
|
||||
/// </summary>
|
||||
/// <param name="skin">The skin to remove.</param>
|
||||
protected void RemoveSource(ISkin skin)
|
||||
{
|
||||
if (skinSources.RemoveAll(s => s.skin == skin) == 0)
|
||||
return;
|
||||
|
||||
if (skin is ISkinSource source)
|
||||
source.SourceChanged -= TriggerSourceChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all skin sources.
|
||||
/// </summary>
|
||||
protected void ResetSources()
|
||||
{
|
||||
foreach (var i in skinSources.ToArray())
|
||||
RemoveSource(i.skin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when any source has changed (either <see cref="ParentSource"/> or a source registered via <see cref="AddSource"/>).
|
||||
/// Invoked after any consumed source change, before the external <see cref="SourceChanged"/> event is fired.
|
||||
/// This is also invoked once initially during <see cref="CreateChildDependencies"/> to ensure sources are ready for children consumption.
|
||||
/// </summary>
|
||||
protected virtual void OnSourceChanged() { }
|
||||
protected virtual void RefreshSources() { }
|
||||
|
||||
protected void TriggerSourceChanged()
|
||||
{
|
||||
// Expose to implementations, giving them a chance to react before notifying external consumers.
|
||||
OnSourceChanged();
|
||||
RefreshSources();
|
||||
|
||||
SourceChanged?.Invoke();
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
@ -22,6 +23,8 @@ namespace osu.Game.Skinning
|
||||
|
||||
public bool ComponentsLoaded { get; private set; }
|
||||
|
||||
private CancellationTokenSource cancellationSource;
|
||||
|
||||
public SkinnableTargetContainer(SkinnableTarget target)
|
||||
{
|
||||
Target = target;
|
||||
@ -38,6 +41,9 @@ namespace osu.Game.Skinning
|
||||
|
||||
content = CurrentSkin.GetDrawableComponent(new SkinnableTargetComponent(Target)) as SkinnableTargetComponentsContainer;
|
||||
|
||||
cancellationSource?.Cancel();
|
||||
cancellationSource = null;
|
||||
|
||||
if (content != null)
|
||||
{
|
||||
LoadComponentAsync(content, wrapper =>
|
||||
@ -45,7 +51,7 @@ namespace osu.Game.Skinning
|
||||
AddInternal(wrapper);
|
||||
components.AddRange(wrapper.Children.OfType<ISkinnableDrawable>());
|
||||
ComponentsLoaded = true;
|
||||
});
|
||||
}, (cancellationSource = new CancellationTokenSource()).Token);
|
||||
}
|
||||
else
|
||||
ComponentsLoaded = true;
|
||||
|
116
osu.Game/Stores/RealmFileStore.cs
Normal file
116
osu.Game/Stores/RealmFileStore.cs
Normal file
@ -0,0 +1,116 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Models;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Stores
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the storing of files to the file system (and database) backing.
|
||||
/// </summary>
|
||||
[ExcludeFromDynamicCompile]
|
||||
public class RealmFileStore
|
||||
{
|
||||
private readonly RealmContextFactory realmFactory;
|
||||
|
||||
public readonly IResourceStore<byte[]> Store;
|
||||
|
||||
public readonly Storage Storage;
|
||||
|
||||
public RealmFileStore(RealmContextFactory realmFactory, Storage storage)
|
||||
{
|
||||
this.realmFactory = realmFactory;
|
||||
|
||||
Storage = storage.GetStorageForDirectory(@"files");
|
||||
Store = new StorageBackedResourceStore(Storage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new file to the game-wide database, copying it to permanent storage if not already present.
|
||||
/// </summary>
|
||||
/// <param name="data">The file data stream.</param>
|
||||
/// <param name="realm">The realm instance to add to. Should already be in a transaction.</param>
|
||||
/// <returns></returns>
|
||||
public RealmFile Add(Stream data, Realm realm)
|
||||
{
|
||||
string hash = data.ComputeSHA2Hash();
|
||||
|
||||
var existing = realm.Find<RealmFile>(hash);
|
||||
|
||||
var file = existing ?? new RealmFile { Hash = hash };
|
||||
|
||||
if (!checkFileExistsAndMatchesHash(file))
|
||||
copyToStore(file, data);
|
||||
|
||||
if (!file.IsManaged)
|
||||
realm.Add(file);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
private void copyToStore(RealmFile file, Stream data)
|
||||
{
|
||||
data.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
using (var output = Storage.GetStream(file.StoragePath, FileAccess.Write))
|
||||
data.CopyTo(output);
|
||||
|
||||
data.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
private bool checkFileExistsAndMatchesHash(RealmFile file)
|
||||
{
|
||||
string path = file.StoragePath;
|
||||
|
||||
// we may be re-adding a file to fix missing store entries.
|
||||
if (!Storage.Exists(path))
|
||||
return false;
|
||||
|
||||
// even if the file already exists, check the existing checksum for safety.
|
||||
using (var stream = Storage.GetStream(path))
|
||||
return stream.ComputeSHA2Hash() == file.Hash;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
|
||||
// can potentially be run asynchronously, although we will need to consider operation order for disk deletion vs realm removal.
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
// TODO: consider using a realm native query to avoid iterating all files (https://github.com/realm/realm-dotnet/issues/2659#issuecomment-927823707)
|
||||
var files = realm.All<RealmFile>().ToList();
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (file.BacklinksCount > 0)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
Storage.Delete(file.StoragePath);
|
||||
realm.Remove(file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, $@"Could not delete databased file {file.Hash}");
|
||||
}
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ using osu.Framework.Graphics.Textures;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.IO.Serialization;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
@ -109,6 +110,8 @@ namespace osu.Game.Tests.Beatmaps
|
||||
{
|
||||
var beatmap = GetBeatmap(name);
|
||||
|
||||
string beforeConversion = beatmap.Serialize();
|
||||
|
||||
var converterResult = new Dictionary<HitObject, IEnumerable<HitObject>>();
|
||||
|
||||
var working = new ConversionWorkingBeatmap(beatmap)
|
||||
@ -122,6 +125,10 @@ namespace osu.Game.Tests.Beatmaps
|
||||
|
||||
working.GetPlayableBeatmap(CreateRuleset().RulesetInfo, mods);
|
||||
|
||||
string afterConversion = beatmap.Serialize();
|
||||
|
||||
Assert.AreEqual(beforeConversion, afterConversion, "Conversion altered original beatmap");
|
||||
|
||||
return new ConvertResult
|
||||
{
|
||||
Mappings = converterResult.Select(r =>
|
||||
|
@ -78,9 +78,11 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
protected void CreateGame()
|
||||
{
|
||||
AddGame(Game = new TestOsuGame(LocalStorage, API));
|
||||
AddGame(Game = CreateTestGame());
|
||||
}
|
||||
|
||||
protected virtual TestOsuGame CreateTestGame() => new TestOsuGame(LocalStorage, API);
|
||||
|
||||
protected void PushAndConfirm(Func<Screen> newScreen)
|
||||
{
|
||||
Screen screen = null;
|
||||
@ -135,7 +137,8 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
public new void PerformFromScreen(Action<IScreen> action, IEnumerable<Type> validScreens = null) => base.PerformFromScreen(action, validScreens);
|
||||
|
||||
public TestOsuGame(Storage storage, IAPIProvider api)
|
||||
public TestOsuGame(Storage storage, IAPIProvider api, string[] args = null)
|
||||
: base(args)
|
||||
{
|
||||
Storage = storage;
|
||||
API = api;
|
||||
|
@ -36,7 +36,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Realm" Version="10.6.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.1004.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.1013.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1004.0" />
|
||||
<PackageReference Include="Sentry" Version="3.9.4" />
|
||||
<PackageReference Include="SharpCompress" Version="0.29.0" />
|
||||
|
@ -70,7 +70,7 @@
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.1004.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.1013.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1004.0" />
|
||||
</ItemGroup>
|
||||
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
|
||||
@ -93,7 +93,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.1004.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.1013.0" />
|
||||
<PackageReference Include="SharpCompress" Version="0.28.3" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
||||
|
Loading…
Reference in New Issue
Block a user