update template

This commit is contained in:
Tobias Berger 2024-10-16 14:11:05 +02:00
parent 95f1229c14
commit 01b89f0473
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
29 changed files with 367 additions and 207 deletions

View file

@ -4,9 +4,7 @@
"tools": { "tools": {
"roslynator.dotnet.cli": { "roslynator.dotnet.cli": {
"version": "0.8.4", "version": "0.8.4",
"commands": [ "commands": ["roslynator"]
"roslynator"
]
} }
} }
} }

2
.envrc
View file

@ -1 +1,3 @@
use flake use flake
npm i

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/.vscode/obj /.vscode/obj
/.direnv/ /.direnv/
/log/rimworld.log /log/rimworld.log
/node_modules/

View file

@ -1,8 +1,5 @@
<xsl:stylesheet version="1.0" <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="utf-8" indent="yes" />
<xsl:output method="xml"
encoding="utf-8"
indent="yes" />
<xsl:strip-space elements="*" /> <xsl:strip-space elements="*" />
<!-- Match ModMetaData and its descendants, modify modVersion element --> <!-- Match ModMetaData and its descendants, modify modVersion element -->
<xsl:template match="/Project/PropertyGroup/ModMetaData|ModMetaData/@*|ModMetaData//node()"> <xsl:template match="/Project/PropertyGroup/ModMetaData|ModMetaData/@*|ModMetaData//node()">

10
.vscode/build.sh vendored
View file

