feat: update template for nixos

This commit is contained in:
Tobias Berger 2024-02-11 17:28:50 +01:00
parent dce259ecf8
commit c229cb42ac
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
26 changed files with 474 additions and 174 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

7
.gitignore vendored
View file

@ -1,6 +1,3 @@
/.vscode/obj
# /*/Assemblies
# /*/Assemblies/*.pdb
# /.vscode
# /Source
/.direnv/
/log/rimworld.log

23
.vscode/about.xml.xslt vendored Normal file
View file

@ -0,0 +1,23 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- Match ModMetaData and its descendants, modify modVersion element -->
<xsl:template match="/Project/PropertyGroup/ModMetaData|ModMetaData/@*[not(name()='Id')]|ModMetaData//node()">
<xsl:copy>
<xsl:apply-templates select="@*[not(name()='Id')]|node()"/>
</xsl:copy>
</xsl:template>
<!-- Modify modVersion element using the value of VersionPrefix -->
<xsl:template match="ModMetaData/modVersion">
<modVersion>
<xsl:copy-of select="@*" />
<xsl:value-of select="/Project/PropertyGroup/VersionPrefix"/>
</modVersion>
</xsl:template>
<!-- Remove other elements and attributes -->
<xsl:template match="@*|node()">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

7
.vscode/build.bat vendored
View file

@ -1,7 +0,0 @@
echo off
REM remove unnecessary assemblies
DEL .\*\Assemblies\*.*
REM build dll
dotnet build .vscode

15
.vscode/build.sh vendored Executable file
View file

@ -0,0 +1,15 @@
set -e
script_dir=$(dirname $(readlink -f $0))
mod_dir=$(dirname $script_dir)
pushd $script_dir
# build dll
rm -f ../1.4/Assemblies/*
dotnet build mod.csproj
# generate About.xml
rm -f ../About/About.xml
xsltproc -o ../About/About.xml ./about.xml.xslt ./mod.csproj
popd

View file

@ -1,5 +0,0 @@
{
"recommendations": [
"ms-dotnettools.csharp"
]
}

9
.vscode/fmt.sh vendored Normal file
View file

@ -0,0 +1,9 @@
set -e
script_dir=$(dirname $(readlink -f $0))
mod_dir=$(dirname $script_dir)
pushd $mod_dir
nix fmt
popd

20
.vscode/launch.json vendored
View file

@ -1,20 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Rimworld Mod Project",
"type": "clr",
"request": "launch",
"preLaunchTask": "build dll",
"args": [],
"program": "../../RimWorldWin64.exe",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"internalConsoleOptions":"neverOpen",
"stopAtEntry": true
}
]
}

9
.vscode/launch.sh vendored Executable file
View file

@ -0,0 +1,9 @@
set -e
script_dir=$(dirname $(readlink -f $0))
mod_dir=$(dirname $script_dir)
pushd $script_dir
LC_ALL=C steam-run ~/.steam/steam/steamapps/common/RimWorld/RimWorldLinux -logfile $mod_dir/log/rimworld.log -popupwindow $@
popd

54
.vscode/mod.csproj vendored
View file

@ -3,32 +3,58 @@
<OutputType>Library</OutputType>
<TargetFramework>net480</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<!-- Modify [RootNamespace], [AssemblyName], [OutputPath], [VersionPrefix] -->
<RootNamespace>Template</RootNamespace>
<AssemblyName>Template</AssemblyName>
<OutputPath>../1.4/Assemblies</OutputPath>
<LangVersion>latest</LangVersion>
<VersionPrefix>0.1.0.0</VersionPrefix>
<!-- do not generate pdb file -->
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<!-- Contents of About.xml
See https://rimworldwiki.com/wiki/Modding_Tutorials/About.xml -->
<ModMetaData>
<packageId>dev.tobot.mod-template</packageId>
<name>Mod Template</name>
<authors>
<li>Toby</li>
</authors>
<description>A mod template.\nReady to build on NixOS.</description>
<supportedVersions>
<li>1.4</li>
</supportedVersions>
<modVersion IgnoreIfNoMatchingField="True" />
<url />
<modDependencies />
<modDependenciesByVersion>
<!-- <v1.4>
<li>
<packageId>brrainz.harmony</packageId>
<displayName>Harmony</displayName>
<steamWorkshopUrl>steam://url/CommunityFilePage/2009463077</steamWorkshopUrl>
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li>
</v1.4> -->
</modDependenciesByVersion>
<loadAfter />
<loadAfterByVersion />
<forceLoadAfter />
<loadBefore />
<loadBeforeByVersion />
<forceLoadBefore />
<incompatibleWith />
<incompatibleWithByVersion />
</ModMetaData>
</PropertyGroup>
<ItemGroup>
<!-- Mod -->
<Compile Include="../Source/*" />
<!-- Rimworld -->
<Reference Include="../../../RimWorldWin64_Data/Managed/*.dll">
<Private>False</Private>
</Reference>
<!-- Harmony -->
<!-- <Reference Include="../../Harmony/Current/Assemblies/0Harmony.dll">
<Private>False</Private>
</Reference> -->
<PackageReference Include="Krafs.Rimworld.Ref"
Version="1.4.3901" />
<PackageReference Include="Lib.Harmony"
Version="2.2.2"
IncludeAssets="none" />
</ItemGroup>
</Project>

10
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,10 @@
{
// "explorer.excludeGitIgnore": true,
"files.exclude": {
".direnv": true,
".vscode/obj": true
},
"files.readonlyInclude": {
"log/rimworld.log": true
}
}

12
.vscode/setup.sh vendored Executable file
View file

@ -0,0 +1,12 @@
set -e
script_dir=$(dirname $(readlink -f $0))
mod_dir=$(dirname $script_dir)
pushd $script_dir
mod_name="${mod_dir##*/}"
# Try to create symlink in RimWorld mod directory
ln -s $mod_dir -t "$(readlink -f ~/.steam/steam/steamapps/common/RimWorld/Mods)" -v || echo "Target directory already exists. This is expected on re-runs"
popd

