Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
cheese3660 committed Dec 22, 2023
2 parents a076919 + 01bbc1a commit 8d63d69
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 36 deletions.
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`.
```
35 changes: 21 additions & 14 deletions .github/workflows/build_spacewarp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,41 @@ on:
branches: [ "main", "dev" ]

jobs:
build-debug:
build:
runs-on: ubuntu-latest

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

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

build-release:
runs-on: ubuntu-latest
- 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
steps:
- name: Check Out Repository
uses: actions/checkout@v3

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

- name: Find zip
id: find-zip
run: |
echo "zip=$(ls -1 dist/SpaceWarp-*.zip | head -n 1)" >> $GITHUB_ENV
echo "artifact_name=SpaceWarpRelease" >> $GITHUB_ENV
- name: Upload Artifact
- 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 }}
1 change: 0 additions & 1 deletion src/SpaceWarp.Game/SpaceWarp.Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- References -->
<ItemGroup Label="NuGet package references">
<PackageReference Include="JsonPeek" Version="1.2.0"/>
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.1.5"/>
</ItemGroup>
<ItemGroup Label="Project references">
Expand Down
12 changes: 10 additions & 2 deletions src/SpaceWarp/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<NuGetExecutable Condition="'$(OS)' == 'Windows_NT'">nuget</NuGetExecutable>
<NuGetExecutable Condition="'$(OS)' != 'Windows_NT'">mono /usr/local/bin/nuget.exe</NuGetExecutable>
</PropertyGroup>
<Target Label="Post build events" Name="PostBuild" AfterTargets="PostBuildEvent">
<!-- Cleanup of older builds -->
<Message Text="Cleaning up previous build directory"/>
Expand Down Expand Up @@ -78,8 +82,12 @@
<Message Text="Compressing built plugin folder" Condition="$(ConfigurationName) == Release"/>
<Delete Condition="$(ConfigurationName) == Release"
Files="$(SolutionDir)/dist/$(SolutionName)-$(Version).zip"/>
<Exec Condition="$(ConfigurationName) == Release"
<!-- 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;"/>

<!-- Packing NuGet package -->
<Message Text="Copying plugin DLLs and XMLs to temporary folder for NuGet packing" Condition="$(ConfigurationName) == Release"/>
Expand All @@ -105,7 +113,7 @@

<Message Text="Packing NuGet package" Condition="$(ConfigurationName) == Release"/>
<Exec Condition="$(ConfigurationName) == Release"
Command="nuget pack &quot;$(SolutionDir)/Package.nuspec&quot; -OutputDirectory &quot;$(SolutionDir)/nuget&quot; -Properties NoWarn=NU5125;id=&quot;$(ProjectName)&quot;;version=&quot;$(Version)&quot;;authors=&quot;$(Authors)&quot;;description=&quot;$(Description)&quot;;repositoryType=&quot;$(RepositoryType)&quot;;repositoryUrl=&quot;$(RepositoryUrl)&quot;" />
Command="$(NuGetExecutable) pack &quot;$(SolutionDir)/Package.nuspec&quot; -OutputDirectory &quot;$(SolutionDir)/nuget&quot; -Properties &quot;NoWarn=NU5125;id=$(ProjectName);version=$(Version);authors=$(Authors);description=$(Description);repositoryType=$(RepositoryType);repositoryUrl=$(RepositoryUrl)&quot;" />

<Message Text="Removing temporary folder" Condition="$(ConfigurationName) == Release"/>
<RemoveDir Condition="$(ConfigurationName) == Release"
Expand Down

0 comments on commit 8d63d69

Please sign in to comment.