diff --git a/.vscode/mod.csproj b/.vscode/mod.csproj index fff177f..8aca5ea 100644 --- a/.vscode/mod.csproj +++ b/.vscode/mod.csproj @@ -57,7 +57,7 @@ - - \ No newline at end of file + + Template Mod + \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index a82555f..0000000 --- a/README.md +++ /dev/null @@ -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 diff --git a/Source/Mod.cs b/Source/Mod.cs new file mode 100644 index 0000000..2e93d94 --- /dev/null +++ b/Source/Mod.cs @@ -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); + } + } +} diff --git a/Source/Settings/SettingsWindow.cs b/Source/Settings/SettingsWindow.cs new file mode 100644 index 0000000..23a0a35 --- /dev/null +++ b/Source/Settings/SettingsWindow.cs @@ -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"); + } +} diff --git a/Source/Settings/TemplateSettings.cs b/Source/Settings/TemplateSettings.cs new file mode 100644 index 0000000..edcaad1 --- /dev/null +++ b/Source/Settings/TemplateSettings.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using Verse; + +namespace Template.Settings; + +public class TemplateSettings : ModSettings +{ + #region Scribe Helpers + private static void LookField(ref T value, string label, T defaultValue) + where T : struct + { + Scribe_Values.Look(ref value, label, defaultValue); + } + + private static void LookHashSet( + ref HashSet valueHashSet, + string label, + HashSet 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(); + } +} diff --git a/Source/Startup.cs b/Source/Startup.cs deleted file mode 100644 index 6173f34..0000000 --- a/Source/Startup.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Verse; - -// using HarmonyLib; - -namespace Template; - -[StaticConstructorOnStartup] -public static class Startup -{ - static Startup() - { - Log.Message("Mod template loaded successfully!"); - } -} diff --git a/Source/TemplateDefOf.cs b/Source/TemplateDefOf.cs index a4f2cf2..0611801 100644 --- a/Source/TemplateDefOf.cs +++ b/Source/TemplateDefOf.cs @@ -6,7 +6,7 @@ using Verse; namespace Template; [DefOf] -public static class TemplateDefOf +public static class StinkyTweaksDefOf { public static LetterDef success_letter; } diff --git a/Source/TemplateMapComponent.cs b/Source/TemplateMapComponent.cs index f559e08..b8af6c6 100644 --- a/Source/TemplateMapComponent.cs +++ b/Source/TemplateMapComponent.cs @@ -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 ); } diff --git a/flake.nix b/flake.nix index b5304c8..e56e5a4 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,6 @@ programs = { nixpkgs-fmt.enable = true; csharpier.enable = true; - prettier.enable = true; }; }; };