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

@@ -8,7 +8,6 @@ namespace Content.Client.Crayon
public sealed class CrayonComponent : SharedCrayonComponent
{
[ViewVariables(VVAccess.ReadWrite)] public bool UIUpdateNeeded;
[ViewVariables(VVAccess.ReadWrite)] public string Color => _color;
[ViewVariables] public int Charges { get; set; }
[ViewVariables] public int Capacity { get; set; }
}

View File

@@ -11,7 +11,7 @@ using Robust.Shared.Timing;
namespace Content.Client.Crayon;
public sealed class CrayonSystem : EntitySystem
public sealed class CrayonSystem : SharedCrayonSystem
{
// Didn't do in shared because I don't think most of the server stuff can be predicted.
public override void Initialize()
@@ -25,7 +25,7 @@ public sealed class CrayonSystem : EntitySystem
{
if (args.Current is not CrayonComponentState state) return;
component._color = state.Color;
component.Color = state.Color;
component.SelectedState = state.State;
component.Charges = state.Charges;
component.Capacity = state.Capacity;

View File

@@ -40,7 +40,7 @@ namespace Content.Client.Crayon.UI
SendMessage(new CrayonSelectMessage(state));
}
public void SelectColor(string color)
public void SelectColor(Color color)
{
SendMessage(new CrayonColorMessage(color));
}

View File

@@ -37,7 +37,7 @@ namespace Content.Client.Crayon.UI
{
_color = color;
Owner.SelectColor(color.ToHex());
Owner.SelectColor(color);
RefreshList();
}

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);
}

View File

@@ -1,18 +1,14 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Crayon
{
[NetworkedComponent, ComponentProtoName("Crayon")]
[NetworkedComponent, ComponentProtoName("Crayon"), Friend(typeof(SharedCrayonSystem))]
public abstract class SharedCrayonComponent : Component
{
public string SelectedState { get; set; } = string.Empty;
[DataField("color")] public string _color = "white";
[ViewVariables] [DataField("color")] public Color Color;
[Serializable, NetSerializable]
public enum CrayonUiKey : byte
@@ -34,8 +30,8 @@ namespace Content.Shared.Crayon
[Serializable, NetSerializable]
public sealed class CrayonColorMessage : BoundUserInterfaceMessage
{
public readonly string Color;
public CrayonColorMessage(string color)
public readonly Color Color;
public CrayonColorMessage(Color color)
{
Color = color;
}
@@ -51,12 +47,12 @@ namespace Content.Shared.Crayon
[Serializable, NetSerializable]
public sealed class CrayonComponentState : ComponentState
{
public readonly string Color;
public readonly Color Color;
public readonly string State;
public readonly int Charges;
public readonly int Capacity;
public CrayonComponentState(string color, string state, int charges, int capacity)
public CrayonComponentState(Color color, string state, int charges, int capacity)
{
Color = color;
State = state;

View File

@@ -0,0 +1,4 @@
namespace Content.Shared.Crayon;
[Virtual]
public abstract class SharedCrayonSystem : EntitySystem { }