Refactor serialization copying to use source generators (#19412)
This commit is contained in:
@@ -11,7 +11,7 @@ using static Content.Shared.Humanoid.HumanoidAppearanceState;
|
||||
namespace Content.Shared.Humanoid;
|
||||
|
||||
[NetworkedComponent, RegisterComponent]
|
||||
public sealed class HumanoidAppearanceComponent : Component
|
||||
public sealed partial class HumanoidAppearanceComponent : Component
|
||||
{
|
||||
[DataField("markingSet")]
|
||||
public MarkingSet MarkingSet = new();
|
||||
@@ -50,7 +50,7 @@ public sealed class HumanoidAppearanceComponent : Component
|
||||
/// The initial profile and base layers to apply to this humanoid.
|
||||
/// </summary>
|
||||
[DataField("initial", customTypeSerializer: typeof(PrototypeIdSerializer<HumanoidProfilePrototype>))]
|
||||
public string? Initial { get; }
|
||||
public string? Initial { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Skin color of this humanoid.
|
||||
@@ -85,7 +85,7 @@ public sealed class HumanoidAppearanceComponent : Component
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class HumanoidAppearanceState : ComponentState
|
||||
public sealed partial class HumanoidAppearanceState : ComponentState
|
||||
{
|
||||
public readonly MarkingSet Markings;
|
||||
public readonly HashSet<HumanoidVisualLayers> PermanentlyHidden;
|
||||
@@ -124,7 +124,7 @@ public sealed class HumanoidAppearanceState : ComponentState
|
||||
|
||||
[DataDefinition]
|
||||
[Serializable, NetSerializable]
|
||||
public readonly struct CustomBaseLayerInfo
|
||||
public readonly partial struct CustomBaseLayerInfo
|
||||
{
|
||||
public CustomBaseLayerInfo(string? id, Color? color = null)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Content.Shared.Humanoid
|
||||
{
|
||||
[DataDefinition]
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class HumanoidCharacterAppearance : ICharacterAppearance
|
||||
public sealed partial class HumanoidCharacterAppearance : ICharacterAppearance
|
||||
{
|
||||
public HumanoidCharacterAppearance(string hairStyleId,
|
||||
Color hairColor,
|
||||
@@ -29,25 +29,25 @@ namespace Content.Shared.Humanoid
|
||||
}
|
||||
|
||||
[DataField("hair")]
|
||||
public string HairStyleId { get; }
|
||||
public string HairStyleId { get; private set; }
|
||||
|
||||
[DataField("hairColor")]
|
||||
public Color HairColor { get; }
|
||||
public Color HairColor { get; private set; }
|
||||
|
||||
[DataField("facialHair")]
|
||||
public string FacialHairStyleId { get; }
|
||||
public string FacialHairStyleId { get; private set; }
|
||||
|
||||
[DataField("facialHairColor")]
|
||||
public Color FacialHairColor { get; }
|
||||
public Color FacialHairColor { get; private set; }
|
||||
|
||||
[DataField("eyeColor")]
|
||||
public Color EyeColor { get; }
|
||||
public Color EyeColor { get; private set; }
|
||||
|
||||
[DataField("skinColor")]
|
||||
public Color SkinColor { get; }
|
||||
public Color SkinColor { get; private set; }
|
||||
|
||||
[DataField("markings")]
|
||||
public List<Marking> Markings { get; }
|
||||
public List<Marking> Markings { get; private set; }
|
||||
|
||||
public HumanoidCharacterAppearance WithHairStyleName(string newName)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Content.Shared.Humanoid.Markings;
|
||||
/// <summary>
|
||||
/// Colors marking in color of first defined marking from specified category (in e.x. from Hair category)
|
||||
/// </summary>
|
||||
public sealed class CategoryColoring : LayerColoringType
|
||||
public sealed partial class CategoryColoring : LayerColoringType
|
||||
{
|
||||
[DataField("category", required: true)]
|
||||
public MarkingCategories Category;
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace Content.Shared.Humanoid.Markings;
|
||||
/// <summary>
|
||||
/// Colors layer in an eye color
|
||||
/// </summary>
|
||||
public sealed class EyeColoring : LayerColoringType
|
||||
public sealed partial class EyeColoring : LayerColoringType
|
||||
{
|
||||
public override Color? GetCleanColor(Color? skin, Color? eyes, MarkingSet markingSet)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace Content.Shared.Humanoid.Markings;
|
||||
/// <summary>
|
||||
/// Colors layer in a specified color
|
||||
/// </summary>
|
||||
public sealed class SimpleColoring : LayerColoringType
|
||||
public sealed partial class SimpleColoring : LayerColoringType
|
||||
{
|
||||
[DataField("color", required: true)]
|
||||
public Color Color = Color.White;
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace Content.Shared.Humanoid.Markings;
|
||||
/// <summary>
|
||||
/// Colors layer in a skin color
|
||||
/// </summary>
|
||||
public sealed class SkinColoring : LayerColoringType
|
||||
public sealed partial class SkinColoring : LayerColoringType
|
||||
{
|
||||
public override Color? GetCleanColor(Color? skin, Color? eyes, MarkingSet markingSet)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace Content.Shared.Humanoid.Markings;
|
||||
/// <summary>
|
||||
/// Colors layer in skin color but much darker.
|
||||
/// </summary>
|
||||
public sealed class TattooColoring : LayerColoringType
|
||||
public sealed partial class TattooColoring : LayerColoringType
|
||||
{
|
||||
public override Color? GetCleanColor(Color? skin, Color? eyes, MarkingSet markingSet)
|
||||
{
|
||||
@@ -11,7 +11,7 @@ public sealed class TattooColoring : LayerColoringType
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
var newColor = Color.ToHsv(skin.Value);
|
||||
newColor.Z = .40f;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Content.Shared.Humanoid.Markings
|
||||
{
|
||||
[DataDefinition]
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class Marking : IEquatable<Marking>, IComparable<Marking>, IComparable<string>
|
||||
public sealed partial class Marking : IEquatable<Marking>, IComparable<Marking>, IComparable<string>
|
||||
{
|
||||
[DataField("markingColor")]
|
||||
private List<Color> _markingColors = new();
|
||||
@@ -50,7 +50,7 @@ namespace Content.Shared.Humanoid.Markings
|
||||
/// ID of the marking prototype.
|
||||
/// </summary>
|
||||
[DataField("markingId", required: true)]
|
||||
public string MarkingId { get; } = default!;
|
||||
public string MarkingId { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// All colors currently on this marking.
|
||||
|
||||
@@ -3,10 +3,10 @@ using Robust.Shared.Utility;
|
||||
namespace Content.Shared.Humanoid.Markings;
|
||||
|
||||
/// <summary>
|
||||
/// Default colors for marking
|
||||
/// Default colors for marking
|
||||
/// </summary>
|
||||
[DataDefinition]
|
||||
public sealed class MarkingColors
|
||||
public sealed partial class MarkingColors
|
||||
{
|
||||
/// <summary>
|
||||
/// Coloring properties that will be used on any unspecified layer
|
||||
@@ -65,7 +65,7 @@ public static class MarkingColoring
|
||||
colors.Add(defaultColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// All specified layers must be colored separately, all unspecified must depend on default coloring
|
||||
if (prototype.Coloring.Layers.TryGetValue(name, out var layerColoring))
|
||||
{
|
||||
@@ -86,7 +86,7 @@ public static class MarkingColoring
|
||||
/// A class that defines coloring type and fallback for markings
|
||||
/// </summary>
|
||||
[DataDefinition]
|
||||
public sealed class LayerColoringDefinition
|
||||
public sealed partial class LayerColoringDefinition
|
||||
{
|
||||
[DataField("type")]
|
||||
public LayerColoringType Type = new SkinColoring();
|
||||
@@ -96,7 +96,7 @@ public sealed class LayerColoringDefinition
|
||||
/// </summary>
|
||||
[DataField("fallbackTypes")]
|
||||
public List<LayerColoringType> FallbackTypes = new() {};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Color that will be used if coloring type and fallback type will return nil
|
||||
/// </summary>
|
||||
@@ -122,13 +122,13 @@ public sealed class LayerColoringDefinition
|
||||
/// An abstract class for coloring types
|
||||
/// </summary>
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
public abstract class LayerColoringType
|
||||
public abstract partial class LayerColoringType
|
||||
{
|
||||
/// <summary>
|
||||
/// Makes output color negative
|
||||
/// </summary>
|
||||
[DataField("negative")]
|
||||
public bool Negative { get; } = false;
|
||||
public bool Negative { get; private set; } = false;
|
||||
public abstract Color? GetCleanColor(Color? skin, Color? eyes, MarkingSet markingSet);
|
||||
public Color? GetColor(Color? skin, Color? eyes, MarkingSet markingSet)
|
||||
{
|
||||
@@ -144,4 +144,4 @@ public abstract class LayerColoringType
|
||||
}
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Content.Shared.Humanoid.Markings;
|
||||
|
||||
[DataDefinition]
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class MarkingPoints
|
||||
public sealed partial class MarkingPoints
|
||||
{
|
||||
[DataField("points", required: true)]
|
||||
public int Points = 0;
|
||||
@@ -47,5 +47,5 @@ public sealed class MarkingPointsPrototype : IPrototype
|
||||
[DataField("onlyWhitelisted")] public bool OnlyWhitelisted;
|
||||
|
||||
[DataField("points", required: true)]
|
||||
public Dictionary<MarkingCategories, MarkingPoints> Points { get; } = default!;
|
||||
public Dictionary<MarkingCategories, MarkingPoints> Points { get; private set; } = default!;
|
||||
}
|
||||
|
||||
@@ -7,27 +7,27 @@ namespace Content.Shared.Humanoid.Markings
|
||||
public sealed class MarkingPrototype : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; } = "uwu";
|
||||
public string ID { get; private set; } = "uwu";
|
||||
|
||||
public string Name { get; private set; } = default!;
|
||||
|
||||
[DataField("bodyPart", required: true)]
|
||||
public HumanoidVisualLayers BodyPart { get; } = default!;
|
||||
public HumanoidVisualLayers BodyPart { get; private set; } = default!;
|
||||
|
||||
[DataField("markingCategory", required: true)]
|
||||
public MarkingCategories MarkingCategory { get; } = default!;
|
||||
|
||||
public MarkingCategories MarkingCategory { get; private set; } = default!;
|
||||
|
||||
[DataField("speciesRestriction")]
|
||||
public List<string>? SpeciesRestrictions { get; }
|
||||
public List<string>? SpeciesRestrictions { get; private set; }
|
||||
|
||||
[DataField("followSkinColor")]
|
||||
public bool FollowSkinColor { get; } = false;
|
||||
public bool FollowSkinColor { get; private set; } = false;
|
||||
|
||||
[DataField("forcedColoring")]
|
||||
public bool ForcedColoring { get; } = false;
|
||||
public bool ForcedColoring { get; private set; } = false;
|
||||
|
||||
[DataField("coloring")]
|
||||
public MarkingColors Coloring { get; } = new();
|
||||
public MarkingColors Coloring { get; private set; } = new();
|
||||
|
||||
[DataField("sprites", required: true)]
|
||||
public List<SpriteSpecifier> Sprites { get; private set; } = default!;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Content.Shared.Humanoid.Markings
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class MarkingsComponent : Component
|
||||
public sealed partial class MarkingsComponent : Component
|
||||
{
|
||||
public Dictionary<HumanoidVisualLayers, List<Marking>> ActiveMarkings = new();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Content.Shared.Humanoid.Markings;
|
||||
/// </remarks>
|
||||
[DataDefinition]
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class MarkingSet
|
||||
public sealed partial class MarkingSet
|
||||
{
|
||||
/// <summary>
|
||||
/// Every single marking in this set.
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace Content.Shared.Humanoid.Prototypes;
|
||||
public sealed class HumanoidProfilePrototype : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; } = default!;
|
||||
public string ID { get; private set; } = default!;
|
||||
|
||||
[DataField("customBaseLayers")]
|
||||
public Dictionary<HumanoidVisualLayers, CustomBaseLayerInfo> CustomBaseLayers = new();
|
||||
|
||||
[DataField("profile")]
|
||||
public HumanoidCharacterProfile Profile { get; } = new();
|
||||
public HumanoidCharacterProfile Profile { get; private set; } = new();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Content.Shared.Humanoid.Prototypes;
|
||||
public sealed class HumanoidSpeciesBaseSpritesPrototype : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; } = default!;
|
||||
public string ID { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Sprites that this species will use on the given humanoid
|
||||
@@ -33,7 +33,7 @@ public sealed class HumanoidSpeciesBaseSpritesPrototype : IPrototype
|
||||
public sealed class HumanoidSpeciesSpriteLayer : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; } = default!;
|
||||
public string ID { get; private set; } = default!;
|
||||
/// <summary>
|
||||
/// The base sprite for this sprite layer. This is what
|
||||
/// will replace the empty layer tagged by the enum
|
||||
@@ -43,7 +43,7 @@ public sealed class HumanoidSpeciesSpriteLayer : IPrototype
|
||||
/// layer will be invisible until otherwise set.
|
||||
/// </summary>
|
||||
[DataField("baseSprite")]
|
||||
public SpriteSpecifier? BaseSprite { get; }
|
||||
public SpriteSpecifier? BaseSprite { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The alpha of this layer. Ensures that
|
||||
@@ -51,20 +51,20 @@ public sealed class HumanoidSpeciesSpriteLayer : IPrototype
|
||||
/// of alpha.
|
||||
/// </summary>
|
||||
[DataField("layerAlpha")]
|
||||
public float LayerAlpha { get; } = 1.0f;
|
||||
public float LayerAlpha { get; private set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// If this sprite layer should allow markings or not.
|
||||
/// </summary>
|
||||
[DataField("allowsMarkings")]
|
||||
public bool AllowsMarkings { get; } = true;
|
||||
public bool AllowsMarkings { get; private set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// If this layer should always match the
|
||||
/// skin tone in a character profile.
|
||||
/// </summary>
|
||||
[DataField("matchSkin")]
|
||||
public bool MatchSkin { get; } = true;
|
||||
public bool MatchSkin { get; private set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// If any markings that go on this layer should
|
||||
@@ -72,5 +72,5 @@ public sealed class HumanoidSpeciesSpriteLayer : IPrototype
|
||||
/// alpha.
|
||||
/// </summary>
|
||||
[DataField("markingsMatchSkin")]
|
||||
public bool MarkingsMatchSkin { get; }
|
||||
public bool MarkingsMatchSkin { get; private set; }
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@ public sealed class RandomHumanoidSettingsPrototype : IPrototype, IInheritingPro
|
||||
/// Whether the humanoid's name should take from the randomized profile or not.
|
||||
/// </summary>
|
||||
[DataField("randomizeName")]
|
||||
public bool RandomizeName { get; } = true;
|
||||
public bool RandomizeName { get; private set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Species that will be ignored by the randomizer.
|
||||
/// </summary>
|
||||
[DataField("speciesBlacklist")]
|
||||
public HashSet<string> SpeciesBlacklist { get; } = new();
|
||||
public HashSet<string> SpeciesBlacklist { get; private set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Extra components to add to this entity.
|
||||
/// </summary>
|
||||
[DataField("components")]
|
||||
public ComponentRegistry? Components { get; }
|
||||
public ComponentRegistry? Components { get; private set; }
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ public sealed class SpeciesPrototype : IPrototype
|
||||
/// Prototype ID of the species.
|
||||
/// </summary>
|
||||
[IdDataField]
|
||||
public string ID { get; } = default!;
|
||||
public string ID { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// User visible name of the species.
|
||||
/// </summary>
|
||||
[DataField("name", required: true)]
|
||||
public string Name { get; } = default!;
|
||||
public string Name { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Descriptor. Unused...? This is intended
|
||||
@@ -24,13 +24,13 @@ public sealed class SpeciesPrototype : IPrototype
|
||||
/// (i.e., young human person, young lizard person, etc.)
|
||||
/// </summary>
|
||||
[DataField("descriptor")]
|
||||
public string Descriptor { get; } = "humanoid";
|
||||
public string Descriptor { get; private set; } = "humanoid";
|
||||
|
||||
/// <summary>
|
||||
/// Whether the species is available "at round start" (In the character editor)
|
||||
/// </summary>
|
||||
[DataField("roundStart", required: true)]
|
||||
public bool RoundStart { get; } = false;
|
||||
public bool RoundStart { get; private set; } = false;
|
||||
|
||||
// The below two are to avoid fetching information about the species from the entity
|
||||
// prototype.
|
||||
@@ -42,59 +42,59 @@ public sealed class SpeciesPrototype : IPrototype
|
||||
// sprite accessories.
|
||||
|
||||
[DataField("sprites")]
|
||||
public string SpriteSet { get; } = default!;
|
||||
public string SpriteSet { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Default skin tone for this species. This applies for non-human skin tones.
|
||||
/// </summary>
|
||||
[DataField("defaultSkinTone")]
|
||||
public Color DefaultSkinTone { get; } = Color.White;
|
||||
public Color DefaultSkinTone { get; private set; } = Color.White;
|
||||
|
||||
/// <summary>
|
||||
/// Default human skin tone for this species. This applies for human skin tones.
|
||||
/// See <see cref="SkinColor.HumanSkinTone"/> for the valid range of skin tones.
|
||||
/// </summary>
|
||||
[DataField("defaultHumanSkinTone")]
|
||||
public int DefaultHumanSkinTone { get; } = 20;
|
||||
public int DefaultHumanSkinTone { get; private set; } = 20;
|
||||
|
||||
/// <summary>
|
||||
/// The limit of body markings that you can place on this species.
|
||||
/// </summary>
|
||||
[DataField("markingLimits")]
|
||||
public string MarkingPoints { get; } = default!;
|
||||
public string MarkingPoints { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Humanoid species variant used by this entity.
|
||||
/// </summary>
|
||||
[DataField("prototype", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string Prototype { get; } = default!;
|
||||
public string Prototype { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Prototype used by the species for the dress-up doll in various menus.
|
||||
/// </summary>
|
||||
[DataField("dollPrototype", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string DollPrototype { get; } = default!;
|
||||
public string DollPrototype { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Method of skin coloration used by the species.
|
||||
/// </summary>
|
||||
[DataField("skinColoration", required: true)]
|
||||
public HumanoidSkinColor SkinColoration { get; }
|
||||
public HumanoidSkinColor SkinColoration { get; private set; }
|
||||
|
||||
[DataField("maleFirstNames")]
|
||||
public string MaleFirstNames { get; } = "names_first_male";
|
||||
public string MaleFirstNames { get; private set; } = "names_first_male";
|
||||
|
||||
[DataField("femaleFirstNames")]
|
||||
public string FemaleFirstNames { get; } = "names_first_female";
|
||||
public string FemaleFirstNames { get; private set; } = "names_first_female";
|
||||
|
||||
[DataField("lastNames")]
|
||||
public string LastNames { get; } = "names_last";
|
||||
public string LastNames { get; private set; } = "names_last";
|
||||
|
||||
[DataField("naming")]
|
||||
public SpeciesNaming Naming { get; } = SpeciesNaming.FirstLast;
|
||||
public SpeciesNaming Naming { get; private set; } = SpeciesNaming.FirstLast;
|
||||
|
||||
[DataField("sexes")]
|
||||
public List<Sex> Sexes { get; } = new() { Sex.Male, Sex.Female };
|
||||
public List<Sex> Sexes { get; private set; } = new() { Sex.Male, Sex.Female };
|
||||
|
||||
/// <summary>
|
||||
/// Characters younger than this are too young to be hired by Nanotrasen.
|
||||
|
||||
Reference in New Issue
Block a user