* Converted all SnapGridPositionChangedEvent subscriptions to AnchorStateChangedEvent. * Fixes power tests with new anchored requirements. * Moved AnchorableComponent into construction. AnchorableComponent now uses Transform.Anchored. * Fixed bug with nodes, power works again. * Adds lifetime stages to Component. * Update Engine to v0.4.70.
89 lines
3.0 KiB
C#
89 lines
3.0 KiB
C#
using Content.Server.Construction.Components;
|
|
using Content.Server.Power.Components;
|
|
using Content.Shared.Computer;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.Computer
|
|
{
|
|
[RegisterComponent]
|
|
public sealed class ComputerComponent : SharedComputerComponent, IMapInit
|
|
{
|
|
[ViewVariables]
|
|
[DataField("board")]
|
|
private string? _boardPrototype;
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
// Let's ensure the container manager and container are here.
|
|
Owner.EnsureContainer<Container>("board", out var _);
|
|
|
|
if (Owner.TryGetComponent(out PowerReceiverComponent? powerReceiver) &&
|
|
Owner.TryGetComponent(out AppearanceComponent? appearance))
|
|
{
|
|
appearance.SetData(ComputerVisuals.Powered, powerReceiver.Powered);
|
|
}
|
|
}
|
|
|
|
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
|
{
|
|
base.HandleMessage(message, component);
|
|
switch (message)
|
|
{
|
|
case PowerChangedMessage powerChanged:
|
|
PowerReceiverOnOnPowerStateChanged(powerChanged);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void PowerReceiverOnOnPowerStateChanged(PowerChangedMessage e)
|
|
{
|
|
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
|
{
|
|
appearance.SetData(ComputerVisuals.Powered, e.Powered);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates the corresponding computer board on the computer.
|
|
/// This exists so when you deconstruct computers that were serialized with the map,
|
|
/// you can retrieve the computer board.
|
|
/// </summary>
|
|
private void CreateComputerBoard()
|
|
{
|
|
// Ensure that the construction component is aware of the board container.
|
|
if (Owner.TryGetComponent(out ConstructionComponent? construction))
|
|
construction.AddContainer("board");
|
|
|
|
// We don't do anything if this is null or empty.
|
|
if (string.IsNullOrEmpty(_boardPrototype))
|
|
return;
|
|
|
|
var container = Owner.EnsureContainer<Container>("board", out var existed);
|
|
|
|
if (existed)
|
|
{
|
|
// We already contain a board. Note: We don't check if it's the right one!
|
|
if (container.ContainedEntities.Count != 0)
|
|
return;
|
|
}
|
|
|
|
var board = Owner.EntityManager.SpawnEntity(_boardPrototype, Owner.Transform.Coordinates);
|
|
|
|
if(!container.Insert(board))
|
|
Logger.Warning($"Couldn't insert board {board} to computer {Owner}!");
|
|
}
|
|
|
|
public void MapInit()
|
|
{
|
|
CreateComputerBoard();
|
|
}
|
|
}
|
|
}
|