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"
|
||||
Version="1.4.3901" />
|
||||
<!-- Set IncludeAssets to 'compile' to enable Harmony -->
|
||||
<PackageReference Include="Lib.Harmony.Thin"
|
||||
<PackageReference Include="Lib.Harmony"
|
||||
Version="2.3.3"
|
||||
IncludeAssets="none" />
|
||||
<PackageReference Include="roslynator.analyzers"
|
||||
|
|
66
.vscode/settings.json
vendored
66
.vscode/settings.json
vendored
|
@ -1,29 +1,43 @@
|
|||
{
|
||||
// "explorer.excludeGitIgnore": true,
|
||||
"files.exclude": {
|
||||
".direnv": true,
|
||||
".vscode/obj": true,
|
||||
"*/Assemblies/": true,
|
||||
// "explorer.excludeGitIgnore": true,
|
||||
"files.exclude": {
|
||||
".direnv": true,
|
||||
".vscode/obj": 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": {
|
||||
"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
|
||||
"editor.suggest.insertMode": "replace",
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
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"
|
||||
else
|
||||
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
|
||||
|
||||
popd
|
||||
|
181
.vscode/tasks.json
vendored
181
.vscode/tasks.json
vendored
|
@ -1,99 +1,86 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "analyze",
|
||||
"type": "shell",
|
||||
"group": "none",
|
||||
"command": ".vscode/roslynator.sh",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "format",
|
||||
"type": "shell",
|
||||
"group": "none",
|
||||
"command": ".vscode/fmt.sh",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "build mod (Debug)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/build.sh",
|
||||
"problemMatcher": [
|
||||
"$msCompile"
|
||||
],
|
||||
"dependsOn": []
|
||||
},
|
||||
{
|
||||
"label": "build mod (Release)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/build.sh Release",
|
||||
"problemMatcher": [
|
||||
"$msCompile"
|
||||
],
|
||||
"dependsOn": []
|
||||
},
|
||||
{
|
||||
"label": "run game (Debug)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "none",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/launch.sh",
|
||||
"problemMatcher": [],
|
||||
"dependsOrder": "sequence",
|
||||
"dependsOn": [
|
||||
"build mod (Debug)",
|
||||
"set up mod directory"
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "run game (Release)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "none",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/launch.sh",
|
||||
"problemMatcher": [],
|
||||
"dependsOrder": "sequence",
|
||||
"dependsOn": [
|
||||
"build mod (Release)",
|
||||
"set up mod directory"
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "run game (Debug + quicktest)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "none",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/launch.sh -quicktest",
|
||||
"problemMatcher": [],
|
||||
"dependsOrder": "sequence",
|
||||
"dependsOn": [
|
||||
"build mod (Debug)",
|
||||
"set up mod directory"
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "set up mod directory",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "none"
|
||||
},
|
||||
"command": ".vscode/setup.sh",
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "analyze",
|
||||
"type": "shell",
|
||||
"group": "none",
|
||||
"command": ".vscode/roslynator.sh",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "format",
|
||||
"type": "shell",
|
||||
"group": "none",
|
||||
"command": ".vscode/fmt.sh",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "build mod (Debug)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/build.sh",
|
||||
"problemMatcher": ["$msCompile"],
|
||||
"dependsOn": []
|
||||
},
|
||||
{
|
||||
"label": "build mod (Release)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/build.sh Release",
|
||||
"problemMatcher": ["$msCompile"],
|
||||
"dependsOn": []
|
||||
},
|
||||
{
|
||||
"label": "run game (Debug)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "none",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/launch.sh",
|
||||
"problemMatcher": [],
|
||||
"dependsOrder": "sequence",
|
||||
"dependsOn": ["build mod (Debug)", "set up mod directory"]
|
||||
},
|
||||
{
|
||||
"label": "run game (Release)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "none",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/launch.sh",
|
||||
"problemMatcher": [],
|
||||
"dependsOrder": "sequence",
|
||||
"dependsOn": ["build mod (Release)", "set up mod directory"]
|
||||
},
|
||||
{
|
||||
"label": "run game (Debug + quicktest)",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "none",
|
||||
"isDefault": true
|
||||
},
|
||||
"command": ".vscode/launch.sh -quicktest",
|
||||
"problemMatcher": [],
|
||||
"dependsOrder": "sequence",
|
||||
"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" ?>
|
||||
<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;
|
||||
|
||||
[DefOf]
|
||||
public static class TemplateDefOf
|
||||
public static class StinkyTweaksDefOf
|
||||
{
|
||||
public static LetterDef success_letter;
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ public class TemplateMapComponent(Map map) : MapComponent(map)
|
|||
Messages.Message("Success", null, MessageTypeDefOf.PositiveEvent);
|
||||
Find.LetterStack.ReceiveLetter(
|
||||
"Success",
|
||||
TemplateDefOf.success_letter.description,
|
||||
TemplateDefOf.success_letter,
|
||||
StinkyTweaksDefOf.success_letter.description,
|
||||
StinkyTweaksDefOf.success_letter,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
programs = {
|
||||
nixpkgs-fmt.enable = true;
|
||||
csharpier.enable = true;
|
||||
prettier.enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue