refactor: moved grow animation to its own class
This commit is contained in:
parent
150b602dc3
commit
779af276d3
14 changed files with 224 additions and 116 deletions
|
@ -5,28 +5,28 @@ namespace Presenter {
|
|||
private readonly Score _score;
|
||||
private readonly IExpressionInput _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) {
|
||||
public ExpressionClick(Score score, IExpressionInput view, IRoseSpawner spawner, IRoseGrow grow, IInputCallback inputCallback) {
|
||||
_score = score;
|
||||
_view = view;
|
||||
_spawner = spawner;
|
||||
_grow = grow;
|
||||
_onInputReceived = inputCallback;
|
||||
}
|
||||
|
||||
public void Execute() {
|
||||
_score.Add();
|
||||
_view.UpdateView(_score.Value, _score.GrowPercentage);
|
||||
_grow.Grow();
|
||||
|
||||
_onInputReceived.OnInputReceived();
|
||||
|
||||
if (CanSpawn)
|
||||
_spawner.SpawnRose();
|
||||
else if (_score.Value % _score.GrowIterations == 0)
|
||||
if (_score.Value % _score.GrowIterations == 0)
|
||||
_grow.GrowStep();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
5
Assets/Scripts/Presenter/IInputCallback.cs
Normal file
5
Assets/Scripts/Presenter/IInputCallback.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
namespace Presenter {
|
||||
public interface IInputCallback {
|
||||
void OnInputReceived();
|
||||
}
|
||||
}
|
3
Assets/Scripts/Presenter/IInputCallback.cs.meta
Normal file
3
Assets/Scripts/Presenter/IInputCallback.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b8d0f034669436ca57e685c00414e3f
|
||||
timeCreated: 1713517680
|
|
@ -1,6 +1,5 @@
|
|||
namespace Presenter {
|
||||
public interface IRoseGrow {
|
||||
void Grow();
|
||||
void GrowStep();
|
||||
}
|
||||
}
|
|
@ -6,18 +6,21 @@ namespace Presenter.SaveSystem {
|
|||
private readonly Score _score;
|
||||
private readonly IExpressionInput _expressionInput;
|
||||
private readonly IRoseSpawner _spawner;
|
||||
private readonly IRoseGrow _growAnimation;
|
||||
|
||||
public LoadGame(IGameRepository repository, Score score, IExpressionInput expressionInput, IRoseSpawner spawner) {
|
||||
public LoadGame(IGameRepository repository, Score score, IExpressionInput expressionInput, IRoseSpawner spawner, IRoseGrow growAnimation) {
|
||||
_repository = repository;
|
||||
_score = score;
|
||||
_expressionInput = expressionInput;
|
||||
_spawner = spawner;
|
||||
_growAnimation = growAnimation;
|
||||
}
|
||||
|
||||
public void Run() {
|
||||
Score newScore = _repository.LoadScore();
|
||||
_score.SetFromOtherScore(newScore);
|
||||
_expressionInput.UpdateView(_score.Value, _score.GrowPercentage);
|
||||
_growAnimation.GrowStep();
|
||||
|
||||
int roses = _score.Value / (_score.SpawnRate * _score.GrowIterations);
|
||||
for (int i = 0; i < roses; i++)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue