refactor: Cleaned up score view interface
This commit is contained in:
parent
779af276d3
commit
858e49e1d9
13 changed files with 36 additions and 123 deletions
|
@ -3,14 +3,14 @@
|
|||
namespace Presenter {
|
||||
public class ExpressionClick {
|
||||
private readonly Score _score;
|
||||
private readonly IExpressionInput _view;
|
||||
private readonly IScoreView _view;
|
||||
private readonly IRoseGrow _grow;
|
||||
private readonly IInputCallback _onInputReceived;
|
||||
private readonly IRoseSpawner _spawner;
|
||||
|
||||
private bool CanSpawn => _score.Value % (_score.GrowIterations * _score.SpawnRate) == 0;
|
||||
|
||||
public ExpressionClick(Score score, IExpressionInput view, IRoseSpawner spawner, IRoseGrow grow, IInputCallback inputCallback) {
|
||||
public ExpressionClick(Score score, IScoreView view, IRoseSpawner spawner, IRoseGrow grow, IInputCallback inputCallback) {
|
||||
_score = score;
|
||||
_view = view;
|
||||
_spawner = spawner;
|
||||
|
@ -20,7 +20,7 @@ namespace Presenter {
|
|||
|
||||
public void Execute() {
|
||||
_score.Add();
|
||||
_view.UpdateView(_score.Value, _score.GrowPercentage);
|
||||
_view.UpdateView(_score.Value);
|
||||
_onInputReceived.OnInputReceived();
|
||||
|
||||
if (CanSpawn)
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
namespace Presenter {
|
||||
public interface IExpressionInput {
|
||||
void UpdateView(int score, float growPercentage);
|
||||
}
|
||||
}
|
5
Assets/Scripts/Presenter/IScoreView.cs
Normal file
5
Assets/Scripts/Presenter/IScoreView.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
namespace Presenter {
|
||||
public interface IScoreView {
|
||||
void UpdateView(int score);
|
||||
}
|
||||
}
|
|
@ -4,14 +4,14 @@ namespace Presenter.SaveSystem {
|
|||
public class LoadGame {
|
||||
private readonly IGameRepository _repository;
|
||||
private readonly Score _score;
|
||||
private readonly IExpressionInput _expressionInput;
|
||||
private readonly IScoreView _scoreView;
|
||||
private readonly IRoseSpawner _spawner;
|
||||
private readonly IRoseGrow _growAnimation;
|
||||
|
||||
public LoadGame(IGameRepository repository, Score score, IExpressionInput expressionInput, IRoseSpawner spawner, IRoseGrow growAnimation) {
|
||||
public LoadGame(IGameRepository repository, Score score, IScoreView scoreView, IRoseSpawner spawner, IRoseGrow growAnimation) {
|
||||
_repository = repository;
|
||||
_score = score;
|
||||
_expressionInput = expressionInput;
|
||||
_scoreView = scoreView;
|
||||
_spawner = spawner;
|
||||
_growAnimation = growAnimation;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace Presenter.SaveSystem {
|
|||
public void Run() {
|
||||
Score newScore = _repository.LoadScore();
|
||||
_score.SetFromOtherScore(newScore);
|
||||
_expressionInput.UpdateView(_score.Value, _score.GrowPercentage);
|
||||
_scoreView.UpdateView(_score.Value);
|
||||
_growAnimation.GrowStep();
|
||||
|
||||
int roses = _score.Value / (_score.SpawnRate * _score.GrowIterations);
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
using Presenter;
|
||||
|
||||
namespace View.Collections {
|
||||
public class ExpressionInputCollection : IExpressionInput {
|
||||
private readonly IExpressionInput[] _inputs;
|
||||
|
||||
public ExpressionInputCollection(IExpressionInput[] inputs) {
|
||||
_inputs = inputs;
|
||||
}
|
||||
|
||||
public void UpdateView(int score, float growPercentage) {
|
||||
foreach (IExpressionInput input in _inputs)
|
||||
input.UpdateView(score, growPercentage);
|
||||
}
|
||||
}
|
||||
}
|
16
Assets/Scripts/View/Collections/ScoreViewCollection.cs
Normal file
16
Assets/Scripts/View/Collections/ScoreViewCollection.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using Presenter;
|
||||
|
||||
namespace View.Collections {
|
||||
public class ScoreViewCollection : IScoreView {
|
||||
private readonly IScoreView[] _inputs;
|
||||
|
||||
public ScoreViewCollection(IScoreView[] inputs) {
|
||||
_inputs = inputs;
|
||||
}
|
||||
|
||||
public void UpdateView(int score) {
|
||||
foreach (IScoreView input in _inputs)
|
||||
input.UpdateView(score);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,9 +19,9 @@ namespace View {
|
|||
private void Awake() {
|
||||
Score = new Score(10, 10);
|
||||
|
||||
IExpressionInput input = FindObjectOfType<ExpressionInput>();
|
||||
IExpressionInput visibility = FindObjectOfType<UIVisibility>();
|
||||
IExpressionInput inputCollections = new ExpressionInputCollection(new[] { input, visibility });
|
||||
IScoreView input = FindObjectOfType<ScoreView>();
|
||||
IScoreView visibility = FindObjectOfType<UIVisibility>();
|
||||
IScoreView inputCollections = new ScoreViewCollection(new[] { input, visibility });
|
||||
|
||||
IRoseSpawner spawner = FindObjectOfType<RoseSpawner>();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ using TMPro;
|
|||
using UnityEngine;
|
||||
|
||||
namespace View.UI {
|
||||
public class ExpressionInput : MonoBehaviour, IExpressionInput {
|
||||
public class ScoreView : MonoBehaviour, IScoreView {
|
||||
[SerializeField] private TMP_Text text;
|
||||
|
||||
private ExpressionClick _click;
|
||||
|
@ -18,7 +18,7 @@ namespace View.UI {
|
|||
private void Update() =>
|
||||
CheckInput();
|
||||
|
||||
public void UpdateView(int score, float growPercentage) =>
|
||||
public void UpdateView(int score) =>
|
||||
text.text = score.ToString();
|
||||
|
||||
private void CheckInput() {
|
|
@ -5,7 +5,7 @@ using UnityEngine.EventSystems;
|
|||
using UnityEngine.UI;
|
||||
|
||||
namespace View.UI {
|
||||
public class UIVisibility : MonoBehaviour, IExpressionInput {
|
||||
public class UIVisibility : MonoBehaviour, IScoreView {
|
||||
[SerializeField] private CanvasGroup ui;
|
||||
[SerializeField] private float fadeDuration = .5f;
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace View.UI {
|
|||
}
|
||||
}
|
||||
|
||||
public void UpdateView(int score, float growPercentage) {
|
||||
public void UpdateView(int score) {
|
||||
if (!_titleVisible) return;
|
||||
_titleVisible = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue