using Content.Shared.Xenoarchaeology.Artifact.Components;
namespace Content.Shared.Xenoarchaeology.Artifact.XAT;
///
/// Base type for xeno artifact trigger systems, that are relied on updating loop.
///
/// Type of XAT component that system will work with.
public abstract class BaseQueryUpdateXATSystem : BaseXATSystem where T : Component
{
protected EntityQuery _xenoArtifactQuery;
///
public override void Initialize()
{
base.Initialize();
_xenoArtifactQuery = GetEntityQuery();
}
///
public override void Update(float frameTime)
{
base.Update(frameTime);
// TODO: add a way to defer triggering artifacts to the end of the Update loop
var query = EntityQueryEnumerator();
while (query.MoveNext(out var uid, out var comp, out var node))
{
if (node.Attached == null)
continue;
var artifact = _xenoArtifactQuery.Get(node.Attached.Value);
if (!CanTrigger(artifact, (uid, node)))
continue;
UpdateXAT(artifact, (uid, comp, node), frameTime);
}
}
///
/// Handles update logic that is related to trigger component.
///
protected abstract void UpdateXAT(
Entity artifact,
Entity node,
float frameTime
);
}