add(FaxComponent): Allows for setting defaults in the component. (#30484)

* add(FaxComponent): Allows for setting defaults in the component.

This wires up the Fax component to allow the default paper and office
paper to be set. The defaults are what they were before, and it's an
optional option. Now Fax machines can be set to print different paper
when using Print File or other cases where the default paper style is
used.

* Requested change to EntProtoId.

* Fix build failure.
This commit is contained in:
CaasGit
2024-08-08 22:54:08 -07:00
committed by GitHub
parent b7ef5ada11
commit c091acd1f5
2 changed files with 28 additions and 24 deletions

View File

@@ -52,16 +52,6 @@ public sealed class FaxSystem : EntitySystem
private const string PaperSlotId = "Paper"; private const string PaperSlotId = "Paper";
/// <summary>
/// The prototype ID to use for faxed or copied entities if we can't get one from
/// the paper entity for whatever reason.
/// </summary>
[ValidatePrototypeId<EntityPrototype>]
private const string DefaultPaperPrototypeId = "Paper";
[ValidatePrototypeId<EntityPrototype>]
private const string OfficePaperPrototypeId = "PaperOffice";
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -242,7 +232,8 @@ public sealed class FaxSystem : EntitySystem
return; return;
} }
_adminLogger.Add(LogType.Action, LogImpact.Low, _adminLogger.Add(LogType.Action,
LogImpact.Low,
$"{ToPrettyString(args.User):user} renamed {ToPrettyString(uid):tool} from \"{component.FaxName}\" to \"{newName}\""); $"{ToPrettyString(args.User):user} renamed {ToPrettyString(uid):tool} from \"{component.FaxName}\" to \"{newName}\"");
component.FaxName = newName; component.FaxName = newName;
_popupSystem.PopupEntity(Loc.GetString("fax-machine-popup-name-set"), uid); _popupSystem.PopupEntity(Loc.GetString("fax-machine-popup-name-set"), uid);
@@ -324,7 +315,7 @@ public sealed class FaxSystem : EntitySystem
private void OnCopyButtonPressed(EntityUid uid, FaxMachineComponent component, FaxCopyMessage args) private void OnCopyButtonPressed(EntityUid uid, FaxMachineComponent component, FaxCopyMessage args)
{ {
if (HasComp<MobStateComponent>(component.PaperSlot.Item)) if (HasComp<MobStateComponent>(component.PaperSlot.Item))
_faxecute.Faxecute(uid, component); /// when button pressed it will hurt the mob. _faxecute.Faxecute(uid, component); // when button pressed it will hurt the mob.
else else
Copy(uid, component, args); Copy(uid, component, args);
} }
@@ -332,7 +323,7 @@ public sealed class FaxSystem : EntitySystem
private void OnSendButtonPressed(EntityUid uid, FaxMachineComponent component, FaxSendMessage args) private void OnSendButtonPressed(EntityUid uid, FaxMachineComponent component, FaxSendMessage args)
{ {
if (HasComp<MobStateComponent>(component.PaperSlot.Item)) if (HasComp<MobStateComponent>(component.PaperSlot.Item))
_faxecute.Faxecute(uid, component); /// when button pressed it will hurt the mob. _faxecute.Faxecute(uid, component); // when button pressed it will hurt the mob.
else else
Send(uid, component, args); Send(uid, component, args);
} }
@@ -425,11 +416,7 @@ public sealed class FaxSystem : EntitySystem
/// </summary> /// </summary>
public void PrintFile(EntityUid uid, FaxMachineComponent component, FaxFileMessage args) public void PrintFile(EntityUid uid, FaxMachineComponent component, FaxFileMessage args)
{ {
string prototype; var prototype = args.OfficePaper ? component.PrintOfficePaperId : component.PrintPaperId;
if (args.OfficePaper)
prototype = OfficePaperPrototypeId;
else
prototype = DefaultPaperPrototypeId;
var name = Loc.GetString("fax-machine-printed-paper-name"); var name = Loc.GetString("fax-machine-printed-paper-name");
@@ -441,7 +428,8 @@ public sealed class FaxSystem : EntitySystem
// Unfortunately, since a paper entity does not yet exist, we have to emulate what LabelSystem will do. // Unfortunately, since a paper entity does not yet exist, we have to emulate what LabelSystem will do.
var nameWithLabel = (args.Label is { } label) ? $"{name} ({label})" : name; var nameWithLabel = (args.Label is { } label) ? $"{name} ({label})" : name;
_adminLogger.Add(LogType.Action, LogImpact.Low, _adminLogger.Add(LogType.Action,
LogImpact.Low,
$"{ToPrettyString(args.Actor):actor} " + $"{ToPrettyString(args.Actor):actor} " +
$"added print job to \"{component.FaxName}\" {ToPrettyString(uid):tool} " + $"added print job to \"{component.FaxName}\" {ToPrettyString(uid):tool} " +
$"of {nameWithLabel}: {args.Content}"); $"of {nameWithLabel}: {args.Content}");
@@ -471,7 +459,7 @@ public sealed class FaxSystem : EntitySystem
var printout = new FaxPrintout(paper.Content, var printout = new FaxPrintout(paper.Content,
nameMod?.BaseName ?? metadata.EntityName, nameMod?.BaseName ?? metadata.EntityName,
labelComponent?.CurrentLabel, labelComponent?.CurrentLabel,
metadata.EntityPrototype?.ID ?? DefaultPaperPrototypeId, metadata.EntityPrototype?.ID ?? component.PrintPaperId,
paper.StampState, paper.StampState,
paper.StampedBy, paper.StampedBy,
paper.EditingDisabled); paper.EditingDisabled);
@@ -484,7 +472,8 @@ public sealed class FaxSystem : EntitySystem
UpdateUserInterface(uid, component); UpdateUserInterface(uid, component);
_adminLogger.Add(LogType.Action, LogImpact.Low, _adminLogger.Add(LogType.Action,
LogImpact.Low,
$"{ToPrettyString(args.Actor):actor} " + $"{ToPrettyString(args.Actor):actor} " +
$"added copy job to \"{component.FaxName}\" {ToPrettyString(uid):tool} " + $"added copy job to \"{component.FaxName}\" {ToPrettyString(uid):tool} " +
$"of {ToPrettyString(sendEntity):subject}: {printout.Content}"); $"of {ToPrettyString(sendEntity):subject}: {printout.Content}");
@@ -531,7 +520,7 @@ public sealed class FaxSystem : EntitySystem
// TODO: Ideally, we could just make a copy of the whole entity when it's // TODO: Ideally, we could just make a copy of the whole entity when it's
// faxed, in order to preserve visuals, etc.. This functionality isn't // faxed, in order to preserve visuals, etc.. This functionality isn't
// available yet, so we'll pass along the originating prototypeId and fall // available yet, so we'll pass along the originating prototypeId and fall
// back to DefaultPaperPrototypeId in SpawnPaperFromQueue if we can't find one here. // back to component.PrintPaperId in SpawnPaperFromQueue if we can't find one here.
payload[FaxConstants.FaxPaperPrototypeData] = metadata.EntityPrototype.ID; payload[FaxConstants.FaxPaperPrototypeData] = metadata.EntityPrototype.ID;
} }
@@ -543,7 +532,8 @@ public sealed class FaxSystem : EntitySystem
_deviceNetworkSystem.QueuePacket(uid, component.DestinationFaxAddress, payload); _deviceNetworkSystem.QueuePacket(uid, component.DestinationFaxAddress, payload);
_adminLogger.Add(LogType.Action, LogImpact.Low, _adminLogger.Add(LogType.Action,
LogImpact.Low,
$"{ToPrettyString(args.Actor):actor} " + $"{ToPrettyString(args.Actor):actor} " +
$"sent fax from \"{component.FaxName}\" {ToPrettyString(uid):tool} " + $"sent fax from \"{component.FaxName}\" {ToPrettyString(uid):tool} " +
$"to \"{faxName}\" ({component.DestinationFaxAddress}) " + $"to \"{faxName}\" ({component.DestinationFaxAddress}) " +
@@ -585,7 +575,7 @@ public sealed class FaxSystem : EntitySystem
var printout = component.PrintingQueue.Dequeue(); var printout = component.PrintingQueue.Dequeue();
var entityToSpawn = printout.PrototypeId.Length == 0 ? DefaultPaperPrototypeId : printout.PrototypeId; var entityToSpawn = printout.PrototypeId.Length == 0 ? component.PrintPaperId.ToString() : printout.PrototypeId;
var printed = EntityManager.SpawnEntity(entityToSpawn, Transform(uid).Coordinates); var printed = EntityManager.SpawnEntity(entityToSpawn, Transform(uid).Coordinates);
if (TryComp<PaperComponent>(printed, out var paper)) if (TryComp<PaperComponent>(printed, out var paper))

View File

@@ -127,6 +127,20 @@ public sealed partial class FaxMachineComponent : Component
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
public float PrintingTime = 2.3f; public float PrintingTime = 2.3f;
/// <summary>
/// The prototype ID to use for faxed or copied entities if we can't get one from
/// the paper entity for whatever reason.
/// </summary>
[DataField]
public EntProtoId PrintPaperId = "Paper";
/// <summary>
/// The prototype ID to use for faxed or copied entities if we can't get one from
/// the paper entity for whatever reason of the Office type.
/// </summary>
[DataField]
public EntProtoId PrintOfficePaperId = "PaperOffice";
} }
[DataDefinition] [DataDefinition]