// Copyright (c) 2007-2017 ppy Pty Ltd . // 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 available_rulesets = new ConcurrentDictionary(); 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 AllRulesets => available_rulesets.Values; } }