51
.vscode/tasks.json vendored
View file

@ -2,13 +2,60 @@
"version": "2.0.0",
"tasks": [
{
"label": "build dll",
"label": "format",
"type": "shell",
"group": "none",
"command": ".vscode/fmt.sh",
"problemMatcher": []
},
{
"label": "build mod",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": ".vscode/build.bat",
"command": ".vscode/build.sh",
"problemMatcher": [
"$msCompile"
]
},
{
"label": "run game",
"type": "shell",
"group": {
"kind": "none",
"isDefault": true
},
"command": ".vscode/launch.sh",
"problemMatcher": [],
"dependsOn": [
"link mod directory",
"build mod"
]
},
{
"label": "run game (quicktest)",
"type": "shell",
"group": {
"kind": "none",
"isDefault": true
},
"command": ".vscode/launch.sh -quicktest",
"problemMatcher": [],
"dependsOn": [
"link mod directory",
"build mod"
]
},
{
"label": "link mod directory",
"type": "shell",
"group": {
"kind": "none"
},
"command": ".vscode/setup.sh",
"problemMatcher": []
}
]
}

BIN
1.4/Assemblies/Template.dll Normal file

Binary file not shown.

View file

@ -1,3 +1,2 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
</LanguageData>
<LanguageData />

View file

@ -1,3 +1,2 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
</Patch>
<Patch />

View file

@ -1,24 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<ModMetaData>
<packageId>username.modname</packageId>
<packageId>dev.tobot.mod-template</packageId>
<name>Mod Template</name>
<author>username</author>
<authors>
<li>Toby</li>
</authors>
<description>A mod template.\nReady to build on NixOS.</description>
<supportedVersions>
<li>1.4</li>
</supportedVersions>
<modDependencies>
<!-- <li>
<modVersion IgnoreIfNoMatchingField="True">0.1.0.0</modVersion>
<url/>
<modDependencies/>
<modDependenciesByVersion>
<!-- <v1.4>
<li>
<packageId>brrainz.harmony</packageId>
<displayName>Harmony</displayName>
<steamWorkshopUrl>steam://url/CommunityFilePage/2009463077</steamWorkshopUrl>
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li> -->
</modDependencies>
<incompatibleWith>
<!-- <li>username.modname</li> -->
</incompatibleWith>
<description>Template</description>
</ModMetaData>
</li>
</v1.4> -->
</modDependenciesByVersion>
<loadAfter/>
<loadAfterByVersion/>
<forceLoadAfter/>
<loadBefore/>
<loadBeforeByVersion/>
<forceLoadBefore/>
<incompatibleWith/>
<incompatibleWithByVersion/>
</ModMetaData>

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Tobias Berger
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
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.

View file

