Use reflection to load Rulesets.

This commit is contained in:
Dean Herbert 2016-11-14 19:20:27 +09:00
parent 6c7fab0e31
commit 07fee61989
1 changed files with 13 additions and 12 deletions

View File

@ -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;
}
}
}