Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.7.0 #275

Merged
merged 37 commits into from
Dec 22, 2023
Merged

1.7.0 #275

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
319bac0
Reworked as a SpaceWarp.Template project with better build process
jan-bures Dec 20, 2023
1f14da3
Fixed workflow (hopefully)
jan-bures Dec 20, 2023
82dc128
Add API for mods to register their custom module PartComponentModule …
Falki-git Dec 20, 2023
c4090f8
Merge branch 'dev' of https://github.com/SpaceWarpDev/SpaceWarp into dev
Falki-git Dec 20, 2023
0705222
Add API for mods to register their custom module PartComponentModule …
Falki-git Dec 20, 2023
612ac57
Merge pull request #274 from Falki-git/dev
jan-bures Dec 20, 2023
2f9458e
Move reflection method outside of loop
cheese3660 Dec 21, 2023
ca4b2cf
Cache part component owners we already checked.
cheese3660 Dec 21, 2023
b6edd30
Use conditionalweaktable
cheese3660 Dec 21, 2023
c941261
undo caching
cheese3660 Dec 21, 2023
3b7ea7d
Possible conditional patching
cheese3660 Dec 21, 2023
57b1031
Fix some dumbassery
cheese3660 Dec 21, 2023
4377c96
Fix possible multi patch
cheese3660 Dec 21, 2023
d57351b
Run specifically the patch on the one type aaaaaa
cheese3660 Dec 21, 2023
00df2e9
Log for testing - safarte
cheese3660 Dec 21, 2023
858e4d4
Revert "Log for testing - safarte"
cheese3660 Dec 22, 2023
f21977e
Revert "Run specifically the patch on the one type aaaaaa"
cheese3660 Dec 22, 2023
016ba57
Revert "Fix possible multi patch"
cheese3660 Dec 22, 2023
f2871af
Revert "Fix some dumbassery"
cheese3660 Dec 22, 2023
f12825b
Revert "Possible conditional patching"
cheese3660 Dec 22, 2023
35edb5d
Revert "undo caching"
cheese3660 Dec 22, 2023
f42756e
Revert "Use conditionalweaktable"
cheese3660 Dec 22, 2023
e0964b3
Revert "Cache part component owners we already checked."
cheese3660 Dec 22, 2023
e1fab4a
Actual acts of the IL god
cheese3660 Dec 22, 2023
8b2d077
Remove bad patch
cheese3660 Dec 22, 2023
10c1b6c
Just making sure the field is set to false by default
cheese3660 Dec 22, 2023
c4e754e
Don't output test dll anymore
cheese3660 Dec 22, 2023
9c52e7a
Updated the outdated README.md
jan-bures Dec 22, 2023
cf5e955
Attempt #2 to fix GH Action building of release zip
jan-bures Dec 22, 2023
bdd9bab
Realized it doesn't make much sense to build in Debug configuration i…
jan-bures Dec 22, 2023
44e1cde
Add actions to upload NuGet package as artifact
jan-bures Dec 22, 2023
4bbb92c
Automatic publishing of NuGet package on release
jan-bures Dec 22, 2023
e53c994
Remove duplicate reference
jan-bures Dec 22, 2023
9017362
NuGet packing with Mono and nuget.exe
jan-bures Dec 22, 2023
88eee98
sudo you dummy
jan-bures Dec 22, 2023
452cf05
sudo in *both* actions, stupid
jan-bures Dec 22, 2023
01bbc1a
Remove mono installation, it's preinstalled in the runner image
jan-bures Dec 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

