Make disposal pipes use generic visualizer (#9672)

This commit is contained in:
Leon Friedrich
2022-07-15 04:04:23 +12:00
committed by GitHub
parent a480b2e2fd
commit 9541eeb189
3 changed files with 79 additions and 119 deletions

View File

@@ -1,67 +0,0 @@
using System;
using Content.Shared.Disposal.Components;
using Content.Shared.SubFloor;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Client.Disposal.Visualizers
{
[UsedImplicitly]
public sealed class DisposalVisualizer : AppearanceVisualizer
{
[DataField("state_free")]
private string? _stateFree;
[DataField("state_anchored")]
private string? _stateAnchored;
private void ChangeState(AppearanceComponent appearance)
{
var entities = IoCManager.Resolve<IEntityManager>();
if (!entities.TryGetComponent(appearance.Owner, out ISpriteComponent? sprite))
{
return;
}
if (!appearance.TryGetData(DisposalTubeVisuals.VisualState, out DisposalTubeVisualState state))
{
return;
}
var texture = state switch
{
DisposalTubeVisualState.Free => _stateFree,
DisposalTubeVisualState.Anchored => _stateAnchored,
_ => throw new ArgumentOutOfRangeException()
};
sprite.LayerSetState(0, texture);
if (state == DisposalTubeVisualState.Anchored)
{
appearance.Owner.EnsureComponent<SubFloorHideComponent>();
}
else if (entities.HasComponent<SubFloorHideComponent>(appearance.Owner))
{
entities.RemoveComponent<SubFloorHideComponent>(appearance.Owner);
}
}
public override void InitializeEntity(EntityUid entity)
{
base.InitializeEntity(entity);
var entityManager = IoCManager.Resolve<IEntityManager>();
var appearance = entityManager.EnsureComponent<ClientAppearanceComponent>(entity);
ChangeState(appearance);
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
ChangeState(component);
}
}
}

View File

@@ -26,11 +26,6 @@ namespace Content.Server.Disposal.Tube.Components
[ViewVariables] [ViewVariables]
public Container Contents { get; private set; } = default!; public Container Contents { get; private set; } = default!;
[ViewVariables]
private bool Anchored =>
!_entMan.TryGetComponent(Owner, out PhysicsComponent? physics) ||
physics.BodyType == BodyType.Static;
/// <summary> /// <summary>
/// The directions that this tube can connect to others from /// The directions that this tube can connect to others from
/// </summary> /// </summary>
@@ -99,7 +94,8 @@ namespace Content.Server.Disposal.Tube.Components
return; return;
} }
var state = Anchored // TODO this should just generalized into some anchored-visuals system/comp, this has nothing to do with disposal tubes.
var state = _entMan.GetComponent<TransformComponent>(Owner).Anchored
? DisposalTubeVisualState.Anchored ? DisposalTubeVisualState.Anchored
: DisposalTubeVisualState.Free; : DisposalTubeVisualState.Free;

View File