@ -1,4 +1,5 @@
set -e set -e
set -x
script_dir=$(dirname $(readlink -f $0)) script_dir=$(dirname $(readlink -f $0))
mod_dir=$(dirname $script_dir) mod_dir=$(dirname $script_dir)
@ -7,11 +8,12 @@ pushd $script_dir
configuration=${1:-Debug} configuration=${1:-Debug}
# build dll # build dll
rm -f ../1.4/Assemblies/* echo "Building for RimWorld 1.5"
dotnet build mod.csproj -c ${configuration} rm -f $mod_dir/1.5/Assemblies/BetterAutocastVPE.dll
dotnet build $script_dir/mod.csproj -c ${configuration} -p:GAME_VERSION=v1.5
# generate About.xml # generate About.xml
rm -f ../About/About.xml rm -f $mod_dir/About/About.xml
xsltproc -o ../About/About.xml ./about.xml.xslt ./mod.csproj xsltproc -o $mod_dir/About/About.xml $script_dir/about.xml.xslt $script_dir/mod.csproj
popd popd

5
.vscode/fmt.sh vendored
View file

@ -1,9 +1,12 @@
set -e set -e
set -x
script_dir=$(dirname $(readlink -f $0)) script_dir=$(dirname $(readlink -f $0))
mod_dir=$(dirname $script_dir) mod_dir=$(dirname $script_dir)
pushd $mod_dir pushd $mod_dir
nix fmt treefmt
dotnet tool restore
dotnet roslynator format $script_dir/mod.csproj
popd popd

6
.vscode/launch.sh vendored
View file

@ -1,9 +1,11 @@
set -e set -e
set -x
script_dir=$(dirname $(readlink -f $0)) script_dir=$(dirname $(readlink -f $0))
mod_dir=$(dirname $script_dir) mod_dir=$(dirname $script_dir)
pushd $script_dir game_dir=$(realpath ~/.local/share/Steam/steamapps/common/RimWorld/)
pushd $mod_dir
SDL_VIDEODRIVER=X11 LC_ALL=C steam-run ~/.local/share/Steam/steamapps/common/RimWorld/RimWorldLinux -logfile $mod_dir/log/rimworld.log -popupwindow $@ SDL_VIDEODRIVER=X11 LC_ALL=C steam-run $game_dir/RimWorldLinux -logfile $mod_dir/log/rimworld.log -popupwindow $@
popd popd

58
.vscode/mod.csproj vendored
View file

@ -1,4 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="'$(GAME_VERSION)'==''">
<DefineConstants>v1_5</DefineConstants>
<OutputPath>../1.5/Assemblies</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(GAME_VERSION)'=='v1.5'">
<DefineConstants>v1_5</DefineConstants>
<OutputPath>../1.5/Assemblies</OutputPath>
</PropertyGroup>
<PropertyGroup> <PropertyGroup>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<TargetFramework>net480</TargetFramework> <TargetFramework>net480</TargetFramework>
@ -6,25 +14,25 @@
<!-- Modify [RootNamespace], [AssemblyName], [OutputPath], [VersionPrefix] --> <!-- Modify [RootNamespace], [AssemblyName], [OutputPath], [VersionPrefix] -->
<RootNamespace>Template</RootNamespace> <RootNamespace>Template</RootNamespace>
<AssemblyName>Template</AssemblyName> <AssemblyName>Template</AssemblyName>
<OutputPath>../1.4/Assemblies</OutputPath>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<VersionPrefix>0.1.0.0</VersionPrefix> <VersionPrefix>0.0.0.0</VersionPrefix>
<!-- do not generate pdb file --> <!-- do not generate pdb file -->
<DebugType>none</DebugType> <DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols> <DebugSymbols>false</DebugSymbols>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Deterministic>True</Deterministic>
<!-- Contents of About.xml <!-- Contents of About.xml
See https://rimworldwiki.com/wiki/Modding_Tutorials/About.xml --> See https://rimworldwiki.com/wiki/Modding_Tutorials/About.xml -->
<ModMetaData> <ModMetaData>
<packageId>dev.tobot.mod-template</packageId> <packageId>dev.tobot.rimworld.template</packageId>
<name>Mod Template</name> <name>Toby's Mod Template</name>
<authors> <authors>
<li>Toby</li> <li>Toby</li>
</authors> </authors>
<description>A mod template.\nReady to build on NixOS.</description> <description>Template mod for nix and VS Code</description>
<supportedVersions> <supportedVersions>
<li>1.4</li> <li>1.5</li>
</supportedVersions> </supportedVersions>
<modVersion IgnoreIfNoMatchingField="True"> <modVersion IgnoreIfNoMatchingField="True">
<!-- Gets automatically populated with VersionPrefix (see above) --> <!-- Gets automatically populated with VersionPrefix (see above) -->
@ -32,17 +40,21 @@
<url>https://git.tobot.dev/toby/rimworld-mod-template</url> <url>https://git.tobot.dev/toby/rimworld-mod-template</url>
<modDependencies /> <modDependencies />
<modDependenciesByVersion> <modDependenciesByVersion>
<!-- <v1.4> <v1.5>
<li> <li>
<packageId>brrainz.harmony</packageId> <packageId>brrainz.harmony</packageId>
<displayName>Harmony</displayName> <displayName>Harmony</displayName>
<steamWorkshopUrl>steam://url/CommunityFilePage/2009463077</steamWorkshopUrl> <steamWorkshopUrl>steam://url/CommunityFilePage/2009463077</steamWorkshopUrl>
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl> <downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li> </li>
</v1.4> --> </v1.5>
</modDependenciesByVersion> </modDependenciesByVersion>
<loadAfter /> <loadAfter />
<loadAfterByVersion /> <loadAfterByVersion>
<v1.5>
<li>brrainz.harmony</li>
</v1.5>
</loadAfterByVersion>
<forceLoadAfter /> <forceLoadAfter />
<loadBefore /> <loadBefore />
<loadBeforeByVersion /> <loadBeforeByVersion />
@ -51,22 +63,20 @@
<incompatibleWithByVersion /> <incompatibleWithByVersion />
</ModMetaData> </ModMetaData>
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition="'$(GAME_VERSION)'==''">
<!-- <PackageReference Include="Krafs.Rimworld.Ref" Version="1.5.4104" /> -->
<Reference Include="RimWorld" HintPath="/home/toby/.local/share/Steam/steamapps/common/RimWorld/RimWorldLinux_Data/Managed/Assembly-CSharp.dll" IncludeAssets="compile" Private="false" />
<PackageReference Include="Lib.Harmony" Version="2.3.3" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(GAME_VERSION)'=='v1.5'">
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.5.4104" />
<!-- <Reference Include="RimWorld" HintPath="/home/toby/.local/share/Steam/steamapps/common/RimWorld/RimWorldLinux_Data/Managed/Assembly-CSharp.dll" IncludeAssets="compile" Private="false" /> -->
<PackageReference Include="Lib.Harmony" Version="2.3.3" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<!-- Mod --> <!-- Mod -->
<Compile Include="../Source/**/*" /> <Compile Include="../Source/**/*.cs" />
<PackageReference Include="Krafs.Rimworld.Ref" <PackageReference Include="roslynator.analyzers" Version="4.12.5" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" PrivateAssets="all" />
Version="1.4.3901" /> <PackageReference Include="roslynator.formatting.analyzers" Version="4.12.5" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" PrivateAssets="all" />
<!-- Set IncludeAssets to 'compile' to enable Harmony -->
<PackageReference Include="Lib.Harmony"
Version="2.3.3"
IncludeAssets="none" />
<PackageReference Include="roslynator.analyzers"
Version="4.12.0"
IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive"
PrivateAssets="all" />
<PackageReference Include="roslynator.formatting.analyzers"
Version="4.12.0"
IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive"
PrivateAssets="all" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -1,9 +1,11 @@
set -e set -e
set -x
script_dir=$(dirname $(readlink -f $0)) script_dir=$(dirname $(readlink -f $0))
mod_dir=$(dirname $script_dir) mod_dir=$(dirname $script_dir)
pushd $mod_dir pushd $mod_dir
dotnet tool restore
dotnet roslynator analyze $script_dir/mod.csproj dotnet roslynator analyze $script_dir/mod.csproj
popd popd