[Documentation](https://docs.spacewarp.org)

Space Warp is a mod loader for Kerbal Space Program 2.
Space Warp is a modding API for Kerbal Space Program 2 with support for BepInEx and the official mod loader.*

Note: Use at your own risk, as this is an early version that is expected to undergo many changes.
*\*Note: The official mod loader is unfinished, so BepInEx is currently still required to enable it.*

## Installation

Expand Down Expand Up @@ -41,11 +41,19 @@ That should be it, you can now launch the game and enjoy!

To compile this project, you will need to follow these steps:

1. Install NuGet
1. Install .NET 7+ SDK
2. Run `dotnet restore` inside the top directory to install the packages.
3. Run one of the build scripts (see below for more info) and copy the contents from the correct build output directory into the KSP2 root director
3. Run `dotnet build -c <Configuration>` to build the project, where `<Configuration>` is one of the following:
- `Debug` - Builds the project in debug mode
- `Deploy` - Builds the project in debug mode and copies the output to the KSP2 directory
- `DeployAndRun` - Builds the project in debug mode, copies the output to the KSP2 directory, and runs the game
- `Release` - Builds the project in release mode, zips the output, and builds a NuGet package

Mods are currently implemented as monobehaviours with two fields: a `Logger` for logging and a `Manager` that points to Spacewarp. A mod template generator exists as a Python script.
or you can use Visual Studio 2022 or JetBrains Rider to build the project.

There are also scripts in the `scripts` folder that can be used to build the project in each of the configurations, they simply run the `dotnet build` command with the correct arguments.

The outputs can be found in `dist/<Configuration>`. The Release zip will be in the `dist` folder, and the NuGet package will be in the `nuget` folder.

## Mod Structure

Expand All @@ -63,23 +71,12 @@ KSP2_Root_Folder/
│ │ │ │ │ ├── *.bundle
│ │ │ │ ├── images/
│ │ │ │ │ ├── *
│ │ │ │ ├── soundbanks/
│ │ │ │ │ ├── *.bnk
│ │ │ ├── localizations/
│ │ │ │ ├── *.csv
│ │ │ ├── addressables/
│ │ │ │ ├── catalog.json
│ │ │ │ ├── *
│ │ │ ├── *.dll
```

## Build Scripts

Each build scripts is essentially just a wrapper around `python3 builder.py $@`. The actual builder code is in `builder.py`.
Before running, open a terminal and `cd` into the repo, then run `pip install -r requirements.txt` to install the required dependencies (its just `argparse`).

The build scripts are:
`build.bat` for Windows, `build.ps1` for Windows (Powershell), and `build.sh` for Linux

The available arguments are:
- `-r` or `--release` to build in release mode

When building, the build output will be in `build/SpaceWarp`, and the compressed version will be `build/SpaceWarp-[Debug|Release]-[commit].zip`.
```
55 changes: 28 additions & 27 deletions .github/workflows/build_spacewarp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,39 @@ on:
jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
run_args: ["" , "-r"]


steps:
- name: Check Out Repository
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.9

- name: Run Python Script
run: sudo python builder.py ${{ matrix.run_args }}
# I'm sure running it in sudo will cause NO issues what so ever.

- name: Find Zip

- name: Download NuGet
id: download-nuget
run: |
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

- name: Build the solution
run: dotnet build "SpaceWarp.sln" -c Release

- name: Find zip
id: find-zip
run: |
if [ "${{ matrix.run_args }}" == "-r" ]; then
echo "zip=$(ls -1 build/SpaceWarp-Release*.zip | head -n 1)" >> $GITHUB_ENV
echo "artifact_name=SpaceWarpRelease" >> $GITHUB_ENV
else
echo "zip=$(ls -1 build/SpaceWarp-Debug*.zip | head -n 1)" >> $GITHUB_ENV
echo "artifact_name=SpaceWarpDebug" >> $GITHUB_ENV
fi
# Least cursed Sinon code.

- name: Upload Artifact
echo "zip=$(ls -1 dist/SpaceWarp-*.zip | head -n 1)" >> $GITHUB_ENV
echo "artifact_name=SpaceWarpRelease" >> $GITHUB_ENV

- name: Upload release zip
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}
path: ${{ env.zip }}

- name: Find NuGet package
id: find-nupkg
run: |
echo "nupkg=$(ls -1 nuget/SpaceWarp.*.nupkg | head -n 1)" >> $GITHUB_ENV
echo "artifact_name=SpaceWarpNuGet" >> $GITHUB_ENV

- name: Upload NuGet package
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}
path: ${{ env.nupkg }}
51 changes: 51 additions & 0 deletions .github/workflows/release_nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish NuGet Package

on:
release:
types: [ "published" ]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Install jq
uses: dcarbone/[email protected]

