refactor: extract GameUiCoordinator from GameBootstrap
This commit is contained in:
@@ -2,7 +2,6 @@ using System.Collections;
|
||||
using Core.Domain;
|
||||
using Core.Domain.Status.Effects;
|
||||
using Core.Ports;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
@@ -23,12 +22,7 @@ namespace Infrastructure.Unity
|
||||
[SerializeField] private HunterNpcController hunterNpcPrefab;
|
||||
[SerializeField] private FloorVisibilityManager floorVisibilityManager;
|
||||
|
||||
[Header("Ui")]
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
[SerializeField] private TMP_Text highScoreText;
|
||||
[SerializeField] private GameObject gameOverUi;
|
||||
[SerializeField] private GameObject pauseUi;
|
||||
[SerializeField] private GameObject startScreenUi;
|
||||
[SerializeField] private GameUiCoordinator uiCoordinator;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private float restartTime = 3f;
|
||||
@@ -44,11 +38,11 @@ namespace Infrastructure.Unity
|
||||
private GameObject _currentOrbInstance;
|
||||
private bool _isGameRunning;
|
||||
private int _currentPlayerFloorIndex;
|
||||
private int _currentDisplayedScore;
|
||||
private float _inputBlockTimer;
|
||||
private bool _isPaused;
|
||||
private bool _levelGenerated;
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_actions = new InputSystem_Actions();
|
||||
@@ -88,18 +82,16 @@ namespace Infrastructure.Unity
|
||||
SpawnDeathPlane();
|
||||
SpawnPlayer();
|
||||
|
||||
if (gameOverUi) gameOverUi.SetActive(false);
|
||||
if (startScreenUi) startScreenUi.SetActive(true); // Show start screen NOW
|
||||
uiCoordinator?.ShowStartScreen();
|
||||
uiCoordinator?.UpdateHighScore(_gameSession.HighScore);
|
||||
|
||||
WireEvents();
|
||||
UpdateScoreUi(_gameSession.Score);
|
||||
|
||||
|
||||
_levelGenerated = true;
|
||||
}));
|
||||
}
|
||||
|
||||
if (gameOverUi) gameOverUi.SetActive(false);
|
||||
if (startScreenUi) startScreenUi.SetActive(true);
|
||||
uiCoordinator?.ShowStartScreen();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -172,14 +164,14 @@ namespace Infrastructure.Unity
|
||||
{
|
||||
Time.timeScale = 0f;
|
||||
if (soundManager) soundManager.SetPaused(true);
|
||||
if (pauseUi) pauseUi.SetActive(true);
|
||||
uiCoordinator?.ShowPauseUi();
|
||||
if (rumbleManager) rumbleManager.SetPaused(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
if (soundManager) soundManager.SetPaused(false);
|
||||
if (pauseUi) pauseUi.SetActive(false);
|
||||
uiCoordinator?.HidePauseUi();
|
||||
if (rumbleManager) rumbleManager.SetPaused(false);
|
||||
}
|
||||
}
|
||||
@@ -207,34 +199,6 @@ namespace Infrastructure.Unity
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScoreUi(int newScore)
|
||||
{
|
||||
if (!scoreText) return;
|
||||
|
||||
LeanTween.cancel(scoreText.gameObject);
|
||||
|
||||
scoreText.rectTransform.localScale = Vector3.one;
|
||||
LeanTween.scale(scoreText.rectTransform, Vector3.one * 1.5f, 0.5f)
|
||||
.setEasePunch();
|
||||
|
||||
LeanTween.value(scoreText.gameObject, (float val) =>
|
||||
{
|
||||
var currentVal = Mathf.RoundToInt(val);
|
||||
|
||||
var combo = _gameSession?.ComboMultiplier ?? 1;
|
||||
var comboText = combo > 1 ? $" <color=yellow>x{combo}</color>" : "";
|
||||
|
||||
scoreText.text = $"{currentVal}{comboText}";
|
||||
}, _currentDisplayedScore, newScore, 0.5f)
|
||||
.setEaseOutExpo();
|
||||
|
||||
_currentDisplayedScore = newScore;
|
||||
|
||||
if (highScoreText && _gameSession != null)
|
||||
highScoreText.text = $"BEST: {_gameSession.HighScore}";
|
||||
|
||||
}
|
||||
|
||||
private void SpawnPlayer()
|
||||
{
|
||||
var spawnPos = new Vector3(0f, 5f, 0f);
|
||||
@@ -268,8 +232,6 @@ namespace Infrastructure.Unity
|
||||
_isGameRunning = false;
|
||||
|
||||
if (beatPulseController) beatPulseController.StopTracking();
|
||||
|
||||
if (gameOverUi) gameOverUi.SetActive(true);
|
||||
|
||||
StartCoroutine(RestartRoutine());
|
||||
}
|
||||
@@ -283,7 +245,7 @@ namespace Infrastructure.Unity
|
||||
|
||||
private void WireEvents()
|
||||
{
|
||||
_gameSession.OnScoreChanged += UpdateScoreUi;
|
||||
uiCoordinator?.Subscribe(_gameSession);
|
||||
_gameSession.OnOrbSpawned += SpawnVisualOrb;
|
||||
_gameSession.OnOrbReset += HandleOrbReset;
|
||||
_gameSession.OnGameOver += HandleGameOver;
|
||||
@@ -340,9 +302,8 @@ namespace Infrastructure.Unity
|
||||
private void StartGameSequence()
|
||||
{
|
||||
_isGameRunning = true;
|
||||
_currentDisplayedScore = 0;
|
||||
|
||||
if (startScreenUi) startScreenUi.SetActive(false);
|
||||
|
||||
uiCoordinator?.HideStartScreen();
|
||||
|
||||
if (soundManager)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user