From ec89baded7899dedf0bb7e2f5362588a2430fa53 Mon Sep 17 00:00:00 2001 From: HoutarouOreki Date: Sun, 15 Mar 2026 00:18:05 +0100 Subject: [PATCH] support: vscode + VINTAGESTORY_DATA env + optional ConfigLib with warning (#1) Co-authored-by: HoutarouOreki Co-committed-by: HoutarouOreki --- .timetracker | 12 +- .vscode/launch.json | 24 ++++ .vscode/tasks.json | 35 ++++++ ChestPreview/ChestPreview/ChestPreview.csproj | 11 +- .../ChestPreview/Configs/ConfigLibBridge.cs | 114 ++++++++++-------- 5 files changed, 143 insertions(+), 53 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.timetracker b/.timetracker index 3b190e8..f66f816 100644 --- a/.timetracker +++ b/.timetracker @@ -1,5 +1,5 @@ { - "total": 51853, + "total": 56092, "sessions": [ { "begin": "2026-03-11T23:50:47+01:00", @@ -10,6 +10,16 @@ "begin": "2026-03-12T17:18:14+01:00", "end": "2026-03-12T22:08:00+01:00", "duration": 17386 + }, + { + "begin": "2026-03-14T13:19:51+01:00", + "end": "2026-03-14T13:47:21+01:00", + "duration": 1650 + }, + { + "begin": "2026-03-14T16:53:26+01:00", + "end": "2026-03-14T17:36:35+01:00", + "duration": 2589 } ] } \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3596cb1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Vintage Story Client", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build mod", + "program": "${env:VINTAGE_STORY}/Vintagestory.dll", + "args": [ + "--tracelog", + "--dataPath", + "${env:VINTAGE_STORY_DATA}", + "--addModPath", + "${workspaceFolder}/ChestPreview/ChestPreview/bin/Debug/Mods", + "--addOrigin", + "${workspaceFolder}/ChestPreview/ChestPreview/assets" + ], + "cwd": "${env:VINTAGE_STORY}", + "console": "integratedTerminal", + "stopAtEntry": false + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..80173e6 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,35 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "check env", + "type": "shell", + "command": "[ -n \"$VINTAGE_STORY\" ] || { echo 'ERROR: VINTAGE_STORY is not set'; exit 1; }; [ -n \"$VINTAGE_STORY_DATA\" ] || { echo 'ERROR: VINTAGE_STORY_DATA is not set'; exit 1; }", + "windows": { + "command": "if (-not $env:VINTAGE_STORY) { Write-Host 'ERROR: VINTAGE_STORY is not set'; exit 1 }; if (-not $env:VINTAGE_STORY_DATA) { Write-Host 'ERROR: VINTAGE_STORY_DATA is not set'; exit 1 }" + }, + "problemMatcher": [] + }, + { + "label": "build mod", + "command": "dotnet", + "type": "process", + "dependsOn": ["check env"], + "dependsOrder": "sequence", + "options": { + "env": { + "VINTAGE_STORY": "${env:VINTAGE_STORY}" + } + }, + "args": [ + "build", + "${workspaceFolder}/ChestPreview/ChestPreview/ChestPreview.csproj", + "-c", + "Debug", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/ChestPreview/ChestPreview/ChestPreview.csproj b/ChestPreview/ChestPreview/ChestPreview.csproj index 5dca78e..d43b131 100644 --- a/ChestPreview/ChestPreview/ChestPreview.csproj +++ b/ChestPreview/ChestPreview/ChestPreview.csproj @@ -7,6 +7,9 @@ enable Debug;Release;Version22 + $([System.Environment]::GetEnvironmentVariable('VS_CONFIGLIB')) + true + $(DefineConstants);CONFIGLIB @@ -59,12 +62,16 @@ - - E:\Code\VintageStory\configlib_1.10.14\configlib.dll + + $(VS_CONFIGLIB) False + + + + PreserveNewest diff --git a/ChestPreview/ChestPreview/Configs/ConfigLibBridge.cs b/ChestPreview/ChestPreview/Configs/ConfigLibBridge.cs index 8b7dddd..2853959 100644 --- a/ChestPreview/ChestPreview/Configs/ConfigLibBridge.cs +++ b/ChestPreview/ChestPreview/Configs/ConfigLibBridge.cs @@ -1,50 +1,64 @@ -using ChestPreview.Core; -using ConfigLib; -using System; -using Vintagestory.API.Client; - -namespace ChestPreview.Configs; - -internal class ConfigLibBridge(Config config) : IDisposable -{ - public const string CONFIGLIB_MODID = "configlib"; - - private readonly Config config = config; - - private ConfigLibModSystem? configLibSystem; - - public static ConfigLibBridge? TryCreate(ICoreClientAPI api, Config config) - { - if (!api.ModLoader.IsModEnabled(CONFIGLIB_MODID)) - return null; - - ConfigLibModSystem? configLibSystem = api.ModLoader.GetModSystem(); - if (configLibSystem == null) - return null; - - var bridge = new ConfigLibBridge(config) - { - configLibSystem = configLibSystem - }; - - configLibSystem.SettingChanged += bridge.OnSettingChanged; - return bridge; - } - - public void Dispose() - { - if (configLibSystem == null) - return; - - configLibSystem.SettingChanged -= OnSettingChanged; - configLibSystem = null; - } - - private void OnSettingChanged(string domain, IConfig configObject, ISetting settingObject) - { - if (domain != ChestPreviewModSystem.CONFIGLIB_DOMAIN || settingObject == null) - return; - - settingObject.AssignSettingValue(config); - } -} \ No newline at end of file +using System; +using Vintagestory.API.Client; + +#if CONFIGLIB +using ChestPreview.Core; +using ConfigLib; +#endif + +namespace ChestPreview.Configs; + +#if CONFIGLIB +internal class ConfigLibBridge(Config config) : IDisposable +{ + public const string CONFIGLIB_MODID = "configlib"; + + private readonly Config config = config; + + private ConfigLibModSystem? configLibSystem; + + public static ConfigLibBridge? TryCreate(ICoreClientAPI api, Config config) + { + if (!api.ModLoader.IsModEnabled(CONFIGLIB_MODID)) + return null; + + ConfigLibModSystem? configLibSystem = api.ModLoader.GetModSystem(); + if (configLibSystem == null) + return null; + + var bridge = new ConfigLibBridge(config) + { + configLibSystem = configLibSystem + }; + + configLibSystem.SettingChanged += bridge.OnSettingChanged; + return bridge; + } + + public void Dispose() + { + if (configLibSystem == null) + return; + + configLibSystem.SettingChanged -= OnSettingChanged; + configLibSystem = null; + } + + private void OnSettingChanged(string domain, IConfig configObject, ISetting settingObject) + { + if (domain != ChestPreviewModSystem.CONFIGLIB_DOMAIN || settingObject == null) + return; + + settingObject.AssignSettingValue(config); + } +} +#else +internal class ConfigLibBridge : IDisposable +{ + public const string CONFIGLIB_MODID = "configlib"; + + public static ConfigLibBridge? TryCreate(ICoreClientAPI api, Config config) => null; + + public void Dispose() { } +} +#endif \ No newline at end of file