Files
RobustToolbox/Robust.Shared/GameObjects/Components/Light/OccluderComponent.cs
Acruid dadd7b4cc3 Remove Static Component NetIds (#1842)
* ComponentNames are not sent over the network when components are created.

* Removed ComponentStates array from EntityState, now the state is stored directly inside the CompChange struct.

* Remove the unnecessary NetID property from ComponentState.

* Remove Component.NetworkSynchronizeExistence.

* Change GetNetComponents to return both the component and the component NetId.

* Remove public usages of the Component.NetID property.

* Adds the NetIDAttribute that can be applied to components.

* Removed Component.NetID.

* Revert changes to GetComponentState and how prediction works.

* Adds component netID automatic generation.

* Modifies ClientConsoleHost so that commands can be called before Initialize().

* Completely remove static NetIds.

* Renamed NetIDAttribute to NetworkedComponentAttribute.

* Fixing unit tests.
2021-07-12 10:23:13 +02:00

116 lines
3.1 KiB
C#

using System;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Robust.Shared.GameObjects
{
[NetworkedComponent()]
public class OccluderComponent : Component
{
public sealed override string Name => "Occluder";
[DataField("enabled")]
private bool _enabled = true;
[DataField("boundingBox")]
private Box2 _boundingBox = new(-0.5f, -0.5f, 0.5f, 0.5f);
[ViewVariables(VVAccess.ReadWrite)]
public Box2 BoundingBox
{
get => _boundingBox;
set
{
_boundingBox = value;
Dirty();
BoundingBoxChanged();
}
}
private void BoundingBoxChanged()
{
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new OccluderBoundingBoxChangedMessage(this));
}
[ViewVariables(VVAccess.ReadWrite)]
public virtual bool Enabled
{
get => _enabled;
set
{
if (_enabled == value)
return;
_enabled = value;
Dirty();
}
}
protected override void Startup()
{
base.Startup();
EntitySystem.Get<OccluderSystem>().AddOrUpdateEntity(Owner, Owner.Transform.Coordinates);
}
protected override void Shutdown()
{
base.Shutdown();
var transform = Owner.Transform;
var map = transform.MapID;
if (map != MapId.Nullspace)
{
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local,
new OccluderTreeRemoveOccluderMessage(this, map, transform.GridID));
}
}
public override ComponentState GetComponentState(ICommonSession player)
{
return new OccluderComponentState(Enabled, BoundingBox);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState == null)
{
return;
}
var cast = (OccluderComponentState) curState;
Enabled = cast.Enabled;
BoundingBox = cast.BoundingBox;
}
[NetSerializable, Serializable]
private sealed class OccluderComponentState : ComponentState
{
public bool Enabled { get; }
public Box2 BoundingBox { get; }
public OccluderComponentState(bool enabled, Box2 boundingBox)
{
Enabled = enabled;
BoundingBox = boundingBox;
}
}
}
internal struct OccluderBoundingBoxChangedMessage
{
public OccluderComponent Occluder;
public OccluderBoundingBoxChangedMessage(OccluderComponent occluder)
{
Occluder = occluder;
}
}
}