diff --git a/.github/workflows/release_nuget.yml b/.github/workflows/release_nuget.yml index 11a70575..a88f85ab 100644 --- a/.github/workflows/release_nuget.yml +++ b/.github/workflows/release_nuget.yml @@ -28,12 +28,15 @@ jobs: run: | version=$(jq -r '.version' plugin_template/BepInEx/plugins/SpaceWarp/swinfo.json) echo "Version is $version" - echo "::set-output name=version::$version" + echo "version=$version" >> $GITHUB_ENV + echo "artifact_name=spacewarp-release-$version.zip" >> $GITHUB_ENV + echo "zip=$(ls -1 dist/SpaceWarp-*.zip | head -n 1)" >> $GITHUB_ENV + echo "upload_url=$(wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq '.[0].upload_url' | tr -d \")" >> $GITHUB_ENV - name: Check if version exists id: check-version run: | - version=${{ steps.get-version.outputs.version }} + version=${{ env.version }} response=$(curl -s "https://nuget.spacewarp.org/v3/search?q=SpaceWarp") exists=$(echo "$response" | jq -r --arg id "SpaceWarp" --arg version "$version" '.data[] | select(.id == $id) | .versions[] | select(.version == $version) | .version') if [ "$exists" == "$version" ]; then @@ -41,11 +44,22 @@ jobs: exit 1 else echo "Version $version does not exist in the NuGet repository" - echo "::set-output name=should_publish::true" + echo "should_publish=true" >> $GITHUB_ENV fi - name: Publish NuGet package - if: steps.check-version.outputs.should_publish == 'true' + if: env.should_publish == 'true' run: | nupkg_path=$(ls -1 nuget/SpaceWarp.*.nupkg | head -n 1) - dotnet nuget push "$nupkg_path" -s https://nuget.spacewarp.org/v3/index.json -k ${{ secrets.NUGET_SERVER_KEY }} \ No newline at end of file + dotnet nuget push "$nupkg_path" -s https://nuget.spacewarp.org/v3/index.json -k ${{ secrets.NUGET_SERVER_KEY }} + + - name: Upload Zip + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.upload_url }} + asset_path: ${{ env.zip }} + asset_name: ${{ env.artifact_name }} + asset_content_type: application/zip + diff --git a/plugin_template/BepInEx/plugins/SpaceWarp/assets/bundles/modlist.bundle b/plugin_template/BepInEx/plugins/SpaceWarp/assets/bundles/modlist.bundle index 968241a1..54924792 100644 Binary files a/plugin_template/BepInEx/plugins/SpaceWarp/assets/bundles/modlist.bundle and b/plugin_template/BepInEx/plugins/SpaceWarp/assets/bundles/modlist.bundle differ diff --git a/plugin_template/BepInEx/plugins/SpaceWarp/assets/bundles/swconsole.bundle b/plugin_template/BepInEx/plugins/SpaceWarp/assets/bundles/swconsole.bundle index 0473f019..cbce5b40 100644 Binary files a/plugin_template/BepInEx/plugins/SpaceWarp/assets/bundles/swconsole.bundle and b/plugin_template/BepInEx/plugins/SpaceWarp/assets/bundles/swconsole.bundle differ diff --git a/src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs b/src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs index 75d3fb6f..e78c2796 100644 --- a/src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs +++ b/src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs @@ -121,6 +121,11 @@ private static Func GenerateEnumDrawerFor(Type t) lab.GetComponent().SetTerm(entry.Definition.Key); lab.GetComponent().text = entry.Definition.Key; var setting = radioCopy.GetChild("Setting"); + foreach (Transform child in setting.transform) + { + if (child.gameObject.GetComponent()) + UnityObject.Destroy(child.gameObject); + } var idx = optionValues.IndexOf((int)entry.BoxedValue); List allToggles = new(); for (var i = 0; i < optionNames.Count; i++) @@ -228,6 +233,11 @@ private static Func GenerateAbstractEnumDrawer lab.GetComponent().SetTerm(name); lab.GetComponent().text = name; var setting = radioCopy.GetChild("Setting"); + foreach (Transform child in setting.transform) + { + if (child.gameObject.GetComponent()) + UnityObject.Destroy(child.gameObject); + } var idx = optionValues.IndexOf((int)entry.Value); List allToggles = new(); for (var i = 0; i < optionNames.Count; i++) @@ -391,6 +401,11 @@ private static GameObject CreateBoolConfig(ConfigEntryBase baseEntry) lab.GetComponent().SetTerm(entry.Definition.Key); lab.GetComponent().text = entry.Definition.Key; var setting = radioCopy.GetChild("Setting"); + foreach (Transform child in setting.transform) + { + if (child.gameObject.GetComponent()) + UnityObject.Destroy(child.gameObject); + } var idx = entry.Value ? 0 : 1; List allToggles = new(); for (var i = 0; i < 2; i++) @@ -449,6 +464,11 @@ private static GameObject CreateBoolConfigAbstracted(string name, IConfigEntry e lab.GetComponent().SetTerm(name); lab.GetComponent().text = name; var setting = radioCopy.GetChild("Setting"); + foreach (Transform child in setting.transform) + { + if (child.gameObject.GetComponent()) + UnityObject.Destroy(child.gameObject); + } var idx = (bool)entry.Value ? 0 : 1; List allToggles = new(); for (var i = 0; i < 2; i++) diff --git a/src/SpaceWarp.UI/UI/Settings/ModsSubMenu.cs b/src/SpaceWarp.UI/UI/Settings/ModsSubMenu.cs index 3a95aea1..392fcacb 100644 --- a/src/SpaceWarp.UI/UI/Settings/ModsSubMenu.cs +++ b/src/SpaceWarp.UI/UI/Settings/ModsSubMenu.cs @@ -27,6 +27,7 @@ public void Awake() public void Start() { + SettingsMenuController.Instance.UpdatePrefabs(); // Lets make sure we clear out the list foreach (Transform child in transform) { @@ -34,7 +35,6 @@ public void Start() Destroy(child.gameObject); } - // Now here is where we go through every single mod #pragma warning disable CS0618 foreach (var mod in BepInEx.Bootstrap.Chainloader.Plugins.Where(mod => diff --git a/src/SpaceWarp.UI/UI/Settings/SettingsMenuController.cs b/src/SpaceWarp.UI/UI/Settings/SettingsMenuController.cs index 5b2d200e..55380a06 100644 --- a/src/SpaceWarp.UI/UI/Settings/SettingsMenuController.cs +++ b/src/SpaceWarp.UI/UI/Settings/SettingsMenuController.cs @@ -42,20 +42,16 @@ internal class SettingsMenuController : KerbalMonoBehaviour private GameObject _headerPrefab; private GameObject _dividerPrefab; private GameObject _sectionPrefab; + internal static SettingsMenuController Instance; private bool _alreadySetup = false; private void Start() { MainMenuPatcher.MainMenuLoaded += Setup; + Instance = this; } - private void Setup() + public void UpdatePrefabs() { - if (_alreadySetup) return; - _alreadySetup = true; - var categories = GameObject.Find(CategoriesPath); - var graphics = GameObject.Find(GraphicsPath); - var modsButton =Instantiate(graphics, categories.transform); - var content = GameObject.Find(ContentPath); var graphicsSettings = GameObject.Find(ContentGraphicsPath); _headerPrefab = Instantiate(graphicsSettings.transform.Find("SettingsMenuHeader").gameObject); _headerPrefab.Persist(); @@ -66,7 +62,7 @@ private void Setup() _sectionPrefab = Instantiate(graphicsSettings.transform.Find("Video").gameObject); foreach (Transform child in _sectionPrefab.transform) { - if (child.gameObject.name != "Title") + if (!child.gameObject.GetComponent()) { Destroy(child.gameObject); } @@ -100,7 +96,6 @@ private void Setup() if (alpha != null) Destroy(alpha); var beta = radioSettingPrefab.GetComponent(); if (beta != null) Destroy(beta); - } radioPrefab.SetActive(false); radioSettingPrefab.SetActive(false); @@ -134,8 +129,20 @@ private void Setup() Destroy(amount.GetComponentInChildren()); sliderPrefab.SetActive(false); ModsPropertyDrawers.SliderPrefab = sliderPrefab; + } + + private void Setup() + { + if (_alreadySetup) return; + _alreadySetup = true; + var categories = GameObject.Find(CategoriesPath); + var graphics = GameObject.Find(GraphicsPath); + var content = GameObject.Find(ContentPath); + var graphicsSettings = GameObject.Find(ContentGraphicsPath); + + var modsButton = Instantiate(graphics, categories.transform); modsButton.GetComponentInChildren().Term = ""; var text = modsButton.GetComponentInChildren(); text.text = "Mods"; @@ -187,6 +194,13 @@ private GameObject GenerateDivider() private GameObject GenerateSection(string section) { var copy = Instantiate(_sectionPrefab); + foreach (Transform child in copy.transform) + { + if (!child.gameObject.GetComponent()) + { + Destroy(child.gameObject); + } + } var text = copy.GetComponentInChildren(); var localize = copy.GetComponentInChildren(); if (localize != null) diff --git a/src/SpaceWarp.VersionChecking/Modules/VersionChecking.cs b/src/SpaceWarp.VersionChecking/Modules/VersionChecking.cs index 84677fed..59f2b8bd 100644 --- a/src/SpaceWarp.VersionChecking/Modules/VersionChecking.cs +++ b/src/SpaceWarp.VersionChecking/Modules/VersionChecking.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections; +using System.Collections; using System.Reflection; using System.Xml; using JetBrains.Annotations; @@ -20,6 +19,7 @@ public class VersionChecking : SpaceWarpModule public ConfigValue ConfigCheckVersions; public static VersionChecking Instance; private string _kspVersion; + public override void LoadModule() { Instance = this; @@ -37,11 +37,11 @@ public override void PreInitializeModule() public override void InitializeModule() { - if (ConfigCheckVersions.Value) { CheckVersions(); } + CheckKspVersions(); } @@ -57,14 +57,43 @@ public void ClearVersions() plugin.Outdated = false; } } + public void CheckVersions() { + var uiModule = (SpaceWarpModule)AppDomain.CurrentDomain.GetAssemblies() + .First(assembly => assembly.FullName.StartsWith("SpaceWarp.UI")) + .GetTypes() + .First(type => type.FullName == "SpaceWarp.Modules.UI") + .GetField("Instance", BindingFlags.Static | BindingFlags.NonPublic) + ?.GetValue(null); + + var modListControllerField = uiModule + ?.GetType() + .GetField("ModListController", BindingFlags.Instance | BindingFlags.NonPublic); + + var versionCheckCallback = (string guid, bool isOutdated) => + { + var modListController = modListControllerField?.GetValue(uiModule); + + if (modListController == null) + { + return false; + } + + modListControllerField + .FieldType + .GetMethod("UpdateOutdated", BindingFlags.Instance | BindingFlags.NonPublic) + ?.Invoke(modListController, new object[] { guid, isOutdated }); + + return true; + }; + ClearVersions(); foreach (var plugin in PluginList.AllEnabledAndActivePlugins) { if (plugin.SWInfo.VersionCheck != null) { - SpaceWarpPlugin.Instance.StartCoroutine(CheckVersion(plugin.Guid, plugin)); + SpaceWarpPlugin.Instance.StartCoroutine(CheckVersion(plugin.Guid, plugin, versionCheckCallback)); } } @@ -72,15 +101,18 @@ public void CheckVersions() { if (info.SWInfo.VersionCheck != null) { - SpaceWarpPlugin.Instance.StartCoroutine(info.Guid, info); + SpaceWarpPlugin.Instance.StartCoroutine(CheckVersion(info.Guid, info, versionCheckCallback)); } } + + return; } - private IEnumerator CheckVersion(string guid, SpaceWarpPluginDescriptor info) + + private IEnumerator CheckVersion(string guid, SpaceWarpPluginDescriptor info, Func callback) { var www = UnityWebRequest.Get(info.SWInfo.VersionCheck); yield return www.SendWebRequest(); - + if (www.result != UnityWebRequest.Result.Success) { ModuleLogger.LogInfo($"Unable to check version for {guid} due to error {www.error}"); @@ -95,14 +127,17 @@ private IEnumerator CheckVersion(string guid, SpaceWarpPluginDescriptor info) { if (info.SWInfo.Spec >= SpecVersion.V2_0) { - isOutdated = CheckSemanticVersion(guid, info.SWInfo.Version, results, out unsupported, out newKSP2Versions); + isOutdated = CheckSemanticVersion(guid, info.SWInfo.Version, results, out unsupported, + out newKSP2Versions); } else { isOutdated = info.SWInfo.VersionCheckType switch { - VersionCheckType.SwInfo => CheckJsonVersion(guid, info.SWInfo.Version, results, out unsupported, out newKSP2Versions), - VersionCheckType.Csproj => CheckCsprojVersion(guid, info.SWInfo.Version, results, out unsupported, out newKSP2Versions), + VersionCheckType.SwInfo => CheckJsonVersion(guid, info.SWInfo.Version, results, out unsupported, + out newKSP2Versions), + VersionCheckType.Csproj => CheckCsprojVersion(guid, info.SWInfo.Version, results, + out unsupported, out newKSP2Versions), _ => throw new ArgumentOutOfRangeException(nameof(info), "Invalid version_check_type") }; } @@ -111,22 +146,29 @@ private IEnumerator CheckVersion(string guid, SpaceWarpPluginDescriptor info) { ModuleLogger.LogError($"Unable to check version for {guid} due to error {e}"); } - + info.Outdated = isOutdated; info.Unsupported = unsupported; if (isOutdated) { ModuleLogger.LogWarning($"{guid} is outdated"); } + if (unsupported) { ModuleLogger.LogWarning($"{guid} is unsupported"); info.SWInfo.SupportedKsp2Versions = newKSP2Versions; } + + while (!callback(guid, isOutdated)) + { + yield return new WaitForUpdate(); + } } } - private bool CheckSemanticVersion(string guid, string version, string json, out bool unsupported, out SupportedVersionsInfo checkVersions) + private bool CheckSemanticVersion(string guid, string version, string json, out bool unsupported, + out SupportedVersionsInfo checkVersions) { var checkInfo = JsonConvert.DeserializeObject(json); var semverOne = new SemanticVersion(version); @@ -138,10 +180,10 @@ private bool CheckSemanticVersion(string guid, string version, string json, out unsupported = true; checkVersions = checkInfo.SupportedKsp2Versions; return false; - } - private bool CheckJsonVersion(string guid, string version, string json, out bool unsupported, out SupportedVersionsInfo checkVersions) + private bool CheckJsonVersion(string guid, string version, string json, out bool unsupported, + out SupportedVersionsInfo checkVersions) { var checkInfo = JsonConvert.DeserializeObject(json); unsupported = false; @@ -153,15 +195,16 @@ private bool CheckJsonVersion(string guid, string version, string json, out bool return false; } - private bool CheckCsprojVersion(string guid, string version, string csproj, out bool unsupported, out SupportedVersionsInfo checkVersions) + private bool CheckCsprojVersion(string guid, string version, string csproj, out bool unsupported, + out SupportedVersionsInfo checkVersions) { var document = new XmlDocument(); document.LoadXml(csproj); var ksp2VersionMin = document.GetElementsByTagName("Ksp2VersionMin")[0]?.InnerText - ?? SupportedVersionsInfo.DefaultMin; + ?? SupportedVersionsInfo.DefaultMin; var ksp2VersionMax = document.GetElementsByTagName("Ksp2VersionMax")[0]?.InnerText - ?? SupportedVersionsInfo.DefaultMax; + ?? SupportedVersionsInfo.DefaultMax; checkVersions = new SupportedVersionsInfo() { Max = ksp2VersionMax, diff --git a/src/SpaceWarp/Directory.Build.targets b/src/SpaceWarp/Directory.Build.targets index 6c8a1ef0..a971e012 100644 --- a/src/SpaceWarp/Directory.Build.targets +++ b/src/SpaceWarp/Directory.Build.targets @@ -3,6 +3,8 @@ nuget mono /usr/local/bin/nuget.exe + powershell + pwsh @@ -82,12 +84,8 @@ - - - - +