feat: load system
This commit is contained in:
		
							parent
							
								
									5d470a57af
								
							
						
					
					
						commit
						60d20bfe4e
					
				
					 20 changed files with 421 additions and 67 deletions
				
			
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
						 | 
					@ -2392,6 +2392,50 @@ CanvasRenderer:
 | 
				
			||||||
  m_PrefabAsset: {fileID: 0}
 | 
					  m_PrefabAsset: {fileID: 0}
 | 
				
			||||||
  m_GameObject: {fileID: 1488567635}
 | 
					  m_GameObject: {fileID: 1488567635}
 | 
				
			||||||
  m_CullTransparentMesh: 1
 | 
					  m_CullTransparentMesh: 1
 | 
				
			||||||
 | 
					--- !u!1 &1524010032
 | 
				
			||||||
 | 
					GameObject:
 | 
				
			||||||
 | 
					  m_ObjectHideFlags: 0
 | 
				
			||||||
 | 
					  m_CorrespondingSourceObject: {fileID: 0}
 | 
				
			||||||
 | 
					  m_PrefabInstance: {fileID: 0}
 | 
				
			||||||
 | 
					  m_PrefabAsset: {fileID: 0}
 | 
				
			||||||
 | 
					  serializedVersion: 6
 | 
				
			||||||
 | 
					  m_Component:
 | 
				
			||||||
 | 
					  - component: {fileID: 1524010034}
 | 
				
			||||||
 | 
					  - component: {fileID: 1524010033}
 | 
				
			||||||
 | 
					  m_Layer: 0
 | 
				
			||||||
 | 
					  m_Name: SaveLoad
 | 
				
			||||||
 | 
					  m_TagString: Untagged
 | 
				
			||||||
 | 
					  m_Icon: {fileID: 0}
 | 
				
			||||||
 | 
					  m_NavMeshLayer: 0
 | 
				
			||||||
 | 
					  m_StaticEditorFlags: 0
 | 
				
			||||||
 | 
					  m_IsActive: 1
 | 
				
			||||||
 | 
					--- !u!114 &1524010033
 | 
				
			||||||
 | 
					MonoBehaviour:
 | 
				
			||||||
 | 
					  m_ObjectHideFlags: 0
 | 
				
			||||||
 | 
					  m_CorrespondingSourceObject: {fileID: 0}
 | 
				
			||||||
 | 
					  m_PrefabInstance: {fileID: 0}
 | 
				
			||||||
 | 
					  m_PrefabAsset: {fileID: 0}
 | 
				
			||||||
 | 
					  m_GameObject: {fileID: 1524010032}
 | 
				
			||||||
 | 
					  m_Enabled: 1
 | 
				
			||||||
 | 
					  m_EditorHideFlags: 0
 | 
				
			||||||
 | 
					  m_Script: {fileID: 11500000, guid: 3c6dab5fe816434381b975fd75b667fc, type: 3}
 | 
				
			||||||
 | 
					  m_Name: 
 | 
				
			||||||
 | 
					  m_EditorClassIdentifier: 
 | 
				
			||||||
 | 
					--- !u!4 &1524010034
 | 
				
			||||||
 | 
					Transform:
 | 
				
			||||||
 | 
					  m_ObjectHideFlags: 0
 | 
				
			||||||
 | 
					  m_CorrespondingSourceObject: {fileID: 0}
 | 
				
			||||||
 | 
					  m_PrefabInstance: {fileID: 0}
 | 
				
			||||||
 | 
					  m_PrefabAsset: {fileID: 0}
 | 
				
			||||||
 | 
					  m_GameObject: {fileID: 1524010032}
 | 
				
			||||||
 | 
					  serializedVersion: 2
 | 
				
			||||||
 | 
					  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
 | 
				
			||||||
 | 
					  m_LocalPosition: {x: 0, y: 0, z: 0}
 | 
				
			||||||
 | 
					  m_LocalScale: {x: 1, y: 1, z: 1}
 | 
				
			||||||
 | 
					  m_ConstrainProportionsScale: 0
 | 
				
			||||||
 | 
					  m_Children: []
 | 
				
			||||||
 | 
					  m_Father: {fileID: 0}
 | 
				
			||||||
 | 
					  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 | 
				
			||||||
--- !u!1 &1631011313
 | 
					--- !u!1 &1631011313
 | 
				
			||||||
GameObject:
 | 
					GameObject:
 | 
				
			||||||
  m_ObjectHideFlags: 0
 | 
					  m_ObjectHideFlags: 0
 | 
				
			||||||
