mirror of https://github.com/ppy/osu
Move statics to RulesetCollection to avoid conflicts later on.
This commit is contained in:
parent
9927f9aca5
commit
59bfc7abad
|
@ -20,10 +20,10 @@ public void TestVisualTests()
|
|||
{
|
||||
using (var host = new HeadlessGameHost())
|
||||
{
|
||||
Ruleset.Register(new OsuRuleset());
|
||||
Ruleset.Register(new TaikoRuleset());
|
||||
Ruleset.Register(new ManiaRuleset());
|
||||
Ruleset.Register(new CatchRuleset());
|
||||
RulesetCollection.Register(typeof(OsuRuleset));
|
||||
RulesetCollection.Register(typeof(TaikoRuleset));
|
||||
RulesetCollection.Register(typeof(ManiaRuleset));
|
||||
RulesetCollection.Register(typeof(CatchRuleset));
|
||||
|
||||
host.Run(new AutomatedVisualTestGame());
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ public static void Main(string[] args)
|
|||
|
||||
using (GameHost host = Host.GetSuitableHost(@"osu"))
|
||||
{
|
||||
Ruleset.Register(new OsuRuleset());
|
||||
Ruleset.Register(new TaikoRuleset());
|
||||
Ruleset.Register(new ManiaRuleset());
|
||||
Ruleset.Register(new CatchRuleset());
|
||||
RulesetCollection.Register(typeof(OsuRuleset));
|
||||
RulesetCollection.Register(typeof(TaikoRuleset));
|
||||
RulesetCollection.Register(typeof(ManiaRuleset));
|
||||
RulesetCollection.Register(typeof(CatchRuleset));
|
||||
|
||||
if (benchmark)
|
||||
host.Run(new AutomatedVisualTestGame());
|
||||
|
|
|
@ -41,10 +41,10 @@ public static int Main(string[] args)
|
|||
}
|
||||
else
|
||||
{
|
||||
Ruleset.Register(new OsuRuleset());
|
||||
Ruleset.Register(new TaikoRuleset());
|
||||
Ruleset.Register(new ManiaRuleset());
|
||||
Ruleset.Register(new CatchRuleset());
|
||||
RulesetCollection.Register(typeof(OsuRuleset));
|
||||
RulesetCollection.Register(typeof(TaikoRuleset));
|
||||
RulesetCollection.Register(typeof(ManiaRuleset));
|
||||
RulesetCollection.Register(typeof(CatchRuleset));
|
||||
|
||||
host.Run(new OsuGameDesktop(args));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class OsuLegacyDecoderTest
|
|||
public void SetUp()
|
||||
{
|
||||
OsuLegacyDecoder.Register();
|
||||
Ruleset.Register(new OsuRuleset());
|
||||
RulesetCollection.Register(typeof(OsuRuleset));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -28,10 +28,10 @@ public class ImportBeatmapTest
|
|||
[OneTimeSetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
Ruleset.Register(new OsuRuleset());
|
||||
Ruleset.Register(new TaikoRuleset());
|
||||
Ruleset.Register(new ManiaRuleset());
|
||||
Ruleset.Register(new CatchRuleset());
|
||||
RulesetCollection.Register(typeof(OsuRuleset));
|
||||
RulesetCollection.Register(typeof(TaikoRuleset));
|
||||
RulesetCollection.Register(typeof(ManiaRuleset));
|
||||
RulesetCollection.Register(typeof(CatchRuleset));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -19,7 +19,7 @@ public class OszArchiveReaderTest
|
|||
public void SetUp()
|
||||
{
|
||||
OszArchiveReader.Register();
|
||||
Ruleset.Register(new OsuRuleset());
|
||||
RulesetCollection.Register(typeof(OsuRuleset));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -54,7 +54,7 @@ public class Beatmap : Beatmap<HitObject>
|
|||
/// Calculates the star difficulty for this Beatmap.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// Constructs a new beatmap.
|
||||
|
|
|
@ -45,7 +45,7 @@ private void load(OsuColour palette)
|
|||
Origin = Anchor.Centre,
|
||||
TextSize = Size.X,
|
||||
Colour = Color4.White,
|
||||
Icon = Ruleset.GetRuleset(beatmap.Mode).Icon
|
||||
Icon = RulesetCollection.GetRuleset((int)beatmap.Mode).Icon
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public Score ReadReplayFile(string replayFilename)
|
|||
using (Stream s = storage.GetStream(Path.Combine(replay_folder, replayFilename)))
|
||||
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.Pass = true;*/
|
||||
|
|
|
@ -22,10 +22,6 @@ public class BeatmapStatistic
|
|||
|
||||
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 abstract IEnumerable<Mod> GetModsFor(ModType type);
|
||||
|
@ -36,8 +32,6 @@ public abstract class Ruleset
|
|||
|
||||
public abstract ScoreProcessor CreateScoreProcessor();
|
||||
|
||||
public static void Register(Ruleset ruleset) => available_rulesets.TryAdd(ruleset.PlayMode, ruleset.GetType());
|
||||
|
||||
protected abstract PlayMode PlayMode { get; }
|
||||
|
||||
public virtual FontAwesome Icon => FontAwesome.fa_question_circle;
|
||||
|
@ -45,16 +39,5 @@ public abstract class Ruleset
|
|||
public abstract string Description { get; }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 @@ public class ModSelectOverlay : WaveOverlayContainer
|
|||
|
||||
private void modeChanged(PlayMode newMode)
|
||||
{
|
||||
var ruleset = Ruleset.GetRuleset(newMode);
|
||||
var ruleset = RulesetCollection.GetRuleset(newMode);
|
||||
foreach (ModSection section in modSectionsContainer.Children)
|
||||
section.Buttons = ruleset.GetModsFor(section.ModType).Select(m => new ModButton(m)).ToArray();
|
||||
refreshSelectedMods();
|
||||
|
|
|
@ -30,7 +30,7 @@ private void load(OsuGameBase game, OsuColour colours)
|
|||
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode)))
|
||||
modes.Add(new TextAwesome
|
||||
{
|
||||
Icon = Ruleset.GetRuleset(m).Icon,
|
||||
Icon = RulesetCollection.GetRuleset(m).Icon,
|
||||
Colour = Color4.Gray,
|
||||
TextSize = 20
|
||||
});
|
||||
|
|
|
@ -109,7 +109,7 @@ private void load(AudioManager audio, BeatmapDatabase beatmaps, OsuConfigManager
|
|||
sourceClock.Reset();
|
||||
});
|
||||
|
||||
ruleset = Ruleset.GetRuleset(Beatmap.PlayMode);
|
||||
ruleset = RulesetCollection.GetRuleset(Beatmap.PlayMode);
|
||||
HitRenderer = ruleset.CreateHitRendererWith(Beatmap);
|
||||
|
||||
scoreProcessor = HitRenderer.CreateScoreProcessor();
|
||||
|
|
|
@ -100,7 +100,7 @@ public void UpdateBeatmap(WorkingBeatmap beatmap)
|
|||
}));
|
||||
|
||||
//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;
|
||||
|
|
|
@ -131,6 +131,7 @@
|
|||
<Compile Include="Modes\Objects\Legacy\LegacyHitObjectType.cs" />
|
||||
<Compile Include="Modes\Replays\ReplayButtonState.cs" />
|
||||
<Compile Include="Modes\Replays\ReplayFrame.cs" />
|
||||
<Compile Include="Modes\RulesetCollection.cs" />
|
||||
<Compile Include="Modes\Scoring\Score.cs" />
|
||||
<Compile Include="Modes\Scoring\ScoreProcessor.cs" />
|
||||
<Compile Include="Modes\UI\HealthDisplay.cs" />
|
||||
|
|
Loading…
Reference in New Issue