air alarm signal ports and other stuff (#18642)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-08-21 22:18:30 +01:00
committed by GitHub
parent 2cbe8609a3
commit e837f2fd85
12 changed files with 181 additions and 59 deletions

View File

@@ -1,3 +1,4 @@
using Content.Server.DeviceLinking.Components;
using Content.Server.DeviceLinking.Events;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
@@ -95,11 +96,25 @@ public sealed class DeviceLinkSystem : SharedDeviceLinkSystem
}
}
_deviceNetworkSystem.QueuePacket(uid, sinkNetworkComponent.Address, payload, sinkNetworkComponent.ReceiveFrequency);
// force using wireless network so things like atmos devices are able to send signals
var network = (int) DeviceNetworkComponent.DeviceNetIdDefaults.Wireless;
_deviceNetworkSystem.QueuePacket(uid, sinkNetworkComponent.Address, payload, sinkNetworkComponent.ReceiveFrequency, network);
}
}
}
/// <summary>
/// Helper function that invokes a port with a high/low binary logic signal.
/// </summary>
public void SendSignal(EntityUid uid, string port, bool signal, DeviceLinkSourceComponent? comp = null)
{
var data = new NetworkPayload
{
[DeviceNetworkConstants.LogicState] = signal ? SignalState.High : SignalState.Low
};
InvokePort(uid, port, data, comp);
}
/// <summary>
/// Checks if the payload has a port defined and if the port is present on the sink.
/// Raises a <see cref="SignalReceivedEvent"/> containing the payload when the check passes

View File

@@ -140,12 +140,7 @@ public sealed class LogicGateSystem : EntitySystem
{
comp.LastOutput = output;
var data = new NetworkPayload
{
[DeviceNetworkConstants.LogicState] = output ? SignalState.High : SignalState.Low
};
_deviceLink.InvokePort(uid, comp.OutputPort, data);
_deviceLink.SendSignal(uid, comp.OutputPort, output);
}
}
}

View File

@@ -30,15 +30,11 @@ public sealed class SignalSwitchSystem : EntitySystem
comp.State = !comp.State;
_deviceLink.InvokePort(uid, comp.State ? comp.OnPort : comp.OffPort);
var data = new NetworkPayload
{
[DeviceNetworkConstants.LogicState] = comp.State ? SignalState.High : SignalState.Low
};
// only send status if it's a toggle switch and not a button
if (comp.OnPort != comp.OffPort)
{
_deviceLink.InvokePort(uid, comp.StatusPort, data);
_deviceLink.SendSignal(uid, comp.StatusPort, comp.State);
}
_audio.PlayPvs(comp.ClickSound, uid, AudioParams.Default.WithVariation(0.125f).WithVolume(8f));