From 85231bb9d6477f2d6c7e2a2d35d442eec03b5ccf Mon Sep 17 00:00:00 2001 From: actually-reb <61338113+actually-reb@users.noreply.github.com> Date: Sun, 27 Mar 2022 01:09:48 -0700 Subject: [PATCH] crayons deleted when used up (#7282) --- Content.Server/Crayon/CrayonComponent.cs | 4 ++++ Content.Server/Crayon/CrayonSystem.cs | 15 ++++++++++++++- .../Locale/en-US/crayon/crayon-component.ftl | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Content.Server/Crayon/CrayonComponent.cs b/Content.Server/Crayon/CrayonComponent.cs index 90c810e742..fbbeb4b3f0 100644 --- a/Content.Server/Crayon/CrayonComponent.cs +++ b/Content.Server/Crayon/CrayonComponent.cs @@ -25,6 +25,10 @@ namespace Content.Server.Crayon [DataField("capacity")] public int Capacity { get; set; } = 30; + [ViewVariables(VVAccess.ReadWrite)] + [DataField("deleteEmpty")] + public bool DeleteEmpty = true; + [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key); void ISerializationHooks.AfterDeserialization() diff --git a/Content.Server/Crayon/CrayonSystem.cs b/Content.Server/Crayon/CrayonSystem.cs index ee5d5623d5..2ec5ac4934 100644 --- a/Content.Server/Crayon/CrayonSystem.cs +++ b/Content.Server/Crayon/CrayonSystem.cs @@ -51,7 +51,11 @@ public sealed class CrayonSystem : EntitySystem if (component.Charges <= 0) { - _popup.PopupEntity(Loc.GetString("crayon-interact-not-enough-left-text"), uid, Filter.Entities(args.User)); + if (component.DeleteEmpty) + UseUpCrayon(uid, args.User); + else + _popup.PopupEntity(Loc.GetString("crayon-interact-not-enough-left-text"), uid, Filter.Entities(args.User)); + args.Handled = true; return; } @@ -74,6 +78,9 @@ public sealed class CrayonSystem : EntitySystem Dirty(component); _logs.Add(LogType.CrayonDraw, LogImpact.Low, $"{EntityManager.ToPrettyString(args.User):user} drew a {component._color:color} {component.SelectedState}"); args.Handled = true; + + if (component.DeleteEmpty && component.Charges <= 0) + UseUpCrayon(uid, args.User); } private void OnCrayonUse(EntityUid uid, CrayonComponent component, UseInHandEvent args) @@ -119,4 +126,10 @@ public sealed class CrayonSystem : EntitySystem if (TryComp(args.User, out var actor)) component.UserInterface?.Close(actor.PlayerSession); } + + private void UseUpCrayon(EntityUid uid, EntityUid user) + { + _popup.PopupEntity(Loc.GetString("crayon-interact-used-up-text", ("owner", uid)), user, Filter.Entities(user)); + EntityManager.QueueDeleteEntity(uid); + } } diff --git a/Resources/Locale/en-US/crayon/crayon-component.ftl b/Resources/Locale/en-US/crayon/crayon-component.ftl index af8e0a7cdb..444ffa4c45 100644 --- a/Resources/Locale/en-US/crayon/crayon-component.ftl +++ b/Resources/Locale/en-US/crayon/crayon-component.ftl @@ -3,6 +3,7 @@ crayon-drawing-label = Drawing: [color={$color}]{$state}[/color] ({$charges}/{$capacity}) crayon-interact-not-enough-left-text = Not enough left. +crayon-interact-used-up-text = The {$owner} got used up. crayon-interact-invalid-location = Can't reach there! ## UI