1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:43:22 +08:00

Store and retrieve offset from realm

This commit is contained in:
Dean Herbert 2022-03-01 16:59:33 +09:00
parent acf8db13ac
commit 047e801da9
3 changed files with 46 additions and 12 deletions

View File

@ -565,6 +565,11 @@ namespace osu.Game.Database
}
break;
case 14:
foreach (var beatmap in migration.NewRealm.All<BeatmapInfo>())
beatmap.UserSettings = new BeatmapUserSettings();
break;
}
}

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database;
namespace osu.Game.Screens.Play
{
@ -43,7 +44,7 @@ namespace osu.Game.Screens.Play
Precision = 0.1,
};
private double totalAppliedOffset => userOffsetClock.RateAdjustedOffset + platformOffsetClock.RateAdjustedOffset;
private double totalAppliedOffset => userBeatmapOffsetClock.RateAdjustedOffset + userGlobalOffsetClock.RateAdjustedOffset + platformOffsetClock.RateAdjustedOffset;
private readonly BindableDouble pauseFreqAdjust = new BindableDouble(1);
@ -52,7 +53,8 @@ namespace osu.Game.Screens.Play
private readonly bool startAtGameplayStart;
private readonly double firstHitObjectTime;
private HardwareCorrectionOffsetClock userOffsetClock;
private HardwareCorrectionOffsetClock userGlobalOffsetClock;
private HardwareCorrectionOffsetClock userBeatmapOffsetClock;
private HardwareCorrectionOffsetClock platformOffsetClock;
private MasterGameplayClock masterGameplayClock;
private Bindable<double> userAudioOffset;
@ -69,10 +71,12 @@ namespace osu.Game.Screens.Play
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
private void load(OsuConfigManager config, RealmAccess realm)
{
userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset);
userAudioOffset.BindValueChanged(offset => userOffsetClock.Offset = offset.NewValue, true);
userAudioOffset.BindValueChanged(offset => userGlobalOffsetClock.Offset = offset.NewValue, true);
userBeatmapOffsetClock.Offset = realm.Run(r => r.Find<BeatmapInfo>(beatmap.BeatmapInfo.ID).UserSettings?.Offset) ?? 0;
// sane default provided by ruleset.
startOffset = gameplayStartTime;
@ -161,9 +165,10 @@ namespace osu.Game.Screens.Play
platformOffsetClock = new HardwareCorrectionOffsetClock(source, pauseFreqAdjust) { Offset = RuntimeInfo.OS == RuntimeInfo.Platform.Windows ? 15 : 0 };
// the final usable gameplay clock with user-set offsets applied.
userOffsetClock = new HardwareCorrectionOffsetClock(platformOffsetClock, pauseFreqAdjust);
userGlobalOffsetClock = new HardwareCorrectionOffsetClock(platformOffsetClock, pauseFreqAdjust);
userBeatmapOffsetClock = new HardwareCorrectionOffsetClock(userGlobalOffsetClock, pauseFreqAdjust);
return masterGameplayClock = new MasterGameplayClock(userOffsetClock);
return masterGameplayClock = new MasterGameplayClock(userBeatmapOffsetClock);
}
/// <summary>

View File

@ -1,9 +1,12 @@
// 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.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Scoring;
@ -60,16 +63,37 @@ namespace osu.Game.Screens.Play.PlayerSettings
},
}
};
}
[Resolved]
private RealmAccess realm { get; set; }
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
ReferenceScore.BindValueChanged(scoreChanged, true);
Current.BindValueChanged(offset =>
Current.BindValueChanged(currentChanged);
Current.Value = realm.Run(r => r.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID).UserSettings?.Offset) ?? 0;
}
private void currentChanged(ValueChangedEvent<double> offset)
{
if (useAverageButton != null)
{
if (useAverageButton != null)
{
useAverageButton.Enabled.Value = offset.NewValue != lastPlayAverage;
}
}, true);
useAverageButton.Enabled.Value = offset.NewValue != lastPlayAverage;
}
realm.Write(r =>
{
var settings = r.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID).UserSettings;
settings.Offset = offset.NewValue;
});
}
private void scoreChanged(ValueChangedEvent<ScoreInfo> score)