- name: Download NuGet
id: download-nuget
run: |
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

- name: Build the solution
run: dotnet build "SpaceWarp.sln" -c Release

- name: Extract current version
id: get-version
run: |
version=$(jq -r '.version' plugin_template/BepInEx/plugins/SpaceWarp/swinfo.json)
echo "Version is $version"
echo "::set-output name=version::$version"

- name: Check if version exists
id: check-version
run: |
version=${{ steps.get-version.outputs.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"
fi

- name: Publish NuGet package
if: steps.check-version.outputs.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 }}
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,10 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Build script folder
build/
# Build folders
/build
/dist
/nuget

# Idea folder
.idea
91 changes: 52 additions & 39 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,51 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<SpaceWarpVersion>1.6.0</SpaceWarpVersion>
<PropertyGroup Label="Framework and language configuration">
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>SpaceWarp</RootNamespace>
<LangVersion>11</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<!-- Disabled warning for publicizer attribute until the NuGet exists for KSP2,
and for missing documentation comments for public types and members -->
<NoWarn>$(NoWarn),CS0436,CS1591</NoWarn>
<LangVersion>latest</LangVersion>
<ImplicitUsings>true</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<!--
Allows use of some newer C# language features that have compiler gates normally.
Do not modify the included types without checking that they don't require runtime support that doesn't exist.
-->
<PropertyGroup Label="Game folder configuration">
<!-- Set this to the path to your KSP 2 folder if you don't have the KSP2DIR environmental variable set -->
<KSP2DIR Condition="'$(KSP2DIR)' == ''">C:/Program Files (x86)/Steam/steamapps/common/Kerbal Space Program 2</KSP2DIR>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PolySharp" Version="1.12.1" PrivateAssets="all"/>
</ItemGroup>
<PropertyGroup>
<PolySharpIncludeGeneratedTypes>
System.Index;
System.Range;
System.Diagnostics.CodeAnalysis.NotNullWhenAttribute;
System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute;
</PolySharpIncludeGeneratedTypes>
<PropertyGroup Label="Build and namespace configuration">
<SolutionDir Condition="'$(SolutionDir)'==''">$(MSBuildThisFileDirectory)</SolutionDir>
<PluginBinPath>$(SolutionDir)build/bin/plugin/$(Configuration)</PluginBinPath>
<PluginObjPath>$(SolutionDir)build/obj/plugin/$(Configuration)</PluginObjPath>
<ModulesBinPath>$(SolutionDir)build/bin/modules/$(Configuration)</ModulesBinPath>
<ModulesObjPath>$(SolutionDir)build/obj/modules/$(Configuration)</ModulesObjPath>
<PatcherBinPath>$(SolutionDir)build/bin/patcher/$(Configuration)</PatcherBinPath>
<PatcherObjPath>$(SolutionDir)build/obj/patcher/$(Configuration)</PatcherObjPath>
<BaseOutputPath>$(ModulesBinPath)/$(MSBuildProjectName)</BaseOutputPath>
<BaseIntermediateOutputPath>$(ModulesObjPath)/$(MSBuildProjectName)</BaseIntermediateOutputPath>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<Configurations>Debug;Release;Deploy;DeployAndRun</Configurations>
<Platforms>AnyCPU</Platforms>
<NoWarn>$(NoWarn);CS0436</NoWarn>
</PropertyGroup>

<!-- <ItemGroup Label="Dependencies for build targets">-->
<!-- <PackageReference Include="JsonPeek" Version="1.2.0" PrivateAssets="all"/>-->
<!-- </ItemGroup>-->
<PropertyGroup Label="Package source configuration">
<RestoreAdditionalProjectSources>
https://nuget.spacewarp.org/v3/index.json
</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup Label="Dependencies for build targets">
<PackageReference Include="JsonPeek" Version="1.2.0" PrivateAssets="all"/>
</ItemGroup>

