diff --git a/Content.Client/Crayon/CrayonComponent.cs b/Content.Client/Crayon/CrayonComponent.cs index 6fa182cc92..3f61961abc 100644 --- a/Content.Client/Crayon/CrayonComponent.cs +++ b/Content.Client/Crayon/CrayonComponent.cs @@ -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; } } diff --git a/Content.Client/Crayon/CrayonSystem.cs b/Content.Client/Crayon/CrayonSystem.cs index 51e2f55694..89726a30ff 100644 --- a/Content.Client/Crayon/CrayonSystem.cs +++ b/Content.Client/Crayon/CrayonSystem.cs @@ -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; diff --git a/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs b/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs index cce8d205cf..d31eb35db9 100644 --- a/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs +++ b/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs @@ -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)); } diff --git a/Content.Client/Crayon/UI/CrayonWindow.xaml.cs b/Content.Client/Crayon/UI/CrayonWindow.xaml.cs index 3a3608e7b1..4e21016196 100644 --- a/Content.Client/Crayon/UI/CrayonWindow.xaml.cs +++ b/Content.Client/Crayon/UI/CrayonWindow.xaml.cs @@ -37,7 +37,7 @@ namespace Content.Client.Crayon.UI { _color = color; - Owner.SelectColor(color.ToHex()); + Owner.SelectColor(color); RefreshList(); } diff --git a/Content.Server/Crayon/CrayonComponent.cs b/Content.Server/Crayon/CrayonComponent.cs index fbecdc6083..9b852eef3f 100644 --- a/Content.Server/Crayon/CrayonComponent.cs +++ b/Content.Server/Crayon/CrayonComponent.cs @@ -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); - } } } diff --git a/Content.Server/Crayon/CrayonSystem.cs b/Content.Server/Crayon/CrayonSystem.cs index 0d3bed6133..88ff713f67 100644 --- a/Content.Server/Crayon/CrayonSystem.cs +++ b/Content.Server/Crayon/CrayonSystem.cs @@ -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); } diff --git a/Content.Shared/Crayon/SharedCrayonComponent.cs b/Content.Shared/Crayon/SharedCrayonComponent.cs index 1a5d62a675..3b8881b5c2 100644 --- a/Content.Shared/Crayon/SharedCrayonComponent.cs +++ b/Content.Shared/Crayon/SharedCrayonComponent.cs @@ -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; diff --git a/Content.Shared/Crayon/SharedCrayonSystem.cs b/Content.Shared/Crayon/SharedCrayonSystem.cs new file mode 100644 index 0000000000..03113f1240 --- /dev/null +++ b/Content.Shared/Crayon/SharedCrayonSystem.cs @@ -0,0 +1,4 @@ +namespace Content.Shared.Crayon; + +[Virtual] +public abstract class SharedCrayonSystem : EntitySystem { }