Exemplo n.º 1
0
        private void StudioSaveLoadApi_SceneLoad(object sender, SceneLoadEventArgs e)
        {
#if DEBUG
            //Logger.LogDebug( $"StudioSaveLoadApi_SceneLoad({sender}, {e}) {CurrentScenePathCandidate}, {e.Operation}");
#endif
            if (e.Operation == SceneOperationKind.Clear)
            {
                _currentScenePath = _currentScenePathCandidate = string.Empty;
            }

            var coroutines = new List <IEnumerator>();

            if (!string.IsNullOrEmpty(_currentScenePathCandidate) && e.Operation == SceneOperationKind.Load)
            {
                _currentScenePath          = _currentScenePathCandidate;
                _currentScenePathCandidate = string.Empty;
                if (_navigationInProgress)
                {
                    coroutines.Add(
                        CoroutineUtils.CreateCoroutine(() => PlayNotificationSound(NotificationSound.Success)));
                    coroutines.Add(SetPageCoroutine(_currentScenePath));
                }
            }

            coroutines.Add(CoroutineUtils.CreateCoroutine(() =>
            {
                _navigationInProgress = false;
                TrackLastLoadedScene();
            }));
            coroutines.Add(SaveTrackingFileCouroutine(_saveTrackingFileDelay));
            StartCoroutine(CoroutineUtils.ComposeCoroutine(coroutines.ToArray()));
        }
Exemplo n.º 2
0
 internal void Update()
 {
     if (_cleaningActive || !CleanCacheHotkey.Value.IsPressed())
     {
         return;
     }
     _cleaningActive = true;
     StartCoroutine(CoroutineUtils.ComposeCoroutine(
                        CleanTranslationCacheCoroutine(),
                        PostCleanupCoroutine(),
                        CoroutineUtils.CreateCoroutine(() => _cleaningActive = false)));
 }
Exemplo n.º 3
0
        private void StudioSaveLoadApi_SceneLoad(object sender, SceneLoadEventArgs e)
        {
            UpdateSaveReady();
            if (e.Operation == SceneOperationKind.Clear)
            {
                _currentScenePath = _currentScenePathCandidate = string.Empty;
            }

            var coroutines = GeBoCommon.Utilities.ListPool <IEnumerator> .Get();

            try
            {
                if (!string.IsNullOrEmpty(_currentScenePathCandidate) && e.Operation == SceneOperationKind.Load)
                {
                    _currentScenePath          = _currentScenePathCandidate;
                    _currentScenePathCandidate = string.Empty;
                    if (_navigationInProgress)
                    {
                        coroutines.Add(
                            CoroutineUtils.CreateCoroutine(() => PlayNotificationSound(NotificationSound.Success)));
                        coroutines.Add(SetPageCoroutine(_currentScenePath));
                    }
                }

                coroutines.Add(CoroutineUtils.CreateCoroutine(() =>
                {
                    _navigationInProgress = false;
                    TrackLastLoadedScene();
                }));
                coroutines.Add(SaveTrackingFileCouroutine());
                StartCoroutine(CoroutineUtils.ComposeCoroutine(coroutines.ToArray()));
            }
            finally
            {
                GeBoCommon.Utilities.ListPool <IEnumerator> .Release(coroutines);
            }
        }
