Add prediction to hand labeler labels (#25869)

Added prediction to labels
This commit is contained in:
Tayrtahn
2024-03-05 20:33:28 -05:00
committed by GitHub
parent 907403759c
commit f4976a3288
6 changed files with 70 additions and 48 deletions

View File

@@ -0,0 +1,7 @@
using Content.Shared.Labels.EntitySystems;
namespace Content.Client.Labels;
public sealed partial class LabelSystem : SharedLabelSystem
{
}

View 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
{

View File

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

View 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)

View File

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

View File

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