crayons deleted when used up (#7282)

This commit is contained in:
actually-reb
2022-03-27 01:09:48 -07:00
committed by GitHub
parent 4a6dfabcae
commit 85231bb9d6
3 changed files with 19 additions and 1 deletions

View File

@@ -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()

View File

@@ -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<ActorComponent>(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);
}
}

View File

@@ -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