feat: load system

This commit is contained in:
Gerard Gascón 2024-04-17 00:37:39 +02:00
parent 5d470a57af
commit 60d20bfe4e
20 changed files with 421 additions and 67 deletions

View file

@ -16,7 +16,7 @@ namespace Presenter {
public void Execute() {
_score.Add();
_view.UpdateView(_score.Value);
_view.UpdateView(_score.Value, _score.GrowPercentage);
if (CanSpawn)
_spawner.SpawnRose();

View file

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

View file

@ -0,0 +1,16 @@
using Domain;
using Presenter.SaveSystem;
using UnityEngine;
namespace Presenter {
public class PlayerPrefsRepository : IGameRepository {
public void SaveScore(Score score) {
PlayerPrefs.SetInt("Score", score.Value);
}
public Score LoadScore() {
int score = PlayerPrefs.GetInt("Score", 0);
return new Score(score, 0, 0);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8dce8a5ed9294a1283494fef143729a4
timeCreated: 1713305716

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f18e98c111ab4c0fa067e9a5039254a7
timeCreated: 1713304989

View file

@ -0,0 +1,8 @@
using Domain;
namespace Presenter.SaveSystem {
public interface IGameRepository {
void SaveScore(Score score);
Score LoadScore();
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 66c3464d602142f5813956378a7071bb
timeCreated: 1713305003

View file

@ -0,0 +1,21 @@
using Domain;
namespace Presenter.SaveSystem {
public class LoadGame {
private readonly IGameRepository _repository;
private readonly Score _score;
private readonly IExpressionInput _expressionInput;
public LoadGame(IGameRepository repository, Score score, IExpressionInput expressionInput) {
_repository = repository;
_score = score;
_expressionInput = expressionInput;
}
public void Run() {
Score newScore = _repository.LoadScore();
_score.SetFromOtherScore(newScore);
_expressionInput.UpdateView(_score.Value, _score.GrowPercentage);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3e87dd4026b94e5e90ce9d2163026446
timeCreated: 1713305374

View file

@ -0,0 +1,17 @@
using Domain;
namespace Presenter.SaveSystem {
public class SaveGame {
private readonly IGameRepository _repository;
private readonly Score _score;
public SaveGame(IGameRepository repository, Score score) {
_repository = repository;
_score = score;
}
public void Run() {
_repository.SaveScore(_score);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c1e36f7baa3d4eccb7073f6b4b803621
timeCreated: 1713305232