36
.vscode/settings.json vendored
View file

@ -3,29 +3,13 @@
"files.exclude": { "files.exclude": {
".direnv": true, ".direnv": true,
".vscode/obj": true, ".vscode/obj": true,
"*/Assemblies/": true "*/Assemblies/": true,
"1.4": true
}, },
"files.readonlyInclude": { "files.readonlyInclude": {
"log/rimworld.log": true, "log/rimworld.log": true,
"About/About.xml": true "About/About.xml": true
}, },
"omnisharp.organizeImportsOnFormat": true,
"dotnet.inlayHints.enableInlayHintsForParameters": true,
"dotnet.inlayHints.enableInlayHintsForLiteralParameters": true,
"dotnet.inlayHints.enableInlayHintsForIndexerParameters": true,
"dotnet.inlayHints.enableInlayHintsForObjectCreationParameters": true,
"dotnet.inlayHints.enableInlayHintsForOtherParameters": true,
"dotnet.inlayHints.suppressInlayHintsForParametersThatDifferOnlyBySuffix": true,
"dotnet.inlayHints.suppressInlayHintsForParametersThatMatchMethodIntent": true,
"dotnet.inlayHints.suppressInlayHintsForParametersThatMatchArgumentName": true,
"csharp.inlayHints.enableInlayHintsForTypes": true,
"csharp.inlayHints.enableInlayHintsForImplicitVariableTypes": true,
"csharp.inlayHints.enableInlayHintsForLambdaParameterTypes": true,
"csharp.inlayHints.enableInlayHintsForImplicitObjectCreation": true,
"csharp.suppressDotnetInstallWarning": true,
"csharp.suppressDotnetRestoreNotification": true,
"dotnet.server.useOmnisharp": true,
"omnisharp.enableLspDriver": false,
"[xml]": { "[xml]": {
"editor.quickSuggestions": { "editor.quickSuggestions": {
"other": "on", "other": "on",
@ -36,8 +20,18 @@
"[jsonc]": { "[jsonc]": {
"editor.quickSuggestions": { "editor.quickSuggestions": {
"strings": true "strings": true
},
"editor.suggest.insertMode": "replace",
"editor.defaultFormatter": "esbenp.prettier-vscode"
} }
},
"csharp.inlayHints.enableInlayHintsForImplicitObjectCreation": true,
"csharp.inlayHints.enableInlayHintsForImplicitVariableTypes": true,
"csharp.inlayHints.enableInlayHintsForLambdaParameterTypes": true,
"csharp.inlayHints.enableInlayHintsForTypes": true,
"dotnet.inlayHints.enableInlayHintsForIndexerParameters": true,
"dotnet.inlayHints.enableInlayHintsForLiteralParameters": true,
"dotnet.inlayHints.enableInlayHintsForObjectCreationParameters": true,
"dotnet.inlayHints.enableInlayHintsForOtherParameters": true,
"dotnet.inlayHints.enableInlayHintsForParameters": true,
"dotnet.inlayHints.suppressInlayHintsForParametersThatDifferOnlyBySuffix": true,
"dotnet.inlayHints.suppressInlayHintsForParametersThatMatchArgumentName": true,
"dotnet.inlayHints.suppressInlayHintsForParametersThatMatchMethodIntent": true
} }

7
.vscode/setup.sh vendored
View file

@ -6,16 +6,13 @@ mod_dir=$(dirname $script_dir)
pushd $script_dir pushd $script_dir
mod_name="${mod_dir##*/}" mod_name="${mod_dir##*/}"
target_dir=$(readlink -f ~/.local/share/Steam/steamapps/common/RimWorld/Mods/)/$mod_name target_dir=${1:-$(realpath ~/.local/share/Steam/steamapps/common/RimWorld/Mods/)/$mod_name}
dotnet tool restore
if [ "$target_dir" = "$mod_dir" ]; then if [ "$target_dir" = "$mod_dir" ]; then
echo "Target directory is the same as the mod directory. Cloned in RimWorld/Mods. Skipping setup" echo "Target directory is the same as the mod directory. Cloned in RimWorld/Mods. Skipping setup"
else else
mkdir -p $target_dir mkdir -p $target_dir
rsync -av --exclude '$mod_dir/*' --delete $mod_dir/1.4 $mod_dir/About $mod_dir/README $mod_dir/LICENSE $target_dir rsync -av --exclude '$mod_dir/*' --delete $mod_dir/1.4 $mod_dir/1.5 $mod_dir/About $mod_dir/README $mod_dir/LICENSE $mod_dir/Changelog.md $target_dir
fi fi
popd popd

Binary file not shown.

View file

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<LetterDef>
<defName>success_letter</defName>
<color>(65, 200, 65)</color>
<flashColor>(85, 255, 85)</flashColor>
<flashInterval>6</flashInterval>
<bounce>false</bounce>
<arriveSound>LetterArrive_Good</arriveSound>
<description>If you can see this letter, then mod template is set up correctly.</description>
</LetterDef>
</Defs>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
<TemplateMod.SettingsCategory>Template Mod</TemplateMod.SettingsCategory>
</LanguageData>

BIN
1.5/Assemblies/Template.dll Normal file

Binary file not shown.

12
1.5/Defs/LetterDef.xml Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<LetterDef>
<defName>success_letter</defName>
<color>(65, 200, 65)</color>
<flashColor>(85, 255, 85)</flashColor>
<flashInterval>6</flashInterval>
<bounce>false</bounce>
<arriveSound>LetterArrive_Good</arriveSound>
<description>If you can see this letter, then mod template is set up correctly.</description>
</LetterDef>
</Defs>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
<TemplateMod.SettingsCategory>Template Mod</TemplateMod.SettingsCategory>
</LanguageData>

24
About/About.xml Normal file → Executable file
View file

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

View file

@ -0,0 +1,21 @@
global using static Template.Extensions.TranslateExtension;
namespace Template.Extensions;
static class TranslateExtension
{
public static Verse.TaggedString TranslateSafe(
this string self,
params Verse.NamedArgument[] args
)
{
if (!Verse.Translator.CanTranslate(self))
{
TemplateMod.DebugError(
$"Untranslated key: {self}",
Verse.GenString.GetHashCodeSafe(self)
);
}
return Verse.TranslatorFormattedStringExtensions.Translate(self, args);
}
}

View file

@ -7,28 +7,33 @@ namespace Template;
using Settings; using Settings;
using UnityEngine; using UnityEngine;
#if DEBUG
#warning Compiling in Debug mode
#endif
public class TemplateMod : Mod public class TemplateMod : Mod
{ {
internal static string Translate(string key)
{
const string TranslationKey = nameof(TemplateMod);
return (TranslationKey + "." + key).Translate();
}
public TemplateMod(ModContentPack content) public TemplateMod(ModContentPack content)
: base(content) : base(content)
{ {
#if v1_5
const string GAME_VERSION = "v1.5";
#else
#error No version defined
const string GAME_VERSION = "UNDEFINED";
#endif
#if DEBUG #if DEBUG
const string build = "Debug"; const string build = "Debug";
#else #else
const string build = "Release"; const string build = "Release";
#endif #endif
Log.Message( Log(
$"Running Version {Assembly.GetAssembly(typeof(TemplateMod)).GetName().Version} " $"Running Version {Assembly.GetAssembly(typeof(TemplateMod)).GetName().Version} {build} compiled for RimWorld version {GAME_VERSION}"
+ build + build
); );
Log.Message(content.ModMetaData.packageIdLowerCase); Log(content.ModMetaData.packageIdLowerCase);
Settings = GetSettings<TemplateSettings>(); Settings = GetSettings<TemplateSettings>();
WriteSettings(); WriteSettings();
@ -42,54 +47,52 @@ public class TemplateMod : Mod
#nullable enable #nullable enable
public void ResetSettings()
{
Settings = new();
}
public override void DoSettingsWindowContents(Rect inRect) => public override void DoSettingsWindowContents(Rect inRect) =>
SettingsWindow.DoSettingsWindowContents(inRect); SettingsWindow.DoSettingsWindowContents(inRect);
public override string SettingsCategory() => SettingsWindow.SettingsCategory(); public override string SettingsCategory() => SettingsWindow.SettingsCategory();
public static class Log
{
const string LogPrefix = "Toby's Template Mod - "; const string LogPrefix = "Toby's Template Mod - ";
public static void DebugError(string message) public static void DebugError(string message, int? key = null)
{ {
#if DEBUG #if DEBUG
Error(message); Error(message, key);
#endif #endif
} }
public static void Error(string message) public static void Error(string message, int? key = null)
{ {
if (key is int keyNotNull)
Verse.Log.ErrorOnce(LogPrefix + message, keyNotNull);
else
Verse.Log.Error(LogPrefix + message); Verse.Log.Error(LogPrefix + message);
} }
public static void DebugWarn(string message) public static void DebugWarn(string message, int? key = null)
{ {
#if DEBUG #if DEBUG
Warn(message); Warn(message, key);
#endif #endif
} }
public static void Warn(string message) public static void Warn(string message, int? key = null)
{ {
if (key is int keyNotNull)
Verse.Log.WarningOnce(LogPrefix + message, keyNotNull);
else
Verse.Log.Warning(LogPrefix + message); Verse.Log.Warning(LogPrefix + message);
} }
public static void DebugLog(string message) public static void DebugLog(string message)
{ {
#if DEBUG #if DEBUG
Message(message); Log(message);
#endif #endif
} }
public static void Message(string message) public static void Log(string message)
{ {
Verse.Log.Message(LogPrefix + message); Verse.Log.Message(LogPrefix + message);
} }
}
} }

View file

@ -25,6 +25,6 @@ public static class SettingsWindow
public static string SettingsCategory() public static string SettingsCategory()
{ {
return TemplateMod.Translate("SettingsCategory"); return "TemplateMod.SettingsCategory".TranslateSafe();
} }
} }

View file

@ -1,15 +1,37 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using Verse; using Verse;
namespace Template.Settings; namespace Template.Settings;
public class TemplateSettings : ModSettings public class TemplateSettings : ModSettings
{ {
private static TemplateSettings DefaultValues() => new();
#region Scribe Helpers #region Scribe Helpers
private static void LookField<T>(ref T value, string label, T defaultValue) private void LookStruct<T>(Expression<Func<T>> expression)
where T : struct
{ {
Scribe_Values.Look(ref value, label, defaultValue); if (
expression.Body
is not MemberExpression
{
Member: MemberInfo { MemberType: MemberTypes.Field, Name: string memberName }
}
)
{
throw new ArgumentException(
"Invalid expression passed to LookField",
nameof(expression)
);
}
FieldInfo fieldInfo = typeof(TemplateSettings).GetField(memberName);
T? value = fieldInfo.GetValue(this).ChangeType<T>();
T defaultValue = fieldInfo.GetValue(DefaultValues()).ChangeType<T>();
Scribe_Values.Look(ref value, memberName, defaultValue);
fieldInfo.SetValue(this, value);
} }
private static void LookHashSet<T>( private static void LookHashSet<T>(
@ -21,24 +43,34 @@ public class TemplateSettings : ModSettings
{ {
if (Scribe.mode == LoadSaveMode.Saving && valueHashSet is null) if (Scribe.mode == LoadSaveMode.Saving && valueHashSet is null)
{ {
TemplateMod.Log.Warn( TemplateMod.Warn(label + " is null before saving. Reinitializing with default values.");
label + " is null before saving. Reinitializing with default values."
);
valueHashSet = defaultValues; valueHashSet = defaultValues;
} }
Scribe_Collections.Look(ref valueHashSet, label, lookMode: LookMode.Value); Scribe_Collections.Look(ref valueHashSet, label, lookMode: LookMode.Value);
if (Scribe.mode == LoadSaveMode.LoadingVars && valueHashSet is null) if (Scribe.mode == LoadSaveMode.LoadingVars && valueHashSet is null)
{ {
TemplateMod.Log.Warn( TemplateMod.Warn(label + " is null after loading. Reinitializing with default values.");
label + " is null after loading. Reinitializing with default values."
);
valueHashSet = defaultValues; valueHashSet = defaultValues;
} }
} }
#endregion #endregion
public bool TemplateEnabled;
public TemplateSettings()
{
Reset();
}
public void Reset()
{
TemplateEnabled = true;
}
public override void ExposeData() public override void ExposeData()
{ {
base.ExposeData(); base.ExposeData();
LookStruct(() => TemplateEnabled);
} }
} }

View file

@ -6,7 +6,7 @@ using Verse;
namespace Template; namespace Template;
[DefOf] [DefOf]
public static class StinkyTweaksDefOf public static class TemplateDefOf
{ {
public static LetterDef success_letter; public static LetterDef success_letter;
} }

View file

@ -12,9 +12,8 @@ public class TemplateMapComponent(Map map) : MapComponent(map)
Messages.Message("Success", null, MessageTypeDefOf.PositiveEvent); Messages.Message("Success", null, MessageTypeDefOf.PositiveEvent);
Find.LetterStack.ReceiveLetter( Find.LetterStack.ReceiveLetter(
"Success", "Success",
StinkyTweaksDefOf.success_letter.description, TemplateDefOf.success_letter.description,
StinkyTweaksDefOf.success_letter, TemplateDefOf.success_letter
null
); );
} }
} }

