From db4322e5b30f2a9eec24346facecc3a4d2200987 Mon Sep 17 00:00:00 2001 From: Alex Evgrashin Date: Tue, 8 Mar 2022 04:06:09 +0300 Subject: [PATCH] Welder flame fix (#7021) --- .../Visualizers/WelderVisualizerSystem.cs | 21 +++++++++++++++++ Content.Server/Tools/ToolSystem.Welder.cs | 23 ++++++++----------- .../Tools/Components/SharedWelderComponent.cs | 13 +++++++++++ .../Entities/Objects/Tools/cowtools.yml | 5 ---- .../Entities/Objects/Tools/welders.yml | 3 +++ 5 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 Content.Client/Tools/Visualizers/WelderVisualizerSystem.cs diff --git a/Content.Client/Tools/Visualizers/WelderVisualizerSystem.cs b/Content.Client/Tools/Visualizers/WelderVisualizerSystem.cs new file mode 100644 index 0000000000..aae51c8fd9 --- /dev/null +++ b/Content.Client/Tools/Visualizers/WelderVisualizerSystem.cs @@ -0,0 +1,21 @@ +using Content.Client.Tools.Components; +using Content.Shared.Tools.Components; +using Robust.Client.GameObjects; + +namespace Content.Client.Tools.Visualizers; + +public sealed class WelderVisualizerSystem : VisualizerSystem +{ + protected override void OnAppearanceChange(EntityUid uid, WelderComponent component, ref AppearanceChangeEvent args) + { + base.OnAppearanceChange(uid, component, ref args); + + if (!TryComp(uid, out SpriteComponent? sprite)) + return; + + if (args.Component.TryGetData(WelderVisuals.Lit, out bool isLit)) + { + sprite.LayerSetVisible(WelderLayers.Flame, isLit); + } + } +} diff --git a/Content.Server/Tools/ToolSystem.Welder.cs b/Content.Server/Tools/ToolSystem.Welder.cs index 5205e135ed..99a10319a0 100644 --- a/Content.Server/Tools/ToolSystem.Welder.cs +++ b/Content.Server/Tools/ToolSystem.Welder.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using Content.Server.Chemistry.Components; using Content.Server.Chemistry.Components.SolutionManager; using Content.Server.Chemistry.EntitySystems; @@ -15,9 +14,7 @@ using Content.Shared.Temperature; using Content.Shared.Tools.Components; using Robust.Server.GameObjects; using Robust.Shared.Audio; -using Robust.Shared.GameObjects; using Robust.Shared.GameStates; -using Robust.Shared.Localization; using Robust.Shared.Player; namespace Content.Server.Tools @@ -64,7 +61,7 @@ namespace Content.Server.Tools SolutionContainerManagerComponent? solutionContainer = null, SharedItemComponent? item = null, PointLightComponent? light = null, - SpriteComponent? sprite = null) + AppearanceComponent? appearance = null) { // Right now, we only need the welder. // So let's not unnecessarily resolve components @@ -72,8 +69,8 @@ namespace Content.Server.Tools return false; return !welder.Lit - ? TryTurnWelderOn(uid, user, welder, solutionContainer, item, light, sprite) - : TryTurnWelderOff(uid, user, welder, item, light, sprite); + ? TryTurnWelderOn(uid, user, welder, solutionContainer, item, light, appearance) + : TryTurnWelderOff(uid, user, welder, item, light, appearance); } public bool TryTurnWelderOn(EntityUid uid, EntityUid? user, @@ -81,13 +78,13 @@ namespace Content.Server.Tools SolutionContainerManagerComponent? solutionContainer = null, SharedItemComponent? item = null, PointLightComponent? light = null, - SpriteComponent? sprite = null) + AppearanceComponent? appearance = null) { if (!Resolve(uid, ref welder, ref solutionContainer)) return false; // Optional components. - Resolve(uid, ref item, ref light, ref sprite); + Resolve(uid, ref item, ref light, ref appearance, false); if (!_solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var solution, solutionContainer)) return false; @@ -109,7 +106,7 @@ namespace Content.Server.Tools if(item != null) item.EquippedPrefix = "on"; - sprite?.LayerSetVisible(1, true); + appearance?.SetData(WelderVisuals.Lit, true); if (light != null) light.Enabled = true; @@ -129,13 +126,13 @@ namespace Content.Server.Tools WelderComponent? welder = null, SharedItemComponent? item = null, PointLightComponent? light = null, - SpriteComponent? sprite = null) + AppearanceComponent? appearance = null) { if (!Resolve(uid, ref welder)) return false; // Optional components. - Resolve(uid, ref item, ref light, ref sprite); + Resolve(uid, ref item, ref light, ref appearance, false); welder.Lit = false; @@ -144,7 +141,7 @@ namespace Content.Server.Tools item.EquippedPrefix = "off"; // Layer 1 is the flame. - sprite?.LayerSetVisible(1, false); + appearance?.SetData(WelderVisuals.Lit, false); if (light != null) light.Enabled = false; diff --git a/Content.Shared/Tools/Components/SharedWelderComponent.cs b/Content.Shared/Tools/Components/SharedWelderComponent.cs index e1460bae82..fd8a3592f2 100644 --- a/Content.Shared/Tools/Components/SharedWelderComponent.cs +++ b/Content.Shared/Tools/Components/SharedWelderComponent.cs @@ -25,4 +25,17 @@ namespace Content.Shared.Tools.Components Lit = lit; } } + + [Serializable, NetSerializable] + public enum WelderVisuals : byte + { + Lit + } + + [Serializable, NetSerializable] + public enum WelderLayers : byte + { + Base, + Flame + } } diff --git a/Resources/Prototypes/Entities/Objects/Tools/cowtools.yml b/Resources/Prototypes/Entities/Objects/Tools/cowtools.yml index 0f6dbe7e5e..6a48d2d098 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/cowtools.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/cowtools.yml @@ -117,11 +117,6 @@ components: - type: Sprite sprite: Objects/Tools/Cowtools/cowelder.rsi - layers: - - state: icon - - state: welder_flame - shader: unshaded - visible: false - type: Item size: 10 sprite: Objects/Tools/Cowtools/cowelder.rsi diff --git a/Resources/Prototypes/Entities/Objects/Tools/welders.yml b/Resources/Prototypes/Entities/Objects/Tools/welders.yml index 6dc395f63e..77fdc1c080 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/welders.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/welders.yml @@ -12,7 +12,9 @@ netsync: false layers: - state: icon + map: ["enum.WelderLayers.Base"] - state: welder_flame + map: ["enum.WelderLayers.Flame"] shader: unshaded visible: false - type: Item @@ -47,6 +49,7 @@ enabled: false radius: 1.5 color: orange + - type: Appearance - type: entity name: experimental welding tool