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); } }
protected override void DidActivate(bool firstActivation, ActivationType type) { base.DidActivate(firstActivation, type); if (firstActivation) { if (Plugin.DownloaderExists) { downloader = new BeatSaverDownloaderInterop(); if (downloader == null) { Plugin.log.Warn($"{nameof(BeatSaverDownloaderInterop)} could not be created."); } else { MoreSongsAvailable = downloader.CanCreate; Plugin.log.Debug($"{nameof(MoreSongsAvailable)} is {MoreSongsAvailable}"); } } else { Plugin.log.Warn($"BeatSaverDownloader not found, More Songs button won't be created."); MoreSongsAvailable = false; } _songsTableView.tableView.didSelectCellWithIdxEvent += SongsTableView_DidSelectRow; _songsTableView.tableView.dataSource = this; _playerDataModel = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().First(); _additionalContentModel = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().First(); } SelectTopButtons(TopButtonsState.Select); }
public static async Task <AdditionalContentModel.EntitlementStatus> GetEntitlementForLevel(IPreviewBeatmapLevel level) { if (AdditionalContentModel != null) { return(await AdditionalContentModel.GetLevelEntitlementStatusAsync(level.levelID, CancellationToken.None)); } return(AdditionalContentModel.EntitlementStatus.Owned); }
public static async Task <bool> HasDLCLevel(string levelId, AdditionalContentModel additionalContentModel = null) { additionalContentModel = additionalContentModel ?? Resources.FindObjectsOfTypeAll <AdditionalContentModel>().FirstOrDefault(); if (additionalContentModel != null) { getStatusCancellationTokenSource?.Cancel(); getStatusCancellationTokenSource = new CancellationTokenSource(); var token = getStatusCancellationTokenSource.Token; return(await additionalContentModel.GetLevelEntitlementStatusAsync(levelId, token) == AdditionalContentModel.EntitlementStatus.Owned); } return(false); }
public static void Init() { if (_loaded) { return; } _loaded = true; Plugin.log.Debug("Loading level loader"); _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault(); _contentModelSO = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().FirstOrDefault(); _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>(); }
protected override void DidActivate(bool firstActivation, ActivationType type) { base.DidActivate(firstActivation, type); if (firstActivation) { _playerDataModel = Resources.FindObjectsOfTypeAll <PlayerDataModel>().First(); _additionalContentModel = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().First(); } if (type == ActivationType.AddedToHierarchy) { songTable.tableView.didSelectCellWithIdxEvent += SongsTableView_DidSelectRow; songTable.tableView.dataSource = this; } }
protected override void DidActivate(bool firstActivation, ActivationType type) { base.DidActivate(firstActivation, type); if (firstActivation) { _songsTableView.tableView.didSelectCellWithIdxEvent += SongsTableView_DidSelectRow; _songsTableView.tableView.dataSource = this; _additionalContentModel = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().First(); _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().First(); } _selectedSong = null; NotifyPropertyChanged(); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// <summary> /// Has a DLC level /// </summary> /// <param name="p_LevelID">Level ID</param> /// <param name="p_AdditionalContentModel">Additional content</param> /// <returns></returns> public static async Task <bool> HasDLCLevel(string p_LevelID, AdditionalContentModel p_AdditionalContentModel = 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_AdditionalContentModel = p_AdditionalContentModel ?? Resources.FindObjectsOfTypeAll <AdditionalContentModel>().FirstOrDefault(); if (p_AdditionalContentModel != null) { m_GetStatusCancellationTokenSource?.Cancel(); m_GetStatusCancellationTokenSource = new CancellationTokenSource(); var l_Token = m_GetStatusCancellationTokenSource.Token; return(await p_AdditionalContentModel.GetLevelEntitlementStatusAsync(p_LevelID, l_Token) == AdditionalContentModel.EntitlementStatus.Owned); } return(false); }
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); } }