support: vscode + VINTAGESTORY_DATA env + optional ConfigLib with warning (#1)
Co-authored-by: HoutarouOreki <thezjarek@gmail.com> Co-committed-by: HoutarouOreki <thezjarek@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<Configurations>Debug;Release;Version22</Configurations>
|
||||
<VintageStoryDataPathArgs></VintageStoryDataPathArgs>
|
||||
<VS_CONFIGLIB Condition="'$(VS_CONFIGLIB)' == ''">$([System.Environment]::GetEnvironmentVariable('VS_CONFIGLIB'))</VS_CONFIGLIB>
|
||||
<ConfigLibAvailable Condition="'$(VS_CONFIGLIB)' != '' and Exists('$(VS_CONFIGLIB)')">true</ConfigLibAvailable>
|
||||
<DefineConstants Condition="'$(ConfigLibAvailable)' == 'true'">$(DefineConstants);CONFIGLIB</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Version22'">
|
||||
@@ -59,12 +62,16 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="configlib">
|
||||
<HintPath>E:\Code\VintageStory\configlib_1.10.14\configlib.dll</HintPath>
|
||||
<Reference Include="configlib" Condition="'$(ConfigLibAvailable)' == 'true'">
|
||||
<HintPath>$(VS_CONFIGLIB)</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="WarnWithoutConfigLib" BeforeTargets="CoreCompile" Condition="'$(ConfigLibAvailable)' != 'true'">
|
||||
<Warning Text="No VS_CONFIGLIB - will compile without supporting ConfigLib. Set VS_CONFIGLIB env var to a path that contains the configlib's dlls." />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="modinfo.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
||||
@@ -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<ConfigLibModSystem>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
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<ConfigLibModSystem>();
|
||||
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
|
||||
Reference in New Issue
Block a user