Reduce Triggers Boilerplate. (#41086)

* Push 1

* cleanup + master merge

* launchontrigger

* A crumb of cleanup

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
Princess Cheeseballs
2025-10-24 17:00:55 -07:00
committed by GitHub
parent 891f5a8f6b
commit c01ec294d0
38 changed files with 223 additions and 513 deletions

View File

@@ -0,0 +1,41 @@
using Content.Shared.Trigger.Components.Effects;
using Content.Shared.Trigger.Systems;
namespace Content.Shared.Trigger;
/// <summary>
/// This is a base Trigger system which handles all the boilerplate for triggers automagically!
/// </summary>
public abstract class TriggerOnXSystem : EntitySystem
{
[Dependency] protected readonly TriggerSystem Trigger = default!;
}
/// <summary>
/// This is a base Trigger system which handles all the boilerplate for triggers automagically!
/// </summary>
public abstract class XOnTriggerSystem<T> : EntitySystem where T : BaseXOnTriggerComponent
{
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<T, TriggerEvent>(OnTrigger);
}
private void OnTrigger(Entity<T> ent, ref TriggerEvent args)
{
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
return;
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
if (target is not { } uid)
return;
OnTrigger(ent, uid, ref args);
}
protected abstract void OnTrigger(Entity<T> ent, EntityUid target, ref TriggerEvent args);
}