<!-- &lt;!&ndash; Define the main target &ndash;&gt;-->
<!-- <Target Label="Reading properties from swinfo.json" Name="ReadPropertiesFromJson" BeforeTargets="PreBuildEvent">-->
<!-- <JsonPeek ContentPath="$(SolutionDir)/SpaceWarpBuildTemplate/swinfo.json" Query="$">-->
<!-- <Output TaskParameter="Result" ItemName="Swinfo"/>-->
<!-- </JsonPeek>-->
<!-- <JsonPeek ContentPath="$(SolutionDir)/SpaceWarpBuildTemplate/swinfo.json" Query="$.dependencies">-->
<!-- <Output TaskParameter="Result" ItemName="Dependencies"/>-->
<!-- </JsonPeek>-->
<!-- Define the main target -->
<Target Label="Reading properties from swinfo.json" Name="ReadPropertiesFromJson" BeforeTargets="PreBuildEvent;AddGeneratedFile">
<JsonPeek ContentPath="$(SolutionDir)/plugin_template/BepInEx/plugins/SpaceWarp/swinfo.json" Query="$">
<Output TaskParameter="Result" ItemName="Swinfo"/>
</JsonPeek>

<!-- &lt;!&ndash; Extract properties from the JSON &ndash;&gt;-->
<!-- <PropertyGroup>-->
<!-- <SpaceWarpVersion>@(Swinfo -> '%(version)')</SpaceWarpVersion>-->
<!-- </PropertyGroup>-->
<!-- </Target>-->
<!-- Extract properties from the JSON -->
<PropertyGroup>
<ModId>@(Swinfo -> '%(mod_id)')</ModId>
<Version>@(Swinfo -> '%(version)')</Version>
<Version Condition="$(Version.Contains('-'))">$(Version.Substring(0, $(Version.IndexOf('-'))))</Version>
<Product>@(Swinfo -> '%(name)')</Product>
<Authors>@(Swinfo -> '%(author)')</Authors>
<Description>@(Swinfo -> '%(description)')</Description>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>@(Swinfo -> '%(source)')</RepositoryUrl>
<BepInExPluginGuid>$(ModId)</BepInExPluginGuid>
<BepInExPluginName>$(Product)</BepInExPluginName>
<BepInExPluginVersion>$(Version)</BepInExPluginVersion>
</PropertyGroup>
</Target>
</Project>
8 changes: 0 additions & 8 deletions Directory.Build.targets

This file was deleted.

3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 X606
Copyright (c) 2023 Space Warp Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

6 changes: 0 additions & 6 deletions NuGet.config

This file was deleted.

22 changes: 11 additions & 11 deletions SpaceWarp.nuspec → Package.nuspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>SpaceWarp</id>
<version>1.6.0</version>
<authors>SpaceWarp contributors</authors>
<id>$id$</id>
<version>$version$</version>
<authors>$authors$</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://raw.githubusercontent.com/SpaceWarp/SpaceWarp/main/LICENSE</licenseUrl>
<description>A C# modding API for KSP2</description>
<tags>spacewarp ksp2 modding</tags>
<icon>icon.png</icon>
<licenseUrl>https://raw.githubusercontent.com/SpaceWarpDev/SpaceWarp/main/LICENSE</licenseUrl>
<description>$description$</description>
<tags>ksp2 mod library api spacewarp</tags>
<projectUrl>https://spacewarp.org</projectUrl>
<repository type="git" url="https://github.com/SpaceWarpDev/SpaceWarp" />
<repository type="$repositoryType$" url="$repositoryUrl$" />
<readme>README.md</readme>
<icon>icon.png</icon>
<dependencies>
<group targetFramework=".NETStandard2.1" />
</dependencies>
</metadata>
<files>
<file src=".github\README.md" target="README.md" />
<file src="images\icon.png" target="icon.png" />
<file src="LICENSE" target="LICENSE" />
<file src="build\nuget_temp\*.dll" target="lib/netstandard2.1/" />
<file src="build\nuget_temp\*.xml" target="lib/netstandard2.1/" />
<file src="images\icon.png" target="icon.png" />
<file src="temp_nuget\*.dll" target="lib/netstandard2.1/" />
<file src="temp_nuget\*.xml" target="lib/netstandard2.1/" />
</files>
</package>
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Space Warp
Space Warp is an API for KSP 2 mod developers.
Loading