]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Content PR for auto-componentstate sourcegen (#14845)
authorKara <lunarautomaton6@gmail.com>
Thu, 6 Apr 2023 17:33:40 +0000 (10:33 -0700)
committerGitHub <noreply@github.com>
Thu, 6 Apr 2023 17:33:40 +0000 (12:33 -0500)
* Content PR for auto-componentstate sourcegen

# Conflicts:
# Content.Shared/Chat/TypingIndicator/TypingIndicatorComponent.cs
# Content.Shared/Content.Shared.csproj
# SpaceStation14.sln

* shared file too

* afterautohandlestate example

* oops

* anudda

* access fixed

* smart

Content.Shared/Access/Components/IdCardComponent.cs
Content.Shared/Access/Systems/SharedIdCardSystem.cs
Content.Shared/Content.Shared.csproj
Content.Shared/Parallax/Biomes/BiomeComponent.cs
Content.Shared/Parallax/Biomes/SharedBiomeSystem.cs
SpaceStation14.sln

index 06dc11b0917bcad5f52b25e6da29483e177b4333..5c11fef78a73dd10ade1dfbd23e9581e98526c53 100644 (file)
@@ -6,28 +6,18 @@ using Robust.Shared.Serialization;
 namespace Content.Shared.Access.Components
 {
     [RegisterComponent, NetworkedComponent]
+    [AutoGenerateComponentState]
     [Access(typeof(SharedIdCardSystem), typeof(SharedPDASystem), typeof(SharedAgentIdCardSystem))]
-    public sealed class IdCardComponent : Component
+    public sealed partial class IdCardComponent : Component
     {
         [DataField("fullName")]
+        [AutoNetworkedField]
         [Access(typeof(SharedIdCardSystem), typeof(SharedPDASystem), typeof(SharedAgentIdCardSystem),
             Other = AccessPermissions.ReadWrite)] // FIXME Friends
         public string? FullName;
 
         [DataField("jobTitle")]
+        [AutoNetworkedField]
         public string? JobTitle;
     }
-
-    [Serializable, NetSerializable]
-    public sealed class IdCardComponentState : ComponentState
-    {
-        public string? FullName;
-        public string? JobTitle;
-
-        public IdCardComponentState(string? fullName, string? jobTitle)
-        {
-            FullName = fullName;
-            JobTitle = jobTitle;
-        }
-    }
 }
index 52b8cc4358cf476b3e3fe8a7ab24f682e83c0c01..dcc5af8bc7b19d94277f740eaf5de8c041eda994 100644 (file)
@@ -11,28 +11,6 @@ public abstract class SharedIdCardSystem : EntitySystem
 {
     [Dependency] private readonly InventorySystem _inventorySystem = default!;
 
-    public override void Initialize()
-    {
-        base.Initialize();
-
-        SubscribeLocalEvent<IdCardComponent, ComponentGetState>(OnComponentGetState);
-        SubscribeLocalEvent<IdCardComponent, ComponentHandleState>(OnComponentHandleState);
-    }
-
-    private void OnComponentGetState(EntityUid uid, IdCardComponent component, ref ComponentGetState args)
-    {
-        args.State = new IdCardComponentState(component.FullName, component.JobTitle);
-    }
-
-    private void OnComponentHandleState(EntityUid uid, IdCardComponent component, ref ComponentHandleState args)
-    {
-        if (args.Current is IdCardComponentState state)
-        {
-            component.FullName = state.FullName;
-            component.JobTitle = state.JobTitle;
-        }
-    }
-
     /// <summary>
     ///     Attempt to find an ID card on an entity. This will look in the entity itself, in the entity's hands, and
     ///     in the entity's inventory.
index c15aecd9628613c644a03247a11fa676d5dcbabe..f9ecb7fb14913428c87a03cb55b85cf011c997f7 100644 (file)
@@ -28,4 +28,5 @@
   </ItemGroup>
 
   <Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
+  <Import Project="..\RobustToolbox\MSBuild\Robust.CompNetworkGenerator.targets" />
 </Project>
index ce9ac6c351b95aeb3e74bc110c6fdb5437f1d8c4..ac960f5ce7a41723ab4a610bbd14b3222660c169 100644 (file)
@@ -4,16 +4,18 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
 
 namespace Content.Shared.Parallax.Biomes;
 
-[RegisterComponent, NetworkedComponent]
-public sealed class BiomeComponent : Component
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
+public sealed partial class BiomeComponent : Component
 {
     public FastNoiseLite Noise = new();
 
     [ViewVariables(VVAccess.ReadWrite), DataField("seed")]
+    [AutoNetworkedField]
     public int Seed;
 
     [ViewVariables(VVAccess.ReadWrite),
      DataField("prototype", customTypeSerializer: typeof(PrototypeIdSerializer<BiomePrototype>))]
+    [AutoNetworkedField]
     public string BiomePrototype = "Grasslands";
 
     // TODO: Need to flag tiles as not requiring custom data anymore, e.g. if we spawn an ent and don't unspawn it.
index f15286849a210fcd36d8a359ac090799f231e463..1e34e63cda5135d564e9432ed45a36e6dd8374be 100644 (file)
@@ -20,25 +20,14 @@ public abstract class SharedBiomeSystem : EntitySystem
     public override void Initialize()
     {
         base.Initialize();
-        SubscribeLocalEvent<BiomeComponent, ComponentGetState>(OnBiomeGetState);
-        SubscribeLocalEvent<BiomeComponent, ComponentHandleState>(OnBiomeHandleState);
+        SubscribeLocalEvent<BiomeComponent, AfterAutoHandleStateEvent>(OnBiomeAfterHandleState);
     }
 
-    private void OnBiomeHandleState(EntityUid uid, BiomeComponent component, ref ComponentHandleState args)
+    private void OnBiomeAfterHandleState(EntityUid uid, BiomeComponent component, ref AfterAutoHandleStateEvent args)
     {
-        if (args.Current is not BiomeComponentState state)
-            return;
-
-        component.Seed = state.Seed;
-        component.BiomePrototype = state.Prototype;
         component.Noise.SetSeed(component.Seed);
     }
 
-    private void OnBiomeGetState(EntityUid uid, BiomeComponent component, ref ComponentGetState args)
-    {
-        args.State = new BiomeComponentState(component.Seed, component.BiomePrototype);
-    }
-
     protected T Pick<T>(List<T> collection, float value)
     {
         DebugTools.Assert(value is >= 0f and <= 1f);
@@ -317,17 +306,4 @@ public abstract class SharedBiomeSystem : EntitySystem
 
         // Domain warps require separate noise
     }
-
-    [Serializable, NetSerializable]
-    private sealed class BiomeComponentState : ComponentState
-    {
-        public int Seed;
-        public string Prototype;
-
-        public BiomeComponentState(int seed, string prototype)
-        {
-            Seed = seed;
-            Prototype = prototype;
-        }
-    }
 }
index 1515cf820a001dac293d2f7c0252c9a19d98b03e..6b71fcce0feb2eda5b245830e3c152aaf56e7003 100644 (file)
@@ -56,6 +56,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MSBuild", "MSBuild", "{5040
                RobustToolbox\MSBuild\Robust.Trimming.targets = RobustToolbox\MSBuild\Robust.Trimming.targets
                RobustToolbox\MSBuild\Robust.Platform.props = RobustToolbox\MSBuild\Robust.Platform.props
                RobustToolbox\MSBuild\Robust.Configurations.props = RobustToolbox\MSBuild\Robust.Configurations.props
+               RobustToolbox\MSBuild\Robust.CompNetworkGenerator.targets = RobustToolbox\MSBuild\Robust.CompNetworkGenerator.targets
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{806ED41A-411B-4B3B-BEB6-DEC6DCA4C205}"
@@ -120,6 +121,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project Files", "Project Fi
                RobustToolbox\RELEASE-NOTES.md = RobustToolbox\RELEASE-NOTES.md
        EndProjectSection
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robust.Shared.CompNetworkGenerator", "RobustToolbox\Robust.Shared.CompNetworkGenerator\Robust.Shared.CompNetworkGenerator.csproj", "{07CA34A1-1D37-4771-A2E3-495A1044AE0B}"
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
@@ -399,6 +402,14 @@ Global
                {424445D4-F5D9-4CA9-A435-0A36E8AA28F3}.DebugOpt|Any CPU.Build.0 = DebugOpt|Any CPU
                {424445D4-F5D9-4CA9-A435-0A36E8AA28F3}.Tools|Any CPU.ActiveCfg = Tools|Any CPU
                {424445D4-F5D9-4CA9-A435-0A36E8AA28F3}.Tools|Any CPU.Build.0 = Tools|Any CPU
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B}.Release|Any CPU.Build.0 = Release|Any CPU
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B}.DebugOpt|Any CPU.ActiveCfg = DebugOpt|Any CPU
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B}.DebugOpt|Any CPU.Build.0 = DebugOpt|Any CPU
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B}.Tools|Any CPU.ActiveCfg = Tools|Any CPU
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B}.Tools|Any CPU.Build.0 = Tools|Any CPU
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
@@ -428,6 +439,7 @@ Global
                {8A21C7CA-2EB8-40E5-8043-33582C06D139} = {83B4CBBA-547A-42F0-A7CD-8A67D93196CE}
                {952AAF2A-DF63-4A7D-8094-3453893EBA80} = {83B4CBBA-547A-42F0-A7CD-8A67D93196CE}
                {A965CB3B-FD31-44AF-8872-85ABA436098D} = {83B4CBBA-547A-42F0-A7CD-8A67D93196CE}
+               {07CA34A1-1D37-4771-A2E3-495A1044AE0B} = {83B4CBBA-547A-42F0-A7CD-8A67D93196CE}
        EndGlobalSection
        GlobalSection(ExtensibilityGlobals) = postSolution
                SolutionGuid = {AA37ED9F-F8D6-468E-A101-658AD605B09A}