mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 09:22:54 +08:00
Move statics to RulesetCollection to avoid conflicts later on.
This commit is contained in:
parent
9927f9aca5
commit
59bfc7abad
@ -20,10 +20,10 @@ namespace osu.Desktop.Tests
|
|||||||
{
|
{
|
||||||
using (var host = new HeadlessGameHost())
|
using (var host = new HeadlessGameHost())
|
||||||
{
|
{
|
||||||
Ruleset.Register(new OsuRuleset());
|
RulesetCollection.Register(typeof(OsuRuleset));
|
||||||
Ruleset.Register(new TaikoRuleset());
|
RulesetCollection.Register(typeof(TaikoRuleset));
|
||||||
Ruleset.Register(new ManiaRuleset());
|
RulesetCollection.Register(typeof(ManiaRuleset));
|
||||||
Ruleset.Register(new CatchRuleset());
|
RulesetCollection.Register(typeof(CatchRuleset));
|
||||||
|
|
||||||
host.Run(new AutomatedVisualTestGame());
|
host.Run(new AutomatedVisualTestGame());
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,10 @@ namespace osu.Desktop.VisualTests
|
|||||||
|
|
||||||
using (GameHost host = Host.GetSuitableHost(@"osu"))
|
using (GameHost host = Host.GetSuitableHost(@"osu"))
|
||||||
{
|
{
|
||||||
Ruleset.Register(new OsuRuleset());
|
RulesetCollection.Register(typeof(OsuRuleset));
|
||||||
Ruleset.Register(new TaikoRuleset());
|
RulesetCollection.Register(typeof(TaikoRuleset));
|
||||||
Ruleset.Register(new ManiaRuleset());
|
RulesetCollection.Register(typeof(ManiaRuleset));
|
||||||
Ruleset.Register(new CatchRuleset());
|
RulesetCollection.Register(typeof(CatchRuleset));
|
||||||
|
|
||||||
if (benchmark)
|
if (benchmark)
|
||||||
host.Run(new AutomatedVisualTestGame());
|
host.Run(new AutomatedVisualTestGame());
|
||||||
|
@ -41,10 +41,10 @@ namespace osu.Desktop
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Ruleset.Register(new OsuRuleset());
|
RulesetCollection.Register(typeof(OsuRuleset));
|
||||||
Ruleset.Register(new TaikoRuleset());
|
RulesetCollection.Register(typeof(TaikoRuleset));
|
||||||
Ruleset.Register(new ManiaRuleset());
|
RulesetCollection.Register(typeof(ManiaRuleset));
|
||||||
Ruleset.Register(new CatchRuleset());
|
RulesetCollection.Register(typeof(CatchRuleset));
|
||||||
|
|
||||||
host.Run(new OsuGameDesktop(args));
|
host.Run(new OsuGameDesktop(args));
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
OsuLegacyDecoder.Register();
|
OsuLegacyDecoder.Register();
|
||||||
Ruleset.Register(new OsuRuleset());
|
RulesetCollection.Register(typeof(OsuRuleset));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -28,10 +28,10 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
[OneTimeSetUp]
|
[OneTimeSetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
Ruleset.Register(new OsuRuleset());
|
RulesetCollection.Register(typeof(OsuRuleset));
|
||||||
Ruleset.Register(new TaikoRuleset());
|
RulesetCollection.Register(typeof(TaikoRuleset));
|
||||||
Ruleset.Register(new ManiaRuleset());
|
RulesetCollection.Register(typeof(ManiaRuleset));
|
||||||
Ruleset.Register(new CatchRuleset());
|
RulesetCollection.Register(typeof(CatchRuleset));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
OszArchiveReader.Register();
|
OszArchiveReader.Register();
|
||||||
Ruleset.Register(new OsuRuleset());
|
RulesetCollection.Register(typeof(OsuRuleset));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps
|
|||||||
/// Calculates the star difficulty for this Beatmap.
|
/// Calculates the star difficulty for this Beatmap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The star difficulty.</returns>
|
/// <returns>The star difficulty.</returns>
|
||||||
public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate();
|
public double CalculateStarDifficulty() => RulesetCollection.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new beatmap.
|
/// Constructs a new beatmap.
|
||||||
|
@ -45,7 +45,7 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
TextSize = Size.X,
|
TextSize = Size.X,
|
||||||
Colour = Color4.White,
|
Colour = Color4.White,
|
||||||
Icon = Ruleset.GetRuleset(beatmap.Mode).Icon
|
Icon = RulesetCollection.GetRuleset((int)beatmap.Mode).Icon
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Database
|
|||||||
using (Stream s = storage.GetStream(Path.Combine(replay_folder, replayFilename)))
|
using (Stream s = storage.GetStream(Path.Combine(replay_folder, replayFilename)))
|
||||||
using (SerializationReader sr = new SerializationReader(s))
|
using (SerializationReader sr = new SerializationReader(s))
|
||||||
{
|
{
|
||||||
var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte());
|
var ruleset = RulesetCollection.GetRuleset((PlayMode)sr.ReadByte());
|
||||||
score = ruleset.CreateScoreProcessor().CreateScore();
|
score = ruleset.CreateScoreProcessor().CreateScore();
|
||||||
|
|
||||||
/* score.Pass = true;*/
|
/* score.Pass = true;*/
|
||||||
|
@ -22,10 +22,6 @@ namespace osu.Game.Modes
|
|||||||
|
|
||||||
public abstract class Ruleset
|
public abstract class Ruleset
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<PlayMode, Type> available_rulesets = new ConcurrentDictionary<PlayMode, Type>();
|
|
||||||
|
|
||||||
public static IEnumerable<PlayMode> PlayModes => available_rulesets.Keys;
|
|
||||||
|
|
||||||
public virtual IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { };
|
public virtual IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { };
|
||||||
|
|
||||||
public abstract IEnumerable<Mod> GetModsFor(ModType type);
|
public abstract IEnumerable<Mod> GetModsFor(ModType type);
|
||||||
@ -36,8 +32,6 @@ namespace osu.Game.Modes
|
|||||||
|
|
||||||
public abstract ScoreProcessor CreateScoreProcessor();
|
public abstract ScoreProcessor CreateScoreProcessor();
|
||||||
|
|
||||||
public static void Register(Ruleset ruleset) => available_rulesets.TryAdd(ruleset.PlayMode, ruleset.GetType());
|
|
||||||
|
|
||||||
protected abstract PlayMode PlayMode { get; }
|
protected abstract PlayMode PlayMode { get; }
|
||||||
|
|
||||||
public virtual FontAwesome Icon => FontAwesome.fa_question_circle;
|
public virtual FontAwesome Icon => FontAwesome.fa_question_circle;
|
||||||
@ -45,16 +39,5 @@ namespace osu.Game.Modes
|
|||||||
public abstract string Description { get; }
|
public abstract string Description { get; }
|
||||||
|
|
||||||
public abstract IEnumerable<KeyCounter> CreateGameplayKeys();
|
public abstract IEnumerable<KeyCounter> CreateGameplayKeys();
|
||||||
|
|
||||||
public static Ruleset GetRuleset(PlayMode mode)
|
|
||||||
{
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
if (!available_rulesets.TryGetValue(mode, out type))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return Activator.CreateInstance(type) as Ruleset;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
osu.Game/Modes/RulesetCollection.cs
Normal file
41
osu.Game/Modes/RulesetCollection.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace osu.Game.Modes
|
||||||
|
{
|
||||||
|
public static class RulesetCollection
|
||||||
|
{
|
||||||
|
private static readonly ConcurrentDictionary<int, Ruleset> available_rulesets = new ConcurrentDictionary<int, Ruleset>();
|
||||||
|
|
||||||
|
public static void Register(Type type)
|
||||||
|
{
|
||||||
|
Ruleset ruleset = Activator.CreateInstance(type) as Ruleset;
|
||||||
|
|
||||||
|
if (ruleset == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
available_rulesets.TryAdd(available_rulesets.Count, ruleset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Ruleset GetRuleset(PlayMode playMode)
|
||||||
|
{
|
||||||
|
return GetRuleset((int)playMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Ruleset GetRuleset(int rulesetId)
|
||||||
|
{
|
||||||
|
Ruleset ruleset;
|
||||||
|
|
||||||
|
if (!available_rulesets.TryGetValue(rulesetId, out ruleset))
|
||||||
|
throw new InvalidOperationException($"Ruleset id {rulesetId} doesn't exist. How did you trigger this?");
|
||||||
|
|
||||||
|
return ruleset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<Ruleset> AllRulesets => available_rulesets.Values;
|
||||||
|
}
|
||||||
|
}
|
@ -41,7 +41,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
private void modeChanged(PlayMode newMode)
|
private void modeChanged(PlayMode newMode)
|
||||||
{
|
{
|
||||||
var ruleset = Ruleset.GetRuleset(newMode);
|
var ruleset = RulesetCollection.GetRuleset(newMode);
|
||||||
foreach (ModSection section in modSectionsContainer.Children)
|
foreach (ModSection section in modSectionsContainer.Children)
|
||||||
section.Buttons = ruleset.GetModsFor(section.ModType).Select(m => new ModButton(m)).ToArray();
|
section.Buttons = ruleset.GetModsFor(section.ModType).Select(m => new ModButton(m)).ToArray();
|
||||||
refreshSelectedMods();
|
refreshSelectedMods();
|
||||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Overlays.Options
|
|||||||
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode)))
|
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode)))
|
||||||
modes.Add(new TextAwesome
|
modes.Add(new TextAwesome
|
||||||
{
|
{
|
||||||
Icon = Ruleset.GetRuleset(m).Icon,
|
Icon = RulesetCollection.GetRuleset(m).Icon,
|
||||||
Colour = Color4.Gray,
|
Colour = Color4.Gray,
|
||||||
TextSize = 20
|
TextSize = 20
|
||||||
});
|
});
|
||||||
|
@ -109,7 +109,7 @@ namespace osu.Game.Screens.Play
|
|||||||
sourceClock.Reset();
|
sourceClock.Reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
ruleset = Ruleset.GetRuleset(Beatmap.PlayMode);
|
ruleset = RulesetCollection.GetRuleset(Beatmap.PlayMode);
|
||||||
HitRenderer = ruleset.CreateHitRendererWith(Beatmap);
|
HitRenderer = ruleset.CreateHitRendererWith(Beatmap);
|
||||||
|
|
||||||
scoreProcessor = HitRenderer.CreateScoreProcessor();
|
scoreProcessor = HitRenderer.CreateScoreProcessor();
|
||||||
|
@ -100,7 +100,7 @@ namespace osu.Game.Screens.Select
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
//get statistics fromt he current ruleset.
|
//get statistics fromt he current ruleset.
|
||||||
labels.AddRange(Ruleset.GetRuleset(beatmap.BeatmapInfo.Mode).GetBeatmapStatistics(beatmap).Select(s => new InfoLabel(s)));
|
labels.AddRange(RulesetCollection.GetRuleset(beatmap.BeatmapInfo.Mode).GetBeatmapStatistics(beatmap).Select(s => new InfoLabel(s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
AlwaysPresent = true;
|
AlwaysPresent = true;
|
||||||
|
@ -131,6 +131,7 @@
|
|||||||
<Compile Include="Modes\Objects\Legacy\LegacyHitObjectType.cs" />
|
<Compile Include="Modes\Objects\Legacy\LegacyHitObjectType.cs" />
|
||||||
<Compile Include="Modes\Replays\ReplayButtonState.cs" />
|
<Compile Include="Modes\Replays\ReplayButtonState.cs" />
|
||||||
<Compile Include="Modes\Replays\ReplayFrame.cs" />
|
<Compile Include="Modes\Replays\ReplayFrame.cs" />
|
||||||
|
<Compile Include="Modes\RulesetCollection.cs" />
|
||||||
<Compile Include="Modes\Scoring\Score.cs" />
|
<Compile Include="Modes\Scoring\Score.cs" />
|
||||||
<Compile Include="Modes\Scoring\ScoreProcessor.cs" />
|
<Compile Include="Modes\Scoring\ScoreProcessor.cs" />
|
||||||
<Compile Include="Modes\UI\HealthDisplay.cs" />
|
<Compile Include="Modes\UI\HealthDisplay.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user