feat: improve template some more
This commit is contained in:
parent
035f652046
commit
e52d10e49a
14 changed files with 301 additions and 165 deletions
2
.vscode/mod.csproj
vendored
2
.vscode/mod.csproj
vendored
|
@ -57,7 +57,7 @@
|
||||||
<PackageReference Include="Krafs.Rimworld.Ref"
|
<PackageReference Include="Krafs.Rimworld.Ref"
|
||||||
Version="1.4.3901" />
|
Version="1.4.3901" />
|
||||||
<!-- Set IncludeAssets to 'compile' to enable Harmony -->
|
<!-- Set IncludeAssets to 'compile' to enable Harmony -->
|
||||||
<PackageReference Include="Lib.Harmony.Thin"
|
<PackageReference Include="Lib.Harmony"
|
||||||
Version="2.3.3"
|
Version="2.3.3"
|
||||||
IncludeAssets="none" />
|
IncludeAssets="none" />
|
||||||
<PackageReference Include="roslynator.analyzers"
|
<PackageReference Include="roslynator.analyzers"
|
||||||
|
|
66
.vscode/settings.json
vendored
66
.vscode/settings.json
vendored
|
@ -1,29 +1,43 @@
|
||||||
{
|
{
|
||||||
// "explorer.excludeGitIgnore": true,
|
// "explorer.excludeGitIgnore": true,
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
".direnv": true,
|
".direnv": true,
|
||||||
".vscode/obj": true,
|
".vscode/obj": true,
|
||||||
"*/Assemblies/": true,
|
"*/Assemblies/": true
|
||||||
|
},
|
||||||
|
"files.readonlyInclude": {
|
||||||
|
"log/rimworld.log": 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]": {
|
||||||
|
"editor.quickSuggestions": {
|
||||||
|
"other": "on",
|
||||||
|
"comments": "off",
|
||||||
|
"strings": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"[jsonc]": {
|
||||||
|
"editor.quickSuggestions": {
|
||||||
|
"strings": true
|
||||||
},
|
},
|
||||||
"files.readonlyInclude": {
|
"editor.suggest.insertMode": "replace",
|
||||||
"log/rimworld.log": true,
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
"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
|
|
||||||
}
|
}
|
3
.vscode/setup.sh
vendored
3
.vscode/setup.sh
vendored
|
@ -14,7 +14,8 @@ 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/About $mod_dir/README $mod_dir/LICENSE $target_dir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
|
181
.vscode/tasks.json
vendored
181
.vscode/tasks.json
vendored
|
@ -1,99 +1,86 @@
|
||||||
{
|
{
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"label": "analyze",
|
"label": "analyze",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"group": "none",
|
"group": "none",
|
||||||
"command": ".vscode/roslynator.sh",
|
"command": ".vscode/roslynator.sh",
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "format",
|
"label": "format",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"group": "none",
|
"group": "none",
|
||||||
"command": ".vscode/fmt.sh",
|
"command": ".vscode/fmt.sh",
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "build mod (Debug)",
|
"label": "build mod (Debug)",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": true
|
"isDefault": true
|
||||||
},
|
},
|
||||||
"command": ".vscode/build.sh",
|
"command": ".vscode/build.sh",
|
||||||
"problemMatcher": [
|
"problemMatcher": ["$msCompile"],
|
||||||
"$msCompile"
|
"dependsOn": []
|
||||||
],
|
},
|
||||||
"dependsOn": []
|
{
|
||||||
},
|
"label": "build mod (Release)",
|
||||||
{
|
"type": "shell",
|
||||||
"label": "build mod (Release)",
|
"group": {
|
||||||
"type": "shell",
|
"kind": "build",
|
||||||
"group": {
|
"isDefault": true
|
||||||
"kind": "build",
|
},
|
||||||
"isDefault": true
|
"command": ".vscode/build.sh Release",
|
||||||
},
|
"problemMatcher": ["$msCompile"],
|
||||||
"command": ".vscode/build.sh Release",
|
"dependsOn": []
|
||||||
"problemMatcher": [
|
},
|
||||||
"$msCompile"
|
{
|
||||||
],
|
"label": "run game (Debug)",
|
||||||
"dependsOn": []
|
"type": "shell",
|
||||||
},
|
"group": {
|
||||||
{
|
"kind": "none",
|
||||||
"label": "run game (Debug)",
|
"isDefault": true
|
||||||
"type": "shell",
|
},
|
||||||
"group": {
|
"command": ".vscode/launch.sh",
|
||||||
"kind": "none",
|
"problemMatcher": [],
|
||||||
"isDefault": true
|
"dependsOrder": "sequence",
|
||||||
},
|
"dependsOn": ["build mod (Debug)", "set up mod directory"]
|
||||||
"command": ".vscode/launch.sh",
|
},
|
||||||
"problemMatcher": [],
|
{
|
||||||
"dependsOrder": "sequence",
|
"label": "run game (Release)",
|
||||||
"dependsOn": [
|
"type": "shell",
|
||||||
"build mod (Debug)",
|
"group": {
|
||||||
"set up mod directory"
|
"kind": "none",
|
||||||
]
|
"isDefault": true
|
||||||
},
|
},
|
||||||
{
|
"command": ".vscode/launch.sh",
|
||||||
"label": "run game (Release)",
|
"problemMatcher": [],
|
||||||
"type": "shell",
|
"dependsOrder": "sequence",
|
||||||
"group": {
|
"dependsOn": ["build mod (Release)", "set up mod directory"]
|
||||||
"kind": "none",
|
},
|
||||||
"isDefault": true
|
{
|
||||||
},
|
"label": "run game (Debug + quicktest)",
|
||||||
"command": ".vscode/launch.sh",
|
"type": "shell",
|
||||||
"problemMatcher": [],
|
"group": {
|
||||||
"dependsOrder": "sequence",
|
"kind": "none",
|
||||||
"dependsOn": [
|
"isDefault": true
|
||||||
"build mod (Release)",
|
},
|
||||||
"set up mod directory"
|
"command": ".vscode/launch.sh -quicktest",
|
||||||
]
|
"problemMatcher": [],
|
||||||
},
|
"dependsOrder": "sequence",
|
||||||
{
|
"dependsOn": ["build mod (Debug)", "set up mod directory"]
|
||||||
"label": "run game (Debug + quicktest)",
|
},
|
||||||
"type": "shell",
|
{
|
||||||
"group": {
|
"label": "set up mod directory",
|
||||||
"kind": "none",
|
"type": "shell",
|
||||||
"isDefault": true
|
"group": {
|
||||||
},
|
"kind": "none"
|
||||||
"command": ".vscode/launch.sh -quicktest",
|
},
|
||||||
"problemMatcher": [],
|
"command": ".vscode/setup.sh",
|
||||||
"dependsOrder": "sequence",
|
"problemMatcher": []
|
||||||
"dependsOn": [
|
}
|
||||||
"build mod (Debug)",
|
]
|
||||||
"set up mod directory"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "set up mod directory",
|
|
||||||
"type": "shell",
|
|
||||||
"group": {
|
|
||||||
"kind": "none"
|
|
||||||
},
|
|
||||||
"command": ".vscode/setup.sh",
|
|
||||||
"problemMatcher": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
Binary file not shown.
|
@ -1,2 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<LanguageData />
|
<LanguageData>
|
||||||
|
<TemplateMod.SettingsCategory>Template Mod</TemplateMod.SettingsCategory>
|
||||||
|
</LanguageData>
|
19
README.md
19
README.md
|
@ -1,19 +0,0 @@
|
||||||
# RimWorld Mod Template
|
|
||||||
|
|
||||||
This template is created for creating RimWorld mods in [VSCodium/Visual Studio Code](https://vscodium.com/)
|
|
||||||
|
|
||||||
## Setup
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
- 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
|
|
92
Source/Mod.cs
Normal file
92
Source/Mod.cs
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
using System.Reflection;
|
||||||
|
// using HarmonyLib;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
namespace Template;
|
||||||
|
|
||||||
|
using Settings;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class TemplateMod : Mod
|
||||||
|
{
|
||||||
|
internal static string Translate(string key)
|
||||||
|
{
|
||||||
|
const string TranslationKey = nameof(TemplateMod);
|
||||||
|
return (TranslationKey + "." + key).Translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TemplateMod(ModContentPack content)
|
||||||
|
: base(content)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
const string build = "Debug";
|
||||||
|
#else
|
||||||
|
const string build = "Release";
|
||||||
|
#endif
|
||||||
|
Log.Message(
|
||||||
|
$"Running Version {Assembly.GetAssembly(typeof(TemplateMod)).GetName().Version} "
|
||||||
|
+ build
|
||||||
|
);
|
||||||
|
|
||||||
|
Log.Message(content.ModMetaData.packageIdLowerCase);
|
||||||
|
|
||||||
|
// Harmony harmony = new(content.ModMetaData.packageIdLowerCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nullable disable // Set in constructor.
|
||||||
|
|
||||||
|
public static TemplateSettings Settings { get; private set; }
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
public void ResetSettings()
|
||||||
|
{
|
||||||
|
Settings = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DoSettingsWindowContents(Rect inRect) =>
|
||||||
|
SettingsWindow.DoSettingsWindowContents(inRect);
|
||||||
|
|
||||||
|
public override string SettingsCategory() => SettingsWindow.SettingsCategory();
|
||||||
|
|
||||||
|
public static class Log
|
||||||
|
{
|
||||||
|
const string LogPrefix = "Toby's Template Mod - ";
|
||||||
|
|
||||||
|
public static void DebugError(string message)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Error(message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Error(string message)
|
||||||
|
{
|
||||||
|
Verse.Log.Error(LogPrefix + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DebugWarn(string message)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Warn(message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Warn(string message)
|
||||||
|
{
|
||||||
|
Verse.Log.Warning(LogPrefix + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DebugLog(string message)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Message(message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Message(string message)
|
||||||
|
{
|
||||||
|
Verse.Log.Message(LogPrefix + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
Source/Settings/SettingsWindow.cs
Normal file
30
Source/Settings/SettingsWindow.cs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
namespace Template.Settings;
|
||||||
|
|
||||||
|
public static class SettingsWindow
|
||||||
|
{
|
||||||
|
private static Vector2 settingsScrollPosition = new();
|
||||||
|
|
||||||
|
private static float settingsHeight;
|
||||||
|
|
||||||
|
private static TemplateSettings Settings => TemplateMod.Settings;
|
||||||
|
|
||||||
|
public static void DoSettingsWindowContents(Rect inRect)
|
||||||
|
{
|
||||||
|
Listing_Standard listing = new();
|
||||||
|
Rect viewRect = new(inRect.x, inRect.y, inRect.width - 16f, settingsHeight);
|
||||||
|
Widgets.BeginScrollView(inRect, ref settingsScrollPosition, viewRect);
|
||||||
|
listing.Begin(new Rect(viewRect.x, viewRect.y, viewRect.width, float.PositiveInfinity));
|
||||||
|
|
||||||
|
listing.End();
|
||||||
|
settingsHeight = listing.CurHeight;
|
||||||
|
Widgets.EndScrollView();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string SettingsCategory()
|
||||||
|
{
|
||||||
|
return TemplateMod.Translate("SettingsCategory");
|
||||||
|
}
|
||||||
|
}
|
44
Source/Settings/TemplateSettings.cs
Normal file
44
Source/Settings/TemplateSettings.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
namespace Template.Settings;
|
||||||
|
|
||||||
|
public class TemplateSettings : ModSettings
|
||||||
|
{
|
||||||
|
#region Scribe Helpers
|
||||||
|
private static void LookField<T>(ref T value, string label, T defaultValue)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
Scribe_Values.Look(ref value, label, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LookHashSet<T>(
|
||||||
|
ref HashSet<T> valueHashSet,
|
||||||
|
string label,
|
||||||
|
HashSet<T> defaultValues
|
||||||
|
)
|
||||||
|
where T : notnull
|
||||||
|
{
|
||||||
|
if (Scribe.mode == LoadSaveMode.Saving && valueHashSet is null)
|
||||||
|
{
|
||||||
|
TemplateMod.Log.Warn(
|
||||||
|
label + " is null before saving. Reinitializing with default values."
|
||||||
|
);
|
||||||
|
valueHashSet = defaultValues;
|
||||||
|
}
|
||||||
|
Scribe_Collections.Look(ref valueHashSet, label, lookMode: LookMode.Value);
|
||||||
|
if (Scribe.mode == LoadSaveMode.LoadingVars && valueHashSet is null)
|
||||||
|
{
|
||||||
|
TemplateMod.Log.Warn(
|
||||||
|
label + " is null after loading. Reinitializing with default values."
|
||||||
|
);
|
||||||
|
valueHashSet = defaultValues;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public override void ExposeData()
|
||||||
|
{
|
||||||
|
base.ExposeData();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
using Verse;
|
|
||||||
|
|
||||||
// using HarmonyLib;
|
|
||||||
|
|
||||||
namespace Template;
|
|
||||||
|
|
||||||
[StaticConstructorOnStartup]
|
|
||||||
public static class Startup
|
|
||||||
{
|
|
||||||
static Startup()
|
|
||||||
{
|
|
||||||
Log.Message("Mod template loaded successfully!");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ using Verse;
|
||||||
namespace Template;
|
namespace Template;
|
||||||
|
|
||||||
[DefOf]
|
[DefOf]
|
||||||
public static class TemplateDefOf
|
public static class StinkyTweaksDefOf
|
||||||
{
|
{
|
||||||
public static LetterDef success_letter;
|
public static LetterDef success_letter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +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",
|
||||||
TemplateDefOf.success_letter.description,
|
StinkyTweaksDefOf.success_letter.description,
|
||||||
TemplateDefOf.success_letter,
|
StinkyTweaksDefOf.success_letter,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
programs = {
|
programs = {
|
||||||
nixpkgs-fmt.enable = true;
|
nixpkgs-fmt.enable = true;
|
||||||
csharpier.enable = true;
|
csharpier.enable = true;
|
||||||
prettier.enable = true;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue