]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Update dice state handling (#23643)
authorTrevor Day <tday93@users.noreply.github.com>
Sun, 7 Jan 2024 01:30:21 +0000 (17:30 -0800)
committerGitHub <noreply@github.com>
Sun, 7 Jan 2024 01:30:21 +0000 (17:30 -0800)
* Auto generate dice component state handling, and update data field annotations

* Missed one.

Content.Shared/Dice/DiceComponent.cs
Content.Shared/Dice/SharedDiceSystem.cs

index e2e23890a41e2574de809b9a7140ffa22902c6e9..c01ad3c451886ecdef3aed571569f3facfb4540c 100644 (file)
@@ -5,40 +5,33 @@ using Robust.Shared.Serialization;
 namespace Content.Shared.Dice;
 
 [RegisterComponent, NetworkedComponent, Access(typeof(SharedDiceSystem))]
+[AutoGenerateComponentState(true)]
 public sealed partial class DiceComponent : Component
 {
-    [DataField("sound")]
+    [DataField]
     public SoundSpecifier Sound { get; private set; } = new SoundCollectionSpecifier("Dice");
 
     /// <summary>
     ///     Multiplier for the value  of a die. Applied after the <see cref="Offset"/>.
     /// </summary>
-    [DataField("multiplier")]
+    [DataField]
     public int Multiplier { get; private set; } = 1;
 
     /// <summary>
     ///     Quantity that is subtracted from the value of a die. Can be used to make dice that start at "0". Applied
     ///     before the <see cref="Multiplier"/>
     /// </summary>
-    [DataField("offset")]
+    [DataField]
     public int Offset { get; private set; } = 0;
 
-    [DataField("sides")]
+    [DataField]
     public int Sides { get; private set; } = 20;
 
     /// <summary>
     ///     The currently displayed value.
     /// </summary>
-    [DataField("currentValue")]
+    [DataField]
+    [AutoNetworkedField]
     public int CurrentValue { get; set; } = 20;
 
-    [Serializable, NetSerializable]
-    public sealed class DiceState : ComponentState
-    {
-        public readonly int CurrentValue;
-        public DiceState(int value)
-        {
-            CurrentValue = value;
-        }
-    }
 }
index be3c912fb54c00b17da8a17abd7cae7606245381..defb3d5f0e3ec18abbe0d18ab5ab93cef0a1c30b 100644 (file)
@@ -14,23 +14,14 @@ public abstract class SharedDiceSystem : EntitySystem
         SubscribeLocalEvent<DiceComponent, UseInHandEvent>(OnUseInHand);
         SubscribeLocalEvent<DiceComponent, LandEvent>(OnLand);
         SubscribeLocalEvent<DiceComponent, ExaminedEvent>(OnExamined);
-        SubscribeLocalEvent<DiceComponent, ComponentGetState>(OnGetState);
-        SubscribeLocalEvent<DiceComponent, ComponentHandleState>(OnHandleState);
+        SubscribeLocalEvent<DiceComponent, AfterAutoHandleStateEvent>(OnDiceAfterHandleState);
     }
 
-    private void OnHandleState(EntityUid uid, DiceComponent component, ref ComponentHandleState args)
+    private void OnDiceAfterHandleState(EntityUid uid, DiceComponent component, ref AfterAutoHandleStateEvent args)
     {
-        if (args.Current is DiceComponent.DiceState state)
-            component.CurrentValue = state.CurrentValue;
-
         UpdateVisuals(uid, component);
     }
 
-    private void OnGetState(EntityUid uid, DiceComponent component, ref ComponentGetState args)
-    {
-        args.State = new DiceComponent.DiceState(component.CurrentValue);
-    }
-
     private void OnUseInHand(EntityUid uid, DiceComponent component, UseInHandEvent args)
     {
         if (args.Handled)