From b005d661f87c3f8823a7aa7e5c2335da0972c616 Mon Sep 17 00:00:00 2001 From: Acruid Date: Sat, 24 Feb 2018 11:48:23 -0800 Subject: [PATCH] Component Messaging Rework (#36) * Remove DiscoBall. * Changes `IEntity.AddComponent(IComponent)` to `IEntity.AddComponent`. * Pulled ComponentManager registration out of Component into Entity. * Killed component message params. * Updated engine submodule. --- .gitmodules | 2 +- Content.Client/Content.Client.csproj | 1 - .../Components/Items/ClientHandsComponent.cs | 5 +-- Content.Client/Prototypes/DiscoBall.cs | 39 ------------------- .../Components/Items/ServerHandsComponent.cs | 17 ++++---- .../Components/Power/PowerDevice.cs | 10 ++--- .../Power/PowerGeneratorComponent.cs | 10 ++--- .../Components/Power/PowerStorageComponent.cs | 10 ++--- .../EntitySystems/InteractionSystem.cs | 1 + Resources/Prototypes/Entities/discoball.yml | 22 ----------- engine | 2 +- 11 files changed, 24 insertions(+), 95 deletions(-) delete mode 100644 Content.Client/Prototypes/DiscoBall.cs delete mode 100644 Resources/Prototypes/Entities/discoball.yml diff --git a/.gitmodules b/.gitmodules index 8e5de4ff59..5e7fdd5053 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "engine"] path = engine url = https://github.com/space-wizards/space-station-14.git - branch = 1771ca4b4c043f95e2a1830e78362df9bb03a656 \ No newline at end of file + branch = 98b7e4ee9ede281f5159539fbb9dba3d08a015cf \ No newline at end of file diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index 78f4483cf9..8678e033df 100644 --- a/Content.Client/Content.Client.csproj +++ b/Content.Client/Content.Client.csproj @@ -60,7 +60,6 @@ - diff --git a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs index 2e694020c7..f61b86d245 100644 --- a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs @@ -1,10 +1,7 @@ using Content.Client.Interfaces.GameObjects; using Content.Client.UserInterface; using Content.Shared.GameObjects; -using Lidgren.Network; using SS14.Client.Interfaces.UserInterface; -using SS14.Client.UserInterface; -using SS14.Shared; using SS14.Shared.GameObjects; using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.IoC; @@ -50,7 +47,7 @@ namespace Content.Client.GameObjects public void SendChangeHand(string index) { - Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, index); + SendNetworkMessage(new ClientChangedHandMsg(index)); } } } diff --git a/Content.Client/Prototypes/DiscoBall.cs b/Content.Client/Prototypes/DiscoBall.cs deleted file mode 100644 index 68efa81968..0000000000 --- a/Content.Client/Prototypes/DiscoBall.cs +++ /dev/null @@ -1,39 +0,0 @@ -using SS14.Client.GameObjects; -using SS14.Shared.GameObjects; -using SS14.Shared.Maths; - -namespace Content.Client.Prototypes -{ - // Instantiated through reflection by the prototype system. - public class DiscoBall : Entity - { - private PointLightComponent _lightComponent; - private float _hue; - - /// - public override void Initialize() - { - base.Initialize(); - _lightComponent = GetComponent(); - } - - /// - public override void Shutdown() - { - base.Shutdown(); - _lightComponent = null; - } - - /// - public override void Update(float frameTime) - { - _hue += frameTime / 10; - if (_hue > 1) - { - _hue -= 1; - } - - _lightComponent.Color = Color4.FromHsl(new Vector4(_hue, 1, 0.5f, 0.5f)); - } - } -} diff --git a/Content.Server/GameObjects/Components/Items/ServerHandsComponent.cs b/Content.Server/GameObjects/Components/Items/ServerHandsComponent.cs index 29c8cd07e6..c6968dcabe 100644 --- a/Content.Server/GameObjects/Components/Items/ServerHandsComponent.cs +++ b/Content.Server/GameObjects/Components/Items/ServerHandsComponent.cs @@ -256,18 +256,17 @@ namespace Content.Server.GameObjects ActiveIndex = orderedHands[index]; } - public override void HandleNetworkMessage(IncomingEntityComponentMessage message) + public override void HandleMessage(object owner, ComponentMessage message) { - if (message.MessageParameters.Count != 1) + base.HandleMessage(owner, message); + + switch (message) { - return; + case ClientChangedHandMsg msg: + if (HasHand(msg.Index)) + ActiveIndex = msg.Index; + break; } - var index = message.MessageParameters[0]; - if (index is string newIndex && HasHand(newIndex)) - { - ActiveIndex = newIndex; - } - base.HandleNetworkMessage(message); } } } diff --git a/Content.Server/GameObjects/Components/Power/PowerDevice.cs b/Content.Server/GameObjects/Components/Power/PowerDevice.cs index d923c43995..e45a8a7912 100644 --- a/Content.Server/GameObjects/Components/Power/PowerDevice.cs +++ b/Content.Server/GameObjects/Components/Power/PowerDevice.cs @@ -84,17 +84,15 @@ namespace Content.Server.GameObjects.Components.Power } } - public override void OnAdd(IEntity owner) + public override void OnAdd() { - base.OnAdd(owner); + base.OnAdd(); if (Drawtype == DrawTypes.Both || Drawtype == DrawTypes.Node) { - if (!owner.TryGetComponent(out PowerNodeComponent node)) + if (!Owner.TryGetComponent(out PowerNodeComponent node)) { - var factory = IoCManager.Resolve(); - node = factory.GetComponent(); - owner.AddComponent(node); + Owner.AddComponent(); } node.OnPowernetConnect += PowernetConnect; node.OnPowernetDisconnect += PowernetDisconnect; diff --git a/Content.Server/GameObjects/Components/Power/PowerGeneratorComponent.cs b/Content.Server/GameObjects/Components/Power/PowerGeneratorComponent.cs index 92d5490108..cb7352f207 100644 --- a/Content.Server/GameObjects/Components/Power/PowerGeneratorComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerGeneratorComponent.cs @@ -33,15 +33,13 @@ namespace Content.Server.GameObjects.Components.Power } } - public override void OnAdd(IEntity owner) + public override void OnAdd() { - base.OnAdd(owner); + base.OnAdd(); - if (!owner.TryGetComponent(out PowerNodeComponent node)) + if (!Owner.TryGetComponent(out PowerNodeComponent node)) { - var factory = IoCManager.Resolve(); - node = factory.GetComponent(); - owner.AddComponent(node); + Owner.AddComponent(); } node.OnPowernetConnect += PowernetConnect; node.OnPowernetDisconnect += PowernetDisconnect; diff --git a/Content.Server/GameObjects/Components/Power/PowerStorageComponent.cs b/Content.Server/GameObjects/Components/Power/PowerStorageComponent.cs index 184fc079f7..2901b9ec9d 100644 --- a/Content.Server/GameObjects/Components/Power/PowerStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerStorageComponent.cs @@ -78,15 +78,13 @@ namespace Content.Server.GameObjects.Components.Power } } - public override void OnAdd(IEntity owner) + public override void OnAdd() { - base.OnAdd(owner); + base.OnAdd(); - if (!owner.TryGetComponent(out PowerNodeComponent node)) + if (!Owner.TryGetComponent(out PowerNodeComponent node)) { - var factory = IoCManager.Resolve(); - node = factory.GetComponent(); - owner.AddComponent(node); + Owner.AddComponent(); } node.OnPowernetConnect += PowernetConnect; node.OnPowernetDisconnect += PowernetDisconnect; diff --git a/Content.Server/GameObjects/EntitySystems/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/InteractionSystem.cs index b1870f5e10..3661962d2b 100644 --- a/Content.Server/GameObjects/EntitySystems/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/InteractionSystem.cs @@ -7,6 +7,7 @@ using SS14.Shared.Interfaces.GameObjects.Components; using SS14.Shared.IoC; using System.Collections.Generic; using System.Linq; +using SS14.Shared.Enums; namespace Content.Server.GameObjects.EntitySystems { diff --git a/Resources/Prototypes/Entities/discoball.yml b/Resources/Prototypes/Entities/discoball.yml deleted file mode 100644 index 5643446694..0000000000 --- a/Resources/Prototypes/Entities/discoball.yml +++ /dev/null @@ -1,22 +0,0 @@ -- type: entity - name: Disco Ball - id: discoball - class: Content.Client.Prototypes.DiscoBall - components: - - type: Transform - - type: Sprite - sprites: - - wall_light - - - type: Icon - icon: wall_light - - - type: PointLight - -- type: entity - name: Disco Ball Small Edition - id: discoballsmall - parent: discoball - components: - - type: PointLight - radius: 128 diff --git a/engine b/engine index 1771ca4b4c..98b7e4ee9e 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 1771ca4b4c043f95e2a1830e78362df9bb03a656 +Subproject commit 98b7e4ee9ede281f5159539fbb9dba3d08a015cf