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){

View File

@@ -13,6 +13,7 @@ using Content.Server.GameObjects.EntitySystems.DoAfter;
using Content.Server.Interfaces;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Server.Utility;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Disposal;
using Content.Shared.GameObjects.EntitySystems;
@@ -603,12 +604,7 @@ namespace Content.Server.GameObjects.Components.Disposal
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
}
var network = IoCManager.Resolve<IDeviceNetwork>();
_connection = new WiredNetworkConnection(OnReceiveNetMessage, false, Owner);
if (Owner.TryGetComponent<ConfigurationComponent>(out var configuration))
configuration.OnConfigUpdate += OnConfigUpdate;
UpdateInterface();
}
@@ -673,6 +669,9 @@ namespace Content.Server.GameObjects.Components.Disposal
switch (message)
{
case SharedConfigurationComponent.ConfigUpdatedComponentMessage msg:
OnConfigUpdate(msg.Config);
break;
case RelayMovementEntityMessage msg:
if (!msg.Entity.TryGetComponent(out HandsComponent? hands) ||
hands.Count == 0 ||
@@ -745,7 +744,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
// Duplicated code here, not sure how else to get actor inside to make UserInterface happy.
// Duplicated code here, not sure how else to get actor inside to make UserInterface happy.
if (IsValidInteraction(eventArgs))
{

View File

@@ -1,27 +1,16 @@
using Content.Server.Interfaces;
using Content.Server.Interfaces;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork
{
public class DeviceNetworkSystem : EntitySystem
internal sealed class DeviceNetworkSystem : EntitySystem
{
private IDeviceNetwork _network;
public override void Initialize()
{
base.Initialize();
_network = IoCManager.Resolve<IDeviceNetwork>();
}
[Dependency] private readonly IDeviceNetwork _network = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
if (_network == null)
return;
//(ノ°Д°)ノ︵ ┻━┻
_network.Update();
}
}