Example #1
0
        private ConvertResult convert(string name)
        {
            var beatmap = getBeatmap(name);

            var rulesetInstance = CreateRuleset();

            beatmap.BeatmapInfo.Ruleset = beatmap.BeatmapInfo.RulesetID == rulesetInstance.RulesetInfo.ID ? rulesetInstance.RulesetInfo : new RulesetInfo();

            Converter = rulesetInstance.CreateBeatmapConverter(beatmap);

            var result = new ConvertResult();

            Converter.ObjectConverted += (orig, converted) =>
            {
                converted.ForEach(h => h.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty));

                var mapping = CreateConvertMapping();
                mapping.StartTime = orig.StartTime;

                foreach (var obj in converted)
                {
                    mapping.Objects.AddRange(CreateConvertValue(obj));
                }
                result.Mappings.Add(mapping);
            };

            IBeatmap convertedBeatmap = Converter.Convert();

            rulesetInstance.CreateBeatmapProcessor(convertedBeatmap)?.PostProcess();

            return(result);
        }
Example #2
0
        public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList <Mod> mods)
        {
            var rulesetInstance = ruleset.CreateInstance();

            IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);

            // Check if the beatmap can be converted
            if (!converter.CanConvert)
            {
                throw new BeatmapInvalidForRulesetException($"{nameof(Beatmaps.Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
            }

            // Apply conversion mods
            foreach (var mod in mods.OfType <IApplicableToBeatmapConverter>())
            {
                mod.ApplyToBeatmapConverter(converter);
            }

            // Convert
            IBeatmap converted = converter.Convert();

            // Apply difficulty mods
            if (mods.Any(m => m is IApplicableToDifficulty))
            {
                converted.BeatmapInfo = converted.BeatmapInfo.Clone();
                converted.BeatmapInfo.BaseDifficulty = converted.BeatmapInfo.BaseDifficulty.Clone();

                foreach (var mod in mods.OfType <IApplicableToDifficulty>())
                {
                    mod.ApplyToDifficulty(converted.BeatmapInfo.BaseDifficulty);
                }
            }

            IBeatmapProcessor processor = rulesetInstance.CreateBeatmapProcessor(converted);

            processor?.PreProcess();

            // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
            foreach (var obj in converted.HitObjects)
            {
                obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty);
            }

            foreach (var mod in mods.OfType <IApplicableToHitObject>())
            {
                foreach (var obj in converted.HitObjects)
                {
                    mod.ApplyToHitObject(obj);
                }
            }

            processor?.PostProcess();

            foreach (var mod in mods.OfType <IApplicableToBeatmap>())
            {
                mod.ApplyToBeatmap(converted);
            }

            return(converted);
        }
Example #3
0
        public virtual IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList <Mod> mods, CancellationToken token)
        {
            var rulesetInstance = ruleset.CreateInstance();

            if (rulesetInstance == null)
            {
                throw new RulesetLoadException("Creating ruleset instance failed when attempting to create playable beatmap.");
            }

            IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);

            // Check if the beatmap can be converted
            if (Beatmap.HitObjects.Count > 0 && !converter.CanConvert())
            {
                throw new BeatmapInvalidForRulesetException($"{nameof(Beatmaps.Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
            }

            // Apply conversion mods
            foreach (var mod in mods.OfType <IApplicableToBeatmapConverter>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmapConverter(converter);
            }

            // Convert
            IBeatmap converted = converter.Convert(token);

            // Apply conversion mods to the result
            foreach (var mod in mods.OfType <IApplicableAfterBeatmapConversion>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmap(converted);
            }

            // Apply difficulty mods
            if (mods.Any(m => m is IApplicableToDifficulty))
            {
                foreach (var mod in mods.OfType <IApplicableToDifficulty>())
                {
                    token.ThrowIfCancellationRequested();
                    mod.ApplyToDifficulty(converted.Difficulty);
                }
            }

            IBeatmapProcessor processor = rulesetInstance.CreateBeatmapProcessor(converted);

            foreach (var mod in mods.OfType <IApplicableToBeatmapProcessor>())
            {
                mod.ApplyToBeatmapProcessor(processor);
            }

            processor?.PreProcess();

            // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
            foreach (var obj in converted.HitObjects)
            {
                token.ThrowIfCancellationRequested();
                obj.ApplyDefaults(converted.ControlPointInfo, converted.Difficulty, token);
            }

            foreach (var mod in mods.OfType <IApplicableToHitObject>())
            {
                foreach (var obj in converted.HitObjects)
                {
                    token.ThrowIfCancellationRequested();
                    mod.ApplyToHitObject(obj);
                }
            }

            processor?.PostProcess();

            foreach (var mod in mods.OfType <IApplicableToBeatmap>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmap(converted);
            }

            return(converted);
        }
Example #4
0
        public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList <Mod> mods = null, TimeSpan?timeout = null)
        {
            using (var cancellationSource = createCancellationTokenSource(timeout))
            {
                mods ??= Array.Empty <Mod>();

                var rulesetInstance = ruleset.CreateInstance();

                IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);

                // Check if the beatmap can be converted
                if (Beatmap.HitObjects.Count > 0 && !converter.CanConvert())
                {
                    throw new BeatmapInvalidForRulesetException($"{nameof(Beatmaps.Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
                }

                // Apply conversion mods
                foreach (var mod in mods.OfType <IApplicableToBeatmapConverter>())
                {
                    if (cancellationSource.IsCancellationRequested)
                    {
                        throw new BeatmapLoadTimeoutException(BeatmapInfo);
                    }

                    mod.ApplyToBeatmapConverter(converter);
                }

                // Convert
                IBeatmap converted = converter.Convert();

                // Apply difficulty mods
                if (mods.Any(m => m is IApplicableToDifficulty))
                {
                    converted.BeatmapInfo = converted.BeatmapInfo.Clone();
                    converted.BeatmapInfo.BaseDifficulty = converted.BeatmapInfo.BaseDifficulty.Clone();

                    foreach (var mod in mods.OfType <IApplicableToDifficulty>())
                    {
                        if (cancellationSource.IsCancellationRequested)
                        {
                            throw new BeatmapLoadTimeoutException(BeatmapInfo);
                        }

                        mod.ApplyToDifficulty(converted.BeatmapInfo.BaseDifficulty);
                    }
                }

                IBeatmapProcessor processor = rulesetInstance.CreateBeatmapProcessor(converted);

                processor?.PreProcess();

                // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
                foreach (var obj in converted.HitObjects)
                {
                    if (cancellationSource.IsCancellationRequested)
                    {
                        throw new BeatmapLoadTimeoutException(BeatmapInfo);
                    }

                    obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty);
                }

                foreach (var mod in mods.OfType <IApplicableToHitObject>())
                {
                    foreach (var obj in converted.HitObjects)
                    {
                        if (cancellationSource.IsCancellationRequested)
                        {
                            throw new BeatmapLoadTimeoutException(BeatmapInfo);
                        }

                        mod.ApplyToHitObject(obj);
                    }
                }

                processor?.PostProcess();

                foreach (var mod in mods.OfType <IApplicableToBeatmap>())
                {
                    cancellationSource.Token.ThrowIfCancellationRequested();
                    mod.ApplyToBeatmap(converted);
                }

                return(converted);
            }
        }