From f35277fe36b6cae7812c6531b3578eaa8e911b03 Mon Sep 17 00:00:00 2001 From: Alexander Evgrashin Date: Wed, 2 Aug 2023 02:52:50 +0200 Subject: [PATCH 1/2] Add auto-renaming faxes --- Content.Server/Fax/FaxMachineComponent.cs | 7 +++ Content.Server/Fax/FaxSystem.cs | 4 ++ .../Components/StationRenameFaxesComponent.cs | 10 +++++ .../Systems/StationRenameFaxesSystem.cs | 45 +++++++++++++++++++ .../Prototypes/Entities/Stations/base.yml | 6 +++ .../Structures/Machines/fax_machine.yml | 8 ++++ .../_NF/Shipyard/default_shipyard_catalog.yml | 2 + 7 files changed, 82 insertions(+) create mode 100644 Content.Server/Station/Components/StationRenameFaxesComponent.cs create mode 100644 Content.Server/Station/Systems/StationRenameFaxesSystem.cs diff --git a/Content.Server/Fax/FaxMachineComponent.cs b/Content.Server/Fax/FaxMachineComponent.cs index bdc97bc2450..a42f399621f 100644 --- a/Content.Server/Fax/FaxMachineComponent.cs +++ b/Content.Server/Fax/FaxMachineComponent.cs @@ -15,6 +15,13 @@ public sealed class FaxMachineComponent : Component [DataField("name")] public string FaxName { get; set; } = "Unknown"; + /// + /// If true, will sync fax name with a station name. + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("useStationName")] + public bool UseStationName { get; set; } + /// /// Device address of fax in network to which data will be send /// diff --git a/Content.Server/Fax/FaxSystem.cs b/Content.Server/Fax/FaxSystem.cs index 26df47ce1b6..ccb48585b30 100644 --- a/Content.Server/Fax/FaxSystem.cs +++ b/Content.Server/Fax/FaxSystem.cs @@ -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; diff --git a/Content.Server/Station/Components/StationRenameFaxesComponent.cs b/Content.Server/Station/Components/StationRenameFaxesComponent.cs new file mode 100644 index 00000000000..49c536e3c61 --- /dev/null +++ b/Content.Server/Station/Components/StationRenameFaxesComponent.cs @@ -0,0 +1,10 @@ +namespace Content.Server.Station.Components; + +/// +/// Rename all faxes on a station when station name changes. +/// Only faxes with "UseStationName" will be affected. +/// +[RegisterComponent] +public sealed class StationRenameFaxesComponent : Component +{ +} diff --git a/Content.Server/Station/Systems/StationRenameFaxesSystem.cs b/Content.Server/Station/Systems/StationRenameFaxesSystem.cs new file mode 100644 index 00000000000..209ad43da50 --- /dev/null +++ b/Content.Server/Station/Systems/StationRenameFaxesSystem.cs @@ -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(OnRenamed); + SubscribeLocalEvent(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(); + 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; + } + } +} diff --git a/Resources/Prototypes/Entities/Stations/base.yml b/Resources/Prototypes/Entities/Stations/base.yml index b758b4e3952..7873b777d0f 100644 --- a/Resources/Prototypes/Entities/Stations/base.yml +++ b/Resources/Prototypes/Entities/Stations/base.yml @@ -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 diff --git a/Resources/Prototypes/Entities/Structures/Machines/fax_machine.yml b/Resources/Prototypes/Entities/Structures/Machines/fax_machine.yml index f680f74d3b8..ed7ec4b67f5 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/fax_machine.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/fax_machine.yml @@ -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 diff --git a/Resources/Prototypes/_NF/Shipyard/default_shipyard_catalog.yml b/Resources/Prototypes/_NF/Shipyard/default_shipyard_catalog.yml index 98c477c5a76..395a6ab504e 100644 --- a/Resources/Prototypes/_NF/Shipyard/default_shipyard_catalog.yml +++ b/Resources/Prototypes/_NF/Shipyard/default_shipyard_catalog.yml @@ -22,6 +22,7 @@ - BaseStationAlertLevels - BaseStationExpeditions - BaseStationAllEventsEligible + - BaseStationRenameFaxes noSpawn: true components: - type: Transform @@ -34,6 +35,7 @@ - BaseStationRecords - BaseStationAlertLevels - BaseStationAllEventsEligible + - BaseStationRenameFaxes noSpawn: true components: - type: Transform From 974c8b7a0f888eeff315d4848af6358c06140c5c Mon Sep 17 00:00:00 2001 From: Alexander Evgrashin Date: Thu, 3 Aug 2023 18:32:52 +0200 Subject: [PATCH 2/2] Moved protos to NF --- Resources/Prototypes/Entities/Stations/base.yml | 6 ------ .../Entities/Structures/Machines/fax_machine.yml | 8 -------- .../Prototypes/_NF/Entities/Structures/machines.yml | 10 +++++++++- .../_NF/Shipyard/default_shipyard_catalog.yml | 6 ++++++ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Resources/Prototypes/Entities/Stations/base.yml b/Resources/Prototypes/Entities/Stations/base.yml index 7873b777d0f..b758b4e3952 100644 --- a/Resources/Prototypes/Entities/Stations/base.yml +++ b/Resources/Prototypes/Entities/Stations/base.yml @@ -71,9 +71,3 @@ abstract: true components: - type: StationEventEligible # For when someone makes this more granular in the future. - -- type: entity - id: BaseStationRenameFaxes - abstract: true - components: - - type: StationRenameFaxes diff --git a/Resources/Prototypes/Entities/Structures/Machines/fax_machine.yml b/Resources/Prototypes/Entities/Structures/Machines/fax_machine.yml index ed7ec4b67f5..f680f74d3b8 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/fax_machine.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/fax_machine.yml @@ -105,11 +105,3 @@ - type: FaxMachine name: "Captain's Office" receiveNukeCodes: true - -- type: entity - parent: FaxMachineBase - id: FaxMachineShip - suffix: Ship - components: - - type: FaxMachine - useStationName: true diff --git a/Resources/Prototypes/_NF/Entities/Structures/machines.yml b/Resources/Prototypes/_NF/Entities/Structures/machines.yml index 560b61fe9d4..1e0292749f6 100644 --- a/Resources/Prototypes/_NF/Entities/Structures/machines.yml +++ b/Resources/Prototypes/_NF/Entities/Structures/machines.yml @@ -261,4 +261,12 @@ energy: 1.3 color: "#ad2c2b" - type: MarketModifier - mod: 50 \ No newline at end of file + mod: 50 + +- type: entity + parent: FaxMachineBase + id: FaxMachineShip + suffix: Ship + components: + - type: FaxMachine + useStationName: true diff --git a/Resources/Prototypes/_NF/Shipyard/default_shipyard_catalog.yml b/Resources/Prototypes/_NF/Shipyard/default_shipyard_catalog.yml index 395a6ab504e..527c264d195 100644 --- a/Resources/Prototypes/_NF/Shipyard/default_shipyard_catalog.yml +++ b/Resources/Prototypes/_NF/Shipyard/default_shipyard_catalog.yml @@ -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: