make crayoncode use the colortype (#7975)
This commit is contained in:
@@ -8,7 +8,6 @@ namespace Content.Client.Crayon
|
|||||||
public sealed class CrayonComponent : SharedCrayonComponent
|
public sealed class CrayonComponent : SharedCrayonComponent
|
||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadWrite)] public bool UIUpdateNeeded;
|
[ViewVariables(VVAccess.ReadWrite)] public bool UIUpdateNeeded;
|
||||||
[ViewVariables(VVAccess.ReadWrite)] public string Color => _color;
|
|
||||||
[ViewVariables] public int Charges { get; set; }
|
[ViewVariables] public int Charges { get; set; }
|
||||||
[ViewVariables] public int Capacity { get; set; }
|
[ViewVariables] public int Capacity { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using Robust.Shared.Timing;
|
|||||||
|
|
||||||
namespace Content.Client.Crayon;
|
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.
|
// Didn't do in shared because I don't think most of the server stuff can be predicted.
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -25,7 +25,7 @@ public sealed class CrayonSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
if (args.Current is not CrayonComponentState state) return;
|
if (args.Current is not CrayonComponentState state) return;
|
||||||
|
|
||||||
component._color = state.Color;
|
component.Color = state.Color;
|
||||||
component.SelectedState = state.State;
|
component.SelectedState = state.State;
|
||||||
component.Charges = state.Charges;
|
component.Charges = state.Charges;
|
||||||
component.Capacity = state.Capacity;
|
component.Capacity = state.Capacity;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace Content.Client.Crayon.UI
|
|||||||
SendMessage(new CrayonSelectMessage(state));
|
SendMessage(new CrayonSelectMessage(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectColor(string color)
|
public void SelectColor(Color color)
|
||||||
{
|
{
|
||||||
SendMessage(new CrayonColorMessage(color));
|
SendMessage(new CrayonColorMessage(color));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Content.Client.Crayon.UI
|
|||||||
{
|
{
|
||||||
_color = color;
|
_color = color;
|
||||||
|
|
||||||
Owner.SelectColor(color.ToHex());
|
Owner.SelectColor(color);
|
||||||
|
|
||||||
RefreshList();
|
RefreshList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,10 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.Crayon
|
namespace Content.Server.Crayon
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class CrayonComponent : SharedCrayonComponent, ISerializationHooks
|
public sealed class CrayonComponent : SharedCrayonComponent
|
||||||
{
|
{
|
||||||
[DataField("useSound")] public SoundSpecifier? UseSound;
|
[DataField("useSound")] public SoundSpecifier? UseSound;
|
||||||
|
|
||||||
[ViewVariables]
|
|
||||||
public Color Color { get; private set; }
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("selectableColor")]
|
[DataField("selectableColor")]
|
||||||
public bool SelectableColor { get; set; }
|
public bool SelectableColor { get; set; }
|
||||||
@@ -34,10 +31,5 @@ namespace Content.Server.Crayon
|
|||||||
public bool DeleteEmpty = true;
|
public bool DeleteEmpty = true;
|
||||||
|
|
||||||
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
|
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
|
||||||
|
|
||||||
void ISerializationHooks.AfterDeserialization()
|
|
||||||
{
|
|
||||||
Color = Color.FromName(_color);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ using Robust.Shared.Prototypes;
|
|||||||
|
|
||||||
namespace Content.Server.Crayon;
|
namespace Content.Server.Crayon;
|
||||||
|
|
||||||
public sealed class CrayonSystem : EntitySystem
|
public sealed class CrayonSystem : SharedCrayonSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly AdminLogSystem _logs = 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)
|
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)
|
private void OnCrayonAfterInteract(EntityUid uid, CrayonComponent component, AfterInteractEvent args)
|
||||||
@@ -69,21 +69,7 @@ public sealed class CrayonSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color color = Color.White;
|
if(!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f,-0.5f)), out _, component.Color, cleanable: true))
|
||||||
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))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (component.UseSound != null)
|
if (component.UseSound != null)
|
||||||
@@ -92,7 +78,7 @@ public sealed class CrayonSystem : EntitySystem
|
|||||||
// Decrease "Ammo"
|
// Decrease "Ammo"
|
||||||
component.Charges--;
|
component.Charges--;
|
||||||
Dirty(component);
|
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;
|
args.Handled = true;
|
||||||
|
|
||||||
if (component.DeleteEmpty && component.Charges <= 0)
|
if (component.DeleteEmpty && component.Charges <= 0)
|
||||||
@@ -131,20 +117,9 @@ public sealed class CrayonSystem : EntitySystem
|
|||||||
private void OnCrayonBoundUIColor(EntityUid uid, CrayonComponent component, CrayonColorMessage args)
|
private void OnCrayonBoundUIColor(EntityUid uid, CrayonComponent component, CrayonColorMessage args)
|
||||||
{
|
{
|
||||||
// you still need to ensure that the given color is a valid color
|
// 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;
|
||||||
{
|
|
||||||
component._color = args.Color;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var hexColor = Color.TryFromHex(component._color);
|
|
||||||
if (hexColor != null)
|
|
||||||
{
|
|
||||||
component._color = args.Color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
using System;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
|
||||||
|
|
||||||
namespace Content.Shared.Crayon
|
namespace Content.Shared.Crayon
|
||||||
{
|
{
|
||||||
[NetworkedComponent, ComponentProtoName("Crayon")]
|
[NetworkedComponent, ComponentProtoName("Crayon"), Friend(typeof(SharedCrayonSystem))]
|
||||||
public abstract class SharedCrayonComponent : Component
|
public abstract class SharedCrayonComponent : Component
|
||||||
{
|
{
|
||||||
public string SelectedState { get; set; } = string.Empty;
|
public string SelectedState { get; set; } = string.Empty;
|
||||||
|
|
||||||
[DataField("color")] public string _color = "white";
|
[ViewVariables] [DataField("color")] public Color Color;
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum CrayonUiKey : byte
|
public enum CrayonUiKey : byte
|
||||||
@@ -34,8 +30,8 @@ namespace Content.Shared.Crayon
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class CrayonColorMessage : BoundUserInterfaceMessage
|
public sealed class CrayonColorMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public readonly string Color;
|
public readonly Color Color;
|
||||||
public CrayonColorMessage(string color)
|
public CrayonColorMessage(Color color)
|
||||||
{
|
{
|
||||||
Color = color;
|
Color = color;
|
||||||
}
|
}
|
||||||
@@ -51,12 +47,12 @@ namespace Content.Shared.Crayon
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class CrayonComponentState : ComponentState
|
public sealed class CrayonComponentState : ComponentState
|
||||||
{
|
{
|
||||||
public readonly string Color;
|
public readonly Color Color;
|
||||||
public readonly string State;
|
public readonly string State;
|
||||||
public readonly int Charges;
|
public readonly int Charges;
|
||||||
public readonly int Capacity;
|
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;
|
Color = color;
|
||||||
State = state;
|
State = state;
|
||||||
|
|||||||
4
Content.Shared/Crayon/SharedCrayonSystem.cs
Normal file
4
Content.Shared/Crayon/SharedCrayonSystem.cs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
namespace Content.Shared.Crayon;
|
||||||
|
|
||||||
|
[Virtual]
|
||||||
|
public abstract class SharedCrayonSystem : EntitySystem { }
|
||||||
Reference in New Issue
Block a user