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
|
- type: Sprite
|
||||||
netsync: false
|
netsync: false
|
||||||
sprite: Structures/conveyor.rsi
|
sprite: Structures/conveyor.rsi
|
||||||
state: switch-off
|
layers:
|
||||||
|
- state: switch-off
|
||||||
|
map: ["enabled", "enum.TwoWayLeverState.Middle"]
|
||||||
- type: TwoWayLever
|
- type: TwoWayLever
|
||||||
- type: UseDelay
|
- type: UseDelay
|
||||||
delay: 0.2 # prevent light-toggling auto-clickers.
|
delay: 0.2 # prevent light-toggling auto-clickers.
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
|
- type: GenericVisualizer
|
||||||
visuals:
|
visuals:
|
||||||
- type: TwoWayLeverVisualizer
|
enum.TwoWayLeverVisuals.State:
|
||||||
state_forward: switch-fwd
|
enabled:
|
||||||
state_off: switch-off
|
Right: { state: switch-fwd }
|
||||||
state_reversed: switch-rev
|
Middle: { state: switch-off }
|
||||||
|
Left: { state: switch-rev }
|
||||||
- type: Damageable
|
- type: Damageable
|
||||||
damageContainer: Inorganic
|
damageContainer: Inorganic
|
||||||
damageModifierSet: Metallic
|
damageModifierSet: Metallic
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
- type: entity
|
- type: entity
|
||||||
id: ConveyorBelt
|
id: ConveyorBelt
|
||||||
name: conveyor belt
|
name: conveyor belt
|
||||||
description: A conveyor belt, commonly used to transport large numbers of items elsewhere quite quickly.
|
description: A conveyor belt, commonly used to transport large numbers of items elsewhere quite quickly.
|
||||||
@@ -20,11 +20,13 @@
|
|||||||
- type: ExtensionCableReceiver
|
- type: ExtensionCableReceiver
|
||||||
- type: Conveyor
|
- type: Conveyor
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
|
- type: GenericVisualizer
|
||||||
visuals:
|
visuals:
|
||||||
- type: ConveyorVisualizer
|
enum.ConveyorVisuals.State:
|
||||||
state_running: conveyor_started_cw
|
enum.ConveyorState.Off:
|
||||||
state_stopped: conveyor_stopped_cw
|
Off: { state: conveyor_stopped_cw }
|
||||||
state_reversed: conveyor_started_cw_r
|
Forward: { state: conveyor_started_cw }
|
||||||
|
Reverse: { state: conveyor_started_cw_r }
|
||||||
- type: Construction
|
- type: Construction
|
||||||
graph: ConveyorGraph
|
graph: ConveyorGraph
|
||||||
node: entity
|
node: entity
|
||||||
|
|||||||
Reference in New Issue
Block a user