spray painter rework (#23287)

* refactor and add Department to PaintableAirlock, move it to server dir since its in namespace

* add departments to doors, cleanup

* add style -> departments mapping

* AirlockDepartmentsPrototype

* update shared spray stuff to have department

* name file the same as the class name

* department optional

* refactor spray painter system + send department

* fixy

* client

* no need to rewrite ActivateableUi

* pro ops

* the reckoning

* hiss

* .

* :trollface:

* add standard atmos colors to palette

* Update Content.Shared/SprayPainter/SharedSprayPainterSystem.cs

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
deltanedas
2024-02-01 22:30:46 +00:00
committed by GitHub
parent e36844de47
commit c49c78bafa
15 changed files with 424 additions and 306 deletions

View File

@@ -1,186 +1,69 @@
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.EntitySystems;
using Content.Server.Popups;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Doors.Components;
using Content.Shared.Interaction;
using Content.Shared.SprayPainter;
using Content.Shared.SprayPainter.Components;
using Content.Shared.SprayPainter.Prototypes;
using Content.Shared.Interaction;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
namespace Content.Server.SprayPainter;
/// <summary>
/// A system for painting airlocks and pipes using enginner painter
/// Handles spraying pipes using a spray painter.
/// Airlocks are handled in shared.
/// </summary>
[UsedImplicitly]
public sealed class SprayPainterSystem : SharedSprayPainterSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly AtmosPipeColorSystem _pipeColorSystem = default!;
[Dependency] private readonly AtmosPipeColorSystem _pipeColor = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SprayPainterComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SprayPainterComponent, AfterInteractEvent>(AfterInteractOn);
SubscribeLocalEvent<SprayPainterComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<SprayPainterComponent, SprayPainterSpritePickedMessage>(OnSpritePicked);
SubscribeLocalEvent<SprayPainterComponent, SprayPainterColorPickedMessage>(OnColorPicked);
SubscribeLocalEvent<SprayPainterComponent, SprayPainterDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<SprayPainterComponent, SprayPainterPipeDoAfterEvent>(OnPipeDoAfter);
SubscribeLocalEvent<AtmosPipeColorComponent, InteractUsingEvent>(OnPipeInteract);
}
private void OnInit(EntityUid uid, SprayPainterComponent component, ComponentInit args)
private void OnPipeDoAfter(Entity<SprayPainterComponent> ent, ref SprayPainterPipeDoAfterEvent args)
{
if (component.ColorPalette.Count == 0)
return;
SetColor(uid, component, component.ColorPalette.First().Key);
}
private void OnDoAfter(EntityUid uid, SprayPainterComponent component, SprayPainterDoAfterEvent args)
{
component.IsSpraying = false;
if (args.Handled || args.Cancelled)
return;
if (args.Args.Target == null)
if (args.Args.Target is not {} target)
return;
EntityUid target = (EntityUid) args.Args.Target;
if (!TryComp<AtmosPipeColorComponent>(target, out var color))
return;
_audio.PlayPvs(component.SpraySound, uid);
Audio.PlayPvs(ent.Comp.SpraySound, ent);
if (TryComp<AtmosPipeColorComponent>(target, out var atmosPipeColorComp))
{
_pipeColorSystem.SetColor(target, atmosPipeColorComp, args.Color ?? Color.White);
} else { // Target is an airlock
if (args.Sprite != null)
{
_appearance.SetData(target, DoorVisuals.BaseRSI, args.Sprite);
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.Args.User):user} painted {ToPrettyString(args.Args.Target.Value):target}");
}
}
_pipeColor.SetColor(target, color, args.Color);
args.Handled = true;
}
private void OnActivate(EntityUid uid, SprayPainterComponent component, ActivateInWorldEvent args)
private void OnPipeInteract(Entity<AtmosPipeColorComponent> ent, ref InteractUsingEvent args)
{
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
return;
DirtyUI(uid, component);
_userInterfaceSystem.TryOpen(uid, SprayPainterUiKey.Key, actor.PlayerSession);
args.Handled = true;
}
private void AfterInteractOn(EntityUid uid, SprayPainterComponent component, AfterInteractEvent args)
{
if (component.IsSpraying || args.Target is not { Valid: true } target || !args.CanReach)
if (args.Handled)
return;
if (EntityManager.TryGetComponent<PaintableAirlockComponent>(target, out var airlock))
if (!TryComp<SprayPainterComponent>(args.Used, out var painter) || painter.PickedColor is not {} colorName)
return;
if (!painter.ColorPalette.TryGetValue(colorName, out var color))
return;
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, painter.PipeSprayTime, new SprayPainterPipeDoAfterEvent(color), args.Used, target: ent, used: args.Used)
{
if (!_prototypeManager.TryIndex<AirlockGroupPrototype>(airlock.Group, out var grp))
{
Log.Error("Group not defined: %s", airlock.Group);
return;
}
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
CancelDuplicate = true,
// multiple pipes can be sprayed at once just not the same one
DuplicateCondition = DuplicateConditions.SameTarget,
NeedHand = true
};
string style = Styles[component.Index];
if (!grp.StylePaths.TryGetValue(style, out var sprite))
{
string msg = Loc.GetString("spray-painter-style-not-available");
_popupSystem.PopupEntity(msg, args.User, args.User);
return;
}
component.IsSpraying = true;
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, component.AirlockSprayTime, new SprayPainterDoAfterEvent(sprite, null), uid, target: target, used: uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
NeedHand = true,
};
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
// Log attempt
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} is painting {ToPrettyString(uid):target} to '{style}' at {Transform(uid).Coordinates:targetlocation}");
} else { // Painting pipes
if(component.PickedColor is null)
return;
if (!EntityManager.HasComponent<AtmosPipeColorComponent>(target))
return;
if(!component.ColorPalette.TryGetValue(component.PickedColor, out var color))
return;
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, component.PipeSprayTime, new SprayPainterDoAfterEvent(null, color), uid, target, uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
CancelDuplicate = true,
DuplicateCondition = DuplicateConditions.SameTarget,
NeedHand = true,
};
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
}
}
private void OnColorPicked(EntityUid uid, SprayPainterComponent component, SprayPainterColorPickedMessage args)
{
SetColor(uid, component, args.Key);
}
private void OnSpritePicked(EntityUid uid, SprayPainterComponent component, SprayPainterSpritePickedMessage args)
{
component.Index = args.Index;
DirtyUI(uid, component);
}
private void SetColor(EntityUid uid, SprayPainterComponent component, string? paletteKey)
{
if (paletteKey == null)
return;
if (!component.ColorPalette.ContainsKey(paletteKey) || paletteKey == component.PickedColor)
return;
component.PickedColor = paletteKey;
DirtyUI(uid, component);
}
private void DirtyUI(EntityUid uid, SprayPainterComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
_userInterfaceSystem.TrySetUiState(
uid,
SprayPainterUiKey.Key,
new SprayPainterBoundUserInterfaceState(
component.Index,
component.PickedColor,
component.ColorPalette));
args.Handled = DoAfter.TryStartDoAfter(doAfterEventArgs);
}
}