Update Mods to be foldered/ own csproj/ ref dll
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<RootNamespace>_4ReadCustomJson5Config</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- TODO: Change to Nuget Package -->
|
||||
<ItemGroup>
|
||||
<Reference Include="Core">
|
||||
<HintPath>..\TempReferences\Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SptCommon">
|
||||
<HintPath>..\TempReferences\SptCommon.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SptDependencyInjection">
|
||||
<HintPath>..\TempReferences\SptDependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
using Core.Models.External;
|
||||
using Core.Models.Utils;
|
||||
using Core.Utils;
|
||||
using SptCommon.Annotations;
|
||||
|
||||
namespace _4ReadCustomJson5Config
|
||||
{
|
||||
[Injectable]
|
||||
public class ReadJson5Config: IPreSptLoadMod
|
||||
{
|
||||
private readonly ISptLogger<ReadJson5Config> _logger;
|
||||
private readonly FileUtil _fileUtil;
|
||||
private readonly JsonUtil _jsonUtil;
|
||||
|
||||
public ReadJson5Config(
|
||||
ISptLogger<ReadJson5Config> logger,
|
||||
FileUtil fileUtil,
|
||||
JsonUtil jsonUtil)
|
||||
{
|
||||
_logger = logger;
|
||||
_fileUtil = fileUtil;
|
||||
_jsonUtil = jsonUtil;
|
||||
}
|
||||
|
||||
public void PreSptLoad()
|
||||
{
|
||||
// Read the content of the config file into a string
|
||||
var rawContent = _fileUtil.ReadFile("config.json5");
|
||||
|
||||
// Take the string above and deserialise it into a config file with a type (defined between the diamond brackets)
|
||||
var config = _jsonUtil.Deserialize<ModConfig>(rawContent);
|
||||
|
||||
_logger.Success($"Read property: 'ExampleProperty' from config with value: {config.ExampleProperty}");
|
||||
}
|
||||
}
|
||||
|
||||
// This class should represent your config structure
|
||||
public class ModConfig
|
||||
{
|
||||
public string ExampleProperty { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
// Comment goes here, wow
|
||||
"ExampleProperty": "boop"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"Name": "4ReadCustomJson5Config",
|
||||
"Version": "1.0.0",
|
||||
"SptVersion": "~4.0",
|
||||
"LoadBefore": [],
|
||||
"LoadAfter": [],
|
||||
"IncompatibileMods": [],
|
||||
"Url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods",
|
||||
"IsBundleMod": false,
|
||||
"Author": "SPT",
|
||||
"Contributors": [],
|
||||
"Licence": "MIT"
|
||||
}
|
||||
Reference in New Issue
Block a user