@@ -11,6 +11,7 @@
- type: Sprite - type: Sprite
netsync: false netsync: false
visible: false visible: false
- type: Appearance
- type: SubFloorHide - type: SubFloorHide
- type: Clickable - type: Clickable
- type: InteractionOutline - type: InteractionOutline
@@ -67,7 +68,9 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: pipe-b layers:
- map: [ "pipe" ]
state: pipe-b
- type: Construction - type: Construction
graph: DisposalPipe graph: DisposalPipe
node: broken node: broken
@@ -81,13 +84,16 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-s layers:
- map: [ "pipe" ]
state: conpipe-s
- type: DisposalTransit - type: DisposalTransit
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-s pipe:
state_anchored: pipe-s Free: { state: conpipe-s }
Anchored: { state: pipe-s }
- type: Construction - type: Construction
graph: DisposalPipe graph: DisposalPipe
node: pipe node: pipe
@@ -101,13 +107,16 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-tagger layers:
- map: [ "pipe" ]
state: conpipe-tagger
- type: DisposalTagger - type: DisposalTagger
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-tagger pipe:
state_anchored: pipe-tagger Free: { state: conpipe-tagger }
Anchored: { state: pipe-tagger }
- type: ActivatableUI - type: ActivatableUI
key: enum.DisposalTaggerUiKey.Key key: enum.DisposalTaggerUiKey.Key
- type: UserInterface - type: UserInterface
@@ -127,13 +136,16 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-t layers:
- map: [ "pipe" ]
state: conpipe-t
- type: DisposalEntry - type: DisposalEntry
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-t pipe:
state_anchored: pipe-t Free: { state: conpipe-t }
Anchored: { state: pipe-t }
- type: Fixtures - type: Fixtures
fixtures: fixtures:
- shape: - shape:
@@ -154,17 +166,20 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-j1s layers:
- map: [ "pipe" ]
state: conpipe-j1s
- type: DisposalRouter - type: DisposalRouter
degrees: degrees:
- 0 - 0
- -90 - -90
- 180 - 180
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-j1s pipe:
state_anchored: pipe-j1s Free: { state: conpipe-j1s }
Anchored: { state: pipe-j1s }
- type: Flippable - type: Flippable
mirrorEntity: DisposalRouterFlipped mirrorEntity: DisposalRouterFlipped
- type: ActivatableUI - type: ActivatableUI
@@ -192,17 +207,20 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-j2s layers:
- map: [ "pipe" ]
state: conpipe-j2s
- type: DisposalRouter - type: DisposalRouter
degrees: degrees:
- 0 - 0
- 90 - 90
- 180 - 180
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-j2s pipe:
state_anchored: pipe-j2s Free: { state: conpipe-j2s }
Anchored: { state: pipe-j2s }
- type: Flippable - type: Flippable
mirrorEntity: DisposalRouter mirrorEntity: DisposalRouter
- type: Fixtures - type: Fixtures
@@ -222,17 +240,21 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-j1 layers:
- map: [ "pipe" ]
state: conpipe-j1
visible: true
- type: DisposalJunction - type: DisposalJunction
degrees: degrees:
- 0 - 0
- -90 - -90
- 180 - 180
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-j1 pipe:
state_anchored: pipe-j1 Free: { state: conpipe-j1 }
Anchored: { state: pipe-j1 }
- type: Flippable - type: Flippable
mirrorEntity: DisposalJunctionFlipped mirrorEntity: DisposalJunctionFlipped
- type: Fixtures - type: Fixtures
@@ -254,17 +276,20 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-j2 layers:
- map: [ "pipe" ]
state: conpipe-j2
- type: DisposalJunction - type: DisposalJunction
degrees: degrees:
- 0 - 0
- 90 - 90
- 180 - 180
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-j2 pipe:
state_anchored: pipe-j2 Free: { state: conpipe-j2 }
Anchored: { state: pipe-j2 }
- type: Flippable - type: Flippable
mirrorEntity: DisposalJunction mirrorEntity: DisposalJunction
- type: Fixtures - type: Fixtures
@@ -284,17 +309,20 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-y layers:
- map: [ "pipe" ]
state: conpipe-y
- type: DisposalJunction - type: DisposalJunction
degrees: degrees:
- 0 - 0
- 90 - 90
- -90 - -90
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-y pipe:
state_anchored: pipe-y Free: { state: conpipe-y }
Anchored: { state: pipe-y }
- type: Fixtures - type: Fixtures
fixtures: fixtures:
- shape: - shape:
@@ -315,13 +343,16 @@
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe
sprite: Structures/Piping/disposal.rsi sprite: Structures/Piping/disposal.rsi
state: conpipe-c layers:
- map: [ "pipe" ]
state: conpipe-c
- type: DisposalBend - type: DisposalBend
- type: Appearance - type: GenericVisualizer
visuals: visuals:
- type: DisposalVisualizer enum.DisposalTubeVisuals.VisualState:
state_free: conpipe-c pipe:
state_anchored: pipe-c Free: { state: conpipe-c }
Anchored: { state: pipe-c }
- type: Fixtures - type: Fixtures
fixtures: fixtures:
- shape: - shape: