mirror of https://github.com/ppy/osu
Use reflection to load Rulesets.
This commit is contained in:
parent
6c7fab0e31
commit
07fee61989
|
@ -4,6 +4,10 @@
|
|||
using System.Collections.Generic;
|
||||
using osu.Game.Modes.Objects;
|
||||
using osu.Game.Modes.UI;
|
||||
using System.Reflection;
|
||||
using osu.Framework.Extensions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Modes
|
||||
{
|
||||
|
@ -15,19 +19,16 @@ public abstract class Ruleset
|
|||
|
||||
public static Ruleset GetRuleset(PlayMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
return null;
|
||||
Type type = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.Where(a => a.FullName.Contains($@"osu.Game.Modes.{mode}"))
|
||||
.SelectMany(a => a.GetTypes())
|
||||
.Where(t => t.Name == $@"{mode}Ruleset")
|
||||
.FirstOrDefault();
|
||||
|
||||
// return new OsuRuleset();
|
||||
//case PlayMode.Catch:
|
||||
// return new CatchRuleset();
|
||||
//case PlayMode.Mania:
|
||||
// return new ManiaRuleset();
|
||||
//case PlayMode.Taiko:
|
||||
// return new TaikoRuleset();
|
||||
}
|
||||
if (type == null)
|
||||
return null;
|
||||
|
||||
return Activator.CreateInstance(type) as Ruleset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue