Generic morgue visualizer (#9696)

This commit is contained in:
Leon Friedrich
2022-07-14 17:25:44 +12:00
committed by GitHub
parent d509aacbf6
commit bad837fb85
7 changed files with 68 additions and 91 deletions

View File

@@ -0,0 +1,7 @@
namespace Content.Client.Morgue.Visualizers;
public enum MorgueVisualLayers : byte
{
Base,
Light,
}

View File

@@ -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);
}
}
}

View File

@@ -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,
}

View File

@@ -36,7 +36,6 @@ namespace Content.Server.Entry
"AMEShieldingVisuals", "AMEShieldingVisuals",
"PipeColorVisuals", "PipeColorVisuals",
"FireVisuals", "FireVisuals",
"MorgueVisuals",
"CrematoriumVisuals", "CrematoriumVisuals",
}; };
} }

View File

@@ -31,40 +31,48 @@ public sealed partial class MorgueSystem : EntitySystem
if (!args.IsInDetailsRange) if (!args.IsInDetailsRange)
return; return;
if (appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul) appearance.TryGetData(MorgueVisuals.Contents, out MorgueContents contents);
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-soul"));
else if (appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob) var text = contents switch
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) MorgueContents.HasSoul => "morgue-entity-storage-component-on-examine-details-body-has-soul",
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-has-contents")); MorgueContents.HasContents => "morgue-entity-storage-component-on-examine-details-has-contents",
else MorgueContents.HasMob => "morgue-entity-storage-component-on-examine-details-body-has-no-soul",
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-empty")); _ => "morgue-entity-storage-component-on-examine-details-empty"
};
args.PushMarkup(Loc.GetString(text));
} }
/// <summary> /// <summary>
/// Updates data periodically in case something died/got deleted in the morgue. /// Updates data periodically in case something died/got deleted in the morgue.
/// </summary> /// </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; return;
if (storage.Contents.ContainedEntities.Count == 0)
{
app.SetData(MorgueVisuals.Contents, MorgueContents.Empty);
return;
}
var hasMob = false; var hasMob = false;
var hasSoul = false;
foreach (var ent in storage.Contents.ContainedEntities) foreach (var ent in storage.Contents.ContainedEntities)
{ {
if (!hasMob && HasComp<SharedBodyComponent>(ent)) if (!hasMob && HasComp<SharedBodyComponent>(ent))
hasMob = true; 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.Contents, hasMob ? MorgueContents.HasMob : MorgueContents.HasContents);
{
app.SetData(MorgueVisuals.HasMob, hasMob);
app.SetData(MorgueVisuals.HasSoul, hasSoul);
}
} }
/// <summary> /// <summary>
@@ -74,18 +82,18 @@ public sealed partial class MorgueSystem : EntitySystem
{ {
base.Update(frameTime); base.Update(frameTime);
foreach (var comp in EntityQuery<MorgueComponent>()) foreach (var (comp, storage, appearance) in EntityQuery<MorgueComponent, EntityStorageComponent, AppearanceComponent>())
{ {
comp.AccumulatedFrameTime += frameTime; comp.AccumulatedFrameTime += frameTime;
CheckContents(comp.Owner, comp); CheckContents(comp.Owner, comp, storage, appearance);
if (comp.AccumulatedFrameTime < comp.BeepTime) if (comp.AccumulatedFrameTime < comp.BeepTime)
continue; continue;
comp.AccumulatedFrameTime -= comp.BeepTime; comp.AccumulatedFrameTime -= comp.BeepTime;
if (comp.DoSoulBeep && TryComp<AppearanceComponent>(comp.Owner, out var appearance) && if (comp.DoSoulBeep && appearance.TryGetData(MorgueVisuals.Contents, out MorgueContents contents) && contents == MorgueContents.HasSoul)
appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
{ {
SoundSystem.Play(comp.OccupantHasSoulAlarmSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner); SoundSystem.Play(comp.OccupantHasSoulAlarmSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner);
} }

View File

@@ -3,14 +3,22 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Morgue; namespace Content.Shared.Morgue;
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum MorgueVisuals public enum MorgueVisuals : byte
{ {
HasMob, Contents
HasSoul,
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum CrematoriumVisuals public enum MorgueContents : byte
{
Empty,
HasMob,
HasSoul,
HasContents,
}
[Serializable, NetSerializable]
public enum CrematoriumVisuals : byte
{ {
Burning, Burning,
} }

View File

@@ -11,6 +11,7 @@
map: ["enum.MorgueVisualLayers.Base"] map: ["enum.MorgueVisualLayers.Base"]
- state: morgue_tray - state: morgue_tray
offset: 0, -1 offset: 0, -1
visible: false
map: ["enum.StorageVisualLayers.Door"] map: ["enum.StorageVisualLayers.Door"]
- state: morgue_nomob_light - state: morgue_nomob_light
visible: false visible: false
@@ -46,15 +47,24 @@
entity_storage: !type:Container entity_storage: !type:Container
morgue_tray: !type:ContainerSlot morgue_tray: !type:ContainerSlot
- type: Appearance - type: Appearance
- type: GenericVisualizer
visuals: visuals:
- type: StorageVisualizer enum.StorageVisuals.Open:
state: morgue_closed # basic open.close layer:
state_alt: morgue_open enum.MorgueVisualLayers.Base:
state_open: morgue_tray True: { state: morgue_open}
- type: MorgueVisuals False: { state: morgue_closed}
lightContents: morgue_nomob_light # show/hide morgue tray:
lightMob: morgue_nosoul_light enum.StorageVisualLayers.Door:
lightSoul: morgue_soul_light 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 - type: Transform
anchored: true anchored: true
- type: AntiRottingContainer - type: AntiRottingContainer