-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from Macoron/fax-rename
Auto rename ship faxes
- Loading branch information
Showing
6 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Content.Server/Station/Components/StationRenameFaxesComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
Content.Server/Station/Systems/StationRenameFaxesSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters