fix: first clicks now are properly detected

This commit is contained in:
Gerard Gascón 2024-04-20 12:22:05 +02:00
parent db839ea96d
commit 2cddb7a7b9
13 changed files with 99 additions and 30 deletions

View file

@ -158,6 +158,7 @@ MonoBehaviour:
y: -5 y: -5
width: 12 width: 12
height: 10 height: 10
initialSpawnerAvoidedRegion: 4
rose: {fileID: 2147392553565862127, guid: 72ac2e17b1585614eb5c2eb65a0d37c0, type: 3} rose: {fileID: 2147392553565862127, guid: 72ac2e17b1585614eb5c2eb65a0d37c0, type: 3}
--- !u!4 &4783506 --- !u!4 &4783506
Transform: Transform:

View file

@ -2,10 +2,13 @@
public class Score { public class Score {
public int Value { private set; get; } public int Value { private set; get; }
public const int InitialRosesThreshold = 5;
public readonly int SpawnRate; public readonly int SpawnRate;
public readonly int GrowIterations; public readonly int GrowIterations;
public float GrowPercentage { private set; get; } public float GrowPercentage { private set; get; }
public int Roses => Value / (SpawnRate * GrowIterations);
public Score(int spawnRate, int growIterations) : this(0, spawnRate, growIterations) { } public Score(int spawnRate, int growIterations) : this(0, spawnRate, growIterations) { }

View file

@ -23,8 +23,12 @@ namespace Presenter {
_view.UpdateView(_score.Value); _view.UpdateView(_score.Value);
_onInputReceived.OnInputReceived(); _onInputReceived.OnInputReceived();
if (CanSpawn) if (CanSpawn) {
if(_score.Value > Score.InitialRosesThreshold)
_spawner.SpawnRose(); _spawner.SpawnRose();
else
_spawner.SpawnInitialRose();
}
if (_score.Value % _score.GrowIterations == 0) if (_score.Value % _score.GrowIterations == 0)
_grow.GrowStep(); _grow.GrowStep();
} }

View file

@ -1,5 +1,6 @@
namespace Presenter { namespace Presenter {
public interface IRoseSpawner { public interface IRoseSpawner {
void SpawnRose(); void SpawnRose();
void SpawnInitialRose();
} }
} }

View file

@ -22,9 +22,12 @@ namespace Presenter.SaveSystem {
_scoreView.UpdateView(_score.Value); _scoreView.UpdateView(_score.Value);
_growAnimation.GrowStep(); _growAnimation.GrowStep();
int roses = _score.Value / (_score.SpawnRate * _score.GrowIterations); for (int i = 0; i < _score.Roses; i++) {
for (int i = 0; i < roses; i++) if (_score.Roses > Score.InitialRosesThreshold)
_spawner.SpawnRose(); _spawner.SpawnRose();
else
_spawner.SpawnInitialRose();
}
} }
} }
} }

View file

@ -0,0 +1,16 @@
using Presenter;
namespace View.Collections {
public class InputCallbackCollection : IInputCallback {
private readonly IInputCallback[] _inputs;
public InputCallbackCollection(IInputCallback[] inputs) {
_inputs = inputs;
}
public void OnInputReceived() {
foreach (IInputCallback input in _inputs)
input.OnInputReceived();
}
}
}

View file

@ -1,16 +0,0 @@
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

