using UnityEngine;
using Zenject;
using FlappyBird.Core;
namespace FlappyBird.Gameplay.Bird
{
///
/// Thin MonoBehaviour view for the bird.
/// Responsibilities:
/// - Hold component references (Rigidbody2D)
/// - Forward Unity lifecycle events to the service
/// - Detect input in Update and delegate to IBirdController
/// NO game logic lives here.
///
[RequireComponent(typeof(Rigidbody2D))]
public sealed class BirdView : MonoBehaviour
{
private IBirdController _birdController;
private IGameStateManager _gameStateManager;
[Inject]
private void Construct(IBirdController birdController, IGameStateManager gameStateManager)
{
_birdController = birdController;
_gameStateManager = gameStateManager;
}
// Unity lifecycle
/// Update: ONLY input detection, no logic.
private void Update()
{
if (_gameStateManager.CurrentState != GameState.Playing) return;
if (IsJumpInputDetected())
_birdController.Jump();
}
/// FixedUpdate: physics tick forwarded to the service.
private void FixedUpdate()
{
_birdController.Tick();
}
// Private helpers
///
/// Returns true when the player taps (touch) or clicks (mouse / Space).
/// Supports mobile touch and desktop mouse / keyboard for editor testing.
///
private static bool IsJumpInputDetected()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
return true;
if (Input.GetMouseButtonDown(0))
return true;
if (Input.GetKeyDown(KeyCode.Space))
return true;
return false;
}
}
}