Converted Conveyor and TwoWayLever Visualizers to ECS format (#10028)
Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using Content.Shared.Conveyor;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Conveyor.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class ConveyorVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("state_running")]
|
||||
private string? _stateRunning;
|
||||
|
||||
[DataField("state_stopped")]
|
||||
private string? _stateStopped;
|
||||
|
||||
[DataField("state_reversed")]
|
||||
private string? _stateReversed;
|
||||
|
||||
private void ChangeState(AppearanceComponent appearance)
|
||||
{
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (appearance.TryGetData(ConveyorVisuals.State, out ConveyorState state))
|
||||
{
|
||||
var texture = state switch
|
||||
{
|
||||
ConveyorState.Off => _stateStopped,
|
||||
ConveyorState.Forward => _stateRunning,
|
||||
ConveyorState.Reverse => _stateReversed,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
sprite.LayerSetState(0, texture);
|
||||
}
|
||||
}
|
||||
|
||||
public override void InitializeEntity(EntityUid entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
var appearance = entities.EnsureComponent<ClientAppearanceComponent>(entity);
|
||||
ChangeState(appearance);
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
ChangeState(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using Content.Shared.MachineLinking;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Conveyor.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class TwoWayLeverVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("state_forward")]
|
||||
private string? _stateForward;
|
||||
|
||||
[DataField("state_off")]
|
||||
private string? _stateOff;
|
||||
|
||||
[DataField("state_reversed")]
|
||||
private string? _stateReversed;
|
||||
|
||||
private void ChangeState(AppearanceComponent appearance)
|
||||
{
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
appearance.TryGetData(TwoWayLeverVisuals.State, out TwoWayLeverState state);
|
||||
|
||||
var texture = state switch
|
||||
{
|
||||
TwoWayLeverState.Middle => _stateOff,
|
||||
TwoWayLeverState.Right => _stateForward,
|
||||
TwoWayLeverState.Left => _stateReversed,
|
||||
_ => _stateOff
|
||||
};
|
||||
|
||||
sprite.LayerSetState(0, texture);
|
||||
}
|
||||
|
||||
public override void InitializeEntity(EntityUid entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
var appearance = entities.EnsureComponent<ClientAppearanceComponent>(entity);
|
||||
ChangeState(appearance);
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
ChangeState(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,16 +92,20 @@
|
||||
- type: Sprite
|
||||
netsync: false
|
||||
sprite: Structures/conveyor.rsi
|
||||
state: switch-off
|
||||
layers:
|
||||
- state: switch-off
|
||||
map: ["enabled", "enum.TwoWayLeverState.Middle"]
|
||||
- type: TwoWayLever
|
||||
- type: UseDelay
|
||||
delay: 0.2 # prevent light-toggling auto-clickers.
|
||||
- type: Appearance
|
||||
- type: GenericVisualizer
|
||||
visuals:
|
||||
- type: TwoWayLeverVisualizer
|
||||
state_forward: switch-fwd
|
||||
state_off: switch-off
|
||||
state_reversed: switch-rev
|
||||
enum.TwoWayLeverVisuals.State:
|
||||
enabled:
|
||||
Right: { state: switch-fwd }
|
||||
Middle: { state: switch-off }
|
||||
Left: { state: switch-rev }
|
||||
- type: Damageable
|
||||
damageContainer: Inorganic
|
||||
damageModifierSet: Metallic
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
- type: entity
|
||||
- type: entity
|
||||
id: ConveyorBelt
|
||||
name: conveyor belt
|
||||
description: A conveyor belt, commonly used to transport large numbers of items elsewhere quite quickly.
|
||||
@@ -20,11 +20,13 @@
|
||||
- type: ExtensionCableReceiver
|
||||
- type: Conveyor
|
||||
- type: Appearance
|
||||
- type: GenericVisualizer
|
||||
visuals:
|
||||
- type: ConveyorVisualizer
|
||||
state_running: conveyor_started_cw
|
||||
state_stopped: conveyor_stopped_cw
|
||||
state_reversed: conveyor_started_cw_r
|
||||
enum.ConveyorVisuals.State:
|
||||
enum.ConveyorState.Off:
|
||||
Off: { state: conveyor_stopped_cw }
|
||||
Forward: { state: conveyor_started_cw }
|
||||
Reverse: { state: conveyor_started_cw_r }
|
||||
- type: Construction
|
||||
graph: ConveyorGraph
|
||||
node: entity
|
||||
|
||||
Reference in New Issue
Block a user