Skip to content

Commit dbb288d

Browse files
committed
[Code Template] Static public fields to properties in core class
1 parent abddf82 commit dbb288d

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
VS Mod Templates v1.3.2
22
- [Code Template] Properly dispose config when config loader unloads
3-
- [Code Template] Slight improvement to mod logger in config loader
3+
- [Code Template] Slight improvement to mod logger in config loader
4+
- [Code Template] Static public fields to properties in core class

templates/VSCodeModTemplate/_ProjectName_/Config/ConfigLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace _ProjectName_.Config;
55

66
public class ConfigLoader : ModSystem
77
{
8-
internal static readonly string ConfigName = "_ProjectName_.json";
8+
private const string ConfigName = = "_ProjectName_.json";
99
public static ModConfig Config { get; private set; }
1010
public override void StartPre(ICoreAPI api)
1111
{

templates/VSCodeModTemplate/_ProjectName_/_ProjectName_Core.PatchCategories.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@ namespace _ProjectName_;
33
public partial class _ProjectName_Core
44
{
55
internal const string ExamplePatchCategory = "examplePatchCategory";
6+
}
7+
8+
public static class PatchExtensions
9+
{
10+
public static void PatchIfEnabled(this string patchCategory, bool configFlag)
11+
{
12+
if (!configFlag) return;
13+
_ProjectName_Core.HarmonyInstance.PatchCategory(patchCategory);
14+
_ProjectName_Core.Logger.VerboseDebug("Patched {0}...", patchCategory);
15+
}
616
}

templates/VSCodeModTemplate/_ProjectName_/_ProjectName_Core.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ public class _ProjectName_Core : ModSystem
2424
#endif
2525
{
2626
#if( QuickStartCode )
27-
public static ILogger Logger;
28-
public static string Modid;
27+
public static ILogger Logger { get; private set; }
28+
public static string Modid { get; private set; }
2929
#if ( ModSide == "client" )
30-
public static ICoreClientAPI Capi;
30+
public static ICoreClientAPI Capi { get; private set; }
3131
#elif ( ModSide == "server" )
32-
public static ICoreServerAPI Sapi;
32+
public static ICoreServerAPI Sapi { get; private set; }
3333
#else
34-
public static ICoreAPI Api;
34+
public static ICoreAPI Api { get; private set; }
3535
#endif
3636
#if( IncludeHarmony )
37-
public static Harmony HarmonyInstance;
37+
public static Harmony HarmonyInstance { get; private set; }
3838
#endif
3939
#if( AddSampleConfig )
40-
public static ModConfig Config;
40+
public static Config => ConfigLoader.Config;
4141
#endif
4242

4343
public override void StartPre(ICoreAPI api)
@@ -93,10 +93,11 @@ public static void Patch()
9393
HarmonyInstance = new Harmony(Modid);
9494
Logger.VerboseDebug("Patching...");
9595
#if( AddSampleConfig )
96-
if (!Config.ExampleConfigSetting) return;
97-
#endif
96+
ExamplePatchCategory.PatchIfEnabled(Config.ExampleConfigSetting);
97+
#else
9898
HarmonyInstance.PatchCategory(ExamplePatchCategory);
9999
Logger.VerboseDebug("Patched example patches...");
100+
#endif
100101
}
101102

102103
public static void Unpatch()

0 commit comments

Comments
 (0)