using Friflo.Engine.ECS.Systems;
using MrGameEng.Core;
namespace MrGameEng.Input;
/// Polls the once per frame. Registered first in the update phase.
public sealed class InputSystem : BaseSystem
{
private readonly InputManager _input;
/// Creates the system for .
public InputSystem(InputManager input) => _input = input;
///
protected override void OnUpdateGroup() => _input.Update();
}
/// Wires the input module into a .
public static class SceneInputExtensions
{
///
/// Returns the shared service (creating it on first use) and
/// inserts at the start of the scene's update phase.
/// Call from OnLoad before adding gameplay systems.
///
public static InputManager UseInput(this Scene scene)
{
var services = scene.Context.Services;
var input = services.GetOrDefault();
if (input is null)
{
var capture = services.GetOrDefault();
if (capture is null)
{
capture = new InputCapture();
services.Add(capture);
}
input = new InputManager(capture);
services.Add(input);
}
scene.UpdateSystems.Insert(0, new InputSystem(input));
return input;
}
}