Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Port] Custom Ghost's #21

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Numerics;
using Content.Shared.Ghost;
using Content.Shared._White.CustomGhostSystem;
using Robust.Client.GameObjects;

namespace Content.Client._White.CustomGhostSpriteSystem;

public sealed class CustomGhostVisualizer : VisualizerSystem<GhostComponent>
{
protected override void OnAppearanceChange(EntityUid uid, GhostComponent component, ref AppearanceChangeEvent args)
{
base.OnAppearanceChange(uid, component, ref args);

if(args.Sprite == null) return;
RedBurningPhoenix marked this conversation as resolved.
Show resolved Hide resolved

if (AppearanceSystem.TryGetData<string>(uid, CustomGhostAppearance.Sprite, out var rsiPath, args.Component))
{
args.Sprite.LayerSetRSI(0, rsiPath);
}

if(AppearanceSystem.TryGetData<float>(uid, CustomGhostAppearance.AlphaOverride, out var alpha, args.Component))
{
args.Sprite.Color = args.Sprite.Color.WithAlpha(alpha);
}

if (AppearanceSystem.TryGetData<Vector2>(uid, CustomGhostAppearance.SizeOverride, out var size, args.Component))
{
args.Sprite.Scale = size;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Content.Server.Ghost.Components;
using Content.Shared.Ghost;
using Content.Shared._White.CustomGhostSystem;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;

namespace Content.Server._White.CustomGhostSpriteSystem;

public sealed class CustomGhostSpriteSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;


RedBurningPhoenix marked this conversation as resolved.
Show resolved Hide resolved
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GhostComponent, PlayerAttachedEvent>(OnShit);
}

private void OnShit(EntityUid uid, GhostComponent component, PlayerAttachedEvent args)
RedBurningPhoenix marked this conversation as resolved.
Show resolved Hide resolved
{
if(!_playerManager.TryGetSessionByEntity(uid, out var session))
return;

TrySetCustomSprite(uid, session.Name);
}


RedBurningPhoenix marked this conversation as resolved.
Show resolved Hide resolved
public void TrySetCustomSprite(EntityUid ghostUid, string ckey)
{
var prototypes = _prototypeManager.EnumeratePrototypes<CustomGhostPrototype>();

foreach (var customGhostPrototype in prototypes)
{
if (string.Equals(customGhostPrototype.Ckey, ckey, StringComparison.CurrentCultureIgnoreCase))
RedBurningPhoenix marked this conversation as resolved.
Show resolved Hide resolved
{
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.Sprite, customGhostPrototype.CustomSpritePath.ToString());
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.SizeOverride, customGhostPrototype.SizeOverride);

if(customGhostPrototype.AlphaOverride > 0)
{
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.AlphaOverride, customGhostPrototype.AlphaOverride);
}

if (customGhostPrototype.GhostName != string.Empty)
{
_metaData.SetEntityName(ghostUid, customGhostPrototype.GhostName);
}

if (customGhostPrototype.GhostDescription != string.Empty)
{
_metaData.SetEntityDescription(ghostUid, customGhostPrototype.GhostDescription);
}




RedBurningPhoenix marked this conversation as resolved.
Show resolved Hide resolved
return;
}

}
}
}
43 changes: 43 additions & 0 deletions Content.Shared/_White/CustomGhostSystem/CustomGhostPrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Numerics;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

namespace Content.Shared._White.CustomGhostSystem;

/// <summary>
/// This is a prototype for...
/// </summary>
RedBurningPhoenix marked this conversation as resolved.
Show resolved Hide resolved
[Prototype("customGhost")]
public sealed class CustomGhostPrototype : IPrototype
{
/// <inheritdoc/>
[IdDataField]
public string ID { get; } = default!;

[DataField("ckey", required: true)]
RedBurningPhoenix marked this conversation as resolved.
Show resolved Hide resolved
public string Ckey { get; } = default!;

[DataField("sprite", required: true)]
public ResPath CustomSpritePath { get; } = default!;

[DataField("alpha")]
public float AlphaOverride { get; } = -1;

[DataField("ghostName")]
public string GhostName = string.Empty;

[DataField("ghostDescription")]
public string GhostDescription = string.Empty;

[DataField("size")]
public Vector2 SizeOverride = Vector2.One;
}

[Serializable, NetSerializable]
public enum CustomGhostAppearance
{
Sprite,
AlphaOverride,
SizeOverride
}
Loading
Loading