Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto rename ship faxes #135

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Content.Server/Fax/FaxMachineComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public sealed class FaxMachineComponent : Component
[DataField("name")]
public string FaxName { get; set; } = "Unknown";

/// <summary>
/// If true, will sync fax name with a station name.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("useStationName")]
public bool UseStationName { get; set; }

/// <summary>
/// Device address of fax in network to which data will be send
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Content.Server/Fax/FaxSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ private void OnInteractUsing(EntityUid uid, FaxMachineComponent component, Inter
component.FaxName = newName;
_popupSystem.PopupEntity(Loc.GetString("fax-machine-popup-name-set"), uid);
UpdateUserInterface(uid, component);

// if we changed our fax name manually
// it will loose sync with station name
component.UseStationName = false;
});

args.Handled = true;
Expand Down
10 changes: 10 additions & 0 deletions Content.Server/Station/Components/StationRenameFaxesComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server.Station.Components;

/// <summary>
/// Rename all faxes on a station when station name changes.
/// Only faxes with "UseStationName" will be affected.
/// </summary>
[RegisterComponent]
public sealed class StationRenameFaxesComponent : Component
{
}
45 changes: 45 additions & 0 deletions Content.Server/Station/Systems/StationRenameFaxesSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Content.Server.Fax;
using Content.Server.Station.Components;
using Content.Server.Station.Events;

namespace Content.Server.Station.Systems;

public sealed class StationRenameFaxesSystem : EntitySystem
{
[Dependency] private readonly StationSystem _stationSystem = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StationRenameFaxesComponent, StationRenamedEvent>(OnRenamed);
SubscribeLocalEvent<StationRenameFaxesComponent, StationPostInitEvent>(OnPostInit);
}

private void OnPostInit(EntityUid uid, StationRenameFaxesComponent component, ref StationPostInitEvent args)
{
SyncFaxesNames(uid);
}

private void OnRenamed(EntityUid uid, StationRenameFaxesComponent component, StationRenamedEvent args)
{
SyncFaxesNames(uid);
}

private void SyncFaxesNames(EntityUid stationUid)
{
// update all faxes that belong to this station grid
var query = EntityQueryEnumerator<FaxMachineComponent>();
while (query.MoveNext(out var uid, out var fax))
{
if (!fax.UseStationName)
continue;

var faxStationUid = _stationSystem.GetOwningStation(uid);
if (faxStationUid != stationUid)
continue;

var stationName = Name(faxStationUid.Value);
fax.FaxName = stationName;
}
}
}
6 changes: 6 additions & 0 deletions Resources/Prototypes/Entities/Stations/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@
abstract: true
components:
- type: StationEventEligible # For when someone makes this more granular in the future.

- type: entity
id: BaseStationRenameFaxes
abstract: true
components:
- type: StationRenameFaxes
Macoron marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,11 @@
- type: FaxMachine
name: "Captain's Office"
receiveNukeCodes: true

- type: entity
parent: FaxMachineBase
id: FaxMachineShip
suffix: Ship
components:
- type: FaxMachine
useStationName: true
Macoron marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- BaseStationAlertLevels
- BaseStationExpeditions
- BaseStationAllEventsEligible
- BaseStationRenameFaxes
noSpawn: true
components:
- type: Transform
Expand All @@ -34,6 +35,7 @@
- BaseStationRecords
- BaseStationAlertLevels
- BaseStationAllEventsEligible
- BaseStationRenameFaxes
noSpawn: true
components:
- type: Transform
Expand Down
Loading