Component Messaging Rework (#36)

* Remove DiscoBall.

* Changes `IEntity.AddComponent(IComponent)` to `IEntity.AddComponent<T>`.

* Pulled ComponentManager registration out of Component into Entity.

* Killed component message params.

* Updated engine submodule.
This commit is contained in:
Acruid
2018-02-24 11:48:23 -08:00
committed by GitHub
parent 05d4b2793b
commit b005d661f8
11 changed files with 24 additions and 95 deletions

2
.gitmodules vendored
View File

@@ -1,4 +1,4 @@
[submodule "engine"] [submodule "engine"]
path = engine path = engine
url = https://github.com/space-wizards/space-station-14.git url = https://github.com/space-wizards/space-station-14.git
branch = 1771ca4b4c043f95e2a1830e78362df9bb03a656 branch = 98b7e4ee9ede281f5159539fbb9dba3d08a015cf

View File

@@ -60,7 +60,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="EntryPoint.cs" /> <Compile Include="EntryPoint.cs" />
<Compile Include="Prototypes\DiscoBall.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" /> <Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" />
<Compile Include="GameObjects\Components\Doors\ClientDoorComponent.cs" /> <Compile Include="GameObjects\Components\Doors\ClientDoorComponent.cs" />

View File

@@ -1,10 +1,7 @@
using Content.Client.Interfaces.GameObjects; using Content.Client.Interfaces.GameObjects;
using Content.Client.UserInterface; using Content.Client.UserInterface;
using Content.Shared.GameObjects; using Content.Shared.GameObjects;
using Lidgren.Network;
using SS14.Client.Interfaces.UserInterface; using SS14.Client.Interfaces.UserInterface;
using SS14.Client.UserInterface;
using SS14.Shared;
using SS14.Shared.GameObjects; using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC; using SS14.Shared.IoC;
@@ -50,7 +47,7 @@ namespace Content.Client.GameObjects
public void SendChangeHand(string index) public void SendChangeHand(string index)
{ {
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, index); SendNetworkMessage(new ClientChangedHandMsg(index));
} }
} }
} }

View File

@@ -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;
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
_lightComponent = GetComponent<PointLightComponent>();
}
/// <inheritdoc />
public override void Shutdown()
{
base.Shutdown();
_lightComponent = null;
}
/// <inheritdoc />
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));
}
}
}

View File

@@ -256,18 +256,17 @@ namespace Content.Server.GameObjects
ActiveIndex = orderedHands[index]; 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))
var index = message.MessageParameters[0]; ActiveIndex = msg.Index;
if (index is string newIndex && HasHand(newIndex)) break;
{ }
ActiveIndex = newIndex;
}
base.HandleNetworkMessage(message);
} }
} }
} }

View File

@@ -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 (Drawtype == DrawTypes.Both || Drawtype == DrawTypes.Node)
{ {
if (!owner.TryGetComponent(out PowerNodeComponent node)) if (!Owner.TryGetComponent(out PowerNodeComponent node))
{ {
var factory = IoCManager.Resolve<IComponentFactory>(); Owner.AddComponent<PowerNodeComponent>();
node = factory.GetComponent<PowerNodeComponent>();
owner.AddComponent(node);
} }
node.OnPowernetConnect += PowernetConnect; node.OnPowernetConnect += PowernetConnect;
node.OnPowernetDisconnect += PowernetDisconnect; node.OnPowernetDisconnect += PowernetDisconnect;

View File

@@ -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<IComponentFactory>(); Owner.AddComponent<PowerNodeComponent>();
node = factory.GetComponent<PowerNodeComponent>();
owner.AddComponent(node);
} }
node.OnPowernetConnect += PowernetConnect; node.OnPowernetConnect += PowernetConnect;
node.OnPowernetDisconnect += PowernetDisconnect; node.OnPowernetDisconnect += PowernetDisconnect;

View File

@@ -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<IComponentFactory>(); Owner.AddComponent<PowerNodeComponent>();
node = factory.GetComponent<PowerNodeComponent>();
owner.AddComponent(node);
} }
node.OnPowernetConnect += PowernetConnect; node.OnPowernetConnect += PowernetConnect;
node.OnPowernetDisconnect += PowernetDisconnect; node.OnPowernetDisconnect += PowernetDisconnect;

View File

@@ -7,6 +7,7 @@ using SS14.Shared.Interfaces.GameObjects.Components;
using SS14.Shared.IoC; using SS14.Shared.IoC;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using SS14.Shared.Enums;
namespace Content.Server.GameObjects.EntitySystems namespace Content.Server.GameObjects.EntitySystems
{ {

View File

@@ -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

2
engine

Submodule engine updated: 1771ca4b4c...98b7e4ee9e