View file

@ -5,11 +5,11 @@
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib"
}, },
"locked": { "locked": {
"lastModified": 1712014858, "lastModified": 1727826117,
"narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=",
"owner": "hercules-ci", "owner": "hercules-ci",
"repo": "flake-parts", "repo": "flake-parts",
"rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -20,52 +20,30 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1712963716, "lastModified": 1728538411,
"narHash": "sha256-WKm9CvgCldeIVvRz87iOMi8CFVB1apJlkUT4GGvA0iM=", "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=",
"owner": "nixos", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "cfd6b5fc90b15709b780a5a1619695a88505a176", "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "NixOS",
"ref": "nixos-unstable", "ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib": { "nixpkgs-lib": {
"locked": { "locked": {
"dir": "lib", "lastModified": 1727825735,
"lastModified": 1711703276, "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=",
"narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", "type": "tarball",
"owner": "NixOS", "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz"
"repo": "nixpkgs",
"rev": "d8fe5e6c92d0d190646fb9f1056741a229980089",
"type": "github"
}, },
"original": { "original": {
"dir": "lib", "type": "tarball",
"owner": "NixOS", "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz"
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1708475490,
"narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0e74ca98a74bc7270d28838369593635a5db3260",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
} }
}, },
"root": { "root": {
@ -93,14 +71,16 @@
}, },
"treefmt-nix": { "treefmt-nix": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_2" "nixpkgs": [
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1711963903, "lastModified": 1729077719,
"narHash": "sha256-N3QDhoaX+paWXHbEXZapqd1r95mdshxToGowtjtYkGI=", "narHash": "sha256-zayHqZO9gA1U85c4CPvVSnLV8/cBgc2yVrSKWaKeBUs=",
"owner": "numtide", "owner": "numtide",
"repo": "treefmt-nix", "repo": "treefmt-nix",
"rev": "49dc4a92b02b8e68798abd99184f228243b6e3ac", "rev": "5307ba60125bb024d7e52d71d582eafd511f3fee",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -1,10 +1,13 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default"; systems.url = "github:nix-systems/default";
# Dev tools # Dev tools
treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = outputs =
@ -22,16 +25,17 @@
... ...
}: }:
{ {
# Rust dev environment
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
inputsFrom = [ config.treefmt.build.devShell ]; inputsFrom = [ config.treefmt.build.devShell ];
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
dotnet-sdk_8 dotnetCorePackages.dotnet_8.sdk
libxslt nixfmt-rfc-style
omnisharp-roslyn
libxslt.bin
nodePackages.npm
]; ];
shellHook = ''
DOTNET_ROOT="${pkgs.dotnet-sdk_8}"; DOTNET_ROOT = "${pkgs.dotnet-sdk_8}";
'';
}; };
# Add your auto-formatters here. # Add your auto-formatters here.
@ -39,10 +43,48 @@
treefmt.config = { treefmt.config = {
projectRootFile = "flake.nix"; projectRootFile = "flake.nix";
programs = { programs = {
nixpkgs-fmt.enable = true; csharpier = {
csharpier.enable = true; enable = true;
nixfmt-rfc-style.enable = true; dotnet-sdk = pkgs.dotnet-sdk_6;
package = pkgs.csharpier;
}; };
nixfmt.enable = true;
shfmt.enable = true;
prettier = {
enable = true;
includes = [
"**/*.xml"
"**/*.xslt"
"**/*.json"
"**/*.csproj"
".github/workflows/*"
];
settings = {
plugins = [ "@prettier/plugin-xml" ];
bracketSameLine = true;
printWidth = 1000;
overrides = [
{
files = "*.xml";
options = {
xmlQuoteAttributes = "double";
xmlSortAttributesByKey = true;
xmlWhitespaceSensitivity = "preserve";
};
}
];
};
};
};
settings.global.excludes = [
".direnv"
"node_modules"
"1.4/**/*"
"*.ase"
"*.dll"
"*.png"
"About/About.xml"
];
}; };
}; };
}; };

