Skip to content

Commit

Permalink
Merge pull request #278 from SpaceWarpDev/dev
Browse files Browse the repository at this point in the history
True 1.7.0
  • Loading branch information
cheese3660 authored Dec 22, 2023
2 parents 7cde6e2 + 7056fb9 commit 8d619dc
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 38 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/release_nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,38 @@ 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
echo "Version $version already exists in the NuGet repository"
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 }}
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

Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ private static Func<ConfigEntryBase, GameObject> GenerateEnumDrawerFor(Type t)
lab.GetComponent<Localize>().SetTerm(entry.Definition.Key);
lab.GetComponent<TextMeshProUGUI>().text = entry.Definition.Key;
var setting = radioCopy.GetChild("Setting");
foreach (Transform child in setting.transform)
{
if (child.gameObject.GetComponent<ToggleExtended>())
UnityObject.Destroy(child.gameObject);
}
var idx = optionValues.IndexOf((int)entry.BoxedValue);
List<ToggleExtended> allToggles = new();
for (var i = 0; i < optionNames.Count; i++)
Expand Down Expand Up @@ -228,6 +233,11 @@ private static Func<string, IConfigEntry, GameObject> GenerateAbstractEnumDrawer
lab.GetComponent<Localize>().SetTerm(name);
lab.GetComponent<TextMeshProUGUI>().text = name;
var setting = radioCopy.GetChild("Setting");
foreach (Transform child in setting.transform)
{
if (child.gameObject.GetComponent<ToggleExtended>())
UnityObject.Destroy(child.gameObject);
}
var idx = optionValues.IndexOf((int)entry.Value);
List<ToggleExtended> allToggles = new();
for (var i = 0; i < optionNames.Count; i++)
Expand Down Expand Up @@ -391,6 +401,11 @@ private static GameObject CreateBoolConfig(ConfigEntryBase baseEntry)
lab.GetComponent<Localize>().SetTerm(entry.Definition.Key);
lab.GetComponent<TextMeshProUGUI>().text = entry.Definition.Key;
var setting = radioCopy.GetChild("Setting");
foreach (Transform child in setting.transform)
{
if (child.gameObject.GetComponent<ToggleExtended>())
UnityObject.Destroy(child.gameObject);
}
var idx = entry.Value ? 0 : 1;
List<ToggleExtended> allToggles = new();
for (var i = 0; i < 2; i++)
Expand Down Expand Up @@ -449,6 +464,11 @@ private static GameObject CreateBoolConfigAbstracted(string name, IConfigEntry e
lab.GetComponent<Localize>().SetTerm(name);
lab.GetComponent<TextMeshProUGUI>().text = name;
var setting = radioCopy.GetChild("Setting");
foreach (Transform child in setting.transform)
{
if (child.gameObject.GetComponent<ToggleExtended>())
UnityObject.Destroy(child.gameObject);
}
var idx = (bool)entry.Value ? 0 : 1;
List<ToggleExtended> allToggles = new();
for (var i = 0; i < 2; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/SpaceWarp.UI/UI/Settings/ModsSubMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public void Awake()

public void Start()
{
SettingsMenuController.Instance.UpdatePrefabs();
// Lets make sure we clear out the list
foreach (Transform child in transform)
{
SpaceWarpPlugin.Logger.LogDebug($"Destroying ---- {child.gameObject.name}");
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 =>
Expand Down
32 changes: 23 additions & 9 deletions src/SpaceWarp.UI/UI/Settings/SettingsMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<TMPro.TextMeshProUGUI>())
{
Destroy(child.gameObject);
}
Expand Down Expand Up @@ -100,7 +96,6 @@ private void Setup()
if (alpha != null) Destroy(alpha);
var beta = radioSettingPrefab.GetComponent<UIAction_Void_Toggle>();
if (beta != null) Destroy(beta);

}
radioPrefab.SetActive(false);
radioSettingPrefab.SetActive(false);
Expand Down Expand Up @@ -134,8 +129,20 @@ private void Setup()
Destroy(amount.GetComponentInChildren<UIValue_ReadString_Text>());
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<Localize>().Term = "";
var text = modsButton.GetComponentInChildren<TMPro.TextMeshProUGUI>();
text.text = "Mods";
Expand Down Expand Up @@ -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<TMPro.TextMeshProUGUI>())
{
Destroy(child.gameObject);
}
}
var text = copy.GetComponentInChildren<TMPro.TextMeshProUGUI>();
var localize = copy.GetComponentInChildren<Localize>();
if (localize != null)
Expand Down
77 changes: 60 additions & 17 deletions src/SpaceWarp.VersionChecking/Modules/VersionChecking.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections;
using System.Reflection;
using System.Xml;
using JetBrains.Annotations;
Expand All @@ -20,6 +19,7 @@ public class VersionChecking : SpaceWarpModule
public ConfigValue<bool> ConfigCheckVersions;
public static VersionChecking Instance;
private string _kspVersion;

