Moves HumanoidAppearanceComponent to ECS (#4855)
* Moves HumanoidCharacterAppearance to ECS * Makes HumanoidAppearanceSystem work over networks * Makes HumanoidAppearanceSystem more efficient * Cleans up the files * Updates privacy on a couple of functions * Fixes a few using references, renames a file * Makes HumanoidAppearanceSystem more cleaner * Fixes Magic Mirror * Cleanup * HumanoidAppearanceComponent now has a friend SharedHumanoidAppearanceSystem is only allowed to act on this, now * Fixes the Body-HumanoidAppearance ECS scaffolding * a little cleanup never hurt anybody * quick fix for magic mirror appearance access * Replaces a networked event with a local one This one was... causing bugs
This commit is contained in:
@@ -8,6 +8,7 @@ using Content.Shared.Body.Part.Property;
|
||||
using Content.Shared.Body.Preset;
|
||||
using Content.Shared.Body.Slot;
|
||||
using Content.Shared.Body.Template;
|
||||
using Content.Shared.CharacterAppearance.Systems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.Movement.Components;
|
||||
@@ -151,6 +152,7 @@ namespace Content.Shared.Body.Components
|
||||
|
||||
var argsAdded = new BodyPartAddedEventArgs(slot.Id, part);
|
||||
|
||||
EntitySystem.Get<SharedHumanoidAppearanceSystem>().BodyPartAdded(Owner.Uid, argsAdded);
|
||||
foreach (var component in Owner.GetAllComponents<IBodyPartAdded>().ToArray())
|
||||
{
|
||||
component.BodyPartAdded(argsAdded);
|
||||
@@ -177,6 +179,8 @@ namespace Content.Shared.Body.Components
|
||||
|
||||
var args = new BodyPartRemovedEventArgs(slot.Id, part);
|
||||
|
||||
|
||||
EntitySystem.Get<SharedHumanoidAppearanceSystem>().BodyPartRemoved(Owner.Uid, args);
|
||||
foreach (var component in Owner.GetAllComponents<IBodyPartRemoved>())
|
||||
{
|
||||
component.BodyPartRemoved(args);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Body.Part
|
||||
{
|
||||
@@ -17,6 +18,8 @@ namespace Content.Shared.Body.Part
|
||||
void BodyPartAdded(BodyPartAddedEventArgs args);
|
||||
}
|
||||
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class BodyPartAddedEventArgs : EventArgs
|
||||
{
|
||||
public BodyPartAddedEventArgs(string slot, SharedBodyPartComponent part)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Body.Part
|
||||
{
|
||||
@@ -16,6 +17,7 @@ namespace Content.Shared.Body.Part
|
||||
void BodyPartRemoved(BodyPartRemovedEventArgs args);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class BodyPartRemovedEventArgs : EventArgs
|
||||
{
|
||||
public BodyPartRemovedEventArgs(string slot, SharedBodyPartComponent part)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Content.Shared.CharacterAppearance;
|
||||
using Content.Shared.CharacterAppearance.Systems;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.CharacterAppearance.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[Friend(typeof(SharedHumanoidAppearanceSystem), typeof(SharedMagicMirrorComponent))]
|
||||
[NetworkedComponent]
|
||||
public class HumanoidAppearanceComponent : Component
|
||||
{
|
||||
public override string Name => "HumanoidAppearance";
|
||||
|
||||
[ViewVariables]
|
||||
public HumanoidCharacterAppearance Appearance { get; set; } = HumanoidCharacterAppearance.Default();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Sex Sex { get; set; } = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Gender Gender { get; set; } = default!;
|
||||
|
||||
[DataField("categoriesHair")]
|
||||
[ViewVariables]
|
||||
public SpriteAccessoryCategories CategoriesHair { get; set; } = SpriteAccessoryCategories.HumanHair;
|
||||
|
||||
[DataField("categoriesFacialHair")]
|
||||
[ViewVariables]
|
||||
public SpriteAccessoryCategories CategoriesFacialHair { get; set; } = SpriteAccessoryCategories.HumanFacialHair;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("canColorHair")]
|
||||
public bool CanColorHair { get; set; } = true;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("canColorFacialHair")]
|
||||
public bool CanColorFacialHair { get; set; } = true;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class HumanoidAppearanceComponentState : ComponentState
|
||||
{
|
||||
public HumanoidCharacterAppearance Appearance { get; }
|
||||
public Sex Sex { get; }
|
||||
public Gender Gender { get; }
|
||||
|
||||
public HumanoidAppearanceComponentState(HumanoidCharacterAppearance appearance,
|
||||
Sex sex,
|
||||
Gender gender)
|
||||
{
|
||||
Appearance = appearance;
|
||||
Sex = sex;
|
||||
Gender = gender;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
using System;
|
||||
using Content.Shared.Preferences;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Localization;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.CharacterAppearance.Components
|
||||
{
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedHumanoidAppearanceComponent : Component
|
||||
{
|
||||
private HumanoidCharacterAppearance _appearance = HumanoidCharacterAppearance.Default();
|
||||
private Sex _sex;
|
||||
private Gender _gender;
|
||||
|
||||
public sealed override string Name => "HumanoidAppearance";
|
||||
|
||||
[DataField("categoriesHair")]
|
||||
[ViewVariables]
|
||||
public SpriteAccessoryCategories CategoriesHair { get; set; } = SpriteAccessoryCategories.HumanHair;
|
||||
|
||||
[DataField("categoriesFacialHair")]
|
||||
[ViewVariables]
|
||||
public SpriteAccessoryCategories CategoriesFacialHair { get; set; } = SpriteAccessoryCategories.HumanFacialHair;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("canColorHair")]
|
||||
public bool CanColorHair { get; set; } = true;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("canColorFacialHair")]
|
||||
public bool CanColorFacialHair { get; set; } = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual HumanoidCharacterAppearance Appearance
|
||||
{
|
||||
get => _appearance;
|
||||
set
|
||||
{
|
||||
_appearance = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual Sex Sex
|
||||
{
|
||||
get => _sex;
|
||||
set
|
||||
{
|
||||
_sex = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public virtual Gender Gender
|
||||
{
|
||||
get => _gender;
|
||||
set
|
||||
{
|
||||
_gender = value;
|
||||
|
||||
if (Owner.TryGetComponent(out GrammarComponent? g))
|
||||
{
|
||||
g.Gender = value;
|
||||
}
|
||||
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new HumanoidAppearanceComponentState(Appearance, Sex, Gender);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not HumanoidAppearanceComponentState cast)
|
||||
return;
|
||||
|
||||
Appearance = cast.Appearance;
|
||||
Sex = cast.Sex;
|
||||
Gender = cast.Gender;
|
||||
}
|
||||
|
||||
public void UpdateFromProfile(ICharacterProfile profile)
|
||||
{
|
||||
var humanoid = (HumanoidCharacterProfile) profile;
|
||||
Appearance = (HumanoidCharacterAppearance) humanoid.CharacterAppearance;
|
||||
Sex = humanoid.Sex;
|
||||
Gender = humanoid.Gender;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[NetSerializable]
|
||||
private sealed class HumanoidAppearanceComponentState : ComponentState
|
||||
{
|
||||
public HumanoidAppearanceComponentState(HumanoidCharacterAppearance appearance, Sex sex, Gender gender)
|
||||
{
|
||||
Appearance = appearance;
|
||||
Sex = sex;
|
||||
Gender = gender;
|
||||
}
|
||||
|
||||
public HumanoidCharacterAppearance Appearance { get; }
|
||||
public Sex Sex { get; }
|
||||
public Gender Gender { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.CharacterAppearance.Components;
|
||||
using Content.Shared.Preferences;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.CharacterAppearance.Systems
|
||||
{
|
||||
public abstract class SharedHumanoidAppearanceSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<HumanoidAppearanceComponent, ComponentGetState>(OnAppearanceGetState);
|
||||
SubscribeLocalEvent<HumanoidAppearanceComponent, ComponentHandleState>(OnAppearanceHandleState);
|
||||
}
|
||||
|
||||
public void UpdateFromProfile(EntityUid uid, ICharacterProfile profile)
|
||||
{
|
||||
var humanoid = (HumanoidCharacterProfile) profile;
|
||||
UpdateAppearance(uid, humanoid.Appearance, humanoid.Sex, humanoid.Gender);
|
||||
}
|
||||
|
||||
// The magic mirror otherwise wouldn't work. (it directly modifies the component server-side)
|
||||
public void ForceAppearanceUpdate(EntityUid uid, HumanoidAppearanceComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component)) return;
|
||||
component.Dirty();
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, HumanoidCharacterAppearance appearance, Sex sex, Gender gender, HumanoidAppearanceComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component)) return;
|
||||
|
||||
component.Appearance = appearance;
|
||||
component.Sex = sex;
|
||||
component.Gender = gender;
|
||||
|
||||
component.Dirty();
|
||||
|
||||
RaiseLocalEvent(uid, new ChangedHumanoidAppearanceEvent(appearance, sex, gender));
|
||||
}
|
||||
|
||||
private void OnAppearanceGetState(EntityUid uid, HumanoidAppearanceComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new HumanoidAppearanceComponentState(component.Appearance, component.Sex, component.Gender);
|
||||
}
|
||||
|
||||
private void OnAppearanceHandleState(EntityUid uid, HumanoidAppearanceComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not HumanoidAppearanceComponentState state)
|
||||
return;
|
||||
|
||||
UpdateAppearance(uid, state.Appearance, state.Sex, state.Gender);
|
||||
}
|
||||
|
||||
// Scaffolding until Body is moved to ECS.
|
||||
public void BodyPartAdded(EntityUid uid, BodyPartAddedEventArgs args)
|
||||
{
|
||||
RaiseLocalEvent(new HumanoidAppearanceBodyPartAddedEvent(uid, args));
|
||||
}
|
||||
|
||||
public void BodyPartRemoved(EntityUid uid, BodyPartRemovedEventArgs args)
|
||||
{
|
||||
RaiseLocalEvent(new HumanoidAppearanceBodyPartRemovedEvent(uid, args));
|
||||
}
|
||||
|
||||
// Scaffolding until Body is moved to ECS.
|
||||
[Serializable, NetSerializable]
|
||||
public class HumanoidAppearanceBodyPartAddedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Uid { get; }
|
||||
public BodyPartAddedEventArgs Args { get; }
|
||||
|
||||
public HumanoidAppearanceBodyPartAddedEvent(EntityUid uid, BodyPartAddedEventArgs args)
|
||||
{
|
||||
Uid = uid;
|
||||
Args = args;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class HumanoidAppearanceBodyPartRemovedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Uid { get; }
|
||||
public BodyPartRemovedEventArgs Args { get; }
|
||||
|
||||
public HumanoidAppearanceBodyPartRemovedEvent(EntityUid uid, BodyPartRemovedEventArgs args)
|
||||
{
|
||||
Uid = uid;
|
||||
Args = args;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class ChangedHumanoidAppearanceEvent : EntityEventArgs
|
||||
{
|
||||
public HumanoidCharacterAppearance Appearance { get; }
|
||||
public Sex Sex { get; }
|
||||
public Gender Gender { get; }
|
||||
|
||||
public ChangedHumanoidAppearanceEvent(HumanoidCharacterProfile profile)
|
||||
{
|
||||
Appearance = profile.Appearance;
|
||||
Sex = profile.Sex;
|
||||
Gender = profile.Gender;
|
||||
}
|
||||
|
||||
public ChangedHumanoidAppearanceEvent(HumanoidCharacterAppearance appearance, Sex sex, Gender gender)
|
||||
{
|
||||
Appearance = appearance;
|
||||
Sex = sex;
|
||||
Gender = gender;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using Content.Shared.CharacterAppearance;
|
||||
|
||||
|
||||
namespace Content.Shared.Preferences
|
||||
{
|
||||
public interface ICharacterProfile
|
||||
|
||||
Reference in New Issue
Block a user