diff --git a/.github/README.md b/.github/README.md index bce3458..98dcc98 100644 --- a/.github/README.md +++ b/.github/README.md @@ -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 @@ -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 ` to build the project, where `` 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/`. The Release zip will be in the `dist` folder, and the NuGet package will be in the `nuget` folder. ## Mod Structure @@ -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`. +``` \ No newline at end of file diff --git a/.github/workflows/build_spacewarp.yml b/.github/workflows/build_spacewarp.yml index 421f9c1..7830926 100644 --- a/.github/workflows/build_spacewarp.yml +++ b/.github/workflows/build_spacewarp.yml @@ -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 }} diff --git a/.github/workflows/release_nuget.yml b/.github/workflows/release_nuget.yml new file mode 100644 index 0000000..11a7057 --- /dev/null +++ b/.github/workflows/release_nuget.yml @@ -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/install-jq-action@v2.1.0 + + - 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 }} \ No newline at end of file diff --git a/src/SpaceWarp.Game/SpaceWarp.Game.csproj b/src/SpaceWarp.Game/SpaceWarp.Game.csproj index 78c4f15..d90289f 100644 --- a/src/SpaceWarp.Game/SpaceWarp.Game.csproj +++ b/src/SpaceWarp.Game/SpaceWarp.Game.csproj @@ -2,7 +2,6 @@ - diff --git a/src/SpaceWarp/Directory.Build.targets b/src/SpaceWarp/Directory.Build.targets index 61d752c..6c8a1ef 100644 --- a/src/SpaceWarp/Directory.Build.targets +++ b/src/SpaceWarp/Directory.Build.targets @@ -1,5 +1,9 @@ + + nuget + mono /usr/local/bin/nuget.exe + @@ -78,8 +82,12 @@ - + + + @@ -105,7 +113,7 @@ + Command="$(NuGetExecutable) pack "$(SolutionDir)/Package.nuspec" -OutputDirectory "$(SolutionDir)/nuget" -Properties "NoWarn=NU5125;id=$(ProjectName);version=$(Version);authors=$(Authors);description=$(Description);repositoryType=$(RepositoryType);repositoryUrl=$(RepositoryUrl)"" />