Ejemplo n.º 1
0
        public async void Initialize()
        {
            if (CreateHsvConfigsFolderIfYeetedByPlayer())
            {
                await SaveConfig(Path.Combine(_hsvConfigsFolderPath, "HitScoreVisualizerConfig (default).json"), Configuration.Default).ConfigureAwait(false);

                var oldHsvConfigPath = Path.Combine(UnityGame.UserDataPath, "HitScoreVisualizerConfig.json");
                if (File.Exists(oldHsvConfigPath))
                {
                    try
                    {
                        var destinationHsvConfigPath = Path.Combine(_hsvConfigsFolderPath, "HitScoreVisualizerConfig (imported).json");
                        File.Move(oldHsvConfigPath, destinationHsvConfigPath);

                        _hsvConfig.ConfigFilePath = destinationHsvConfigPath;
                    }
                    catch (Exception e)
                    {
                        _siraLog.Warning(e);
                    }
                }
            }

            if (_hsvConfig.ConfigFilePath == null)
            {
                return;
            }

            var fullPath = Path.Combine(_hsvConfigsFolderPath, _hsvConfig.ConfigFilePath);

            if (!File.Exists(fullPath))
            {
                _hsvConfig.ConfigFilePath = null;
                return;
            }

            var userConfig = await LoadConfig(_hsvConfig.ConfigFilePath).ConfigureAwait(false);

            if (userConfig == null)
            {
                _siraLog.Warning($"Couldn't load userConfig at {fullPath}");
                return;
            }

            var configFileInfo = new ConfigFileInfo(Path.GetFileNameWithoutExtension(_hsvConfig.ConfigFilePath), _hsvConfig.ConfigFilePath)
            {
                Configuration = userConfig,
                State         = GetConfigState(userConfig, Path.GetFileNameWithoutExtension(_hsvConfig.ConfigFilePath), true)
            };

            await SelectUserConfig(configFileInfo).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        private Sprite?LoadSpriteFromResources(Assembly assembly, string resourcePath, float pixelsPerUnit = 256.0f)
        {
            using var stream = assembly.GetManifestResourceStream(resourcePath);
            if (stream == null)
            {
                _siraLog.Warning($"Couldn't find embedded resource {resourcePath}");
                return(null);
            }

            byte[] imageData = new byte[stream.Length];
            stream.Read(imageData, 0, (int)stream.Length);
            if (imageData.Length == 0)
            {
                return(null);
            }

            var texture = new Texture2D(2, 2, TextureFormat.RGBA32, false, false);

            texture.LoadImage(imageData);

            var rect   = new Rect(0, 0, texture.width, texture.height);
            var sprite = Sprite.Create(texture, rect, Vector2.zero, pixelsPerUnit);

            _siraLog.Info($"Successfully loaded sprite {resourcePath}, w={texture.width}, h={texture.height}");

            return(sprite);
        }
Ejemplo n.º 3
0
        internal void UnpickConfig()
        {
            if (HasConfigCurrently)
            {
                UnityMainThreadTaskScheduler.Factory.StartNew(() =>
                {
                    if (customListTableData == null)
                    {
                        _siraLog.Warning($"{nameof(customListTableData)} is null.");
                        return;
                    }

                    customListTableData.tableView.ClearSelection();
                });

                _configProvider.UnselectUserConfig();
                NotifyPropertyChanged(nameof(HasConfigCurrently));
                NotifyPropertyChanged(nameof(LoadedConfigText));
            }
        }
Ejemplo n.º 4
0
        public void Initialize()
        {
            DisableScoreSubmissionIfNeeded();

            try
            {
                CreateCheckbox();
            }
            catch
            {
                _logger.Warning($"No checkbox for you sir");
            }
        }
Ejemplo n.º 5
0
        public void Initialize()
        {
            RegisterPluginChangeListeners();

            _logger.Info("Checking for Counters+");
            var pluginMetaData = PluginManager.EnabledPlugins.FirstOrDefault(x => x.Id == COUNTERS_PLUS_MOD_ID);

            if (pluginMetaData == null)
            {
                return;
            }

            if (pluginMetaData.HVersion.Major < 2)
            {
                _logger.Warning($"Version {pluginMetaData.HVersion} of Counters+ has been found, but is deemed incompatible with FPS Counter. NOT INTEGRATING!");
                return;
            }

            IsCountersPlusPresent = true;
            _logger.Info("Found Counters+");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Changes to a specific <see cref="CustomPlatform"/>
        /// </summary>
        /// <param name="index">The index of the new <see cref="CustomPlatform"/> in the list <see cref="AllPlatforms"/></param>
        internal void ChangeToPlatform(int index)
        {
            if (!_platformManager.allPlatforms[index].requirements.All(x => _platformManager.allPluginNames.Contains(x)))
            {
                _siraLog.Warning("Missing requirement for platform " + _platformManager.allPlatforms[index].name);
                ChangeToPlatform(0);
                return;
            }

            _siraLog.Info("Switching to " + _platformManager.allPlatforms[index].name);
            _platformManager.activePlatform?.gameObject.SetActive(false);
            DestroyCustomObjects();
            _platformManager.activePlatform = _platformManager.allPlatforms[index];

            SharedCoroutineStarter.instance.StartCoroutine(WaitAndSpawn());
            IEnumerator WaitAndSpawn()
            {
                if (_platformManager.activePlatform.transform.childCount == 0 && index != 0)
                {
                    yield return(SharedCoroutineStarter.instance.StartCoroutine(_platformLoader.LoadFromFileAsync(_platformManager.activePlatform.fullPath, _platformManager.HandlePlatformLoaded)));
                }

                yield return(new WaitForEndOfFrame());

                if (index != 0)
                {
                    _platformManager.activePlatform.gameObject.SetActive(true);
                    AddManagers(_platformManager.activePlatform);
                    SpawnCustomObjects();
                }
                else
                {
                    _platformManager.activePlatform = null;
                }

                _hider.HideObjectsForPlatform(_platformManager.allPlatforms[index]);
            }
        }