refactor: Cleaned up score view interface

This commit is contained in:
Gerard Gascón 2024-04-19 11:28:39 +02:00
parent 779af276d3
commit 858e49e1d9
13 changed files with 36 additions and 123 deletions

View file

@ -3,14 +3,14 @@
namespace Presenter { namespace Presenter {
public class ExpressionClick { public class ExpressionClick {
private readonly Score _score; private readonly Score _score;
private readonly IExpressionInput _view; private readonly IScoreView _view;
private readonly IRoseGrow _grow; private readonly IRoseGrow _grow;
private readonly IInputCallback _onInputReceived; private readonly IInputCallback _onInputReceived;
private readonly IRoseSpawner _spawner; private readonly IRoseSpawner _spawner;
private bool CanSpawn => _score.Value % (_score.GrowIterations * _score.SpawnRate) == 0; 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; _score = score;
_view = view; _view = view;
_spawner = spawner; _spawner = spawner;
@ -20,7 +20,7 @@ namespace Presenter {
public void Execute() { public void Execute() {
_score.Add(); _score.Add();
_view.UpdateView(_score.Value, _score.GrowPercentage); _view.UpdateView(_score.Value);
_onInputReceived.OnInputReceived(); _onInputReceived.OnInputReceived();
if (CanSpawn) if (CanSpawn)

View file

@ -1,5 +0,0 @@
namespace Presenter {
public interface IExpressionInput {
void UpdateView(int score, float growPercentage);
}
}

View file

@ -0,0 +1,5 @@
namespace Presenter {
public interface IScoreView {
void UpdateView(int score);
}
}

View file

@ -4,14 +4,14 @@ namespace Presenter.SaveSystem {
public class LoadGame { public class LoadGame {
private readonly IGameRepository _repository; private readonly IGameRepository _repository;
private readonly Score _score; private readonly Score _score;
private readonly IExpressionInput _expressionInput; private readonly IScoreView _scoreView;
private readonly IRoseSpawner _spawner; private readonly IRoseSpawner _spawner;
private readonly IRoseGrow _growAnimation; 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; _repository = repository;
_score = score; _score = score;
_expressionInput = expressionInput; _scoreView = scoreView;
_spawner = spawner; _spawner = spawner;
_growAnimation = growAnimation; _growAnimation = growAnimation;
} }
@ -19,7 +19,7 @@ namespace Presenter.SaveSystem {
public void Run() { public void Run() {
Score newScore = _repository.LoadScore(); Score newScore = _repository.LoadScore();
_score.SetFromOtherScore(newScore); _score.SetFromOtherScore(newScore);
_expressionInput.UpdateView(_score.Value, _score.GrowPercentage); _scoreView.UpdateView(_score.Value);
_growAnimation.GrowStep(); _growAnimation.GrowStep();
int roses = _score.Value / (_score.SpawnRate * _score.GrowIterations); int roses = _score.Value / (_score.SpawnRate * _score.GrowIterations);

View file

@ -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);
}
}
}

View 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);
}
}
}

View file

@ -19,9 +19,9 @@ namespace View {
private void Awake() { private void Awake() {
Score = new Score(10, 10); Score = new Score(10, 10);
IExpressionInput input = FindObjectOfType<ExpressionInput>(); IScoreView input = FindObjectOfType<ScoreView>();
IExpressionInput visibility = FindObjectOfType<UIVisibility>(); IScoreView visibility = FindObjectOfType<UIVisibility>();
IExpressionInput inputCollections = new ExpressionInputCollection(new[] { input, visibility }); IScoreView inputCollections = new ScoreViewCollection(new[] { input, visibility });
IRoseSpawner spawner = FindObjectOfType<RoseSpawner>(); IRoseSpawner spawner = FindObjectOfType<RoseSpawner>();

View file

@ -4,7 +4,7 @@ using TMPro;
using UnityEngine; using UnityEngine;
namespace View.UI { namespace View.UI {
public class ExpressionInput : MonoBehaviour, IExpressionInput { public class ScoreView : MonoBehaviour, IScoreView {
[SerializeField] private TMP_Text text; [SerializeField] private TMP_Text text;
private ExpressionClick _click; private ExpressionClick _click;
@ -18,7 +18,7 @@ namespace View.UI {
private void Update() => private void Update() =>
CheckInput(); CheckInput();
public void UpdateView(int score, float growPercentage) => public void UpdateView(int score) =>
text.text = score.ToString(); text.text = score.ToString();
private void CheckInput() { private void CheckInput() {

View file

@ -5,7 +5,7 @@ using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
namespace View.UI { namespace View.UI {
public class UIVisibility : MonoBehaviour, IExpressionInput { public class UIVisibility : MonoBehaviour, IScoreView {
[SerializeField] private CanvasGroup ui; [SerializeField] private CanvasGroup ui;
[SerializeField] private float fadeDuration = .5f; [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; if (!_titleVisible) return;
_titleVisible = false; _titleVisible = false;

View file

@ -7,97 +7,10 @@
[LOG] OutputWASAPI::init : Output buffer size: 4096 samples, latency: 0.00ms, period: 10.67ms, DSP buffer: 1024 * 4 [LOG] OutputWASAPI::init : Output buffer size: 4096 samples, latency: 0.00ms, period: 10.67ms, DSP buffer: 1024 * 4
[LOG] Thread::initThread : Init FMOD stream thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFB, Stack Size: 98304, Semaphore: No, Sleep Time: 10, Looping: Yes. [LOG] Thread::initThread : Init FMOD stream thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFB, Stack Size: 98304, Semaphore: No, Sleep Time: 10, Looping: Yes.
[LOG] Thread::initThread : Init FMOD mixer thread. Affinity: 0x4000000000000001, Priority: 0xFFFF7FFA, Stack Size: 81920, Semaphore: No, Sleep Time: 0, Looping: Yes. [LOG] Thread::initThread : Init FMOD mixer thread. Affinity: 0x4000000000000001, Priority: 0xFFFF7FFA, Stack Size: 81920, Semaphore: No, Sleep Time: 0, Looping: Yes.
[LOG] AsyncManager::init : manager 0000020359CFD0D8 isAsync 0 updatePeriod 0.02 [LOG] AsyncManager::init : manager 000002035DC49838 isAsync 0 updatePeriod 0.02
[LOG] AsyncManager::init : done [LOG] AsyncManager::init : done
[LOG] PlaybackSystem::init : [LOG] PlaybackSystem::init :
[LOG] Thread::initThread : Init FMOD Studio sample load thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No. [LOG] Thread::initThread : Init FMOD Studio sample load thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[LOG] PlaybackSystem::init : done [LOG] PlaybackSystem::init : done
[LOG] Thread::initThread : Init FMOD Studio bank load thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No. [LOG] Thread::initThread : Init FMOD Studio bank load thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[LOG] Manager::init : done. [LOG] Manager::init : done.
[LOG] SystemI::createSound : filename = Assets/Audio/Master.bank : mode 02010082
[LOG] SystemI::createSound : FMOD_NONBLOCKING specified. Putting into queue to be opened asynchronously!
[LOG] Thread::initThread : Init FMOD nonblocking thread (0). Affinity: 0x4000000000000003, Priority: 0xFFFF7FFC, Stack Size: 114688, Semaphore: Yes, Sleep Time: 0, Looping: Yes.
[LOG] SystemI::createSound : setdata soundi = 00000202A2449798 : node = 00000202A9AFA2E0
[LOG] SystemI::createSound : add node to async list : head = 000002023A6557E8. list count = 0
[LOG] AsyncThread::threadFunc : Starting Asynchronous operation on sound 00000202A2449798
[LOG] SystemI::createSound : filename = Assets/Audio/Master.bank : mode 02010082
[LOG] SystemI::createSound : FMOD_NONBLOCKING specified. Putting into queue to be opened asynchronously!
[LOG] SystemI::createSoundInternal : Create name='Assets/Audio/Master.bank', mode=0x02010082
[LOG] SystemI::createSound : setdata soundi = 00000202A2449948 : node = 00000202A9AFA6A0
[LOG] SystemI::createSoundInternal : exinfo->cbsize = 224
[LOG] SystemI::createSound : add node to async list : head = 000002023A6557E8. list count = 0
[LOG] SystemI::createSoundInternal : exinfo->length = 27574784
[LOG] SystemI::createSoundInternal : exinfo->fileoffset = 10144
[LOG] SystemI::createSoundInternal : exinfo->numsubsounds = 1
[LOG] SystemI::createSound : filename = Assets/Audio/Master.bank : mode 02010082
[LOG] SystemI::createSoundInternal : exinfo->inclusionlist = 00000202A9AFA3F0
[LOG] SystemI::createSound : FMOD_NONBLOCKING specified. Putting into queue to be opened asynchronously!
[LOG] SystemI::createSoundInternal : exinfo->inclusionlistnum = 1
[LOG] SystemI::createSound : setdata soundi = 00000202A2449AF8 : node = 00000202A9AFA060
[LOG] SystemI::createSoundInternal : exinfo->suggestedsoundtype = 5
[LOG] SystemI::createSound : add node to async list : head = 000002023A6557E8. list count = 1
[LOG] SystemI::createSoundInternal : exinfo->initialseekpostype = 1
[LOG] SystemI::createSoundInternal : Create name='', mode=0x02000202
[LOG] SystemI::createSoundInternal : exinfo->cbsize = 224
[LOG] SystemI::createSoundInternal : exinfo->length = 27574784
[LOG] SystemI::createSoundInternal : exinfo->fileoffset = 10144
[LOG] SystemI::createSoundInternal : exinfo->numsubsounds = 1
[LOG] SystemI::createSoundInternal : exinfo->inclusionlist = 0000003163DFF568
[LOG] SystemI::createSoundInternal : exinfo->inclusionlistnum = 1
[LOG] SystemI::createSoundInternal : exinfo->suggestedsoundtype = 5
[LOG] SystemI::createSoundInternal : exinfo->useropen = 00007FFBF0674660
[LOG] SystemI::createSoundInternal : exinfo->userclose = 00007FFBF0674630
[LOG] SystemI::createSoundInternal : exinfo->userread = 00007FFBF0674730
[LOG] SystemI::createSoundInternal : exinfo->userseek = 00007FFBF06747F0
[LOG] SystemI::createSoundInternal : exinfo->fileuserdata = 000002035A1A08B8
[LOG] SystemI::createSoundInternal : exinfo->initialseekpostype = 1
[LOG] SystemI::createSoundInternal : Stream 0/1: name='Rosa_Melo_02', format=5, channels=2, frequency=48000, lengthbytes=3260640, lengthpcm=17145600, pcmblocksize=0, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.248419.
[LOG] SystemI::DSPCodecPoolRegister : register codec pool for pool type 5
[LOG] SystemI::createSoundInternal : Sample 0/1: name='foliage_dry_crush_squeeze_crunchy_crispy_001_55111', format=5, channels=2, frequency=48000, lengthbytes=34880, lengthpcm=101376, pcmblocksize=0, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.731995.
[LOG] Thread::initThread : Init FMOD file thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFC, Stack Size: 65536, Semaphore: No, Sleep Time: 10, Looping: Yes.
[LOG] AsyncThread::threadFunc : Finished Asynchronous operation on sound 00000202A2449798
[LOG] AsyncThread::threadFunc : Starting Asynchronous operation on sound 00000202A2449948
[LOG] SystemI::createSoundInternal : Create name='Assets/Audio/Master.bank', mode=0x02010082
[LOG] SystemI::createSoundInternal : exinfo->cbsize = 224
[LOG] SystemI::createSoundInternal : exinfo->length = 27574784
[LOG] SystemI::createSoundInternal : exinfo->fileoffset = 10144
[LOG] SystemI::createSoundInternal : exinfo->numsubsounds = 1
[LOG] SystemI::createSoundInternal : exinfo->inclusionlist = 00000202A9AFA7B0
[LOG] SystemI::createSoundInternal : exinfo->inclusionlistnum = 1
[LOG] SystemI::createSoundInternal : exinfo->suggestedsoundtype = 5
[LOG] SystemI::createSoundInternal : exinfo->initialseekpostype = 1
[LOG] SystemI::createSoundInternal : Stream 0/1: name='Rosa_Base_01', format=5, channels=2, frequency=48000, lengthbytes=3775680, lengthpcm=17193600, pcmblocksize=0, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.174706.
[LOG] AsyncThread::threadFunc : Finished Asynchronous operation on sound 00000202A2449948
[LOG] AsyncThread::threadFunc : Starting Asynchronous operation on sound 00000202A2449AF8
[LOG] SystemI::createSoundInternal : Create name='Assets/Audio/Master.bank', mode=0x02010082
[LOG] SystemI::createSoundInternal : exinfo->cbsize = 224
[LOG] SystemI::createSoundInternal : exinfo->length = 27574784
[LOG] SystemI::createSoundInternal : exinfo->fileoffset = 10144
[LOG] SystemI::createSoundInternal : exinfo->numsubsounds = 1
[LOG] SystemI::createSoundInternal : exinfo->inclusionlist = 00000202A9AFA170
[LOG] SystemI::createSoundInternal : exinfo->inclusionlistnum = 1
[LOG] SystemI::createSoundInternal : exinfo->suggestedsoundtype = 5
[LOG] SystemI::createSoundInternal : exinfo->initialseekpostype = 1
[LOG] SystemI::createSoundInternal : Stream 0/1: name='Rosa_Ambient_Birds_01', format=5, channels=2, frequency=48000, lengthbytes=3372608, lengthpcm=17049600, pcmblocksize=0, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.007681.
[LOG] AsyncThread::threadFunc : Finished Asynchronous operation on sound 00000202A2449AF8
[LOG] SoundI::release : Rosa_Ambient_Birds_01 (00000202A2449AF8)
[LOG] SoundI::release : Rosa_Ambient_Birds_01 (00000202A1232718)
[LOG] SoundI::release : Rosa_Ambient_Birds_01 (0000020235D40CE8)
[LOG] SoundI::release : Rosa_Base_01 (00000202A2449948)
[LOG] SoundI::release : Rosa_Base_01 (00000202A1232098)
[LOG] SoundI::release : Rosa_Base_01 (0000020235D40B38)
[LOG] SoundI::release : Rosa_Melo_02 (00000202A2449798)
[LOG] SoundI::release : Rosa_Melo_02 (00000202A1231A18)
[LOG] SoundI::release : Rosa_Melo_02 (0000020235D40628)
[LOG] SoundI::release : (00000202A4073688)
[LOG] SoundI::release : foliage_dry_crush_squeeze_crunchy_crispy_001_55111 (00000202A3AD7F48)
[LOG] Thread::callback : FMOD Studio update thread finished.
[LOG] Thread::callback : FMOD Studio bank load thread finished.
[LOG] Profile::disconnectAll : Profiler disconnecting all clients
[LOG] Thread::callback : FMOD Studio sample load thread finished.
[LOG] LiveUpdate::release :
[LOG] LiveUpdate::reset : Reset connection (reason Disconnected)
[LOG] Thread::callback : FMOD stream thread finished.
[LOG] Thread::callback : FMOD mixer thread finished.
[LOG] Profile::disconnectAll : Profiler disconnecting all clients
[LOG] SystemI::close : Closed.