Ejemplo n.º 1
0
        public static async Task <BeatmapLevelsModel.GetBeatmapLevelResult?> GetLevelFromPreview(IPreviewBeatmapLevel level, BeatmapLevelsModel beatmapLevelsModel = null)
        {
            beatmapLevelsModel = beatmapLevelsModel ?? Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault();

            if (beatmapLevelsModel != null)
            {
                getLevelCancellationTokenSource?.Cancel();
                getLevelCancellationTokenSource = new CancellationTokenSource();

                var token = getLevelCancellationTokenSource.Token;

                BeatmapLevelsModel.GetBeatmapLevelResult?result = null;
                try
                {
                    result = await beatmapLevelsModel.GetBeatmapLevelAsync(level.levelID, token);
                }
                catch (OperationCanceledException) { }
                if (result?.isError == true || result?.beatmapLevel == null)
                {
                    return(null);                                                         //Null out entirely in case of error
                }
                return(result);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public static async void LoadBeatmapLevelAsync(
            BeatmapCharacteristicSO characteristic, IPreviewBeatmapLevel selectedLevel, BeatmapDifficulty difficulty,
            Action <AdditionalContentModel.EntitlementStatus, bool, IBeatmapLevel> callback)
        {
            _beatmapLevelsModel     = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault();
            _contentModelSO         = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().FirstOrDefault();
            _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>();

            var token = new CancellationTokenSource();

            Plugin.log.Info("Checking entitlement");

            var entitlementStatus =
                await _contentModelSO.GetLevelEntitlementStatusAsync(selectedLevel.levelID, token.Token);

            if (entitlementStatus == AdditionalContentModel.EntitlementStatus.Owned)
            {
                Plugin.log.Info("Level owned. Loading...");

                var getBeatmapLevelResult =
                    await _beatmapLevelsModel.GetBeatmapLevelAsync(selectedLevel.levelID, token.Token);

                callback?.Invoke(entitlementStatus, !getBeatmapLevelResult.isError, getBeatmapLevelResult.beatmapLevel);

                Plugin.log.Info("Starting...");
                StartLevel(getBeatmapLevelResult.beatmapLevel, characteristic, difficulty,
                           GameplayModifiers.defaultModifiers);
            }
            else
            {
                callback?.Invoke(entitlementStatus, false, null);
            }
        }
Ejemplo n.º 3
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Get a level from a level preview
        /// </summary>
        /// <param name="p_Level">Level instance</param>
        /// <param name="p_BeatmapLevelsModel">Model</param>
        /// <returns>Level instance</returns>
        private static async Task <BeatmapLevelsModel.GetBeatmapLevelResult?> GetLevelFromPreview(IPreviewBeatmapLevel p_Level, BeatmapLevelsModel p_BeatmapLevelsModel = null)
        {
            /*
             *  Code from https://github.com/MatrikMoon/TournamentAssistant
             *
             *  MIT License
             *
             *  Permission is hereby granted, free of charge, to any person obtaining a copy
             *  of this software and associated documentation files (the "Software"), to deal
             *  in the Software without restriction, including without limitation the rights
             *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
             *  copies of the Software, and to permit persons to whom the Software is
             *  furnished to do so, subject to the following conditions:
             *
             *  The above copyright notice and this permission notice shall be included in all
             *  copies or substantial portions of the Software.
             *
             *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
             *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
             *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
             *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
             *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
             *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
             *  SOFTWARE.
             */
            p_BeatmapLevelsModel = p_BeatmapLevelsModel ?? Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault();

            if (p_BeatmapLevelsModel != null)
            {
                m_GetLevelCancellationTokenSource?.Cancel();
                m_GetLevelCancellationTokenSource = new CancellationTokenSource();

                var l_Token = m_GetLevelCancellationTokenSource.Token;

                BeatmapLevelsModel.GetBeatmapLevelResult?l_Result = null;

                try
                {
                    l_Result = await p_BeatmapLevelsModel.GetBeatmapLevelAsync(p_Level.levelID, l_Token);
                }
                catch (OperationCanceledException)
                {
                }

                if (l_Result?.isError == true || l_Result?.beatmapLevel == null)
                {
                    return(null); /// Null out entirely in case of error
                }
                return(l_Result);
            }

            return(null);
        }
Ejemplo n.º 4
0
        private async Task <IDifficultyBeatmap> NextDifficultyBeatmap()
        {
            IPreviewBeatmapLevel previewBeatmapLevel = _previewBeatmapLevels[_random.Next(0, _previewBeatmapLevels.Length)];

            BeatmapLevelsModel.GetBeatmapLevelResult getBeatmapLevelResult = await _beatmapLevelsModel.GetBeatmapLevelAsync(previewBeatmapLevel.levelID, CancellationToken.None);

            if (getBeatmapLevelResult.isError)
            {
                return(await NextDifficultyBeatmap());
            }
            IDifficultyBeatmapSet?difficultyBeatmapSet = getBeatmapLevelResult.beatmapLevel.beatmapLevelData.difficultyBeatmapSets.FirstOrDefault(x => x.beatmapCharacteristic.serializedName == _gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName)
                                                         ?? getBeatmapLevelResult.beatmapLevel.beatmapLevelData.difficultyBeatmapSets.First();
            IDifficultyBeatmap difficultyBeatmap = difficultyBeatmapSet.difficultyBeatmaps.FirstOrDefault(x => x.difficultyRank <= _gameplayCoreSceneSetupData.difficultyBeatmap.difficultyRank)
                                                   ?? difficultyBeatmapSet.difficultyBeatmaps.Last(x => x.difficultyRank > _gameplayCoreSceneSetupData.difficultyBeatmap.difficultyRank);

            string[]? requirements = SongCore.Collections.RetrieveExtraSongData(previewBeatmapLevel.levelID)?._difficulties?.First(x => x._difficulty == difficultyBeatmap.difficulty).additionalDifficultyData._requirements;
            return(requirements?.All(x => SongCore.Collections.capabilities.Contains(x)) ?? true ? difficultyBeatmap : await NextDifficultyBeatmap());
        }
Ejemplo n.º 5
0
        public static async void PreloadBeatmapLevelAsync(
            BeatmapCharacteristicSO characteristic,
            IPreviewBeatmapLevel selectedLevel,
            BeatmapDifficulty difficulty,
            GameplayModifiers modifiers,
            Action <PreloadedLevel> callback)
        {
            _beatmapLevelsModel     = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault();
            _contentModelSO         = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().FirstOrDefault();
            _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>();

            var token = new CancellationTokenSource();

            var previewCache = _beatmapLevelsModel
                               .GetPrivateField <Dictionary <string, IPreviewBeatmapLevel> >("_loadedPreviewBeatmapLevels");

            if (!previewCache.ContainsKey(selectedLevel.levelID))
            {
                previewCache.Add(selectedLevel.levelID, selectedLevel);
                _beatmapLevelsModel.SetPrivateField("_loadedPreviewBeatmapLevels", previewCache);
            }

            var entitlementStatus =
                await _contentModelSO.GetLevelEntitlementStatusAsync(selectedLevel.levelID, token.Token);

            if (entitlementStatus == AdditionalContentModel.EntitlementStatus.Owned)
            {
                var getBeatmapLevelResult =
                    await _beatmapLevelsModel.GetBeatmapLevelAsync(selectedLevel.levelID, token.Token);

                if (getBeatmapLevelResult.isError)
                {
                    callback?.Invoke(null);
                    return;
                }

                var playerData = Resources.FindObjectsOfTypeAll <PlayerDataModel>().FirstOrDefault().playerData;

                var playerSettings = playerData.playerSpecificSettings;
                var environmentOverrideSettings = playerData.overrideEnvironmentSettings;

                var colorSchemesSettings = playerData.colorSchemesSettings.overrideDefaultColors
                    ? playerData.colorSchemesSettings.GetColorSchemeForId(playerData.colorSchemesSettings
                                                                          .selectedColorSchemeId)
                    : null;


                var difficultyBeatmap =
                    getBeatmapLevelResult.beatmapLevel.GetDifficultyBeatmap(characteristic, difficulty, false);

                callback?.Invoke(new PreloadedLevel()
                {
                    characteristic         = characteristic,
                    levelResult            = getBeatmapLevelResult,
                    modifiers              = modifiers,
                    difficulty             = difficultyBeatmap,
                    playerData             = playerData,
                    playerSpecificSettings = playerSettings,
                    environmentSettings    = environmentOverrideSettings,
                    colorScheme            = colorSchemesSettings
                });
            }
            else
            {
                callback?.Invoke(null);
            }
        }