@ -1,23 +1,19 @@
# Rimworld Mod Template
# RimWorld Mod Template
This template is created for Rimworld modders who use [Visual Studio Code](https://code.visualstudio.com/) instead of Visual Studio IDE.
* __No virtual folders__. Easy to manage and edit both `xml` and `cs` files.
* __Lightweight__. Visual Studio Code only takes up to 200 MB of storage space and is lighting fast.
* __Automated__. Integrated build, scripting and management tools to perform common tasks making everyday workflows faster.
* __Customizable__. Almost every feature can be changed, whenever it is editor UI, keybinds or folder structure.
This template is created for creating RimWorld mods in [VSCodium/Visual Studio Code](https://vscodium.com/)
## Setup
1. Download and install [.NET Core SDK](https://dotnet.microsoft.com/download/dotnet-core) and [.Net Framework 4.8 Developer Pack](https://dotnet.microsoft.com/download/dotnet-framework/net48). This step can be skipped if you already have required C# packages from Visual Studio IDE.
2. Install [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp).
3. Clone, pull or download this template into your Rimworld `Mods` folder.
1. Ensure the extension `ms-dotnettools.csharp` (a.k.a. [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp)) is installed
1. Run the task `link mod directory`.
- This should symlink the mod directory to RimWorld's mod folder.
- The script won't work if you have installed RimWorld anywhere else than the default steam install.
1. Run the task `build mod` to compile assemblies and About.xml
1. Run the task `run game` to launch the game
- The script won't work if you have installed RimWorld anywhere else than the default steam install.
## Additional notes
* By pressing `F5` key VS Code will perform 2 operations: build assembly file and launch Rimworld executable.
* All intermediate files are kept inside `.vscode` folder.
* For XML only modders remove preLaunchTask line from `.vscode/launch.json` file.
* Modify `.vscode/mod.csproj` and `About/About.xml` according to your needs.
- All attributes for `About.xml` are kept in `.vscode/mod.csproj`, `About.xml` will get overriden each build.
- You can run `nix fmt` to format all code in the repository.
- While this template is designed for VSCodium, it works just as well with any other editor, simply launch the scripts manually

View file

@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using Verse.AI;
using Verse.AI.Group;
using Verse.Sound;
using Verse.Noise;
using Verse.Grammar;
using RimWorld;
using RimWorld.Planet;
// using System.Reflection;
// using HarmonyLib;
namespace Template
{
[DefOf]
public class TemplateDefOf
{
public static LetterDef success_letter;
}
public class MyMapComponent : MapComponent
{
public MyMapComponent(Map map) : base(map){}
public override void FinalizeInit()
{
Messages.Message("Success", null, MessageTypeDefOf.PositiveEvent);
Find.LetterStack.ReceiveLetter("Success", TemplateDefOf.success_letter.description, TemplateDefOf.success_letter, null);
}
}
[StaticConstructorOnStartup]
public static class Start
{
static Start()
{
Log.Message("Mod template loaded successfully!");
}
}
}

16
Source/Startup.cs Normal file
View file

@ -0,0 +1,16 @@
#nullable enable
using Verse;
// using HarmonyLib;
namespace Template;
[StaticConstructorOnStartup]
public static class Startup
{
static Startup()
{
Log.Message("Mod template loaded successfully!");
}
}

13
Source/TemplateDefOf.cs Normal file
View file

@ -0,0 +1,13 @@
#nullable disable // Populated at runtime ; Will error if Def isn't added in Defs
using RimWorld;
using Verse;
namespace Template;
[DefOf]
public class TemplateDefOf
{
public static LetterDef success_letter;
}
#nullable enable

View file

@ -0,0 +1,25 @@
#nullable enable
using RimWorld;
using Verse;
// using HarmonyLib;
namespace Template;
public class TemplateMapComponent : MapComponent
{
public TemplateMapComponent(Map map)
: base(map) { }
public override void FinalizeInit()
{
Messages.Message("Success", null, MessageTypeDefOf.PositiveEvent);
Find.LetterStack.ReceiveLetter(
"Success",
TemplateDefOf.success_letter.description,
TemplateDefOf.success_letter,
null
);
}
}

115
flake.lock Normal file
View file

@ -0,0 +1,115 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1706830856,
"narHash": "sha256-a0NYyp+h9hlb7ddVz4LUn1vT/PLwqfrWYcHMvFB1xYg=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "b253292d9c0a5ead9bc98c4e9a26c6312e27d69f",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1707546158,
"narHash": "sha256-nYYJTpzfPMDxI8mzhQsYjIUX+grorqjKEU9Np6Xwy/0=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d934204a0f8d9198e1e4515dd6fec76a139c87f0",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1706550542,
"narHash": "sha256-UcsnCG6wx++23yeER4Hg18CXWbgNpqNXcHIo5/1Y+hc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "97b17f32362e475016f942bbdfda4a4a72a8a652",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1705856552,
"narHash": "sha256-JXfnuEf5Yd6bhMs/uvM67/joxYKoysyE3M2k6T3eWbg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "612f97239e2cc474c13c9dafa0df378058c5ad8d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1707300477,
"narHash": "sha256-qQF0fEkHlnxHcrKIMRzOETnRBksUK048MXkX0SOmxvA=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "ac599dab59a66304eb511af07b3883114f061b9d",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

37
flake.nix Normal file
View file

@ -0,0 +1,37 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
# Dev tools
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [ inputs.treefmt-nix.flakeModule ];
perSystem = { config, self', pkgs, lib, system, ... }: {
# Rust dev environment
devShells.default = pkgs.mkShell {
inputsFrom = [ config.treefmt.build.devShell ];
nativeBuildInputs = with pkgs; [ dotnet-sdk mono libxslt ];
shellHook = ''
DOTNET_ROOT="${pkgs.dotnet-sdk}";
'';
};
# Add your auto-formatters here.
# cf. https://numtide.github.io/treefmt/
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
nixpkgs-fmt.enable = true;
csharpier.enable = true;
prettier.enable = true;
nixfmt.enable = true;
};
};
};
};
}