Exemplo n.º 4
0
        private void NavigateScene(int offset)
        {
            var navigated = false;

            if (_navigationInProgress)
            {
                return;
            }

            _navigationInProgress = true;
            Logger.LogDebug($"Attempting navigate to scene: {offset:+#;-#;0}");
            try
            {
                var paths = NormalizedScenePaths;
                var index = -1;
                if (!_currentScenePath.IsNullOrEmpty() && !paths.IsNullOrEmpty())
                {
                    index = paths.IndexOf(_currentScenePath);
                }

                if (index == -1)
                {
                    if (!paths.IsNullOrEmpty())
                    {
                        Logger.LogDebug(
                            $"Folder changed, resuming navigation for: {PathUtils.GetRelativePath(SceneUtils.StudioSceneRootFolder, _currentSceneFolder)}");
                        if (LoadLastLoadedScene())
                        {
                            navigated = true;
                        }
                    }
                }
                else
                {
                    string nextImage = null;
                    while (nextImage is null)
                    {
                        index -= offset;
                        if (index < 0 || index >= paths.Count)
                        {
                            Logger.LogInfoMessage("No further scenes to navigate to.");
                            return;
                        }

                        nextImage = paths[index];
                        if (IsSceneValid(nextImage))
                        {
                            continue;
                        }

                        Logger.LogWarningMessage($"Skipping invalid scene file: {nextImage}");
                        nextImage = null;
                    }

                    var coroutines = GeBoCommon.Utilities.ListPool <IEnumerator> .Get();

                    try
                    {
                        coroutines.Add(CoroutineUtils.CreateCoroutine(
                                           () => Logger.LogInfoMessage(
                                               $"Loading scene {paths.Count - index}/{paths.Count} ('{PathUtils.GetRelativePath(SceneUtils.StudioSceneRootFolder, nextImage)}')")));
                        coroutines.Add(LoadScene(nextImage));

                        StartCoroutine(CoroutineUtils.ComposeCoroutine(coroutines.ToArray()));
                    }
                    finally
                    {
                        GeBoCommon.Utilities.ListPool <IEnumerator> .Release(coroutines);
                    }

                    navigated = true;
                }
            }
            catch (Exception err)
            {
                Logger.LogException(err, this, nameof(NavigateScene));
            }
            finally
            {
                // error encountered during navigation
                if (!navigated)
                {
                    _navigationInProgress = false;
                    PlayNotificationSound(NotificationSound.Error);
                }
            }

            if (navigated)
            {
                _setPage = true;
            }
        }
Exemplo n.º 5
0
        private void NavigateScene(int offset)
        {
            var navigated = false;

            if (!_navigationInProgress)
            {
                _navigationInProgress = true;
                Logger.LogDebug($"Attempting navigate to scene: {offset}");
                try
                {
                    var paths = NormalizedScenePaths;
                    var index = -1;
                    if (!_currentScenePath.IsNullOrEmpty() && !paths.IsNullOrEmpty())
                    {
                        index = paths.IndexOf(_currentScenePath);
                    }

                    if (index == -1)
                    {
                        if (!paths.IsNullOrEmpty())
                        {
                            Logger.LogInfo(
                                $"Folder changed, resuming navigation for: {PathUtils.GetRelativePath(SceneUtils.StudioSceneRootFolder, _currentSceneFolder)}");
                            if (LoadLastLoadedScene())
                            {
                                navigated = true;
                            }
                        }
                    }
                    else
                    {
                        string nextImage = null;
                        while (nextImage is null)
                        {
                            index -= offset;
                            if (index < 0 || index >= paths.Count)
                            {
                                Logger.Log(BepInLogLevel.Info | BepInLogLevel.Message,
                                           "No further scenes to navigate to.");
                                return;
                            }

                            nextImage = paths[index];
                            if (IsSceneValid(nextImage))
                            {
                                continue;
                            }

                            Logger.Log(BepInLogLevel.Warning | BepInLogLevel.Message,
                                       $"Skipping invalid scene file: {nextImage}");
                            nextImage = null;
                        }

                        var coroutines = new List <IEnumerator>
                        {
                            CoroutineUtils.CreateCoroutine(
                                () => Logger.Log(BepInLogLevel.Message | BepInLogLevel.Info,
                                                 $"Loading scene {paths.Count - index}/{paths.Count} ('{PathUtils.GetRelativePath(SceneUtils.StudioSceneRootFolder, nextImage)}')")),
                            Singleton <Studio.Studio> .Instance.LoadSceneCoroutine(nextImage)
                        };

                        StartCoroutine(CoroutineUtils.ComposeCoroutine(coroutines.ToArray()));

                        navigated = true;
                    }
                }
                catch (Exception err)
                {
                    Logger.LogError($"Error navigating scene: {err}");
                }
                finally
                {
                    // error encountered during navigation
                    if (!navigated)
                    {
                        _navigationInProgress = false;
                        PlayNotificationSound(NotificationSound.Error);
                    }
                }

                if (navigated)
                {
                    _setPage = true;
                }
            }
        }