| 
						 | 
					@ -3418,3 +3462,4 @@ SceneRoots:
 | 
				
			||||||
  - {fileID: 1652443528}
 | 
					  - {fileID: 1652443528}
 | 
				
			||||||
  - {fileID: 902566663}
 | 
					  - {fileID: 902566663}
 | 
				
			||||||
  - {fileID: 4783506}
 | 
					  - {fileID: 4783506}
 | 
				
			||||||
 | 
					  - {fileID: 1524010034}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,15 +15,23 @@
 | 
				
			||||||
			GrowIterations = growIterations;
 | 
								GrowIterations = growIterations;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void SetFromOtherScore(Score other) {
 | 
				
			||||||
 | 
								Value = other.Value;
 | 
				
			||||||
 | 
								UpdateGrowPercentage();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void Add() {
 | 
							public void Add() {
 | 
				
			||||||
			Value++;
 | 
								Value++;
 | 
				
			||||||
 | 
								UpdateGrowPercentage();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (Value % GrowIterations == 0) {
 | 
							private void UpdateGrowPercentage() {
 | 
				
			||||||
				float relativeScore = Value % (GrowIterations * SpawnRate);
 | 
								int value = Value % GrowIterations == 0 ? Value : Value / GrowIterations * GrowIterations;
 | 
				
			||||||
				if (relativeScore == 0 && Value != 0)
 | 
					
 | 
				
			||||||
 | 
								float relativeScore = value % (GrowIterations * SpawnRate);
 | 
				
			||||||
 | 
								if (relativeScore == 0 && value != 0)
 | 
				
			||||||
				relativeScore = GrowIterations * SpawnRate;
 | 
									relativeScore = GrowIterations * SpawnRate;
 | 
				
			||||||
			GrowPercentage = relativeScore / (SpawnRate * GrowIterations);
 | 
								GrowPercentage = relativeScore / (SpawnRate * GrowIterations);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -16,7 +16,7 @@ namespace Presenter {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void Execute() {
 | 
							public void Execute() {
 | 
				
			||||||
			_score.Add();
 | 
								_score.Add();
 | 
				
			||||||
			_view.UpdateView(_score.Value);
 | 
								_view.UpdateView(_score.Value, _score.GrowPercentage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (CanSpawn)
 | 
								if (CanSpawn)
 | 
				
			||||||
				_spawner.SpawnRose();
 | 
									_spawner.SpawnRose();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
namespace Presenter {
 | 
					namespace Presenter {
 | 
				
			||||||
	public interface IExpressionInput {
 | 
						public interface IExpressionInput {
 | 
				
			||||||
		void UpdateView(int score);
 | 
							void UpdateView(int score, float growPercentage);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								Assets/Scripts/Presenter/PlayerPrefsRepository.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Assets/Scripts/Presenter/PlayerPrefsRepository.cs
									
										
									
									
									
										Normal 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);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								Assets/Scripts/Presenter/PlayerPrefsRepository.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Assets/Scripts/Presenter/PlayerPrefsRepository.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: 8dce8a5ed9294a1283494fef143729a4
 | 
				
			||||||
 | 
					timeCreated: 1713305716
 | 
				
			||||||
							
								
								
									
										3
									
								
								Assets/Scripts/Presenter/SaveSystem.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Assets/Scripts/Presenter/SaveSystem.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: f18e98c111ab4c0fa067e9a5039254a7
 | 
				
			||||||
 | 
					timeCreated: 1713304989
 | 
				
			||||||
							
								
								
									
										8
									
								
								Assets/Scripts/Presenter/SaveSystem/GameRepository.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assets/Scripts/Presenter/SaveSystem/GameRepository.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					using Domain;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Presenter.SaveSystem {
 | 
				
			||||||
 | 
						public interface IGameRepository {
 | 
				
			||||||
 | 
							void SaveScore(Score score);
 | 
				
			||||||
 | 
							Score LoadScore();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: 66c3464d602142f5813956378a7071bb
 | 
				
			||||||
 | 
					timeCreated: 1713305003
 | 
				
			||||||
							
								
								
									
										21
									
								
								Assets/Scripts/Presenter/SaveSystem/LoadGame.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								Assets/Scripts/Presenter/SaveSystem/LoadGame.cs
									
										
									
									
									
										Normal 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);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								Assets/Scripts/Presenter/SaveSystem/LoadGame.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Assets/Scripts/Presenter/SaveSystem/LoadGame.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: 3e87dd4026b94e5e90ce9d2163026446
 | 
				
			||||||
 | 
					timeCreated: 1713305374
 | 
				
			||||||
							
								
								
									
										17
									
								
								Assets/Scripts/Presenter/SaveSystem/SaveGame.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Assets/Scripts/Presenter/SaveSystem/SaveGame.cs
									
										
									
									
									
										Normal 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);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								Assets/Scripts/Presenter/SaveSystem/SaveGame.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Assets/Scripts/Presenter/SaveSystem/SaveGame.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: c1e36f7baa3d4eccb7073f6b4b803621
 | 
				
			||||||
 | 
					timeCreated: 1713305232
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using Domain;
 | 
					using Domain;
 | 
				
			||||||
using Presenter;
 | 
					using Presenter;
 | 
				
			||||||
 | 
					using Presenter.SaveSystem;
 | 
				
			||||||
using UnityEngine;
 | 
					using UnityEngine;
 | 
				
			||||||
using View.UI;
 | 
					using View.UI;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +11,9 @@ namespace View {
 | 
				
			||||||
		public Score Score { private set; get; }
 | 
							public Score Score { private set; get; }
 | 
				
			||||||
		public CustomInput CustomInput { private set; get; }
 | 
							public CustomInput CustomInput { private set; get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public SaveGame Saver { private set; get; }
 | 
				
			||||||
 | 
							public LoadGame Loader { private set; get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private void Awake() {
 | 
							private void Awake() {
 | 
				
			||||||
			Score = new Score(20, 5);
 | 
								Score = new Score(20, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +26,10 @@ namespace View {
 | 
				
			||||||
			ExpressionClick = new ExpressionClick(Score, inputCollections, spawner);
 | 
								ExpressionClick = new ExpressionClick(Score, inputCollections, spawner);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			CustomInput = new CustomInput();
 | 
								CustomInput = new CustomInput();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								PlayerPrefsRepository repository = new();
 | 
				
			||||||
 | 
								Saver = new SaveGame(repository, Score);
 | 
				
			||||||
 | 
								Loader = new LoadGame(repository, Score, inputCollections);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -8,9 +8,9 @@ namespace View {
 | 
				
			||||||
			_inputs = inputs;
 | 
								_inputs = inputs;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void UpdateView(int score) {
 | 
							public void UpdateView(int score, float growPercentage) {
 | 
				
			||||||
			foreach (IExpressionInput input in _inputs)
 | 
								foreach (IExpressionInput input in _inputs)
 | 
				
			||||||
				input.UpdateView(score);
 | 
									input.UpdateView(score, growPercentage);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										12
									
								
								Assets/Scripts/View/SaveLoad.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Assets/Scripts/View/SaveLoad.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					using UnityEngine;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace View {
 | 
				
			||||||
 | 
						public class SaveLoad : MonoBehaviour {
 | 
				
			||||||
 | 
							private void Start() => LoadGame();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							private void LoadGame() => FindObjectOfType<Dependencies>().Loader.Run();
 | 
				
			||||||
 | 
							private void SaveGame() => FindObjectOfType<Dependencies>().Saver.Run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							private void OnApplicationQuit() => SaveGame();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								Assets/Scripts/View/SaveLoad.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Assets/Scripts/View/SaveLoad.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: 3c6dab5fe816434381b975fd75b667fc
 | 
				
			||||||
 | 
					timeCreated: 1713306082
 | 
				
			||||||
| 
						 | 
					@ -11,13 +11,10 @@ namespace View.UI {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private ExpressionClick _click;
 | 
							private ExpressionClick _click;
 | 
				
			||||||
		private CustomInput _customInput;
 | 
							private CustomInput _customInput;
 | 
				
			||||||
		private Score _score;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[SerializeField] private FramedAnimator.FramedAnimator animator;
 | 
							[SerializeField] private FramedAnimator.FramedAnimator animator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private void Start() {
 | 
							private void Start() {
 | 
				
			||||||
			_score = FindObjectOfType<Dependencies>().Score;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			_click = FindObjectOfType<Dependencies>().ExpressionClick;
 | 
								_click = FindObjectOfType<Dependencies>().ExpressionClick;
 | 
				
			||||||
			_customInput = FindObjectOfType<Dependencies>().CustomInput;
 | 
								_customInput = FindObjectOfType<Dependencies>().CustomInput;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -26,8 +23,8 @@ namespace View.UI {
 | 
				
			||||||
			CheckInput();
 | 
								CheckInput();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void UpdateView(int score) {
 | 
							public void UpdateView(int score, float growPercentage) {
 | 
				
			||||||
			animator.PlayUntil(_score.GrowPercentage);
 | 
								animator.PlayUntil(growPercentage);
 | 
				
			||||||
			text.text = score.ToString();
 | 
								text.text = score.ToString();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,7 @@ namespace View.UI {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void UpdateView(int score) {
 | 
							public void UpdateView(int score, float growPercentage) {
 | 
				
			||||||
			if (!_titleVisible) return;
 | 
								if (!_titleVisible) return;
 | 
				
			||||||
			_titleVisible = false;
 | 
								_titleVisible = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue