Wire action cleanup (#13496)

This commit is contained in:
Leon Friedrich
2023-01-21 12:51:02 +13:00
committed by GitHub
parent 319cf162fd
commit b20b4b11cc
21 changed files with 294 additions and 627 deletions

View File

@@ -1,4 +1,3 @@
using Content.Server.Doors.Components;
using Content.Server.Doors.Systems;
using Content.Server.Wires;
using Content.Shared.Doors;
@@ -7,68 +6,31 @@ using Content.Shared.Wires;
namespace Content.Server.Doors;
[DataDefinition]
public sealed class DoorBoltLightWireAction : BaseWireAction
public sealed class DoorBoltLightWireAction : ComponentWireAction<AirlockComponent>
{
[DataField("color")]
private Color _statusColor = Color.Lime;
public override Color Color { get; set; } = Color.Lime;
public override string Name { get; set; } = "wire-name-bolt-light";
[DataField("name")]
private string _text = "BLIT";
protected override string Text
{
get => _text;
set => _text = value;
}
public override StatusLightData? GetStatusLightData(Wire wire)
{
var lightState = StatusLightState.Off;
if (IsPowered(wire.Owner) && EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
lightState = door.BoltLightsEnabled
? StatusLightState.On
: StatusLightState.Off;
}
return new StatusLightData(
_statusColor,
lightState,
_text);
}
public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
=> comp.BoltLightsEnabled ? StatusLightState.On : StatusLightState.Off;
public override object StatusKey { get; } = AirlockWireStatus.BoltLightIndicator;
public override bool Cut(EntityUid user, Wire wire)
public override bool Cut(EntityUid user, Wire wire, AirlockComponent door)
{
base.Cut(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, false);
}
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, false);
return true;
}
public override bool Mend(EntityUid user, Wire wire)
public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
{
base.Mend(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, true);
}
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, true);
return true;
}
public override bool Pulse(EntityUid user, Wire wire)
public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
{
base.Pulse(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, !door.BoltLightsEnabled);
}
return true;
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, !door.BoltLightsEnabled);
}
}

View File

@@ -1,4 +1,3 @@
using Content.Server.Doors.Components;
using Content.Server.Doors.Systems;
using Content.Server.Wires;
using Content.Shared.Doors;
@@ -8,78 +7,36 @@ using Content.Shared.Wires;
namespace Content.Server.Doors;
[DataDefinition]
public sealed class DoorBoltWireAction : BaseWireAction
public sealed class DoorBoltWireAction : ComponentWireAction<AirlockComponent>
{
[DataField("color")]
private Color _statusColor = Color.Red;
[DataField("name")]
private string _text = "BOLT";
protected override string Text
{
get => _text;
set => _text = value;
}
public override StatusLightData? GetStatusLightData(Wire wire)
{
StatusLightState lightState = StatusLightState.Off;
if (IsPowered(wire.Owner)
&& EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
if (door.BoltsDown)
{
lightState = StatusLightState.On;
}
}
return new StatusLightData(
_statusColor,
lightState,
_text);
}
public override Color Color { get; set; } = Color.Red;
public override string Name { get; set; } = "wire-name-door-bolt";
public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
=> comp.BoltsDown ? StatusLightState.On : StatusLightState.Off;
public override object StatusKey { get; } = AirlockWireStatus.BoltIndicator;
public override bool Cut(EntityUid user, Wire wire)
public override bool Cut(EntityUid user, Wire wire, AirlockComponent airlock)
{
base.Cut(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var airlock))
{
EntityManager.System<SharedAirlockSystem>().SetBoltWireCut(airlock, true);
if (!airlock.BoltsDown && IsPowered(wire.Owner))
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, airlock, true);
}
EntityManager.System<SharedAirlockSystem>().SetBoltWireCut(airlock, true);
if (!airlock.BoltsDown && IsPowered(wire.Owner))
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, airlock, true);
return true;
}
public override bool Mend(EntityUid user, Wire wire)
public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
{
base.Mend(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
EntityManager.System<SharedAirlockSystem>().SetBoltWireCut(door, true);
EntityManager.System<SharedAirlockSystem>().SetBoltWireCut(door, true);
return true;
}
public override bool Pulse(EntityUid user, Wire wire)
public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
{
base.Pulse(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
if (IsPowered(wire.Owner))
{
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, door, !door.BoltsDown);
}
else if (!door.BoltsDown)
{
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, door, true);
}
}
return true;
if (IsPowered(wire.Owner))
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, door, !door.BoltsDown);
else if (!door.BoltsDown)
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, door, true);
}
}

