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:
Flipp Syder
2021-10-16 15:28:02 -07:00
committed by GitHub
parent f69575e15a
commit 7dc6b95a10
17 changed files with 275 additions and 240 deletions

View File

@@ -1,9 +1,9 @@
using Content.Server.CharacterAppearance.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Actions.Behaviors;
using Content.Shared.Actions.Components;
using Content.Shared.Audio;
using Content.Shared.CharacterAppearance;
using Content.Shared.CharacterAppearance.Components;
using Content.Shared.Cooldown;
using Content.Shared.Sound;
using JetBrains.Annotations;

View File

@@ -1,52 +0,0 @@
using Content.Shared.Body.Components;
using Content.Shared.CharacterAppearance;
using Content.Shared.CharacterAppearance.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.CharacterAppearance.Components
{
[RegisterComponent]
public sealed class HumanoidAppearanceComponent : SharedHumanoidAppearanceComponent
{
public override HumanoidCharacterAppearance Appearance
{
get => base.Appearance;
set
{
base.Appearance = value;
if (Owner.TryGetComponent(out SharedBodyComponent? body))
{
foreach (var (part, _) in body.Parts)
{
if (!part.Owner.TryGetComponent(out SpriteComponent? sprite))
{
continue;
}
sprite.Color = value.SkinColor;
}
}
}
}
protected override void Startup()
{
base.Startup();
if (Appearance != null! && Owner.TryGetComponent(out SharedBodyComponent? body))
{
foreach (var (part, _) in body.Parts)
{
if (!part.Owner.TryGetComponent(out SpriteComponent? sprite))
{
continue;
}
sprite.Color = Appearance.SkinColor;
}
}
}
}
}

View File

@@ -1,3 +1,4 @@
using Content.Server.CharacterAppearance.Systems;
using Content.Server.UserInterface;
using Content.Shared.CharacterAppearance;
using Content.Shared.CharacterAppearance.Components;
@@ -89,6 +90,8 @@ namespace Content.Server.CharacterAppearance.Components
break;
}
EntitySystem.Get<HumanoidAppearanceSystem>().ForceAppearanceUpdate(obj.Session.AttachedEntity.Uid);
}
void IActivate.Activate(ActivateEventArgs eventArgs)

View File

@@ -0,0 +1,32 @@
using Content.Shared.Body.Components;
using Content.Shared.CharacterAppearance.Components;
using Content.Shared.CharacterAppearance.Systems;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.CharacterAppearance.Systems
{
public sealed class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HumanoidAppearanceComponent, ChangedHumanoidAppearanceEvent>(UpdateSkinColor);
}
private void UpdateSkinColor(EntityUid uid, HumanoidAppearanceComponent component, ChangedHumanoidAppearanceEvent _)
{
if (EntityManager.TryGetComponent<SharedBodyComponent>(uid, out SharedBodyComponent? body))
{
foreach (var (part, _) in body.Parts)
{
if (part.Owner.TryGetComponent(out SpriteComponent? sprite))
{
sprite!.Color = component.Appearance.SkinColor;
}
}
}
}
}
}

View File

@@ -4,6 +4,7 @@ using Content.Server.EUI;
using Content.Server.Mind.Components;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using Content.Shared.CharacterAppearance.Systems;
using Content.Shared.Cloning;
using Content.Shared.MobState;
using Content.Shared.Popups;
@@ -136,7 +137,8 @@ namespace Content.Server.Cloning.Components
var mob = Owner.EntityManager.SpawnEntity("MobHuman", Owner.Transform.MapPosition);
mob.GetComponent<HumanoidAppearanceComponent>().UpdateFromProfile(dna.Profile);
EntitySystem.Get<SharedHumanoidAppearanceSystem>().UpdateFromProfile(mob.Uid, dna.Profile);
mob.Name = dna.Profile.Name;
var cloneMindReturn = mob.AddComponent<BeingClonedComponent>();

View File

@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using Content.Server.Access.Components;
using Content.Server.CharacterAppearance.Components;
using Content.Server.Ghost.Components;
using Content.Server.Hands.Components;
using Content.Server.Inventory.Components;
@@ -12,6 +11,7 @@ using Content.Server.Players;
using Content.Server.Roles;
using Content.Server.Spawners.Components;
using Content.Server.Speech.Components;
using Content.Shared.CharacterAppearance.Systems;
using Content.Shared.GameTicking;
using Content.Shared.Ghost;
using Content.Shared.Inventory;
@@ -171,7 +171,7 @@ namespace Content.Server.GameTicking
if (profile != null)
{
entity.GetComponent<HumanoidAppearanceComponent>().UpdateFromProfile(profile);
EntitySystem.Get<SharedHumanoidAppearanceSystem>().UpdateFromProfile(entity.Uid, profile);
entity.Name = profile.Name;
}