Files
brick-framework/GameCore/Input/PlayerInputSystem.cs

41 lines
1.4 KiB
C#

using GameCore.AI;
using GameCore.ECS;
using GameCore.ECS.Interfaces;
using GameCore.Player;
namespace GameCore.Input;
public class PlayerInputSystem : ISystem
{
public void Update(World world, float deltaTime)
{
var playerEntities = world.GetEntitiesWith<PlayerComponent>().ToList();
if (!playerEntities.Any())
{
world.Logger.Warn("No player entity found for input processing.");
return;
}
var playerEntity = playerEntities.First();
if (world.GetComponent<AIComponent>(playerEntity) != null)
{
world.Logger.Warn("Player entity has AIComponent; skipping input processing.");
return;
}
var inputState = world.GetComponent<InputStateComponent>(playerEntity);
if (inputState == null)
{
world.Logger.Warn("Player entity is missing InputStateComponent; cannot process input.");
return;
}
inputState.MoveDirection = world.InputService.MoveDirection.Normalize();
inputState.LookDirection = world.InputService.LookDirection;
inputState.IsJumping = world.InputService.IsJumping;
inputState.IsInteracting = world.InputService.IsInteracting;
inputState.IsFiring = world.InputService.IsFiring;
inputState.IsSwapWeaponNext = world.InputService.IsSwapWeaponNext;
inputState.IsSwapWeaponPrevious = world.InputService.IsSwapWeaponPrevious;
}
}