Generic morgue visualizer (#9696)
This commit is contained in:
7
Content.Client/Morgue/Visualizers/MorgueVisualLayers.cs
Normal file
7
Content.Client/Morgue/Visualizers/MorgueVisualLayers.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Content.Client.Morgue.Visualizers;
|
||||
|
||||
public enum MorgueVisualLayers : byte
|
||||
{
|
||||
Base,
|
||||
Light,
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using Content.Shared.Morgue;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Morgue.Visualizers;
|
||||
|
||||
public sealed class MorgueVisualizerSystem : VisualizerSystem<MorgueVisualsComponent>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
protected override void OnAppearanceChange(EntityUid uid, MorgueVisualsComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (args.Sprite == null)
|
||||
return;
|
||||
|
||||
string? lightState = null;
|
||||
if (args.Component.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
lightState = component.LightSoul;
|
||||
else if (args.Component.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob)
|
||||
lightState = component.LightMob;
|
||||
else if (args.Component.TryGetData(StorageVisuals.HasContents, out bool hasContents) && hasContents)
|
||||
lightState = component.LightContents;
|
||||
|
||||
if (lightState != null)
|
||||
{
|
||||
args.Sprite.LayerSetState(MorgueVisualLayers.Light, lightState);
|
||||
args.Sprite.LayerSetVisible(MorgueVisualLayers.Light, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Sprite.LayerSetVisible(MorgueVisualLayers.Light, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
namespace Content.Client.Morgue.Visualizers;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class MorgueVisualsComponent : Component
|
||||
{
|
||||
[DataField("lightContents", required: true)]
|
||||
public string LightContents = default!;
|
||||
[DataField("lightMob", required: true)]
|
||||
public string LightMob = default!;
|
||||
[DataField("lightSoul", required: true)]
|
||||
public string LightSoul = default!;
|
||||
}
|
||||
|
||||
public enum MorgueVisualLayers : byte
|
||||
{
|
||||
Base,
|
||||
Light,
|
||||
}
|
||||
@@ -36,7 +36,6 @@ namespace Content.Server.Entry
|
||||
"AMEShieldingVisuals",
|
||||
"PipeColorVisuals",
|
||||
"FireVisuals",
|
||||
"MorgueVisuals",
|
||||
"CrematoriumVisuals",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,40 +31,48 @@ public sealed partial class MorgueSystem : EntitySystem
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
if (appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-soul"));
|
||||
else if (appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob)
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-no-soul"));
|
||||
else if (appearance.TryGetData(StorageVisuals.HasContents, out bool hasContents) && hasContents)
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-has-contents"));
|
||||
else
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-empty"));
|
||||
appearance.TryGetData(MorgueVisuals.Contents, out MorgueContents contents);
|
||||
|
||||
var text = contents switch
|
||||
{
|
||||
MorgueContents.HasSoul => "morgue-entity-storage-component-on-examine-details-body-has-soul",
|
||||
MorgueContents.HasContents => "morgue-entity-storage-component-on-examine-details-has-contents",
|
||||
MorgueContents.HasMob => "morgue-entity-storage-component-on-examine-details-body-has-no-soul",
|
||||
_ => "morgue-entity-storage-component-on-examine-details-empty"
|
||||
};
|
||||
|
||||
args.PushMarkup(Loc.GetString(text));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates data periodically in case something died/got deleted in the morgue.
|
||||
/// </summary>
|
||||
private void CheckContents(EntityUid uid, MorgueComponent? morgue = null, EntityStorageComponent? storage = null)
|
||||
private void CheckContents(EntityUid uid, MorgueComponent? morgue = null, EntityStorageComponent? storage = null, AppearanceComponent? app = null)
|
||||
{
|
||||
if (!Resolve(uid, ref morgue, ref storage))
|
||||
if (!Resolve(uid, ref morgue, ref storage, ref app))
|
||||
return;
|
||||
|
||||
if (storage.Contents.ContainedEntities.Count == 0)
|
||||
{
|
||||
app.SetData(MorgueVisuals.Contents, MorgueContents.Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
var hasMob = false;
|
||||
var hasSoul = false;
|
||||
|
||||
foreach (var ent in storage.Contents.ContainedEntities)
|
||||
{
|
||||
if (!hasMob && HasComp<SharedBodyComponent>(ent))
|
||||
hasMob = true;
|
||||
if (!hasSoul && TryComp<ActorComponent?>(ent, out var actor) && actor.PlayerSession != null)
|
||||
hasSoul = true;
|
||||
|
||||
if (TryComp<ActorComponent?>(ent, out var actor) && actor.PlayerSession != null)
|
||||
{
|
||||
app.SetData(MorgueVisuals.Contents, MorgueContents.HasSoul);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (TryComp<AppearanceComponent>(uid, out var app))
|
||||
{
|
||||
app.SetData(MorgueVisuals.HasMob, hasMob);
|
||||
app.SetData(MorgueVisuals.HasSoul, hasSoul);
|
||||
}
|
||||
app.SetData(MorgueVisuals.Contents, hasMob ? MorgueContents.HasMob : MorgueContents.HasContents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,18 +82,18 @@ public sealed partial class MorgueSystem : EntitySystem
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var comp in EntityQuery<MorgueComponent>())
|
||||
foreach (var (comp, storage, appearance) in EntityQuery<MorgueComponent, EntityStorageComponent, AppearanceComponent>())
|
||||
{
|
||||
comp.AccumulatedFrameTime += frameTime;
|
||||
|
||||
CheckContents(comp.Owner, comp);
|
||||
CheckContents(comp.Owner, comp, storage, appearance);
|
||||
|
||||
if (comp.AccumulatedFrameTime < comp.BeepTime)
|
||||
continue;
|
||||
|
||||
comp.AccumulatedFrameTime -= comp.BeepTime;
|
||||
|
||||
if (comp.DoSoulBeep && TryComp<AppearanceComponent>(comp.Owner, out var appearance) &&
|
||||
appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
if (comp.DoSoulBeep && appearance.TryGetData(MorgueVisuals.Contents, out MorgueContents contents) && contents == MorgueContents.HasSoul)
|
||||
{
|
||||
SoundSystem.Play(comp.OccupantHasSoulAlarmSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner);
|
||||
}
|
||||
|
||||
@@ -3,14 +3,22 @@ using Robust.Shared.Serialization;
|
||||
namespace Content.Shared.Morgue;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum MorgueVisuals
|
||||
public enum MorgueVisuals : byte
|
||||
{
|
||||
HasMob,
|
||||
HasSoul,
|
||||
Contents
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum CrematoriumVisuals
|
||||
public enum MorgueContents : byte
|
||||
{
|
||||
Empty,
|
||||
HasMob,
|
||||
HasSoul,
|
||||
HasContents,
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum CrematoriumVisuals : byte
|
||||
{
|
||||
Burning,
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
map: ["enum.MorgueVisualLayers.Base"]
|
||||
- state: morgue_tray
|
||||
offset: 0, -1
|
||||
visible: false
|
||||
map: ["enum.StorageVisualLayers.Door"]
|
||||
- state: morgue_nomob_light
|
||||
visible: false
|
||||
@@ -46,15 +47,24 @@
|
||||
entity_storage: !type:Container
|
||||
morgue_tray: !type:ContainerSlot
|
||||
- type: Appearance
|
||||
- type: GenericVisualizer
|
||||
visuals:
|
||||
- type: StorageVisualizer
|
||||
state: morgue_closed
|
||||
state_alt: morgue_open
|
||||
state_open: morgue_tray
|
||||
- type: MorgueVisuals
|
||||
lightContents: morgue_nomob_light
|
||||
lightMob: morgue_nosoul_light
|
||||
lightSoul: morgue_soul_light
|
||||
enum.StorageVisuals.Open:
|
||||
# basic open.close layer:
|
||||
enum.MorgueVisualLayers.Base:
|
||||
True: { state: morgue_open}
|
||||
False: { state: morgue_closed}
|
||||
# show/hide morgue tray:
|
||||
enum.StorageVisualLayers.Door:
|
||||
True: { visible: true}
|
||||
False: { visible: false}
|
||||
enum.MorgueVisuals.Contents:
|
||||
# toggle contents light indicator:
|
||||
enum.MorgueVisualLayers.Light:
|
||||
Empty: {visible: false}
|
||||
HasContents: {visible: true, state: morgue_nomob_light}
|
||||
HasMob: {visible: true, state: morgue_nosoul_light}
|
||||
HasSoul: {visible: true, state: morgue_soul_light}
|
||||
- type: Transform
|
||||
anchored: true
|
||||
- type: AntiRottingContainer
|
||||
|
||||
Reference in New Issue
Block a user