@ -20,21 +20,21 @@ namespace View {
Score = new Score(10, 10); Score = new Score(10, 10);
IScoreView input = FindObjectOfType<ScoreView>(); IScoreView input = FindObjectOfType<ScoreView>();
IScoreView visibility = FindObjectOfType<UIVisibility>();
IScoreView inputCollections = new ScoreViewCollection(new[] { input, visibility });
IRoseSpawner spawner = FindObjectOfType<RoseSpawner>(); IRoseSpawner spawner = FindObjectOfType<RoseSpawner>();
IInputCallback visibility = FindObjectOfType<UIVisibility>();
IInputCallback growParticles = FindObjectOfType<GrowParticlesSpawner>(); IInputCallback growParticles = FindObjectOfType<GrowParticlesSpawner>();
IInputCallback inputCallback = new InputCallbackCollection(new[] { visibility, growParticles });
IRoseGrow growAnimation = FindObjectOfType<GrowAnimation>(); IRoseGrow growAnimation = FindObjectOfType<GrowAnimation>();
ExpressionClick = new ExpressionClick(Score, inputCollections, spawner, growAnimation, growParticles); ExpressionClick = new ExpressionClick(Score, input, spawner, growAnimation, inputCallback);
CustomInput = new CustomInput(); CustomInput = new CustomInput();
PlayerPrefsRepository repository = new(); PlayerPrefsRepository repository = new();
Saver = new SaveGame(repository, Score); Saver = new SaveGame(repository, Score);
Loader = new LoadGame(repository, Score, inputCollections, spawner, growAnimation); Loader = new LoadGame(repository, Score, input, spawner, growAnimation);
} }
} }
} }

View file

@ -6,6 +6,7 @@ using Random = UnityEngine.Random;
namespace View { namespace View {
public class RoseSpawner : MonoBehaviour, IRoseSpawner { public class RoseSpawner : MonoBehaviour, IRoseSpawner {
[SerializeField] private Rect spawnerRegion; [SerializeField] private Rect spawnerRegion;
[SerializeField] private float initialSpawnerAvoidedRegion;
[SerializeField] private GameObject rose; [SerializeField] private GameObject rose;
public void SpawnRose() { public void SpawnRose() {
@ -14,11 +15,35 @@ namespace View {
spawnerRegion.position.y + Random.Range(-spawnerRegion.size.y / 2f, spawnerRegion.size.y / 2f) spawnerRegion.position.y + Random.Range(-spawnerRegion.size.y / 2f, spawnerRegion.size.y / 2f)
); );
Instantiate(rose, spawnPos, Quaternion.identity); Spawn(spawnPos);
}
public void SpawnInitialRose() {
bool spawnOnRight = Random.Range(0, 2) == 0;
Vector2 spawnPos;
if (spawnOnRight) {
spawnPos = new Vector2(
spawnerRegion.position.x + Random.Range(initialSpawnerAvoidedRegion / 2f, spawnerRegion.size.x / 2f),
spawnerRegion.position.y + Random.Range(-spawnerRegion.size.y / 2f, spawnerRegion.size.y / 2f)
);
} else {
spawnPos = new Vector2(
spawnerRegion.position.x + Random.Range(-spawnerRegion.size.x / 2f, -initialSpawnerAvoidedRegion / 2f),
spawnerRegion.position.y + Random.Range(-spawnerRegion.size.y / 2f, spawnerRegion.size.y / 2f)
);
}
Spawn(spawnPos);
}
private void Spawn(Vector2 pos) {
Instantiate(rose, pos, Quaternion.identity);
} }
private void OnDrawGizmos() { private void OnDrawGizmos() {
Gizmos.DrawWireCube(spawnerRegion.position, spawnerRegion.size); Gizmos.DrawWireCube(spawnerRegion.position, spawnerRegion.size);
Gizmos.color = Color.red;
Gizmos.DrawWireCube(spawnerRegion.position, new Vector2(initialSpawnerAvoidedRegion, spawnerRegion.size.y));
} }
} }
} }

View file

