mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 09:23:06 +08:00
Allow rulesets to create their own instantiation info
This commit is contained in:
parent
fe7ce26b84
commit
58626e3b30
@ -101,7 +101,7 @@ namespace osu.Game.Rulesets.Catch
|
||||
|
||||
public override int LegacyID => 2;
|
||||
|
||||
public CatchRuleset(RulesetInfo rulesetInfo)
|
||||
public CatchRuleset(RulesetInfo rulesetInfo = null)
|
||||
: base(rulesetInfo)
|
||||
{
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
[Ignore("getting CI working")]
|
||||
public class TestCaseCatchPlayer : Game.Tests.Visual.TestCasePlayer
|
||||
{
|
||||
public TestCaseCatchPlayer() : base(typeof(CatchRuleset))
|
||||
public TestCaseCatchPlayer() : base(new CatchRuleset())
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
public class TestCaseCatchStacker : Game.Tests.Visual.TestCasePlayer
|
||||
{
|
||||
public TestCaseCatchStacker()
|
||||
: base(typeof(CatchRuleset))
|
||||
: base(new CatchRuleset())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
public class TestCaseHyperdash : Game.Tests.Visual.TestCasePlayer
|
||||
{
|
||||
public TestCaseHyperdash()
|
||||
: base(typeof(CatchRuleset))
|
||||
: base(new CatchRuleset())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
public class TestCasePerformancePoints : Game.Tests.Visual.TestCasePerformancePoints
|
||||
{
|
||||
public TestCasePerformancePoints()
|
||||
: base(new CatchRuleset(new RulesetInfo()))
|
||||
: base(new CatchRuleset())
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ namespace osu.Game.Rulesets.Mania
|
||||
|
||||
public override int LegacyID => 3;
|
||||
|
||||
public ManiaRuleset(RulesetInfo rulesetInfo)
|
||||
public ManiaRuleset(RulesetInfo rulesetInfo = null)
|
||||
: base(rulesetInfo)
|
||||
{
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Mania.Tests
|
||||
public class TestCasePerformancePoints : Game.Tests.Visual.TestCasePerformancePoints
|
||||
{
|
||||
public TestCasePerformancePoints()
|
||||
: base(new ManiaRuleset(new RulesetInfo()))
|
||||
: base(new ManiaRuleset())
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ namespace osu.Game.Rulesets.Osu
|
||||
|
||||
public override int LegacyID => 0;
|
||||
|
||||
public OsuRuleset(RulesetInfo rulesetInfo)
|
||||
public OsuRuleset(RulesetInfo rulesetInfo = null)
|
||||
: base(rulesetInfo)
|
||||
{
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
public class TestCasePerformancePoints : Game.Tests.Visual.TestCasePerformancePoints
|
||||
{
|
||||
public TestCasePerformancePoints()
|
||||
: base(new OsuRuleset(new RulesetInfo()))
|
||||
: base(new OsuRuleset())
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ namespace osu.Game.Rulesets.Taiko
|
||||
|
||||
public override int LegacyID => 1;
|
||||
|
||||
public TaikoRuleset(RulesetInfo rulesetInfo)
|
||||
public TaikoRuleset(RulesetInfo rulesetInfo = null)
|
||||
: base(rulesetInfo)
|
||||
{
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
||||
public class TestCasePerformancePoints : Game.Tests.Visual.TestCasePerformancePoints
|
||||
{
|
||||
public TestCasePerformancePoints()
|
||||
: base(new TaikoRuleset(new RulesetInfo()))
|
||||
: base(new TaikoRuleset())
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -56,25 +56,25 @@ namespace osu.Game.Tests.Visual
|
||||
Clock = new FramedClock(),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuRulesetContainer(new OsuRuleset(new RulesetInfo()), beatmap, false)
|
||||
new OsuRulesetContainer(new OsuRuleset(), beatmap, false)
|
||||
{
|
||||
Scale = new Vector2(0.5f),
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.TopLeft
|
||||
},
|
||||
new TaikoRulesetContainer(new TaikoRuleset(new RulesetInfo()),beatmap, false)
|
||||
new TaikoRulesetContainer(new TaikoRuleset(),beatmap, false)
|
||||
{
|
||||
Scale = new Vector2(0.5f),
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight
|
||||
},
|
||||
new CatchRulesetContainer(new CatchRuleset(new RulesetInfo()),beatmap, false)
|
||||
new CatchRulesetContainer(new CatchRuleset(),beatmap, false)
|
||||
{
|
||||
Scale = new Vector2(0.5f),
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft
|
||||
},
|
||||
new ManiaRulesetContainer(new ManiaRuleset(new RulesetInfo()),beatmap, false)
|
||||
new ManiaRulesetContainer(new ManiaRuleset(),beatmap, false)
|
||||
{
|
||||
Scale = new Vector2(0.5f),
|
||||
Anchor = Anchor.BottomRight,
|
||||
|
@ -64,7 +64,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
public override string ShortName => "dummy";
|
||||
|
||||
public DummyRuleset(RulesetInfo rulesetInfo)
|
||||
public DummyRuleset(RulesetInfo rulesetInfo = null)
|
||||
: base(rulesetInfo)
|
||||
{
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ namespace osu.Game.Rulesets
|
||||
|
||||
public Mod GetAutoplayMod() => GetAllMods().First(mod => mod is ModAutoplay);
|
||||
|
||||
protected Ruleset(RulesetInfo rulesetInfo)
|
||||
protected Ruleset(RulesetInfo rulesetInfo = null)
|
||||
{
|
||||
RulesetInfo = rulesetInfo;
|
||||
RulesetInfo = rulesetInfo ?? createRulesetInfo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -88,5 +88,17 @@ namespace osu.Game.Rulesets
|
||||
/// <param name="variant">The variant.</param>
|
||||
/// <returns>A descriptive name of the variant.</returns>
|
||||
public virtual string GetVariantName(int variant) => string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Create a ruleset info based on this ruleset.
|
||||
/// </summary>
|
||||
/// <returns>A filled <see cref="RulesetInfo"/>.</returns>
|
||||
private RulesetInfo createRulesetInfo() => new RulesetInfo
|
||||
{
|
||||
Name = Description,
|
||||
ShortName = ShortName,
|
||||
InstantiationInfo = GetType().AssemblyQualifiedName,
|
||||
ID = LegacyID
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -58,30 +58,21 @@ namespace osu.Game.Rulesets
|
||||
{
|
||||
var context = GetContext();
|
||||
|
||||
var instances = loaded_assemblies.Values.Select(r => (Ruleset)Activator.CreateInstance(r, new RulesetInfo())).ToList();
|
||||
var instances = loaded_assemblies.Values.Select(r => (Ruleset)Activator.CreateInstance(r, (RulesetInfo)null)).ToList();
|
||||
|
||||
//add all legacy modes in correct order
|
||||
foreach (var r in instances.Where(r => r.LegacyID >= 0).OrderBy(r => r.LegacyID))
|
||||
{
|
||||
var rulesetInfo = createRulesetInfo(r);
|
||||
if (context.RulesetInfo.SingleOrDefault(rsi => rsi.ID == rulesetInfo.ID) == null)
|
||||
{
|
||||
context.RulesetInfo.Add(rulesetInfo);
|
||||
}
|
||||
if (context.RulesetInfo.SingleOrDefault(rsi => rsi.ID == r.RulesetInfo.ID) == null)
|
||||
context.RulesetInfo.Add(r.RulesetInfo);
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
//add any other modes
|
||||
foreach (var r in instances.Where(r => r.LegacyID < 0))
|
||||
{
|
||||
var us = createRulesetInfo(r);
|
||||
|
||||
var existing = context.RulesetInfo.FirstOrDefault(ri => ri.InstantiationInfo == us.InstantiationInfo);
|
||||
|
||||
if (existing == null)
|
||||
context.RulesetInfo.Add(us);
|
||||
}
|
||||
if (context.RulesetInfo.FirstOrDefault(ri => ri.InstantiationInfo == r.RulesetInfo.InstantiationInfo) == null)
|
||||
context.RulesetInfo.Add(r.RulesetInfo);
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
@ -124,13 +115,5 @@ namespace osu.Game.Rulesets
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private RulesetInfo createRulesetInfo(Ruleset ruleset) => new RulesetInfo
|
||||
{
|
||||
Name = ruleset.Description,
|
||||
ShortName = ruleset.ShortName,
|
||||
InstantiationInfo = ruleset.GetType().AssemblyQualifiedName,
|
||||
ID = ruleset.LegacyID
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -18,24 +17,19 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public abstract class TestCasePlayer : ScreenTestCase
|
||||
{
|
||||
private readonly Type ruleset;
|
||||
private readonly Ruleset ruleset;
|
||||
|
||||
protected Player Player;
|
||||
|
||||
private TestWorkingBeatmap working;
|
||||
|
||||
/// <summary>
|
||||
/// Create a TestCase which runs through the Player screen.
|
||||
/// </summary>
|
||||
/// <param name="ruleset">An optional ruleset type which we want to target. If not provided we'll allow all rulesets to be tested.</param>
|
||||
protected TestCasePlayer(Type ruleset)
|
||||
protected TestCasePlayer(Ruleset ruleset)
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
}
|
||||
|
||||
protected TestCasePlayer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -48,14 +42,21 @@ namespace osu.Game.Tests.Visual
|
||||
Depth = int.MaxValue
|
||||
});
|
||||
|
||||
string instantiation = ruleset?.AssemblyQualifiedName;
|
||||
|
||||
foreach (var r in rulesets.AvailableRulesets.Where(rs => instantiation == null || rs.InstantiationInfo == instantiation))
|
||||
if (ruleset != null)
|
||||
{
|
||||
Player p = null;
|
||||
AddStep(r.Name, () => p = loadPlayerFor(r));
|
||||
AddStep(ruleset.RulesetInfo.Name, () => p = loadPlayerFor(ruleset));
|
||||
AddUntilStep(() => p.IsLoaded);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var r in rulesets.AvailableRulesets)
|
||||
{
|
||||
Player p = null;
|
||||
AddStep(r.Name, () => p = loadPlayerFor(r));
|
||||
AddUntilStep(() => p.IsLoaded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Beatmap CreateBeatmap()
|
||||
@ -69,21 +70,21 @@ namespace osu.Game.Tests.Visual
|
||||
return beatmap;
|
||||
}
|
||||
|
||||
private Player loadPlayerFor(RulesetInfo r)
|
||||
private Player loadPlayerFor(RulesetInfo ri) => loadPlayerFor(ri.CreateInstance());
|
||||
|
||||
private Player loadPlayerFor(Ruleset r)
|
||||
{
|
||||
var beatmap = CreateBeatmap();
|
||||
|
||||
beatmap.BeatmapInfo.Ruleset = r;
|
||||
|
||||
var instance = r.CreateInstance();
|
||||
beatmap.BeatmapInfo.Ruleset = r.RulesetInfo;
|
||||
|
||||
working = new TestWorkingBeatmap(beatmap);
|
||||
working.Mods.Value = new[] { instance.GetAllMods().First(m => m is ModNoFail) };
|
||||
working.Mods.Value = new[] { r.GetAllMods().First(m => m is ModNoFail) };
|
||||
|
||||
if (Player != null)
|
||||
Remove(Player);
|
||||
|
||||
var player = CreatePlayer(working, instance);
|
||||
var player = CreatePlayer(working, r);
|
||||
|
||||
LoadComponentAsync(player, LoadScreen);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user