make crayoncode use the colortype (#7975)

This commit is contained in:
Paul Ritter
2022-05-09 07:16:43 +02:00
committed by GitHub
parent aa61feb85d
commit 005321e484
8 changed files with 21 additions and 55 deletions

View File

@@ -11,13 +11,10 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Crayon
{
[RegisterComponent]
public sealed class CrayonComponent : SharedCrayonComponent, ISerializationHooks
public sealed class CrayonComponent : SharedCrayonComponent
{
[DataField("useSound")] public SoundSpecifier? UseSound;
[ViewVariables]
public Color Color { get; private set; }
[ViewVariables(VVAccess.ReadWrite)]
[DataField("selectableColor")]
public bool SelectableColor { get; set; }
@@ -34,10 +31,5 @@ namespace Content.Server.Crayon
public bool DeleteEmpty = true;
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
void ISerializationHooks.AfterDeserialization()
{
Color = Color.FromName(_color);
}
}
}

View File

@@ -22,7 +22,7 @@ using Robust.Shared.Prototypes;
namespace Content.Server.Crayon;
public sealed class CrayonSystem : EntitySystem
public sealed class CrayonSystem : SharedCrayonSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly AdminLogSystem _logs = default!;
@@ -43,7 +43,7 @@ public sealed class CrayonSystem : EntitySystem
private static void OnCrayonGetState(EntityUid uid, CrayonComponent component, ref ComponentGetState args)
{
args.State = new CrayonComponentState(component._color, component.SelectedState, component.Charges, component.Capacity);
args.State = new CrayonComponentState(component.Color, component.SelectedState, component.Charges, component.Capacity);
}
private void OnCrayonAfterInteract(EntityUid uid, CrayonComponent component, AfterInteractEvent args)
@@ -69,21 +69,7 @@ public sealed class CrayonSystem : EntitySystem
return;
}
Color color = Color.White;
if (Color.TryFromName(component._color, out var namedColor))
{
color = namedColor;
}
else
{
var hexColor = Color.TryFromHex(component._color);
if (hexColor != null)
{
color = (Color) hexColor;
}
}
if(!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f,-0.5f)), out _, color, cleanable: true))
if(!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f,-0.5f)), out _, component.Color, cleanable: true))
return;
if (component.UseSound != null)
@@ -92,7 +78,7 @@ public sealed class CrayonSystem : EntitySystem
// Decrease "Ammo"
component.Charges--;
Dirty(component);
_logs.Add(LogType.CrayonDraw, LogImpact.Low, $"{EntityManager.ToPrettyString(args.User):user} drew a {component._color:color} {component.SelectedState}");
_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)
@@ -131,20 +117,9 @@ public sealed class CrayonSystem : EntitySystem
private void OnCrayonBoundUIColor(EntityUid uid, CrayonComponent component, CrayonColorMessage args)
{
// you still need to ensure that the given color is a valid color
if (component.SelectableColor && args.Color != component._color)
if (component.SelectableColor && args.Color != component.Color)
{
if (Color.TryFromName(component._color, out var namedColor))
{
component._color = args.Color;
}
else
{
var hexColor = Color.TryFromHex(component._color);
if (hexColor != null)
{
component._color = args.Color;
}
}
component.Color = args.Color;
Dirty(component);
}