@ -16,7 +16,7 @@ namespace View.Scene {
[SerializeField] private EventReference gloomEvent; [SerializeField] private EventReference gloomEvent;
private Score _score; private Score _score;
private bool _firstUpdate; private bool _firstUpdate = true;
private void Start() { private void Start() {
_score = FindObjectOfType<Dependencies>().Score; _score = FindObjectOfType<Dependencies>().Score;
@ -41,7 +41,7 @@ namespace View.Scene {
public void GrowStep() { public void GrowStep() {
if (animator.CurrentAnimation == "Rosa_Grow") { if (animator.CurrentAnimation == "Rosa_Grow") {
animator.PlayUntil(IsLastGrowState(_score.Value, _score.GrowPercentage) ? 1f : _score.GrowPercentage); animator.PlayUntil(IsLastGrowState(_score.Value, _score.GrowPercentage) ? 1f : _score.GrowPercentage);
if (_score.GrowPercentage < 1f) if (_score.GrowPercentage < 1f && !_firstUpdate)
RuntimeManager.PlayOneShot(growEvent); RuntimeManager.PlayOneShot(growEvent);
} }
_firstUpdate = false; _firstUpdate = false;

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, IScoreView { public class UIVisibility : MonoBehaviour, IInputCallback {
[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) { public void OnInputReceived() {
if (!_titleVisible) return; if (!_titleVisible) return;
_titleVisible = false; _titleVisible = false;

View file

@ -0,0 +1,32 @@
[LOG] System::create : Header version = 2.02.06. Current version = 2.02.06.
[LOG] Manager::init : maxchannels = 256 studioflags = 00000006 flags 00000000 extradriverdata 0000000000000000.
[LOG] SystemI::init : Initialize version=20206 (124257), maxchannels=256, flags=0x00020000
[LOG] SystemI::setOutputInternal : Setting output to 'FMOD WASAPI Output'
[LOG] OutputWASAPI::init : Mix Format (WAVEFORMATEX): wFormatTag=0xFFFE, nChannels=2, nSamplesPerSec=48000, nAvgBytesPerSec=384000, nBlockAlign=8, wBitsPerSample=32, cbSize=22.
[LOG] OutputWASAPI::init : Mix Format (WAVEFORMATEXTENSIBLE): wValidBitsPerSample=32, dwChannelMask=0x00000003, SubFormat=00000003-0000-0010-8000-00AA00389B71.
[LOG] OutputWASAPI::init : Output buffer size: 4096 samples, latency: 0.00ms, period: 10.00ms, 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 mixer thread. Affinity: 0x4000000000000001, Priority: 0xFFFF7FFA, Stack Size: 81920, Semaphore: No, Sleep Time: 0, Looping: Yes.
[LOG] AsyncManager::init : manager 000001B757DCD1A8 isAsync 0 updatePeriod 0.02
[LOG] AsyncManager::init : done
[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] 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] Manager::init : done.
[LOG] SystemI::createSoundInternal : Create name='', mode=0x02000202
[LOG] SystemI::createSoundInternal : exinfo->cbsize = 224
[LOG] SystemI::createSoundInternal : exinfo->length = 28161664
[LOG] SystemI::createSoundInternal : exinfo->fileoffset = 10400
[LOG] SystemI::createSoundInternal : exinfo->numsubsounds = 1
[LOG] SystemI::createSoundInternal : exinfo->inclusionlist = 0000009D2BA6F328
[LOG] SystemI::createSoundInternal : exinfo->inclusionlistnum = 1
[LOG] SystemI::createSoundInternal : exinfo->suggestedsoundtype = 5
[LOG] SystemI::createSoundInternal : exinfo->useropen = 00007FF880C04660
[LOG] SystemI::createSoundInternal : exinfo->userclose = 00007FF880C04630
[LOG] SystemI::createSoundInternal : exinfo->userread = 00007FF880C04730
[LOG] SystemI::createSoundInternal : exinfo->userseek = 00007FF880C047F0
[LOG] SystemI::createSoundInternal : exinfo->fileuserdata = 000001B764B2DF88
[LOG] SystemI::createSoundInternal : exinfo->initialseekpostype = 1
[LOG] SystemI::DSPCodecPoolRegister : register codec pool for pool type 5
[LOG] SystemI::createSoundInternal : Sample 0/1: name='Rosa_grow_01', format=5, channels=2, frequency=48000, lengthbytes=53664, lengthpcm=264000, pcmblocksize=0, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.124284.