Update trivial components to use auto comp states (#20539)

This commit is contained in:
DrSmugleaf
2023-09-28 16:20:29 -07:00
committed by GitHub
parent 14cfe44ece
commit a44fa86b68
158 changed files with 806 additions and 2866 deletions

View File

@@ -4,31 +4,31 @@ using Robust.Shared.Enums;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Utility;
using static Content.Shared.Humanoid.HumanoidAppearanceState;
namespace Content.Shared.Humanoid;
[NetworkedComponent, RegisterComponent]
[NetworkedComponent, RegisterComponent, AutoGenerateComponentState(true)]
public sealed partial class HumanoidAppearanceComponent : Component
{
[DataField("markingSet")]
public MarkingSet ClientOldMarkings = new();
[DataField]
public MarkingSet MarkingSet = new();
[DataField("baseLayers")]
[DataField]
public Dictionary<HumanoidVisualLayers, HumanoidSpeciesSpriteLayer> BaseLayers = new();
[DataField("permanentlyHidden")]
[DataField, AutoNetworkedField(true)]
public HashSet<HumanoidVisualLayers> PermanentlyHidden = new();
// Couldn't these be somewhere else?
[DataField("gender")]
[ViewVariables] public Gender Gender = default!;
[DataField, AutoNetworkedField]
public Gender Gender;
[DataField("age")]
[ViewVariables] public int Age = 18;
[DataField, AutoNetworkedField]
public int Age = 18;
/// <summary>
/// Any custom base layers this humanoid might have. See:
@@ -36,39 +36,39 @@ public sealed partial class HumanoidAppearanceComponent : Component
/// Stored on the server, this is merged in the client into
/// all layer settings.
/// </summary>
[DataField("customBaseLayers")]
[DataField, AutoNetworkedField(true)]
public Dictionary<HumanoidVisualLayers, CustomBaseLayerInfo> CustomBaseLayers = new();
/// <summary>
/// Current species. Dictates things like base body sprites,
/// base humanoid to spawn, etc.
/// </summary>
[DataField("species", customTypeSerializer: typeof(PrototypeIdSerializer<SpeciesPrototype>), required: true)]
public string Species { get; set; } = default!;
[DataField(required: true), AutoNetworkedField]
public ProtoId<SpeciesPrototype> Species { get; set; }
/// <summary>
/// The initial profile and base layers to apply to this humanoid.
/// </summary>
[DataField("initial", customTypeSerializer: typeof(PrototypeIdSerializer<HumanoidProfilePrototype>))]
public string? Initial { get; private set; }
[DataField]
public ProtoId<HumanoidProfilePrototype>? Initial { get; private set; }
/// <summary>
/// Skin color of this humanoid.
/// </summary>
[DataField("skinColor")]
[DataField, AutoNetworkedField]
public Color SkinColor { get; set; } = Color.FromHex("#C0967F");
/// <summary>
/// Visual layers currently hidden. This will affect the base sprite
/// on this humanoid layer, and any markings that sit above it.
/// </summary>
[DataField("hiddenLayers")]
[DataField, AutoNetworkedField(true)]
public HashSet<HumanoidVisualLayers> HiddenLayers = new();
[DataField("sex")]
[DataField, AutoNetworkedField]
public Sex Sex = Sex.Male;
[DataField("eyeColor")]
[DataField, AutoNetworkedField]
public Color EyeColor = Color.Brown;
/// <summary>
@@ -84,65 +84,26 @@ public sealed partial class HumanoidAppearanceComponent : Component
public Color? CachedFacialHairColor;
}
[DataDefinition]
[Serializable, NetSerializable]
public sealed partial class HumanoidAppearanceState : ComponentState
public readonly partial struct CustomBaseLayerInfo
{
public readonly MarkingSet Markings;
public readonly HashSet<HumanoidVisualLayers> PermanentlyHidden;
public readonly HashSet<HumanoidVisualLayers> HiddenLayers;
public readonly Dictionary<HumanoidVisualLayers, CustomBaseLayerInfo> CustomBaseLayers;
public readonly Sex Sex;
public readonly Gender Gender;
public readonly int Age = 18;
public readonly string Species;
public readonly Color SkinColor;
public readonly Color EyeColor;
public HumanoidAppearanceState(
MarkingSet currentMarkings,
HashSet<HumanoidVisualLayers> permanentlyHidden,
HashSet<HumanoidVisualLayers> hiddenLayers,
Dictionary<HumanoidVisualLayers, CustomBaseLayerInfo> customBaseLayers,
Sex sex,
Gender gender,
int age,
string species,
Color skinColor,
Color eyeColor)
public CustomBaseLayerInfo(string? id, Color? color = null)
{
Markings = currentMarkings;
PermanentlyHidden = permanentlyHidden;
HiddenLayers = hiddenLayers;
CustomBaseLayers = customBaseLayers;
Sex = sex;
Gender = gender;
Age = age;
Species = species;
SkinColor = skinColor;
EyeColor = eyeColor;
DebugTools.Assert(id == null || IoCManager.Resolve<IPrototypeManager>().HasIndex<HumanoidSpeciesSpriteLayer>(id));
Id = id;
Color = color;
}
[DataDefinition]
[Serializable, NetSerializable]
public readonly partial struct CustomBaseLayerInfo
{
public CustomBaseLayerInfo(string? id, Color? color = null)
{
DebugTools.Assert(id == null || IoCManager.Resolve<IPrototypeManager>().HasIndex<HumanoidSpeciesSpriteLayer>(id));
ID = id;
Color = color;
}
/// <summary>
/// ID of this custom base layer. Must be a <see cref="HumanoidSpeciesSpriteLayer"/>.
/// </summary>
[DataField]
public ProtoId<HumanoidSpeciesSpriteLayer>? Id { get; init; }
/// <summary>
/// ID of this custom base layer. Must be a <see cref="HumanoidSpeciesSpriteLayer"/>.
/// </summary>
[DataField("id", customTypeSerializer: typeof(PrototypeIdSerializer<HumanoidSpeciesSpriteLayer>))]
public string? ID { init; get; }
/// <summary>
/// Color of this custom base layer. Null implies skin colour if the corresponding <see cref="HumanoidSpeciesSpriteLayer"/> is set to match skin.
/// </summary>
[DataField("color")]
public Color? Color { init; get; }
}
/// <summary>
/// Color of this custom base layer. Null implies skin colour if the corresponding <see cref="HumanoidSpeciesSpriteLayer"/> is set to match skin.
/// </summary>
[DataField]
public Color? Color { get; init; }
}

View File

@@ -1,6 +1,5 @@
using Content.Shared.Preferences;
using Robust.Shared.Prototypes;
using static Content.Shared.Humanoid.HumanoidAppearanceState;
namespace Content.Shared.Humanoid.Prototypes;

View File

@@ -1,11 +1,10 @@
using System.Linq;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using System.Linq;
using Content.Shared.Preferences;
using Robust.Shared.GameObjects.Components.Localization;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
namespace Content.Shared.Humanoid;
@@ -31,7 +30,6 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem
{
base.Initialize();
SubscribeLocalEvent<HumanoidAppearanceComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<HumanoidAppearanceComponent, ComponentGetState>(OnGetState);
}
private void OnInit(EntityUid uid, HumanoidAppearanceComponent humanoid, ComponentInit args)
@@ -57,20 +55,6 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem
LoadProfile(uid, startingSet.Profile, humanoid);
}
private void OnGetState(EntityUid uid, HumanoidAppearanceComponent component, ref ComponentGetState args)
{
args.State = new HumanoidAppearanceState(component.MarkingSet,
component.PermanentlyHidden,
component.HiddenLayers,
component.CustomBaseLayers,
component.Sex,
component.Gender,
component.Age,
component.Species,
component.SkinColor,
component.EyeColor);
}
/// <summary>
/// Toggles a humanoid's sprite layer visibility.
/// </summary>
@@ -211,7 +195,7 @@ public abstract class SharedHumanoidAppearanceSystem : EntitySystem
return;
if (humanoid.CustomBaseLayers.TryGetValue(layer, out var info))
humanoid.CustomBaseLayers[layer] = info with { ID = id };
humanoid.CustomBaseLayers[layer] = info with { Id = id };
else
humanoid.CustomBaseLayers[layer] = new(id);

View File

@@ -1,6 +1,5 @@
using Content.Shared.Humanoid.Markings;
using Robust.Shared.Serialization;
using static Content.Shared.Humanoid.HumanoidAppearanceState;
namespace Content.Shared.Humanoid;