Skip to content

Commit

Permalink
Fix build (space-wizards#26258)
Browse files Browse the repository at this point in the history
* Fix build

- Fixes a couple paint things that were broken.

* wat
  • Loading branch information
metalgearsloth authored Mar 19, 2024
1 parent 362d569 commit 6de5fbf
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 96 deletions.
152 changes: 74 additions & 78 deletions Content.Client/Paint/PaintVisualizerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,112 +7,108 @@
using Robust.Client.Graphics;
using Robust.Shared.Prototypes;

namespace Content.Client.Paint
{
public sealed class PaintedVisualizerSystem : VisualizerSystem<PaintedComponent>
{
/// <summary>
/// Visualizer for Paint which applies a shader and colors the entity.
/// </summary>
namespace Content.Client.Paint;

[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly IPrototypeManager _protoMan = default!;
public sealed class PaintedVisualizerSystem : VisualizerSystem<PaintedComponent>
{
/// <summary>
/// Visualizer for Paint which applies a shader and colors the entity.
/// </summary>

public ShaderInstance? Shader; // in Robust.Client.Graphics so cannot move to shared component.
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly IPrototypeManager _protoMan = default!;

public override void Initialize()
{
base.Initialize();
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<PaintedComponent, HeldVisualsUpdatedEvent>(OnHeldVisualsUpdated);
SubscribeLocalEvent<PaintedComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<PaintedComponent, EquipmentVisualsUpdatedEvent>(OnEquipmentVisualsUpdated);
}
SubscribeLocalEvent<PaintedComponent, HeldVisualsUpdatedEvent>(OnHeldVisualsUpdated);
SubscribeLocalEvent<PaintedComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<PaintedComponent, EquipmentVisualsUpdatedEvent>(OnEquipmentVisualsUpdated);
}

protected override void OnAppearanceChange(EntityUid uid, PaintedComponent component, ref AppearanceChangeEvent args)
{
// ShaderPrototype sadly in Robust.Client, cannot move to shared component.
Shader = _protoMan.Index<ShaderPrototype>(component.ShaderName).Instance();
protected override void OnAppearanceChange(EntityUid uid, PaintedComponent component, ref AppearanceChangeEvent args)
{
var shader = _protoMan.Index<ShaderPrototype>(component.ShaderName).Instance();

if (args.Sprite == null)
return;
if (args.Sprite == null)
return;

if (!_appearance.TryGetData<bool>(uid, PaintVisuals.Painted, out bool isPainted))
return;
// What is this even doing? It's not even checking what the value is.
if (!_appearance.TryGetData(uid, PaintVisuals.Painted, out bool isPainted))
return;

var sprite = args.Sprite;
var sprite = args.Sprite;

foreach (var spriteLayer in sprite.AllLayers)
{
if (spriteLayer is not Layer layer)
continue;

foreach (var spriteLayer in sprite.AllLayers)
if (layer.Shader == null) // If shader isn't null we dont want to replace the original shader.
{
if (spriteLayer is not Layer layer)
continue;

if (layer.Shader == null) // If shader isn't null we dont want to replace the original shader.
{
layer.Shader = Shader;
layer.Color = component.Color;
}
layer.Shader = shader;
layer.Color = component.Color;
}
}
}

private void OnHeldVisualsUpdated(EntityUid uid, PaintedComponent component, HeldVisualsUpdatedEvent args)
{
if (args.RevealedLayers.Count == 0)
return;
private void OnHeldVisualsUpdated(EntityUid uid, PaintedComponent component, HeldVisualsUpdatedEvent args)
{
if (args.RevealedLayers.Count == 0)
return;

if (!TryComp(args.User, out SpriteComponent? sprite))
return;
if (!TryComp(args.User, out SpriteComponent? sprite))
return;

foreach (var revealed in args.RevealedLayers)
{
if (!sprite.LayerMapTryGet(revealed, out var layer) || sprite[layer] is not Layer notlayer)
continue;
foreach (var revealed in args.RevealedLayers)
{
if (!sprite.LayerMapTryGet(revealed, out var layer))
continue;

sprite.LayerSetShader(layer, component.ShaderName);
sprite.LayerSetColor(layer, component.Color);
}
sprite.LayerSetShader(layer, component.ShaderName);
sprite.LayerSetColor(layer, component.Color);
}
}

private void OnEquipmentVisualsUpdated(EntityUid uid, PaintedComponent component, EquipmentVisualsUpdatedEvent args)
{
if (args.RevealedLayers.Count == 0)
return;
private void OnEquipmentVisualsUpdated(EntityUid uid, PaintedComponent component, EquipmentVisualsUpdatedEvent args)
{
if (args.RevealedLayers.Count == 0)
return;

if (!TryComp(args.Equipee, out SpriteComponent? sprite))
return;
if (!TryComp(args.Equipee, out SpriteComponent? sprite))
return;

foreach (var revealed in args.RevealedLayers)
{
if (!sprite.LayerMapTryGet(revealed, out var layer) || sprite[layer] is not Layer notlayer)
continue;
foreach (var revealed in args.RevealedLayers)
{
if (!sprite.LayerMapTryGet(revealed, out var layer))
continue;

sprite.LayerSetShader(layer, component.ShaderName);
sprite.LayerSetColor(layer, component.Color);
}
sprite.LayerSetShader(layer, component.ShaderName);
sprite.LayerSetColor(layer, component.Color);
}
}

private void OnShutdown(EntityUid uid, PaintedComponent component, ref ComponentShutdown args)
{
if (!TryComp(uid, out SpriteComponent? sprite))
return;
private void OnShutdown(EntityUid uid, PaintedComponent component, ref ComponentShutdown args)
{
if (!TryComp(uid, out SpriteComponent? sprite))
return;

component.BeforeColor = sprite.Color;
Shader = _protoMan.Index<ShaderPrototype>(component.ShaderName).Instance();
component.BeforeColor = sprite.Color;
var shader = _protoMan.Index<ShaderPrototype>(component.ShaderName).Instance();

if (!Terminating(uid))
if (!Terminating(uid))
{
foreach (var spriteLayer in sprite.AllLayers)
{
foreach (var spriteLayer in sprite.AllLayers)
if (spriteLayer is not Layer layer)
continue;

if (layer.Shader == shader) // If shader isn't same as one in component we need to ignore it.
{
if (spriteLayer is not Layer layer)
continue;

if (layer.Shader == Shader) // If shader isn't same as one in component we need to ignore it.
{
layer.Shader = null;
if (layer.Color == component.Color) // If color isn't the same as one in component we don't want to change it.
layer.Color = component.BeforeColor;
}
layer.Shader = null;
if (layer.Color == component.Color) // If color isn't the same as one in component we don't want to change it.
layer.Color = component.BeforeColor;
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions Content.Server/Paint/PaintSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,12 @@ private void PrepPaint(EntityUid uid, PaintComponent component, EntityUid target

var doAfterEventArgs = new DoAfterArgs(EntityManager, user, component.Delay, new PaintDoAfterEvent(), uid, target: target, used: uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
BreakOnMove = true,
NeedHand = true,
BreakOnHandChange = true
};

if (!_doAfterSystem.TryStartDoAfter(doAfterEventArgs))
return;
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
}

private void OnPaint(Entity<PaintComponent> entity, ref PaintDoAfterEvent args)
Expand Down Expand Up @@ -112,7 +109,6 @@ private void OnPaint(Entity<PaintComponent> entity, ref PaintDoAfterEvent args)
return;
}


if (TryPaint(entity, target))
{
EnsureComp<PaintedComponent>(target, out PaintedComponent? paint);
Expand All @@ -131,12 +127,14 @@ private void OnPaint(Entity<PaintComponent> entity, ref PaintDoAfterEvent args)
if (!_inventory.TryGetSlotEntity(target, slot.Name, out var slotEnt))
continue;

if (slotEnt == null)
return;

if (HasComp<PaintedComponent>(slotEnt.Value) || !entity.Comp.Blacklist?.IsValid(slotEnt.Value, EntityManager) != true
|| HasComp<RandomSpriteComponent>(slotEnt.Value) || HasComp<HumanoidAppearanceComponent>(slotEnt.Value))
return;
if (HasComp<PaintedComponent>(slotEnt.Value) || !entity.Comp.Blacklist?.IsValid(slotEnt.Value,
EntityManager) != true
|| HasComp<RandomSpriteComponent>(slotEnt.Value) ||
HasComp<HumanoidAppearanceComponent>(
slotEnt.Value))
{
continue;
}

EnsureComp<PaintedComponent>(slotEnt.Value, out PaintedComponent? slotpaint);
EnsureComp<AppearanceComponent>(slotEnt.Value);
Expand Down
10 changes: 4 additions & 6 deletions Content.Shared/Paint/PaintRemoverSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public sealed class PaintRemoverSystem : SharedPaintSystem
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;

public override void Initialize()
Expand All @@ -39,9 +38,8 @@ private void OnInteract(EntityUid uid, PaintRemoverComponent component, AfterInt

_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, component.CleanDelay, new PaintRemoverDoAfterEvent(), uid, args.Target, uid)
{
BreakOnUserMove = true,
BreakOnMove = true,
BreakOnDamage = true,
BreakOnTargetMove = true,
MovementThreshold = 1.0f,
});
args.Handled = true;
Expand Down Expand Up @@ -77,13 +75,13 @@ private void OnPaintRemoveVerb(EntityUid uid, PaintRemoverComponent component, G

var verb = new UtilityVerb()
{
Act = () => {
Act = () =>
{
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, component.CleanDelay, new PaintRemoverDoAfterEvent(), uid, args.Target, uid)
{
BreakOnUserMove = true,
BreakOnMove = true,
BreakOnDamage = true,
BreakOnTargetMove = true,
MovementThreshold = 1.0f,
});
},
Expand Down

0 comments on commit 6de5fbf

Please sign in to comment.