58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using CryptonymThunder.Code.Extensions;
|
|
using GameCore.ECS;
|
|
using GameCore.ECS.Interfaces;
|
|
using GameCore.Input;
|
|
using GameCore.Movement;
|
|
using Godot;
|
|
|
|
namespace CryptonymThunder.Code.Presenters;
|
|
|
|
[GlobalClass]
|
|
public partial class CameraPresenterComponent : Node3D, IPresenterComponent
|
|
{
|
|
private Entity _coreEntity;
|
|
private World _world;
|
|
private Camera3D _camera;
|
|
private RotationComponent _rotationComponent;
|
|
|
|
private bool _cursorLocked = true;
|
|
|
|
public void Initialize(Entity coreEntity, World world)
|
|
{
|
|
_coreEntity = coreEntity;
|
|
_world = world;
|
|
_rotationComponent = _world.GetComponent<RotationComponent>(_coreEntity);
|
|
_camera = GetNode<Camera3D>("Camera3D");
|
|
|
|
if (_cursorLocked) Input.MouseMode = Input.MouseModeEnum.Captured;
|
|
}
|
|
|
|
public void SyncToPresentation(float delta)
|
|
{
|
|
if (_rotationComponent == null || _camera == null) return;
|
|
|
|
var coreRotation = _rotationComponent.Rotation;
|
|
_camera.Rotation = new Vector3(coreRotation.X, 0f, 0f);
|
|
}
|
|
|
|
public void SyncToCore(float delta)
|
|
{
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (Input.IsActionJustPressed("ui_cancel"))
|
|
{
|
|
if (_cursorLocked)
|
|
{
|
|
Input.MouseMode = Input.MouseModeEnum.Visible;
|
|
_cursorLocked = false;
|
|
}
|
|
else
|
|
{
|
|
Input.MouseMode = Input.MouseModeEnum.Captured;
|
|
_cursorLocked = true;
|
|
}
|
|
}
|
|
}
|
|
} |