Skip to content

Commit

Permalink
Merge pull request #275 from SpaceWarpDev/dev
Browse files Browse the repository at this point in the history
1.7.0
  • Loading branch information
cheese3660 authored Dec 22, 2023
2 parents d7f4545 + 01bbc1a commit 7cde6e2
Show file tree
Hide file tree
Showing 217 changed files with 761 additions and 735 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`.
```
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

0 comments on commit 7cde6e2

Please sign in to comment.