public override void LoadModule()
{
Instance = this;
Expand All @@ -37,11 +37,11 @@ public override void PreInitializeModule()

public override void InitializeModule()
{

if (ConfigCheckVersions.Value)
{
CheckVersions();
}

CheckKspVersions();
}

Expand All @@ -57,30 +57,62 @@ 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));
}
}

foreach (var info in PluginList.AllDisabledPlugins)
{
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<string, bool, bool> 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}");
Expand All @@ -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")
};
}
Expand All @@ -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<ModInfo>(json);
var semverOne = new SemanticVersion(version);
Expand All @@ -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<ModInfo>(json);
unsupported = false;
Expand All @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/SpaceWarp/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<NuGetExecutable Condition="'$(OS)' == 'Windows_NT'">nuget</NuGetExecutable>
<NuGetExecutable Condition="'$(OS)' != 'Windows_NT'">mono /usr/local/bin/nuget.exe</NuGetExecutable>
<PowerShellExecutable Condition="'$(OS)' == 'Windows_NT'">powershell</PowerShellExecutable>
<PowerShellExecutable Condition="'$(OS)' != 'Windows_NT'">pwsh</PowerShellExecutable>
</PropertyGroup>
<Target Label="Post build events" Name="PostBuild" AfterTargets="PostBuildEvent">
<!-- Cleanup of older builds -->
Expand Down Expand Up @@ -82,12 +84,8 @@
<Message Text="Compressing built plugin folder" Condition="$(ConfigurationName) == Release"/>
<Delete Condition="$(ConfigurationName) == Release"
Files="$(SolutionDir)/dist/$(SolutionName)-$(Version).zip"/>
<!-- Windows command is "powershell" -->
<Exec Condition="$(ConfigurationName) == 'Release' and '$(OS)' == 'Windows_NT'"
Command="powershell -Command &quot;&amp; {Push-Location '$(SolutionDir)/dist/$(ConfigurationName)'; Compress-Archive -Path './*' -DestinationPath '$(SolutionDir)/dist/$(SolutionName)-$(Version).zip'; Pop-Location}&quot;"/>
<!-- Linux command is "pwsh" -->
<Exec Condition="$(ConfigurationName) == 'Release' and '$(OS)' != 'Windows_NT'"
Command="pwsh -Command &quot;&amp; {Push-Location '$(SolutionDir)/dist/$(ConfigurationName)'; Compress-Archive -Path './*' -DestinationPath '$(SolutionDir)/dist/$(SolutionName)-$(Version).zip'; Pop-Location}&quot;"/>
<Exec Condition="$(ConfigurationName) == 'Release'"
Command="$(PowerShellExecutable) -Command &quot;&amp; {Push-Location '$(SolutionDir)/dist/$(ConfigurationName)'; Compress-Archive -Path './*' -DestinationPath '$(SolutionDir)/dist/$(SolutionName)-$(Version).zip'; Pop-Location}&quot;"/>

<!-- Packing NuGet package -->
<Message Text="Copying plugin DLLs and XMLs to temporary folder for NuGet packing" Condition="$(ConfigurationName) == Release"/>
Expand Down

0 comments on commit 8d619dc

Please sign in to comment.