1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 21:27:24 +08:00
osu-lazer/osu.Game/Screens/OsuScreenDependencies.cs

47 lines
1.9 KiB
C#
Raw Normal View History

2019-02-02 16:11:25 +08:00
// 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.
2019-04-08 17:32:05 +08:00
using System.Collections.Generic;
2019-02-02 16:11:25 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2019-02-02 16:11:25 +08:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
2019-04-08 17:32:05 +08:00
using osu.Game.Rulesets.Mods;
2019-02-02 16:11:25 +08:00
namespace osu.Game.Screens
{
public class OsuScreenDependencies : DependencyContainer
{
public Bindable<WorkingBeatmap> Beatmap { get; }
public Bindable<RulesetInfo> Ruleset { get; }
2019-04-08 17:32:05 +08:00
public Bindable<IEnumerable<Mod>> SelectedMods { get; }
2019-02-02 16:11:25 +08:00
public OsuScreenDependencies(bool requireLease, IReadOnlyDependencyContainer parent)
: base(parent)
{
if (requireLease)
{
Beatmap = parent.Get<LeasedBindable<WorkingBeatmap>>()?.GetBoundCopy();
if (Beatmap == null)
Cache(Beatmap = parent.Get<Bindable<WorkingBeatmap>>().BeginLease(false));
2019-02-02 16:11:25 +08:00
Ruleset = parent.Get<LeasedBindable<RulesetInfo>>()?.GetBoundCopy();
if (Ruleset == null)
Cache(Ruleset = parent.Get<Bindable<RulesetInfo>>().BeginLease(true));
2019-04-08 17:32:05 +08:00
SelectedMods = parent.Get<LeasedBindable<IEnumerable<Mod>>>()?.GetBoundCopy();
if (SelectedMods == null)
Cache(SelectedMods = parent.Get<Bindable<IEnumerable<Mod>>>().BeginLease(true));
2019-02-02 16:11:25 +08:00
}
else
{
Beatmap = (parent.Get<LeasedBindable<WorkingBeatmap>>() ?? parent.Get<Bindable<WorkingBeatmap>>()).GetBoundCopy();
Ruleset = (parent.Get<LeasedBindable<RulesetInfo>>() ?? parent.Get<Bindable<RulesetInfo>>()).GetBoundCopy();
2019-04-08 17:32:05 +08:00
SelectedMods = (parent.Get<LeasedBindable<IEnumerable<Mod>>>() ?? parent.Get<Bindable<IEnumerable<Mod>>>()).GetBoundCopy();
2019-02-02 16:11:25 +08:00
}
}
}
}