64
package-lock.json generated Normal file
View file

@ -0,0 +1,64 @@
{
"name": "no-nutrient-ingredients",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@prettier/plugin-xml": "^3.4.1"
}
},
"node_modules/@prettier/plugin-xml": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/@prettier/plugin-xml/-/plugin-xml-3.4.1.tgz",
"integrity": "sha512-Uf/6/+9ez6z/IvZErgobZ2G9n1ybxF5BhCd7eMcKqfoWuOzzNUxBipNo3QAP8kRC1VD18TIo84no7LhqtyDcTg==",
"license": "MIT",
"dependencies": {
"@xml-tools/parser": "^1.0.11"
},
"peerDependencies": {
"prettier": "^3.0.0"
}
},
"node_modules/@xml-tools/parser": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@xml-tools/parser/-/parser-1.0.11.tgz",
"integrity": "sha512-aKqQ077XnR+oQtHJlrAflaZaL7qZsulWc/i/ZEooar5JiWj1eLt0+Wg28cpa+XLney107wXqneC+oG1IZvxkTA==",
"license": "Apache-2.0",
"dependencies": {
"chevrotain": "7.1.1"
}
},
"node_modules/chevrotain": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-7.1.1.tgz",
"integrity": "sha512-wy3mC1x4ye+O+QkEinVJkPf5u2vsrDIYW9G7ZuwFl6v/Yu0LwUuT2POsb+NUWApebyxfkQq6+yDfRExbnI5rcw==",
"license": "Apache-2.0",
"dependencies": {
"regexp-to-ast": "0.5.0"
}
},
"node_modules/prettier": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz",
"integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==",
"license": "MIT",
"peer": true,
"bin": {
"prettier": "bin/prettier.cjs"
},
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/regexp-to-ast": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.5.0.tgz",
"integrity": "sha512-tlbJqcMHnPKI9zSrystikWKwHkBqu2a/Sgw01h3zFjvYrMxEDYHzzoMZnUrbIfpTFEsoRnnviOXNCzFiSc54Qw==",
"license": "MIT"
}
}
}

5
package.json Normal file
View file

@ -0,0 +1,5 @@
{
"dependencies": {
"@prettier/plugin-xml": "^3.4.1"
}
}