Fishy swarmers: Carp content and Space Dragon! (#7395)

Co-authored-by: mirrorcult <lunarautomaton6@gmail.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
CrudeWax
2022-06-16 07:14:06 +03:00
committed by GitHub
parent 5e00d83569
commit c210239f45
46 changed files with 1206 additions and 432 deletions

View File

@@ -1,109 +0,0 @@
using System.Collections.Generic;
using Content.Shared.MobState;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.MobState
{
[UsedImplicitly]
public sealed class DamageStateVisualizer : AppearanceVisualizer, ISerializationHooks
{
private DamageState _data = DamageState.Alive;
private Dictionary<DamageState, string> _stateMap = new();
private int? _originalDrawDepth;
[DataField("normal")]
private string? _normal;
[DataField("crit")]
private string? _crit;
[DataField("dead")]
private string? _dead;
/// <summary>
/// Should noRot be turned off when crit / dead.
/// </summary>
[DataField("rotate")]
private bool _rotate;
void ISerializationHooks.BeforeSerialization()
{
_stateMap.TryGetValue(DamageState.Alive, out _normal);
_stateMap.TryGetValue(DamageState.Critical, out _crit);
_stateMap.TryGetValue(DamageState.Dead, out _dead);
}
void ISerializationHooks.AfterDeserialization()
{
if (_normal != null)
{
_stateMap.Add(DamageState.Alive, _normal);
}
if (_crit != null)
{
_stateMap.Add(DamageState.Critical, _crit);
}
if (_dead != null)
{
_stateMap.Add(DamageState.Dead, _dead);
}
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<ISpriteComponent>(component.Owner);
if (!component.TryGetData(DamageStateVisuals.State, out DamageState data))
{
return;
}
if (_data == data)
{
return;
}
_data = data;
if (_rotate)
{
sprite.NoRotation = data switch
{
DamageState.Critical => false,
DamageState.Dead => false,
_ => true
};
}
if (_stateMap.TryGetValue(_data, out var state))
{
sprite.LayerSetState(DamageStateVisualLayers.Base, state);
}
// So they don't draw over mobs anymore
if (_data == DamageState.Dead && sprite.DrawDepth > (int) DrawDepth.Items)
{
_originalDrawDepth = sprite.DrawDepth;
sprite.DrawDepth = (int) DrawDepth.Items;
}
else if (_originalDrawDepth != null)
{
sprite.DrawDepth = _originalDrawDepth.Value;
_originalDrawDepth = null;
}
}
}
public enum DamageStateVisualLayers : byte
{
Base
}
}

View File

@@ -0,0 +1,57 @@
using Content.Shared.MobState;
using Robust.Client.GameObjects;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.MobState;
public sealed class DamageStateVisualizerSystem : VisualizerSystem<DamageStateVisualsComponent>
{
protected override void OnAppearanceChange(EntityUid uid, DamageStateVisualsComponent component, ref AppearanceChangeEvent args)
{
var sprite = args.Sprite;
if (sprite == null || !args.Component.TryGetData(DamageStateVisuals.State, out DamageState data))
{
return;
}
if (!component.States.TryGetValue(data, out var layers))
{
return;
}
if (component.Rotate)
{
sprite.NoRotation = data switch
{
DamageState.Critical => false,
DamageState.Dead => false,
_ => true
};
}
// Brain no worky rn so this was just easier.
foreach (var layer in sprite.AllLayers)
{
layer.Visible = false;
}
foreach (var (key, state) in layers)
{
sprite.LayerSetVisible(key, true);
sprite.LayerSetState(key, state);
}
// So they don't draw over mobs anymore
if (data == DamageState.Dead && sprite.DrawDepth > (int) DrawDepth.Items)
{
component.OriginalDrawDepth = sprite.DrawDepth;
sprite.DrawDepth = (int) DrawDepth.Items;
}
else if (component.OriginalDrawDepth != null)
{
sprite.DrawDepth = component.OriginalDrawDepth.Value;
component. OriginalDrawDepth = null;
}
}
}

View File

@@ -0,0 +1,22 @@
using Content.Shared.MobState;
namespace Content.Client.MobState;
[RegisterComponent]
public sealed class DamageStateVisualsComponent : Component
{
public int? OriginalDrawDepth;
[DataField("states")] public Dictionary<DamageState, Dictionary<string, string>> States = new();
/// <summary>
/// Should noRot be turned off when crit / dead.
/// </summary>
[DataField("rotate")] public bool Rotate;
}
public enum DamageStateVisualLayers : byte
{
Base,
BaseUnshaded,
}