- Fixed networking sync vars failing to sync initially.
- Fixed lua failing to differentiate overloads ISettingBase.
This commit is contained in:
@@ -24,7 +24,7 @@ public sealed class SettingControl : SettingBase, ISettingControl
|
|||||||
public SettingControl(IConfigInfo configInfo, Func<OneOf<string, XElement, object>, bool> valueChangePredicate) : base(configInfo)
|
public SettingControl(IConfigInfo configInfo, Func<OneOf<string, XElement, object>, bool> valueChangePredicate) : base(configInfo)
|
||||||
{
|
{
|
||||||
_valueChangePredicate = valueChangePredicate;
|
_valueChangePredicate = valueChangePredicate;
|
||||||
TrySetValue(configInfo.Element);
|
TrySetSerializedValue(configInfo.Element);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDispose()
|
protected override void OnDispose()
|
||||||
@@ -37,7 +37,7 @@ public sealed class SettingControl : SettingBase, ISettingControl
|
|||||||
public override string GetStringValue() => Value.ToString();
|
public override string GetStringValue() => Value.ToString();
|
||||||
public override string GetDefaultStringValue() => new KeyOrMouse(Keys.NumLock).ToString();
|
public override string GetDefaultStringValue() => new KeyOrMouse(Keys.NumLock).ToString();
|
||||||
|
|
||||||
public override bool TrySetValue(OneOf<string, XElement> value)
|
public override bool TrySetSerializedValue(OneOf<string, XElement> value)
|
||||||
{
|
{
|
||||||
var newVal = value.Match<KeyOrMouse>(
|
var newVal = value.Match<KeyOrMouse>(
|
||||||
(string v) => GetKeyOrMouse(v),
|
(string v) => GetKeyOrMouse(v),
|
||||||
|
|||||||
+1
-1
@@ -303,7 +303,7 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
kvp.Key.TrySetValue(kvp.Value);
|
kvp.Key.TrySetSerializedValue(kvp.Value);
|
||||||
ConfigService.SaveConfigValue(kvp.Key);
|
ConfigService.SaveConfigValue(kvp.Key);
|
||||||
}
|
}
|
||||||
NewValuesCache.Clear();
|
NewValuesCache.Clear();
|
||||||
|
|||||||
@@ -159,11 +159,15 @@ partial class NetworkingService : INetworkingService, IEventClientRawNetMessageR
|
|||||||
|
|
||||||
SendToClient(message, client.Connection, DeliveryMethod.Reliable);
|
SendToClient(message, client.Connection, DeliveryMethod.Reliable);
|
||||||
|
|
||||||
// TODO: when we move to using GUIDs for everything, this should combined into a single message
|
// delay by 1s to allow above id sync to reach the client.
|
||||||
foreach (INetworkSyncVar netVar in netVars.Keys)
|
CoroutineManager.Invoke(() =>
|
||||||
{
|
{
|
||||||
SendNetVar(netVar, client.Connection);
|
// TODO: when we move to using GUIDs for everything, this should combined into a single message
|
||||||
}
|
foreach (INetworkSyncVar netVar in netVars.Keys)
|
||||||
|
{
|
||||||
|
SendNetVar(netVar, client.Connection);
|
||||||
|
}
|
||||||
|
},1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendToClient(IWriteMessage netMessage, NetworkConnection connection = null, DeliveryMethod deliveryMethod = DeliveryMethod.Reliable)
|
public void SendToClient(IWriteMessage netMessage, NetworkConnection connection = null, DeliveryMethod deliveryMethod = DeliveryMethod.Reliable)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Xml.Linq;
|
|||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
using Barotrauma.LuaCs;
|
using Barotrauma.LuaCs;
|
||||||
using Barotrauma.Networking;
|
using Barotrauma.Networking;
|
||||||
|
using OneOf;
|
||||||
|
|
||||||
namespace Barotrauma.LuaCs.Data;
|
namespace Barotrauma.LuaCs.Data;
|
||||||
|
|
||||||
@@ -34,8 +35,8 @@ public partial interface ISettingBase : IDataInfo, IEquatable<ISettingBase>, IDi
|
|||||||
Type GetValueType();
|
Type GetValueType();
|
||||||
string GetStringValue();
|
string GetStringValue();
|
||||||
string GetDefaultStringValue();
|
string GetDefaultStringValue();
|
||||||
bool TrySetValue(OneOf.OneOf<string, XElement> value);
|
bool TrySetSerializedValue(OneOf<string, XElement> value);
|
||||||
event Action<ISettingBase> OnValueChanged;
|
event Action<ISettingBase> OnValueChanged;
|
||||||
OneOf.OneOf<string, XElement> GetSerializableValue();
|
OneOf.OneOf<string, XElement> GetSerializableValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
using Microsoft.Toolkit.Diagnostics;
|
using Microsoft.Toolkit.Diagnostics;
|
||||||
@@ -59,8 +60,8 @@ public abstract class SettingBase : ISettingBase
|
|||||||
public abstract Type GetValueType();
|
public abstract Type GetValueType();
|
||||||
public abstract string GetStringValue();
|
public abstract string GetStringValue();
|
||||||
public abstract string GetDefaultStringValue();
|
public abstract string GetDefaultStringValue();
|
||||||
|
public abstract bool TrySetSerializedValue(OneOf<string, XElement> value);
|
||||||
|
|
||||||
public abstract bool TrySetValue(OneOf<string, XElement> value);
|
|
||||||
public abstract event Action<ISettingBase> OnValueChanged;
|
public abstract event Action<ISettingBase> OnValueChanged;
|
||||||
public abstract OneOf<string, XElement> GetSerializableValue();
|
public abstract OneOf<string, XElement> GetSerializableValue();
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public partial class SettingEntry<T> : SettingBase, ISettingBase<T>, INetworkSyn
|
|||||||
|
|
||||||
public override string GetDefaultStringValue() => DefaultValue.ToString();
|
public override string GetDefaultStringValue() => DefaultValue.ToString();
|
||||||
|
|
||||||
public override bool TrySetValue(OneOf<string, XElement> value)
|
public override bool TrySetSerializedValue(OneOf<string, XElement> value)
|
||||||
{
|
{
|
||||||
bool isFailed = false;
|
bool isFailed = false;
|
||||||
var typeConvertedValue = value.Match<T>(
|
var typeConvertedValue = value.Match<T>(
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setting.TrySetValue(valueString))
|
if (setting.TrySetSerializedValue(valueString))
|
||||||
{
|
{
|
||||||
_logger.LogMessage($"Set config {internalName} value to {valueString}", Color.Green);
|
_logger.LogMessage($"Set config {internalName} value to {valueString}", Color.Green);
|
||||||
if (SaveConfigValue(setting) is { IsFailed: true } res)
|
if (SaveConfigValue(setting) is { IsFailed: true } res)
|
||||||
@@ -445,7 +445,7 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
{
|
{
|
||||||
if (_settingsInstances.TryGetValue((info.OwnerPackage, value.SettingName), out var instance))
|
if (_settingsInstances.TryGetValue((info.OwnerPackage, value.SettingName), out var instance))
|
||||||
{
|
{
|
||||||
instance.TrySetValue(value.Element);
|
instance.TrySetSerializedValue(value.Element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -495,7 +495,7 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
return FluentResults.Result.Ok();
|
return FluentResults.Result.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FluentResults.Result.OkIf(setting.TrySetValue(cfgValueElement), new Error($"Failed to set value for [{setting.OwnerPackage.Name}.{setting.InternalName}]"));
|
return FluentResults.Result.OkIf(setting.TrySetSerializedValue(cfgValueElement), new Error($"Failed to set value for [{setting.OwnerPackage.Name}.{setting.InternalName}]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluentResults.Result LoadSavedConfigsValues()
|
public FluentResults.Result LoadSavedConfigsValues()
|
||||||
@@ -544,7 +544,7 @@ public sealed partial class ConfigService : IConfigService
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance.TrySetValue(profileValue.Element))
|
if (!instance.TrySetSerializedValue(profileValue.Element))
|
||||||
{
|
{
|
||||||
result.WithError(new Error($"{nameof(ApplyConfigProfile)}: Failed to set value for [{profileValue.SettingName}]."));
|
result.WithError(new Error($"{nameof(ApplyConfigProfile)}: Failed to set value for [{profileValue.SettingName}]."));
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -370,7 +370,8 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService,
|
|||||||
UserData.RegisterType(typeof(ILuaConfigService));
|
UserData.RegisterType(typeof(ILuaConfigService));
|
||||||
UserData.RegisterType(typeof(ILoggerService));
|
UserData.RegisterType(typeof(ILoggerService));
|
||||||
|
|
||||||
//UserData.RegisterType(typeof(ISettingBase));
|
UserData.RegisterType(typeof(ISettingBase));
|
||||||
|
UserData.RegisterType(typeof(IDataInfo));
|
||||||
|
|
||||||
Type[] settingBaseTypes = [
|
Type[] settingBaseTypes = [
|
||||||
typeof(ISettingBase<bool>),
|
typeof(ISettingBase<bool>),
|
||||||
|
|||||||
Reference in New Issue
Block a user