Content PR for auto-componentstate sourcegen (#14845)

* 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
This commit is contained in:
Kara
2023-04-06 10:33:40 -07:00
committed by GitHub
parent b943d83ae1
commit 9688544e78
6 changed files with 23 additions and 64 deletions

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

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

View File

@@ -28,4 +28,5 @@
</ItemGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<Import Project="..\RobustToolbox\MSBuild\Robust.CompNetworkGenerator.targets" />
</Project>

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

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

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