From 6ddc5ac3deebdd2a62f762c962e927add63a5795 Mon Sep 17 00:00:00 2001 From: Julian Kittel <62687014+ToniMacaroni@users.noreply.github.com> Date: Fri, 17 Dec 2021 12:37:26 +0100 Subject: [PATCH 1/3] SiraUtil3 --- SaberFactory/DataStore/MainAssetStore.cs | 1 + SaberFactory/Editor/Editor.cs | 1 + SaberFactory/Editor/EditorInstanceManager.cs | 1 + SaberFactory/EmbeddedAssetLoader.cs | 1 + SaberFactory/Game/EventPlayer.cs | 10 +++++----- SaberFactory/Game/SFSaberModelController.cs | 7 ++++++- SaberFactory/Game/SFSaberProvider.cs | 10 +++++----- SaberFactory/Game/SaberMovementTester.cs | 6 +++--- SaberFactory/Helpers/DebugTimer.cs | 1 + SaberFactory/Installers/PluginAppInstaller.cs | 2 +- SaberFactory/Installers/PluginGameInstaller.cs | 3 ++- .../Instances/CustomSaber/CustomSaberInstance.cs | 1 + SaberFactory/Instances/InstanceFactory.cs | 1 + SaberFactory/Instances/SaberInstance.cs | 1 + SaberFactory/Models/RemoteLocationPart.cs | 12 +++++++----- SaberFactory/Models/SaberSet.cs | 1 + SaberFactory/Plugin.cs | 7 ++++--- SaberFactory/PluginManager.cs | 11 ++++++----- .../UI/CustomSaber/CustomSaberUiComposition.cs | 1 + SaberFactory/UI/Lib/BSML/CustomComponentHandler.cs | 1 + SaberFactory/UI/Lib/BaseUiComposition.cs | 1 + SaberFactory/UI/Lib/CustomScreen.cs | 1 + SaberFactory/UI/Lib/CustomViewController.cs | 1 + SaberFactory/UI/Lib/SubView.cs | 1 + SaberFactory/UI/TrailPreviewer.cs | 1 + 25 files changed, 55 insertions(+), 29 deletions(-) diff --git a/SaberFactory/DataStore/MainAssetStore.cs b/SaberFactory/DataStore/MainAssetStore.cs index eee6ff9..c168ad1 100644 --- a/SaberFactory/DataStore/MainAssetStore.cs +++ b/SaberFactory/DataStore/MainAssetStore.cs @@ -8,6 +8,7 @@ using SaberFactory.Loaders; using SaberFactory.Models; using SaberFactory.Models.CustomSaber; +using SiraUtil.Logging; using SiraUtil.Tools; namespace SaberFactory.DataStore diff --git a/SaberFactory/Editor/Editor.cs b/SaberFactory/Editor/Editor.cs index 335eb88..271cad4 100644 --- a/SaberFactory/Editor/Editor.cs +++ b/SaberFactory/Editor/Editor.cs @@ -8,6 +8,7 @@ using SaberFactory.Models; using SaberFactory.UI; using SaberFactory.UI.Lib; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using Zenject; diff --git a/SaberFactory/Editor/EditorInstanceManager.cs b/SaberFactory/Editor/EditorInstanceManager.cs index 9bdfaed..bc8b726 100644 --- a/SaberFactory/Editor/EditorInstanceManager.cs +++ b/SaberFactory/Editor/EditorInstanceManager.cs @@ -2,6 +2,7 @@ using SaberFactory.Instances; using SaberFactory.Models; using SaberFactory.Serialization; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; diff --git a/SaberFactory/EmbeddedAssetLoader.cs b/SaberFactory/EmbeddedAssetLoader.cs index 7686ccc..093a0c2 100644 --- a/SaberFactory/EmbeddedAssetLoader.cs +++ b/SaberFactory/EmbeddedAssetLoader.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using SaberFactory.Helpers; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using Object = UnityEngine.Object; diff --git a/SaberFactory/Game/EventPlayer.cs b/SaberFactory/Game/EventPlayer.cs index 927c15b..f0b0196 100644 --- a/SaberFactory/Game/EventPlayer.cs +++ b/SaberFactory/Game/EventPlayer.cs @@ -18,7 +18,7 @@ internal class EventPlayer : IDisposable [Inject] private readonly GameEnergyCounter _energyCounter = null; - [Inject] private readonly ObstacleSaberSparkleEffectManager _obstacleSaberSparkleEffectManager = null; + //[Inject] private readonly ObstacleSaberSparkleEffectManager _obstacleSaberSparkleEffectManager = null; [Inject] private readonly PluginConfig _pluginConfig = null; @@ -36,8 +36,8 @@ public void Dispose() _beatmapObjectManager.noteWasCutEvent -= OnNoteCut; _beatmapObjectManager.noteWasMissedEvent -= OnNoteMiss; - _obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent -= SaberStartCollide; - _obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent -= SaberEndCollide; + //_obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent -= SaberStartCollide; + //_obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent -= SaberEndCollide; _energyCounter.gameEnergyDidReach0Event -= InvokeOnLevelFail; @@ -64,8 +64,8 @@ public void SetPartEventList(List partEventsList, SaberType saberTyp _beatmapObjectManager.noteWasMissedEvent += OnNoteMiss; // Sabers clashing - _obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent += SaberStartCollide; - _obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent += SaberEndCollide; + //_obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent += SaberStartCollide; + //_obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent += SaberEndCollide; // OnLevelFail _energyCounter.gameEnergyDidReach0Event += InvokeOnLevelFail; diff --git a/SaberFactory/Game/SFSaberModelController.cs b/SaberFactory/Game/SFSaberModelController.cs index e330c06..f9e883b 100644 --- a/SaberFactory/Game/SFSaberModelController.cs +++ b/SaberFactory/Game/SFSaberModelController.cs @@ -3,6 +3,7 @@ using SaberFactory.Instances; using SaberFactory.Models; using SiraUtil.Interfaces; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using Zenject; @@ -27,7 +28,11 @@ public void SetColor(Color color) _saberInstance.SetColor(color); } - public Color Color => _saberColor.GetValueOrDefault(); + public Color Color + { + get => _saberColor.GetValueOrDefault(); + set => SetColor(value); + } public override async void Init(Transform parent, Saber saber) { diff --git a/SaberFactory/Game/SFSaberProvider.cs b/SaberFactory/Game/SFSaberProvider.cs index 7e16914..42409d4 100644 --- a/SaberFactory/Game/SFSaberProvider.cs +++ b/SaberFactory/Game/SFSaberProvider.cs @@ -3,9 +3,9 @@ namespace SaberFactory.Game { - public class SFSaberProvider : IModelProvider - { - public Type Type => typeof(SfSaberModelController); - public int Priority => 300; - } + //public class SFSaberProvider : IModelProvider + //{ + // public Type Type => typeof(SfSaberModelController); + // public int Priority => 300; + //} } \ No newline at end of file diff --git a/SaberFactory/Game/SaberMovementTester.cs b/SaberFactory/Game/SaberMovementTester.cs index a4c66c4..527bafe 100644 --- a/SaberFactory/Game/SaberMovementTester.cs +++ b/SaberFactory/Game/SaberMovementTester.cs @@ -10,12 +10,12 @@ internal class SaberMovementTester : IInitializable { private readonly AudioTimeSyncController _audioController; private readonly InitData _initData; - private readonly SiraSaber.Factory _saberFactory; + private readonly SiraSaberFactory _saberFactory; private Transform _movementContainer; private SiraSaber _saber; - private SaberMovementTester(InitData initData, SiraSaber.Factory saberFactory, AudioTimeSyncController audioController) + private SaberMovementTester(InitData initData, SiraSaberFactory saberFactory, AudioTimeSyncController audioController) { _initData = initData; _saberFactory = saberFactory; @@ -35,7 +35,7 @@ public async void Initialize() _movementContainer = new GameObject("SaberTester").transform; _movementContainer.localPosition = new Vector3(0, 1.5f, 0); - _saber = _saberFactory.Create(); + _saber = _saberFactory.Spawn(SaberType.SaberA); _saber.transform.SetParent(_movementContainer, false); SharedCoroutineStarter.instance.StartCoroutine(AnimationCoroutine()); diff --git a/SaberFactory/Helpers/DebugTimer.cs b/SaberFactory/Helpers/DebugTimer.cs index 63f90af..8699486 100644 --- a/SaberFactory/Helpers/DebugTimer.cs +++ b/SaberFactory/Helpers/DebugTimer.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using SiraUtil.Logging; using SiraUtil.Tools; using Debug = UnityEngine.Debug; diff --git a/SaberFactory/Installers/PluginAppInstaller.cs b/SaberFactory/Installers/PluginAppInstaller.cs index 25f4249..595e093 100644 --- a/SaberFactory/Installers/PluginAppInstaller.cs +++ b/SaberFactory/Installers/PluginAppInstaller.cs @@ -50,7 +50,7 @@ public override void InstallBindings() Container.Bind().AsSingle(); Container.BindInstance(_metadata).WithId(nameof(SaberFactory)).AsCached(); - Container.BindLoggerAsSiraLogger(_logger); + //Container.BindLoggerAsSiraLogger(_logger); Container.BindInstance(_config).AsSingle(); Container.Bind().AsSingle(); diff --git a/SaberFactory/Installers/PluginGameInstaller.cs b/SaberFactory/Installers/PluginGameInstaller.cs index 536ee41..8a5a2b3 100644 --- a/SaberFactory/Installers/PluginGameInstaller.cs +++ b/SaberFactory/Installers/PluginGameInstaller.cs @@ -32,7 +32,8 @@ public override void InstallBindings() //Container.BindInterfacesAndSelfTo().AsSingle(); Container.BindInterfacesAndSelfTo().AsSingle(); - Container.Bind().To().AsSingle(); + //Container.Bind().To().AsSingle(); + Container.BindInstance(SiraUtil.Sabers.SaberModelRegistration.Create()); #if DEBUG && TEST_TRAIL diff --git a/SaberFactory/Instances/CustomSaber/CustomSaberInstance.cs b/SaberFactory/Instances/CustomSaber/CustomSaberInstance.cs index c590578..1721ac8 100644 --- a/SaberFactory/Instances/CustomSaber/CustomSaberInstance.cs +++ b/SaberFactory/Instances/CustomSaber/CustomSaberInstance.cs @@ -7,6 +7,7 @@ using SaberFactory.Instances.Trail; using SaberFactory.Models; using SaberFactory.Models.CustomSaber; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; diff --git a/SaberFactory/Instances/InstanceFactory.cs b/SaberFactory/Instances/InstanceFactory.cs index 8cd3ffb..358dd5b 100644 --- a/SaberFactory/Instances/InstanceFactory.cs +++ b/SaberFactory/Instances/InstanceFactory.cs @@ -1,5 +1,6 @@ using System; using SaberFactory.Models; +using SiraUtil.Logging; using SiraUtil.Tools; using Zenject; diff --git a/SaberFactory/Instances/SaberInstance.cs b/SaberFactory/Instances/SaberInstance.cs index a16520e..9d46802 100644 --- a/SaberFactory/Instances/SaberInstance.cs +++ b/SaberFactory/Instances/SaberInstance.cs @@ -9,6 +9,7 @@ using SaberFactory.Instances.PostProcessors; using SaberFactory.Instances.Trail; using SaberFactory.Models; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using Zenject; diff --git a/SaberFactory/Models/RemoteLocationPart.cs b/SaberFactory/Models/RemoteLocationPart.cs index a61d1ce..0898039 100644 --- a/SaberFactory/Models/RemoteLocationPart.cs +++ b/SaberFactory/Models/RemoteLocationPart.cs @@ -3,10 +3,12 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; +using BeatSaberMarkupLanguage; using SaberFactory.Helpers; using SaberFactory.UI; using SaberFactory.UI.Lib; using SiraUtil; +using SiraUtil.Web; using UnityEngine; namespace SaberFactory.Models @@ -17,9 +19,9 @@ internal class RemoteLocationPart : ICustomListItem private readonly DirectoryInfo _customSaberDir; private readonly string _filename; - private readonly WebClient _webClient; + private readonly IHttpService _webClient; - private RemoteLocationPart(InitData initData, WebClient webClient, PluginDirectories pluginDirs) + private RemoteLocationPart(InitData initData, IHttpService webClient, PluginDirectories pluginDirs) { _webClient = webClient; _customSaberDir = pluginDirs.CustomSaberDir; @@ -48,14 +50,14 @@ public async Task> Download(CancellationToken token) { try { - var response = await _webClient.GetAsync(RemoteLocation, token); - if (!response.IsSuccessStatusCode) + var response = await _webClient.GetAsync(RemoteLocation, null, token); + if (!response.Successful) { return default; } var filename = GetFilename(); - File.WriteAllBytes(_customSaberDir.GetFile(filename).FullName, response.ContentToBytes()); + File.WriteAllBytes(_customSaberDir.GetFile(filename).FullName, await response.ReadAsByteArrayAsync()); return new Tuple(true, "CustomSabers\\" + filename); } catch (Exception) diff --git a/SaberFactory/Models/SaberSet.cs b/SaberFactory/Models/SaberSet.cs index 45f8e19..59b2e92 100644 --- a/SaberFactory/Models/SaberSet.cs +++ b/SaberFactory/Models/SaberSet.cs @@ -5,6 +5,7 @@ using SaberFactory.DataStore; using SaberFactory.Helpers; using SaberFactory.Serialization; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using Zenject; diff --git a/SaberFactory/Plugin.cs b/SaberFactory/Plugin.cs index 882a2d1..548845e 100644 --- a/SaberFactory/Plugin.cs +++ b/SaberFactory/Plugin.cs @@ -36,9 +36,10 @@ public async void Init(IPALogger logger, Config conf, Zenjector zenjector, Plugi return; } - zenjector.OnApp().WithParameters(logger, pluginConfig, metadata); - zenjector.OnMenu(); - zenjector.OnGame(false); + zenjector.UseLogger(); + zenjector.Install(Location.App, logger, pluginConfig, metadata); + zenjector.Install(Location.Menu); + zenjector.Install(Location.Player | Location.MultiPlayer); } [OnEnable] diff --git a/SaberFactory/PluginManager.cs b/SaberFactory/PluginManager.cs index 321f292..1dcf197 100644 --- a/SaberFactory/PluginManager.cs +++ b/SaberFactory/PluginManager.cs @@ -4,6 +4,7 @@ using Hive.Versioning; using Newtonsoft.Json; using SiraUtil; +using SiraUtil.Web; using Version = Hive.Versioning.Version; //using SemVer; @@ -17,13 +18,13 @@ internal class PluginManager public Version LocalVersion => _localVersion ??= IPA.Loader.PluginManager.GetPluginFromId("SaberFactory").HVersion; - private readonly WebClient _webClient; + private readonly IHttpService _webClient; private Task _loadingTask; private Version _localVersion; - private PluginManager(WebClient webClient) + private PluginManager(IHttpService webClient) { _webClient = webClient; } @@ -38,10 +39,10 @@ private async Task GetNewestReleaseAsyncInternal(CancellationToken canc { try { - var response = await _webClient.GetAsync("https://api.github.com/repos/ToniMacaroni/SaberFactoryV2/releases", cancellationToken); - if (response.IsSuccessStatusCode) + var response = await _webClient.GetAsync("https://api.github.com/repos/ToniMacaroni/SaberFactoryV2/releases", null, cancellationToken); + if (response.Successful) { - var releases = response.ContentToJson(); + var releases = JsonConvert.DeserializeObject(await response.ReadAsStringAsync()); var release = releases[0]; release.LocalVersion = LocalVersion; return release; diff --git a/SaberFactory/UI/CustomSaber/CustomSaberUiComposition.cs b/SaberFactory/UI/CustomSaber/CustomSaberUiComposition.cs index 45aff10..70f3fc7 100644 --- a/SaberFactory/UI/CustomSaber/CustomSaberUiComposition.cs +++ b/SaberFactory/UI/CustomSaber/CustomSaberUiComposition.cs @@ -1,6 +1,7 @@ using SaberFactory.Models; using SaberFactory.UI.CustomSaber.Views; using SaberFactory.UI.Lib; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using VRUIControls; diff --git a/SaberFactory/UI/Lib/BSML/CustomComponentHandler.cs b/SaberFactory/UI/Lib/BSML/CustomComponentHandler.cs index 7d7d654..3f1349c 100644 --- a/SaberFactory/UI/Lib/BSML/CustomComponentHandler.cs +++ b/SaberFactory/UI/Lib/BSML/CustomComponentHandler.cs @@ -15,6 +15,7 @@ using IPA.Utilities; using Newtonsoft.Json.Linq; using SaberFactory.UI.Lib.BSML.Tags; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using Zenject; diff --git a/SaberFactory/UI/Lib/BaseUiComposition.cs b/SaberFactory/UI/Lib/BaseUiComposition.cs index 1f63f1d..902a2c6 100644 --- a/SaberFactory/UI/Lib/BaseUiComposition.cs +++ b/SaberFactory/UI/Lib/BaseUiComposition.cs @@ -3,6 +3,7 @@ using HMUI; using IPA.Utilities; using SaberFactory.Helpers; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using UnityEngine.UI; diff --git a/SaberFactory/UI/Lib/CustomScreen.cs b/SaberFactory/UI/Lib/CustomScreen.cs index c850ecd..ef0eb67 100644 --- a/SaberFactory/UI/Lib/CustomScreen.cs +++ b/SaberFactory/UI/Lib/CustomScreen.cs @@ -1,6 +1,7 @@ using System.Threading; using HMUI; using SaberFactory.Helpers; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using UnityEngine.UI; diff --git a/SaberFactory/UI/Lib/CustomViewController.cs b/SaberFactory/UI/Lib/CustomViewController.cs index b1bb6e2..7e17ff7 100644 --- a/SaberFactory/UI/Lib/CustomViewController.cs +++ b/SaberFactory/UI/Lib/CustomViewController.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using HMUI; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using Zenject; diff --git a/SaberFactory/UI/Lib/SubView.cs b/SaberFactory/UI/Lib/SubView.cs index 089030e..b233e4c 100644 --- a/SaberFactory/UI/Lib/SubView.cs +++ b/SaberFactory/UI/Lib/SubView.cs @@ -6,6 +6,7 @@ using HMUI; using JetBrains.Annotations; using SaberFactory.Helpers; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using UnityEngine.UI; diff --git a/SaberFactory/UI/TrailPreviewer.cs b/SaberFactory/UI/TrailPreviewer.cs index d9090bd..6c80854 100644 --- a/SaberFactory/UI/TrailPreviewer.cs +++ b/SaberFactory/UI/TrailPreviewer.cs @@ -3,6 +3,7 @@ using HarmonyLib; using SaberFactory.Helpers; using SaberFactory.Instances.Trail; +using SiraUtil.Logging; using SiraUtil.Tools; using UnityEngine; using Object = UnityEngine.Object; From b2484d4f830f53f8a684106fb0accd6e943898a5 Mon Sep 17 00:00:00 2001 From: Julian Kittel <62687014+ToniMacaroni@users.noreply.github.com> Date: Wed, 22 Dec 2021 16:17:54 +0100 Subject: [PATCH 2/3] Colorscheme shader props --- SaberFactory/Editor/Editor.cs | 8 ++++++++ SaberFactory/Helpers/MaterialProperties.cs | 3 +++ SaberFactory/Plugin.cs | 1 + SaberFactory/manifest.json | 2 +- changelog.md | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/SaberFactory/Editor/Editor.cs b/SaberFactory/Editor/Editor.cs index 271cad4..dbe1fc8 100644 --- a/SaberFactory/Editor/Editor.cs +++ b/SaberFactory/Editor/Editor.cs @@ -93,6 +93,7 @@ public async void Initialize() // Create Pedestal var pos = new Vector3(0.3f, 0, 0.9f); await _pedestal.Instantiate(pos, Quaternion.Euler(0, 25, 0)); + SetupGlobalShaderVars(); } public async void Open() @@ -184,5 +185,12 @@ private async void OnModelCompositionSet(ModelComposition composition) await AnimationHelper.AsyncAnimation(0.3f, CancellationToken.None, t => { parent.localScale = new Vector3(t, t, t); }); } } + + private void SetupGlobalShaderVars() + { + var scheme = _playerDataModel.playerData.colorSchemesSettings.GetSelectedColorScheme(); + Shader.SetGlobalColor(MaterialProperties.UserColorLeft, scheme.saberAColor); + Shader.SetGlobalColor(MaterialProperties.UserColorRight, scheme.saberBColor); + } } } \ No newline at end of file diff --git a/SaberFactory/Helpers/MaterialProperties.cs b/SaberFactory/Helpers/MaterialProperties.cs index 9459222..a0a4af3 100644 --- a/SaberFactory/Helpers/MaterialProperties.cs +++ b/SaberFactory/Helpers/MaterialProperties.cs @@ -9,5 +9,8 @@ internal static class MaterialProperties public static readonly int CustomColors = Shader.PropertyToID("_CustomColors"); public static readonly int Glow = Shader.PropertyToID("_Glow"); public static readonly int Bloom = Shader.PropertyToID("_Bloom"); + + public static readonly int UserColorLeft = Shader.PropertyToID("_UserColorLeft"); + public static readonly int UserColorRight = Shader.PropertyToID("_UserColorRight"); } } \ No newline at end of file diff --git a/SaberFactory/Plugin.cs b/SaberFactory/Plugin.cs index 548845e..736ce8f 100644 --- a/SaberFactory/Plugin.cs +++ b/SaberFactory/Plugin.cs @@ -37,6 +37,7 @@ public async void Init(IPALogger logger, Config conf, Zenjector zenjector, Plugi } zenjector.UseLogger(); + zenjector.UseHttpService(); zenjector.Install(Location.App, logger, pluginConfig, metadata); zenjector.Install(Location.Menu); zenjector.Install(Location.Player | Location.MultiPlayer); diff --git a/SaberFactory/manifest.json b/SaberFactory/manifest.json index b51e710..62e5a91 100644 --- a/SaberFactory/manifest.json +++ b/SaberFactory/manifest.json @@ -8,7 +8,7 @@ "gameVersion": "1.16.4", "dependsOn": { "BSIPA": "^4.2.0", - "SiraUtil": "^2.5.8", + "SiraUtil": "^3.0.0", "BeatSaberMarkupLanguage": "^1.5.4" } } \ No newline at end of file diff --git a/changelog.md b/changelog.md index a57d5b9..07203b1 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ - Added option to automatically reload the saber when the file changes (`ReloadOnSaberUpdate` in config) - Added option to modify saber length (added by @9cxndy) - Moved .meta and .trail files to seperate folder (`UserData\Saber Factory\Cache`) to not fill up the CustomSabers folder +- Added `_UserColorLeft` and `_UserColorRight` global shader variables that will be assigned to left saber/right saber color - Fixed compatibility issues with mods that bind `PluginMetadata` - Fixed particle systems sometimes hiding behind ui - Many internal code changes From fff26f2f63a332bf8d1f128aac9e3ea98e11c137 Mon Sep 17 00:00:00 2001 From: Julian Kittel <62687014+ToniMacaroni@users.noreply.github.com> Date: Wed, 22 Dec 2021 22:29:40 +0100 Subject: [PATCH 3/3] code quality changes --- .editorconfig | 13 +++++++++ SaberFactory.sln | 9 ++++-- SaberFactory/DataStore/TextureAsset.cs | 13 ++++++++- SaberFactory/Editor/Pedestal.cs | 4 +-- SaberFactory/Editor/SaberGrabController.cs | 12 ++++++-- SaberFactory/Game/AFHandler.cs | 7 ++++- SaberFactory/Game/EventPlayer.cs | 18 ++++++++---- SaberFactory/Helpers/DebugMenu.cs | 1 - SaberFactory/Helpers/ShaderPropertyInfo.cs | 2 +- .../Installers/PluginGameInstaller.cs | 3 +- SaberFactory/Instances/Trail/SFTrail.cs | 7 ++++- SaberFactory/Misc/VertexPool.cs | 5 ++-- SaberFactory/Models/PreloadMetaData.cs | 29 +++++++++++++++++-- SaberFactory/Plugin.cs | 5 ++-- SaberFactory/SaberFactory.csproj | 5 ++++ SaberFactory/UI/CustomSaber/Views/MainView.cs | 2 +- .../UI/CustomSaber/Views/SaberSelectorView.cs | 2 +- .../UI/Lib/BSML/BackgroundableHandler.cs | 10 +++---- .../Lib/BSML/ButtonImageControllerHandler.cs | 10 +++++-- SaberFactory/UI/Lib/SubViewSwitcher.cs | 20 ++++++++++--- SaberFactory/UI/TrailPreviewer.cs | 2 +- 21 files changed, 141 insertions(+), 38 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..257a0b7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +[*.cs] + +# UNT0023: Coalescing assignment on Unity objects +dotnet_diagnostic.UNT0023.severity = error + +# UNT0022: Inefficient position/rotation assignment +dotnet_diagnostic.UNT0022.severity = error + +# UNT0007: Null coalescing on Unity objects +dotnet_diagnostic.UNT0007.severity = error + +# UNT0008: Null propagation on Unity objects +dotnet_diagnostic.UNT0008.severity = error diff --git a/SaberFactory.sln b/SaberFactory.sln index d399265..29d309f 100644 --- a/SaberFactory.sln +++ b/SaberFactory.sln @@ -1,12 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29709.97 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.31911.260 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaberFactory", "SaberFactory\SaberFactory.csproj", "{C287398D-B333-4DFE-9C7E-9518D9D09745}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SaberFactory.Unity", "SaberFactory.Unity\SaberFactory.Unity.csproj", "{42D12C91-86D3-4006-8D15-0291488970B6}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2B173B38-BE01-4606-9F77-D09B360CBC69}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/SaberFactory/DataStore/TextureAsset.cs b/SaberFactory/DataStore/TextureAsset.cs index a6a5709..a62b227 100644 --- a/SaberFactory/DataStore/TextureAsset.cs +++ b/SaberFactory/DataStore/TextureAsset.cs @@ -7,7 +7,18 @@ namespace SaberFactory.DataStore { internal class TextureAsset : IDisposable { - public Sprite Sprite => _cachedSprite ??= CreateSprite(); + public Sprite Sprite + { + get + { + if (_cachedSprite == null) + { + _cachedSprite = CreateSprite(); + } + return _cachedSprite; + } + } + public bool IsInUse; public string Name; public EAssetOrigin Origin; diff --git a/SaberFactory/Editor/Pedestal.cs b/SaberFactory/Editor/Pedestal.cs index 44d80bd..27ea8a7 100644 --- a/SaberFactory/Editor/Pedestal.cs +++ b/SaberFactory/Editor/Pedestal.cs @@ -60,8 +60,8 @@ public async Task Instantiate(Vector3 pos, Quaternion rot) SaberContainerTransform.localPosition += new Vector3(0, 1, 0); SaberContainerTransform.localEulerAngles = new Vector3(-90, 0, 0); - _rootTransform.position = pos; - _rootTransform.rotation = rot; + _rootTransform.SetPositionAndRotation(pos, rot); + IsVisible = false; } diff --git a/SaberFactory/Editor/SaberGrabController.cs b/SaberFactory/Editor/SaberGrabController.cs index e8f6531..36cdda6 100644 --- a/SaberFactory/Editor/SaberGrabController.cs +++ b/SaberFactory/Editor/SaberGrabController.cs @@ -33,7 +33,11 @@ public void ShowHandle() } _isHandleVisisble = true; - _menuPlayerController.leftController?.transform.Find("MenuHandle")?.gameObject.SetActive(_isHandleVisisble); + + if (_menuPlayerController.leftController != null && _menuPlayerController.leftController.transform.Find("MenuHandle") is { } handle) + { + handle.gameObject.SetActive(_isHandleVisisble); + } } public void HideHandle() @@ -44,7 +48,11 @@ public void HideHandle() } _isHandleVisisble = false; - _menuPlayerController.leftController?.transform.Find("MenuHandle")?.gameObject.SetActive(_isHandleVisisble); + + if (_menuPlayerController != null && _menuPlayerController.leftController.transform.Find("MenuHandle") is { } handle) + { + handle.gameObject.SetActive(_isHandleVisisble); + } } } } \ No newline at end of file diff --git a/SaberFactory/Game/AFHandler.cs b/SaberFactory/Game/AFHandler.cs index 5f7e951..69e2a73 100644 --- a/SaberFactory/Game/AFHandler.cs +++ b/SaberFactory/Game/AFHandler.cs @@ -78,7 +78,12 @@ public async Task InitPosition(Transform transform, float xPos) private async Task GetThruster() { - return _thruster ??= await _assetLoader.LoadAsset("Thruster"); + if (_thruster == null) + { + _thruster = await _assetLoader.LoadAsset("Thruster"); + } + + return _thruster; } } } \ No newline at end of file diff --git a/SaberFactory/Game/EventPlayer.cs b/SaberFactory/Game/EventPlayer.cs index f0b0196..70e750d 100644 --- a/SaberFactory/Game/EventPlayer.cs +++ b/SaberFactory/Game/EventPlayer.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using IPA.Utilities; +using ModestTree; using SaberFactory.Configuration; using SaberFactory.Models; using UnityEngine; @@ -18,11 +19,14 @@ internal class EventPlayer : IDisposable [Inject] private readonly GameEnergyCounter _energyCounter = null; - //[Inject] private readonly ObstacleSaberSparkleEffectManager _obstacleSaberSparkleEffectManager = null; + [InjectOptional] private ObstacleSaberSparkleEffectManager _obstacleSaberSparkleEffectManager; [Inject] private readonly PluginConfig _pluginConfig = null; [Inject] private readonly ScoreController _scoreController = null; + + [Inject] private readonly MonoKernel _monoKernel = null; + private bool _didInit; [Inject(Id = "LastNoteId")] private float _lastNoteTime; @@ -36,8 +40,8 @@ public void Dispose() _beatmapObjectManager.noteWasCutEvent -= OnNoteCut; _beatmapObjectManager.noteWasMissedEvent -= OnNoteMiss; - //_obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent -= SaberStartCollide; - //_obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent -= SaberEndCollide; + _obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent -= SaberStartCollide; + _obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent -= SaberEndCollide; _energyCounter.gameEnergyDidReach0Event -= InvokeOnLevelFail; @@ -64,8 +68,12 @@ public void SetPartEventList(List partEventsList, SaberType saberTyp _beatmapObjectManager.noteWasMissedEvent += OnNoteMiss; // Sabers clashing - //_obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent += SaberStartCollide; - //_obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent += SaberEndCollide; + if (_obstacleSaberSparkleEffectManager == null) + { + _obstacleSaberSparkleEffectManager = _monoKernel.GetComponentInChildren(); + } + _obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent += SaberStartCollide; + _obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent += SaberEndCollide; // OnLevelFail _energyCounter.gameEnergyDidReach0Event += InvokeOnLevelFail; diff --git a/SaberFactory/Helpers/DebugMenu.cs b/SaberFactory/Helpers/DebugMenu.cs index 9d4570a..5f6020b 100644 --- a/SaberFactory/Helpers/DebugMenu.cs +++ b/SaberFactory/Helpers/DebugMenu.cs @@ -11,7 +11,6 @@ public class DebugMenu : MonoBehaviour private void Start() { - Debug.LogWarning("Hello"); } private void OnGUI() diff --git a/SaberFactory/Helpers/ShaderPropertyInfo.cs b/SaberFactory/Helpers/ShaderPropertyInfo.cs index 0c73de3..05ebba2 100644 --- a/SaberFactory/Helpers/ShaderPropertyInfo.cs +++ b/SaberFactory/Helpers/ShaderPropertyInfo.cs @@ -184,7 +184,7 @@ public override void FromJson(JToken token, Material mat, params object[] args) public override JToken ToJson(Material mat) { var tex = (Texture)GetValue(mat); - return JToken.FromObject(tex?.name??""); + return JToken.FromObject(tex != null ? tex.name : ""); } } diff --git a/SaberFactory/Installers/PluginGameInstaller.cs b/SaberFactory/Installers/PluginGameInstaller.cs index 8a5a2b3..49783f8 100644 --- a/SaberFactory/Installers/PluginGameInstaller.cs +++ b/SaberFactory/Installers/PluginGameInstaller.cs @@ -6,6 +6,7 @@ using SaberFactory.Helpers; using SaberFactory.Models; using SiraUtil.Interfaces; +using SiraUtil.Sabers; using Zenject; namespace SaberFactory.Installers @@ -33,7 +34,7 @@ public override void InstallBindings() //Container.BindInterfacesAndSelfTo().AsSingle(); Container.BindInterfacesAndSelfTo().AsSingle(); //Container.Bind().To().AsSingle(); - Container.BindInstance(SiraUtil.Sabers.SaberModelRegistration.Create()); + Container.BindInstance(SaberModelRegistration.Create()); #if DEBUG && TEST_TRAIL diff --git a/SaberFactory/Instances/Trail/SFTrail.cs b/SaberFactory/Instances/Trail/SFTrail.cs index ad93bd5..6533feb 100644 --- a/SaberFactory/Instances/Trail/SFTrail.cs +++ b/SaberFactory/Instances/Trail/SFTrail.cs @@ -1,5 +1,6 @@ using System; using SaberFactory.Helpers; +using TMPro; using UnityEngine; namespace SaberFactory.Instances.Trail @@ -115,7 +116,11 @@ public override float GetTrailWidth(BladeMovementDataElement lastAddedData) public void SetMaterial(Material newMaterial) { _customMaterial = newMaterial; - _trailRenderer?.Cast().SetMaterial(_customMaterial); + + if (_trailRenderer != null) + { + _trailRenderer.Cast().SetMaterial(_customMaterial); + } } } } \ No newline at end of file diff --git a/SaberFactory/Misc/VertexPool.cs b/SaberFactory/Misc/VertexPool.cs index 064a0a0..ab1db92 100644 --- a/SaberFactory/Misc/VertexPool.cs +++ b/SaberFactory/Misc/VertexPool.cs @@ -9,7 +9,7 @@ internal class VertexPool { public const int BlockSize = 108; - public Mesh MyMesh => _meshFilter?.sharedMesh; + public Mesh MyMesh => _meshFilter != null ? _meshFilter.sharedMesh : null; public float BoundsScheduleTime = 1f; public bool ColorChanged; @@ -73,8 +73,7 @@ private void CreateMeshObj(AltTrail owner, Material material) _meshFilter = _gameObject.AddComponent(); var meshrenderer = _gameObject.AddComponent(); - _gameObject.transform.position = Vector3.zero; - _gameObject.transform.rotation = Quaternion.identity; + _gameObject.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); meshrenderer.shadowCastingMode = ShadowCastingMode.Off; meshrenderer.receiveShadows = false; diff --git a/SaberFactory/Models/PreloadMetaData.cs b/SaberFactory/Models/PreloadMetaData.cs index a3ca10a..79d4c9b 100644 --- a/SaberFactory/Models/PreloadMetaData.cs +++ b/SaberFactory/Models/PreloadMetaData.cs @@ -5,6 +5,7 @@ using SaberFactory.Loaders; using SaberFactory.UI; using SaberFactory.UI.Lib; +using TMPro; using UnityEngine; namespace SaberFactory.Models @@ -13,8 +14,32 @@ internal class PreloadMetaData : ICustomListItem { public AssetTypeDefinition AssetTypeDefinition { get; private set; } - public Texture2D CoverTex => _coverTex ??= LoadTexture(); - public Sprite CoverSprite => _coverSprite ??= LoadSprite(); + public Texture2D CoverTex + { + get + { + if (_coverTex == null) + { + _coverTex = LoadTexture(); + } + + return _coverTex; + } + } + + public Sprite CoverSprite + { + get + { + if (_coverSprite == null) + { + _coverSprite = LoadSprite(); + } + + return _coverSprite; + } + } + public readonly AssetMetaPath AssetMetaPath; private byte[] _coverData; diff --git a/SaberFactory/Plugin.cs b/SaberFactory/Plugin.cs index 736ce8f..bfe1a7a 100644 --- a/SaberFactory/Plugin.cs +++ b/SaberFactory/Plugin.cs @@ -36,8 +36,9 @@ public async void Init(IPALogger logger, Config conf, Zenjector zenjector, Plugi return; } - zenjector.UseLogger(); + zenjector.UseLogger(logger); zenjector.UseHttpService(); + zenjector.Expose("Gameplay"); zenjector.Install(Location.App, logger, pluginConfig, metadata); zenjector.Install(Location.Menu); zenjector.Install(Location.Player | Location.MultiPlayer); @@ -52,7 +53,7 @@ public void OnEnable() [OnDisable] public void OnDisable() { - _harmony.UnpatchAll(HarmonyId); + _harmony.UnpatchSelf(); } /// diff --git a/SaberFactory/SaberFactory.csproj b/SaberFactory/SaberFactory.csproj index b1bb0a7..7667110 100644 --- a/SaberFactory/SaberFactory.csproj +++ b/SaberFactory/SaberFactory.csproj @@ -209,6 +209,7 @@ + @@ -303,6 +304,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + \ No newline at end of file diff --git a/SaberFactory/UI/CustomSaber/Views/MainView.cs b/SaberFactory/UI/CustomSaber/Views/MainView.cs index 53c718f..195f2e0 100644 --- a/SaberFactory/UI/CustomSaber/Views/MainView.cs +++ b/SaberFactory/UI/CustomSaber/Views/MainView.cs @@ -37,7 +37,7 @@ public void ChangeCategory(ENavigationCategory category) private T AddView(bool switchToView = false, Transform container = null) where T : SubView { - var view = CreateSubView(container ?? _subViewContainer, switchToView); + var view = CreateSubView(container != null ? container : _subViewContainer, switchToView); if (view is INavigationCategoryView navView) { _navViews.Add(navView.Category, navView); diff --git a/SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs b/SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs index 30140de..fe438d5 100644 --- a/SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs +++ b/SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs @@ -114,7 +114,7 @@ private async void Setup() if (CommonHelpers.IsDate(null, 10) && _pluginConfig.SpecialBackground && - _saberList.transform.GetChild(0)?.GetComponent() is { } imageView) + _saberList.transform.GetChild(0) is {} child && child.GetComponent() is { } imageView) { imageView.sprite = Utilities.FindSpriteInAssembly("SaberFactory.Resources.UI.halloween_bg.png"); imageView.overrideSprite = imageView.sprite; diff --git a/SaberFactory/UI/Lib/BSML/BackgroundableHandler.cs b/SaberFactory/UI/Lib/BSML/BackgroundableHandler.cs index f407792..f55f452 100644 --- a/SaberFactory/UI/Lib/BSML/BackgroundableHandler.cs +++ b/SaberFactory/UI/Lib/BSML/BackgroundableHandler.cs @@ -93,7 +93,7 @@ private void AddBorder(GameObject go, bool squareSprite = false) if (_borderTemplate == null) { var button = Resources.FindObjectsOfTypeAll