Add SaveLoadSavePrototype test (#18859)

This commit is contained in:
Leon Friedrich
2023-08-08 19:27:16 +12:00
committed by GitHub
parent b345625de9
commit 6982f238e8
16 changed files with 272 additions and 117 deletions

View File

@@ -1,7 +1,7 @@
using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor;
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Server.Atmos.Monitor.Components;
@@ -19,19 +19,19 @@ public sealed class AtmosMonitorComponent : Component
// Note that this cancels every single network
// event, including ones that may not be
// related to atmos monitor events.
[ViewVariables]
[DataField("netEnabled")]
public bool NetEnabled = true;
[DataField("temperatureThreshold", customTypeSerializer: (typeof(PrototypeIdSerializer<AtmosAlarmThreshold>)))]
[DataField("temperatureThresholdId", customTypeSerializer: (typeof(PrototypeIdSerializer<AtmosAlarmThresholdPrototype>)))]
public readonly string? TemperatureThresholdId;
[ViewVariables]
[DataField("temperatureThreshold")]
public AtmosAlarmThreshold? TemperatureThreshold;
[DataField("pressureThreshold", customTypeSerializer: (typeof(PrototypeIdSerializer<AtmosAlarmThreshold>)))]
[DataField("pressureThresholdId", customTypeSerializer: (typeof(PrototypeIdSerializer<AtmosAlarmThresholdPrototype>)))]
public readonly string? PressureThresholdId;
[ViewVariables]
[DataField("pressureThreshold")]
public AtmosAlarmThreshold? PressureThreshold;
// monitor fire - much different from temperature
@@ -41,14 +41,11 @@ public sealed class AtmosMonitorComponent : Component
[DataField("monitorFire")]
public bool MonitorFire = false;
// really messy but this is parsed at runtime after
// prototypes are initialized, there's no
// way without implementing a new
// type serializer
[DataField("gasThresholds")]
public Dictionary<Gas, string>? GasThresholdIds;
[DataField("gasThresholdPrototypes",
customTypeSerializer:typeof(PrototypeIdValueDictionarySerializer<Gas, AtmosAlarmThresholdPrototype>))]
public Dictionary<Gas, string>? GasThresholdPrototypes;
[ViewVariables]
[DataField("gasThresholds")]
public Dictionary<Gas, AtmosAlarmThreshold>? GasThresholds;
// Stores a reference to the gas on the tile this is on.
@@ -56,14 +53,16 @@ public sealed class AtmosMonitorComponent : Component
public GasMixture? TileGas;
// Stores the last alarm state of this alarm.
[ViewVariables]
[DataField("lastAlarmState")]
public AtmosAlarmType LastAlarmState = AtmosAlarmType.Normal;
[ViewVariables] public HashSet<AtmosMonitorThresholdType> TrippedThresholds = new();
[DataField("trippedThresholds")]
public HashSet<AtmosMonitorThresholdType> TrippedThresholds = new();
/// <summary>
/// Registered devices in this atmos monitor. Alerts will be sent directly
/// to these devices.
/// </summary>
[ViewVariables] public HashSet<string> RegisteredDevices = new();
[DataField("registeredDevices")]
public HashSet<string> RegisteredDevices = new();
}

View File

@@ -37,8 +37,8 @@ public sealed class AtmosMonitorSystem : EntitySystem
public override void Initialize()
{
SubscribeLocalEvent<AtmosMonitorComponent, ComponentInit>(OnAtmosMonitorInit);
SubscribeLocalEvent<AtmosMonitorComponent, ComponentStartup>(OnAtmosMonitorStartup);
SubscribeLocalEvent<AtmosMonitorComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<AtmosMonitorComponent, AtmosDeviceUpdateEvent>(OnAtmosUpdate);
SubscribeLocalEvent<AtmosMonitorComponent, TileFireEvent>(OnFireEvent);
SubscribeLocalEvent<AtmosMonitorComponent, PowerChangedEvent>(OnPowerChangedEvent);
@@ -57,23 +57,28 @@ public sealed class AtmosMonitorSystem : EntitySystem
{
atmosMonitor.TileGas = _atmosphereSystem.GetContainingMixture(uid, true);
}
private void OnAtmosMonitorInit(EntityUid uid, AtmosMonitorComponent component, ComponentInit args)
private void OnMapInit(EntityUid uid, AtmosMonitorComponent component, MapInitEvent args)
{
if (component.TemperatureThresholdId != null)
component.TemperatureThreshold = new(_prototypeManager.Index<AtmosAlarmThreshold>(component.TemperatureThresholdId));
{
var proto = _prototypeManager.Index<AtmosAlarmThresholdPrototype>(component.TemperatureThresholdId);
component.TemperatureThreshold ??= new(proto);
}
if (component.PressureThresholdId != null)
component.PressureThreshold = new(_prototypeManager.Index<AtmosAlarmThreshold>(component.PressureThresholdId));
if (component.GasThresholdIds != null)
{
component.GasThresholds = new();
foreach (var (gas, id) in component.GasThresholdIds)
{
if (_prototypeManager.TryIndex<AtmosAlarmThreshold>(id, out var gasThreshold))
component.GasThresholds.Add(gas, new(gasThreshold));
}
var proto = _prototypeManager.Index<AtmosAlarmThresholdPrototype>(component.PressureThresholdId);
component.PressureThreshold ??= new(proto);
}
if (component.GasThresholdPrototypes == null)
return;
component.GasThresholds ??= new();
foreach (var (gas, id) in component.GasThresholdPrototypes)
{
var proto = _prototypeManager.Index<AtmosAlarmThresholdPrototype>(id);
component.GasThresholds.TryAdd(gas, new(proto));
}
}

View File

@@ -6,7 +6,7 @@ namespace Content.Server.DeviceLinking.Components;
[RegisterComponent]
public sealed class AutoLinkReceiverComponent : Component
{
[DataField("channel", required: true, readOnly: true)]
[DataField("channel", required: true)]
public string AutoLinkChannel = default!;
}

View File

@@ -6,7 +6,7 @@ namespace Content.Server.DeviceLinking.Components;
[RegisterComponent]
public sealed class AutoLinkTransmitterComponent : Component
{
[DataField("channel", required: true, readOnly: true)]
[DataField("channel", required: true)]
public string AutoLinkChannel = default!;
}

View File

@@ -25,7 +25,7 @@ namespace Content.Server.UserInterface
[DataField("adminOnly")]
public bool AdminOnly { get; set; } = false;
[DataField("key", readOnly: true, required: true)]
[DataField("key", required: true)]
private string _keyRaw = default!;
[DataField("verbText")]

View File

@@ -27,12 +27,12 @@ public sealed class IntrinsicUIComponent : Component, ISerializationHooks
[DataDefinition]
public struct IntrinsicUIEntry
{
[ViewVariables] public Enum? Key { get; set; } = null;
[ViewVariables] public Enum? Key { get; private set; } = null;
/// <summary>
/// The BUI key that this intrinsic UI should open.
/// </summary>
[DataField("key", readOnly: true, required: true)]
[DataField("key", required: true)]
private string _keyRaw = default!;
/// <summary>

View File

@@ -7,9 +7,9 @@ namespace Content.Server.UserInterface;
public sealed class OpenUiActionEvent : InstantActionEvent, ISerializationHooks
{
[ViewVariables]
public Enum? Key { get; set; }
public Enum? Key { get; private set; }
[DataField("key", readOnly: true, required: true)]
[DataField("key", required: true)]
private string _keyRaw = default!;
void ISerializationHooks.AfterDeserialization()