Skip to content

Commit

Permalink
Merge pull request #135 from Macoron/fax-rename
Browse files Browse the repository at this point in the history
Auto rename ship faxes
  • Loading branch information
Cheackraze authored Aug 4, 2023
2 parents 6e1fc08 + f5a44a0 commit 989c1be
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
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;
}
}
}
10 changes: 9 additions & 1 deletion Resources/Prototypes/_NF/Entities/Structures/machines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,12 @@
- type: PointLight
radius: 1.5
energy: 1.6
color: "#4b93ad"
color: "#4b93ad"

- type: entity
parent: FaxMachineBase
id: FaxMachineShip
suffix: Ship
components:
- type: FaxMachine
useStationName: true
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## This file is getting bloated and needs to be renamed/properly split next update or addition

- type: entity
id: BaseStationRenameFaxes
abstract: true
components:
- type: StationRenameFaxes

- type: entity
id: StandardFrontierStation
parent:
Expand All @@ -22,6 +28,7 @@
- BaseStationAlertLevels
- BaseStationExpeditions
- BaseStationAllEventsEligible
- BaseStationRenameFaxes
noSpawn: true
components:
- type: Transform
Expand All @@ -34,6 +41,7 @@
- BaseStationRecords
- BaseStationAlertLevels
- BaseStationAllEventsEligible
- BaseStationRenameFaxes
noSpawn: true
components:
- type: Transform
Expand Down

0 comments on commit 989c1be

Please sign in to comment.