]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add prediction to hand labeler labels (#25869)
authorTayrtahn <tayrtahn@gmail.com>
Wed, 6 Mar 2024 01:33:28 +0000 (20:33 -0500)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2024 01:33:28 +0000 (12:33 +1100)
Added prediction to labels

Content.Client/Labels/EntitySystems/LabelSystem.cs [new file with mode: 0644]
Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs
Content.Server/Labels/Label/Components/LabelComponent.cs [deleted file]
Content.Server/Labels/Label/LabelSystem.cs
Content.Shared/Labels/Components/LabelComponent.cs [new file with mode: 0644]
Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs [new file with mode: 0644]

diff --git a/Content.Client/Labels/EntitySystems/LabelSystem.cs b/Content.Client/Labels/EntitySystems/LabelSystem.cs
new file mode 100644 (file)
index 0000000..baa9f7f
--- /dev/null
@@ -0,0 +1,7 @@
+using Content.Shared.Labels.EntitySystems;
+
+namespace Content.Client.Labels;
+
+public sealed partial class LabelSystem : SharedLabelSystem
+{
+}
index 7a09d16265e0353b23f6b8bc4c4e6f101e68803d..b93498fe31bcdded5256240bdf9f85c1eaf38d8e 100644 (file)
@@ -1,17 +1,11 @@
 using Content.Server.Administration.Logs;
 using Content.Server.Chemistry.Components;
 using Content.Server.Chemistry.Containers.EntitySystems;
-using Content.Server.Nutrition.Components;
 using Content.Server.Nutrition.EntitySystems;
-using Content.Server.Labels.Components;
-using Content.Server.Chemistry;
 using Content.Shared.Chemistry;
-using Content.Shared.Chemistry.Components.SolutionManager;
 using Content.Shared.Chemistry.Dispenser;
 using Content.Shared.Chemistry.EntitySystems;
-using Content.Shared.Chemistry.Reagent;
 using Content.Shared.Containers.ItemSlots;
-using Content.Shared.Database;
 using Content.Shared.FixedPoint;
 using JetBrains.Annotations;
 using Robust.Server.Audio;
@@ -19,7 +13,7 @@ using Robust.Server.GameObjects;
 using Robust.Shared.Audio;
 using Robust.Shared.Containers;
 using Robust.Shared.Prototypes;
-using System.Linq;
+using Content.Shared.Labels.Components;
 
 namespace Content.Server.Chemistry.EntitySystems
 {
diff --git a/Content.Server/Labels/Label/Components/LabelComponent.cs b/Content.Server/Labels/Label/Components/LabelComponent.cs
deleted file mode 100644 (file)
index a23acc5..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-namespace Content.Server.Labels.Components
-{
-    /// <summary>
-    /// Makes entities have a label in their name. Labels are normally given by <see cref="HandLabelerComponent"/>
-    /// </summary>
-    [RegisterComponent]
-    public sealed partial class LabelComponent : Component
-    {
-        /// <summary>
-        /// Current text on the label. If set before map init, during map init this string will be localized.
-        /// This permits localized preset labels with fallback to the text written on the label.
-        /// </summary>
-        [ViewVariables(VVAccess.ReadWrite)]
-        [DataField("currentLabel")]
-        public string? CurrentLabel { get; set; }
-
-        /// <summary>
-        ///  The original name of the entity
-        ///  Used for reverting the modified entity name when the label is removed
-        /// </summary>
-        [DataField("originalName")]
-        public string? OriginalName { get; set; }
-    }
-}
index 69b4b47f4cdbfc4dfb0f5bb949ec5bd338956758..59a1a3b213401d791af74f23444b3281c8c04e04 100644 (file)
@@ -3,10 +3,10 @@ using Content.Server.Paper;
 using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Examine;
 using Content.Shared.Labels;
+using Content.Shared.Labels.Components;
+using Content.Shared.Labels.EntitySystems;
 using JetBrains.Annotations;
-using Robust.Server.GameObjects;
 using Robust.Shared.Containers;
-using Robust.Shared.Utility;
 
 namespace Content.Server.Labels
 {
@@ -14,7 +14,7 @@ namespace Content.Server.Labels
     /// A system that lets players see the contents of a label on an object.
     /// </summary>
     [UsedImplicitly]
-    public sealed class LabelSystem : EntitySystem
+    public sealed class LabelSystem : SharedLabelSystem
     {
         [Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
         [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
@@ -26,7 +26,6 @@ namespace Content.Server.Labels
         {
             base.Initialize();
 
-            SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
             SubscribeLocalEvent<LabelComponent, MapInitEvent>(OnLabelCompMapInit);
             SubscribeLocalEvent<PaperLabelComponent, ComponentInit>(OnComponentInit);
             SubscribeLocalEvent<PaperLabelComponent, ComponentRemove>(OnComponentRemove);
@@ -38,7 +37,10 @@ namespace Content.Server.Labels
         private void OnLabelCompMapInit(EntityUid uid, LabelComponent component, MapInitEvent args)
         {
             if (!string.IsNullOrEmpty(component.CurrentLabel))
+            {
                 component.CurrentLabel = Loc.GetString(component.CurrentLabel);
+                Dirty(uid, component);
+            }
         }
 
         /// <summary>
@@ -65,6 +67,8 @@ namespace Content.Server.Labels
                 label.CurrentLabel = null;
                 label.OriginalName = null;
 
+                Dirty(uid, label);
+
                 return;
             }
 
@@ -72,6 +76,8 @@ namespace Content.Server.Labels
             label.OriginalName ??= metadata.EntityName;
             label.CurrentLabel = text;
             _metaData.SetEntityName(uid, $"{label.OriginalName} ({text})", metadata);
+
+            Dirty(uid, label);
         }
 
         private void OnComponentInit(EntityUid uid, PaperLabelComponent component, ComponentInit args)
@@ -89,19 +95,6 @@ namespace Content.Server.Labels
             _itemSlotsSystem.RemoveItemSlot(uid, component.LabelSlot);
         }
 
-        private void OnExamine(EntityUid uid, LabelComponent? label, ExaminedEvent args)
-        {
-            if (!Resolve(uid, ref label))
-                return;
-
-            if (label.CurrentLabel == null)
-                return;
-
-            var message = new FormattedMessage();
-            message.AddText(Loc.GetString("hand-labeler-has-label", ("label", label.CurrentLabel)));
-            args.PushMessage(message);
-        }
-
         private void OnExamined(EntityUid uid, PaperLabelComponent comp, ExaminedEvent args)
         {
             if (comp.LabelSlot.Item is not {Valid: true} item)
diff --git a/Content.Shared/Labels/Components/LabelComponent.cs b/Content.Shared/Labels/Components/LabelComponent.cs
new file mode 100644 (file)
index 0000000..c0dccd3
--- /dev/null
@@ -0,0 +1,24 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Labels.Components;
+
+/// <summary>
+/// Makes entities have a label in their name. Labels are normally given by <see cref="HandLabelerComponent"/>
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class LabelComponent : Component
+{
+    /// <summary>
+    /// Current text on the label. If set before map init, during map init this string will be localized.
+    /// This permits localized preset labels with fallback to the text written on the label.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public string? CurrentLabel { get; set; }
+
+    /// <summary>
+    ///  The original name of the entity
+    ///  Used for reverting the modified entity name when the label is removed
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public string? OriginalName { get; set; }
+}
diff --git a/Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs b/Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs
new file mode 100644 (file)
index 0000000..a8239e7
--- /dev/null
@@ -0,0 +1,28 @@
+using Content.Shared.Examine;
+using Content.Shared.Labels.Components;
+using Robust.Shared.Utility;
+
+namespace Content.Shared.Labels.EntitySystems;
+
+public abstract partial class SharedLabelSystem : EntitySystem
+{
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
+    }
+
+    private void OnExamine(EntityUid uid, LabelComponent? label, ExaminedEvent args)
+    {
+        if (!Resolve(uid, ref label))
+            return;
+
+        if (label.CurrentLabel == null)
+            return;
+
+        var message = new FormattedMessage();
+        message.AddText(Loc.GetString("hand-labeler-has-label", ("label", label.CurrentLabel)));
+        args.PushMessage(message);
+    }
+}