Minor device network changes (#2499)

* Device network changes

* Update too

* Update Content.Server/GameObjects/EntitySystems/DeviceNetworkSystem.cs

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
metalgearsloth
2020-11-06 04:04:21 +11:00
committed by GitHub
parent e62df15ef9
commit 864fa0a57c
7 changed files with 53 additions and 51 deletions

View File

@@ -8,9 +8,7 @@ using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -28,18 +26,24 @@ namespace Content.Server.GameObjects.Components
private Regex _validation;
public event Action<Dictionary<string, string>> OnConfigUpdate;
public override void Initialize()
public override void OnAdd()
{
base.Initialize();
base.OnAdd();
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
}
}
public override void OnRemove()
{
base.OnRemove();
if (UserInterface != null)
{
UserInterface.OnReceiveMessage -= UserInterfaceOnReceiveMessage;
}
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -48,7 +52,7 @@ namespace Content.Server.GameObjects.Components
(list) => FillConfiguration(list, _config, ""),
() => _config.Keys.ToList());
serializer.DataReadFunction("vailidation", "^[a-zA-Z0-9 ]*$", value => _validation = new Regex("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled));
serializer.DataReadFunction("validation", "^[a-zA-Z0-9 ]*$", value => _validation = new Regex("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled));
}
public string GetConfig(string name)
@@ -90,22 +94,19 @@ namespace Content.Server.GameObjects.Components
{
var value = msg.Config.GetValueOrDefault(key);
if (_validation != null && !_validation.IsMatch(value) && value != "")
if (value == null || _validation != null && !_validation.IsMatch(value) && value != "")
continue;
_config[key] = value;
}
OnConfigUpdate(_config);
SendMessage(new ConfigUpdatedComponentMessage(config));
}
}
private void UpdateUserInterface()
{
if (UserInterface == null)
return;
UserInterface.SetState(new ConfigurationBoundUserInterfaceState(_config));
UserInterface?.SetState(new ConfigurationBoundUserInterfaceState(_config));
}
private static void FillConfiguration<T>(List<string> list, Dictionary<string, T> configuration, T value){