Predict dumping (#32394)
* Predict dumping - This got soaped really fucking hard. - Dumping is predicted, this required disposals to be predicte.d - Disposals required mailing (because it's tightly coupled), and a smidge of other content systems. - I also had to fix a compnetworkgenerator issue at the same time so it wouldn't mispredict. * Fix a bunch of stuff * nasty merge * Some reviews * Some more reviews while I stash * Fix merge * Fix merge * Half of review * Review * re(h)f * lizards * feexes * feex
This commit is contained in:
@@ -2,34 +2,38 @@ using System.Text.RegularExpressions;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.Tools.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Configurable
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
/// <summary>
|
||||
/// Configuration for mailing units.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If you want a more detailed description ask the original coder.
|
||||
/// </remarks>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class ConfigurationComponent : Component
|
||||
{
|
||||
[DataField("config")]
|
||||
/// <summary>
|
||||
/// Tags for mail unit routing.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public Dictionary<string, string?> Config = new();
|
||||
|
||||
[DataField("qualityNeeded", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
public string QualityNeeded = SharedToolSystem.PulseQuality;
|
||||
/// <summary>
|
||||
/// Quality to open up the configuration UI.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<ToolQualityPrototype> QualityNeeded = SharedToolSystem.PulseQuality;
|
||||
|
||||
[DataField("validation")]
|
||||
/// <summary>
|
||||
/// Validate tags in <see cref="Config"/>.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public Regex Validation = new("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ConfigurationBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public Dictionary<string, string?> Config { get; }
|
||||
|
||||
public ConfigurationBoundUserInterfaceState(Dictionary<string, string?> config)
|
||||
{
|
||||
Config = config;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message data sent from client to server when the device configuration is updated.
|
||||
/// </summary>
|
||||
|
||||
77
Content.Shared/Configurable/SharedConfigurationSystem.cs
Normal file
77
Content.Shared/Configurable/SharedConfigurationSystem.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Tools.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using static Content.Shared.Configurable.ConfigurationComponent;
|
||||
|
||||
namespace Content.Shared.Configurable;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ConfigurationComponent"/>
|
||||
/// </summary>
|
||||
public abstract class SharedConfigurationSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ConfigurationComponent, ConfigurationUpdatedMessage>(OnUpdate);
|
||||
SubscribeLocalEvent<ConfigurationComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<ConfigurationComponent, ContainerIsInsertingAttemptEvent>(OnInsert);
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, ConfigurationComponent component, InteractUsingEvent args)
|
||||
{
|
||||
// TODO use activatable ui system
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!_toolSystem.HasQuality(args.Used, component.QualityNeeded))
|
||||
return;
|
||||
|
||||
args.Handled = _uiSystem.TryOpenUi(uid, ConfigurationUiKey.Key, args.User);
|
||||
}
|
||||
|
||||
private void OnUpdate(EntityUid uid, ConfigurationComponent component, ConfigurationUpdatedMessage args)
|
||||
{
|
||||
foreach (var key in component.Config.Keys)
|
||||
{
|
||||
var value = args.Config.GetValueOrDefault(key);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value) || component.Validation != null && !component.Validation.IsMatch(value))
|
||||
continue;
|
||||
|
||||
component.Config[key] = value;
|
||||
}
|
||||
|
||||
Dirty(uid, component);
|
||||
var updatedEvent = new ConfigurationUpdatedEvent(component);
|
||||
RaiseLocalEvent(uid, updatedEvent);
|
||||
|
||||
// TODO support float (spinbox) and enum (drop-down) configurations
|
||||
// TODO support verbs.
|
||||
}
|
||||
|
||||
private void OnInsert(EntityUid uid, ConfigurationComponent component, ContainerIsInsertingAttemptEvent args)
|
||||
{
|
||||
if (!_toolSystem.HasQuality(args.EntityUid, component.QualityNeeded))
|
||||
return;
|
||||
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sent when configuration values got changes
|
||||
/// </summary>
|
||||
public sealed class ConfigurationUpdatedEvent : EntityEventArgs
|
||||
{
|
||||
public ConfigurationComponent Configuration;
|
||||
|
||||
public ConfigurationUpdatedEvent(ConfigurationComponent configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user