Files
tbd-station-14/Content.Shared/Gravity/GravityComponent.cs
Acruid 59e5cc5e3c Remove Static Component NetIds (#4247)
* Remove the unnecessary NetID property from ComponentState.

* Remove Component.NetworkSynchronizeExistence.

* Removed Component.NetID.

* Adds component netID automatic generation.

* Removed NetIdAttribute from serverside components with no corresponding clientside registration.

* Completely remove static NetIds.

* Renamed NetIDAttribute to NetworkedComponentAttribute.

* Add GenerateNetIds calls to client and server entry points.
Add test to make sure auto generated NetIds are identical.

* Component changes when rebasing that I am too lazy to rewrite into the branch.

Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
2021-07-12 10:32:10 +02:00

63 lines
1.7 KiB
C#

using System;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Log;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Gravity
{
[RegisterComponent]
[NetworkedComponent]
public sealed class GravityComponent : Component
{
public override string Name => "Gravity";
[ViewVariables(VVAccess.ReadWrite)]
public bool Enabled
{
get => _enabled;
set
{
if (_enabled == value) return;
_enabled = value;
if (_enabled)
{
Logger.Info($"Enabled gravity for {Owner}");
}
else
{
Logger.Info($"Disabled gravity for {Owner}");
}
Dirty();
}
}
private bool _enabled;
public override ComponentState GetComponentState(ICommonSession player)
{
return new GravityComponentState(_enabled);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not GravityComponentState state) return;
Enabled = state.Enabled;
}
[Serializable, NetSerializable]
protected sealed class GravityComponentState : ComponentState
{
public bool Enabled { get; }
public GravityComponentState(bool enabled)
{
Enabled = enabled;
}
}
}
}