View File

@@ -7,75 +7,37 @@ using Content.Shared.Wires;
namespace Content.Server.Doors;
[DataDefinition]
public sealed class DoorSafetyWireAction : BaseWireAction
public sealed class DoorSafetyWireAction : ComponentWireAction<AirlockComponent>
{
[DataField("color")]
private Color _statusColor = Color.Red;
[DataField("name")]
private string _text = "SAFE";
protected override string Text
{
get => _text;
set => _text = value;
}
public override Color Color { get; set; } = Color.Red;
public override string Name { get; set; } = "wire-name-door-safety";
[DataField("timeout")]
private int _timeout = 30;
public override StatusLightData? GetStatusLightData(Wire wire)
{
var lightState = StatusLightState.Off;
if (IsPowered(wire.Owner)
&& EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
lightState = door.Safety
? StatusLightState.On
: StatusLightState.Off;
}
return new StatusLightData(
_statusColor,
lightState,
_text);
}
public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
=> comp.Safety ? StatusLightState.On : StatusLightState.Off;
public override object StatusKey { get; } = AirlockWireStatus.SafetyIndicator;
public override bool Cut(EntityUid user, Wire wire)
public override bool Cut(EntityUid user, Wire wire, AirlockComponent door)
{
base.Cut(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
EntityManager.System<SharedAirlockSystem>().SetSafety(door, false);
}
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
EntityManager.System<SharedAirlockSystem>().SetSafety(door, false);
return true;
}
public override bool Mend(EntityUid user, Wire wire)
public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
{
base.Mend(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<SharedAirlockSystem>().SetSafety(door, true);
}
EntityManager.System<SharedAirlockSystem>().SetSafety(door, true);
return true;
}
public override bool Pulse(EntityUid user, Wire wire)
public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
{
base.Pulse(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<SharedAirlockSystem>().SetSafety(door, false);
WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitSafetyTimerFinish, wire));
}
return true;
EntityManager.System<SharedAirlockSystem>().SetSafety(door, false);
WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitSafetyTimerFinish, wire));
}
public override void Update(Wire wire)

View File

@@ -7,85 +7,46 @@ using Content.Shared.Wires;
namespace Content.Server.Doors;
[DataDefinition]
public sealed class DoorTimingWireAction : BaseWireAction
public sealed class DoorTimingWireAction : ComponentWireAction<AirlockComponent>
{
[DataField("color")]
private Color _statusColor = Color.Orange;
[DataField("name")]
private string _text = "TIMR";
protected override string Text
{
get => _text;
set => _text = value;
}
public override Color Color { get; set; } = Color.Orange;
public override string Name { get; set; } = "wire-name-door-timer";
[DataField("timeout")]
private int _timeout = 30;
public override StatusLightData? GetStatusLightData(Wire wire)
public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
{
var lightState = StatusLightState.Off;
if (IsPowered(wire.Owner)
&& EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
switch (comp.AutoCloseDelayModifier)
{
switch (door.AutoCloseDelayModifier)
{
case 0.01f:
lightState = StatusLightState.Off;
break;
case <= 0.5f:
lightState = StatusLightState.BlinkingSlow;
break;
default:
lightState = StatusLightState.On;
break;
}
case 0.01f:
return StatusLightState.Off;
case <= 0.5f:
return StatusLightState.BlinkingSlow;
default:
return StatusLightState.On;
}
return new StatusLightData(
_statusColor,
lightState,
_text);
}
public override object StatusKey { get; } = AirlockWireStatus.TimingIndicator;
public override bool Cut(EntityUid user, Wire wire)
public override bool Cut(EntityUid user, Wire wire, AirlockComponent door)
{
base.Cut(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.01f);
}
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.01f);
return true;
}
public override bool Mend(EntityUid user, Wire wire)
public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
{
base.Mend(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 1f);
}
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 1f);
return true;
}
public override bool Pulse(EntityUid user, Wire wire)
public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
{
base.Pulse(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.5f);
WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire));
}
return true;
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.5f);
WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire));
}
public override void Update(Wire wire)