-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbf0bf7
commit eb4ce6c
Showing
14 changed files
with
192 additions
and
32 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
Content.Client/Electrocution/ElectrocutionOverlaySystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using Content.Shared.Electrocution; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Client.Electrocution; | ||
|
||
/// <summary> | ||
/// Shows the ElectrocutionOverlay to entities with the ElectrocutionOverlayComponent. | ||
/// </summary> | ||
public sealed class ElectrocutionOverlaySystem : EntitySystem | ||
{ | ||
|
||
[Dependency] private readonly AppearanceSystem _appearance = default!; | ||
[Dependency] private readonly IPlayerManager _playerMan = default!; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<ElectrocutionOverlayComponent, ComponentInit>(OnInit); | ||
SubscribeLocalEvent<ElectrocutionOverlayComponent, ComponentShutdown>(OnShutdown); | ||
SubscribeLocalEvent<ElectrocutionOverlayComponent, LocalPlayerAttachedEvent>(OnPlayerAttached); | ||
SubscribeLocalEvent<ElectrocutionOverlayComponent, LocalPlayerDetachedEvent>(OnPlayerDetached); | ||
|
||
SubscribeLocalEvent<ElectrifiedComponent, AppearanceChangeEvent>(OnAppearanceChange); | ||
} | ||
|
||
private void OnPlayerAttached(Entity<ElectrocutionOverlayComponent> ent, ref LocalPlayerAttachedEvent args) | ||
{ | ||
ShowOverlay(); | ||
} | ||
|
||
private void OnPlayerDetached(Entity<ElectrocutionOverlayComponent> ent, ref LocalPlayerDetachedEvent args) | ||
{ | ||
RemoveOverlay(); | ||
} | ||
|
||
private void OnInit(Entity<ElectrocutionOverlayComponent> ent, ref ComponentInit args) | ||
{ | ||
if (_playerMan.LocalEntity == ent) | ||
{ | ||
ShowOverlay(); | ||
} | ||
} | ||
|
||
private void OnShutdown(Entity<ElectrocutionOverlayComponent> ent, ref ComponentShutdown args) | ||
{ | ||
if (_playerMan.LocalEntity == ent) | ||
{ | ||
RemoveOverlay(); | ||
} | ||
} | ||
|
||
private void ShowOverlay() | ||
{ | ||
var electrifiedQuery = AllEntityQuery<ElectrifiedComponent, AppearanceComponent, SpriteComponent>(); | ||
while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp)) | ||
{ | ||
if (!_appearance.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, appearanceComp)) | ||
continue; | ||
|
||
if (!spriteComp.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer)) | ||
continue; | ||
|
||
if (electrified) | ||
spriteComp.LayerSetVisible(ElectrifiedLayers.Overlay, true); | ||
else | ||
spriteComp.LayerSetVisible(ElectrifiedLayers.Overlay, false); | ||
} | ||
} | ||
|
||
private void RemoveOverlay() | ||
{ | ||
var electrifiedQuery = AllEntityQuery<ElectrifiedComponent, AppearanceComponent, SpriteComponent>(); | ||
while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp)) | ||
{ | ||
if (!spriteComp.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer)) | ||
continue; | ||
|
||
spriteComp.LayerSetVisible(layer, false); | ||
} | ||
} | ||
|
||
private void OnAppearanceChange(Entity<ElectrifiedComponent> ent, ref AppearanceChangeEvent args) | ||
{ | ||
if (args.Sprite == null) | ||
return; | ||
|
||
if (!_appearance.TryGetData<bool>(ent.Owner, ElectrifiedVisuals.IsElectrified, out var electrified, args.Component)) | ||
return; | ||
|
||
if (!args.Sprite.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer)) | ||
return; | ||
|
||
var player = _playerMan.LocalEntity; | ||
if (electrified && HasComp<ElectrocutionOverlayComponent>(player)) | ||
args.Sprite.LayerSetVisible(layer, true); | ||
else | ||
args.Sprite.LayerSetVisible(layer, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Content.Shared/Electrocution/Components/ElectrocutionOverlayComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.Electrocution; | ||
|
||
/// <summary> | ||
/// Allow an entity to see the ElectrocutionOverlay showing electrocuted doors. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class ElectrocutionOverlayComponent : Component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"version": 1, | ||
"license": "CC-BY-SA-3.0", | ||
"copyright": "taken from tgstation at commit https://github.com/tgstation/tgstation/commit/d170a410d40eec4fc19fe5eb8d561d58a0902082", | ||
"size": { | ||
"x": 32, | ||
"y": 32 | ||
}, | ||
"states": [ | ||
{ | ||
"name": "electrified", | ||
"delays": [ | ||
[ | ||
0.2, | ||
0.2, | ||
0.2, | ||
0.2, | ||
0.2, | ||
0.2 | ||
] | ||
] | ||
}, | ||
{ | ||
"name": "apc_hacked", | ||
"delays": [ | ||
[ | ||
0.2, | ||
0.2, | ||
0.2, | ||
0.2, | ||
0.2, | ||
0.2 | ||
] | ||
] | ||
} | ||
] | ||
} |