1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 11:12:54 +08:00

create base dependencies before caching, create player in playerloader

This commit is contained in:
David Zhao 2019-07-08 15:40:10 +09:00
parent 2747d7692b
commit 5853a877c2
2 changed files with 12 additions and 11 deletions

View File

@ -285,7 +285,7 @@ namespace osu.Game
Ruleset.Value = databasedScoreInfo.Ruleset;
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(databasedBeatmap);
menuScreen.Push(new ReplayPlayerLoader(() => new ReplayPlayer(databasedScore), databasedScoreInfo.Mods));
menuScreen.Push(new ReplayPlayerLoader(databasedScore, databasedScoreInfo.Mods));
}, $"watch {databasedScoreInfo}", bypassScreenAllowChecks: true);
}

View File

@ -1,32 +1,33 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
namespace osu.Game.Screens.Play
{
public class ReplayPlayerLoader : PlayerLoader
{
private readonly IReadOnlyList<Mod> mods;
private readonly Bindable<IReadOnlyList<Mod>> mods;
public ReplayPlayerLoader(Func<Player> player, IReadOnlyList<Mod> mods)
: base(player)
public ReplayPlayerLoader(Score score, IReadOnlyList<Mod> mods)
: base(() => new ReplayPlayer(score))
{
this.mods = mods;
this.mods = new Bindable<IReadOnlyList<Mod>>(mods);
}
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
dependencies = new DependencyContainer(parent);
dependencies.Cache(new Bindable<IReadOnlyList<Mod>>(mods));
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.Cache(mods);
return base.CreateChildDependencies(dependencies);
// Overwrite the global mods here for use in the mod hud.
Mods.Value = mods.Value;
return dependencies;
}
}
}