From 04d85e080b3f40e0770ed4bdd9d373e25500ad23 Mon Sep 17 00:00:00 2001 From: Davcris911 Date: Tue, 16 Nov 2021 09:55:09 -0500 Subject: [PATCH] Refactor --- Assets/Scripts/HammerScript/Executable.cs | 154 +++++++++---------- Assets/Scripts/HammerScript/HammerTrigger.cs | 43 +++--- Assets/Scripts/MovementGen.cs | 100 ++++++------ Assets/Scripts/RandomDemonSpawn.cs | 32 ++-- Assets/Scripts/Utilities/Constant.cs | 10 +- Assets/Scripts/Utilities/DataSaver.cs | 18 +-- Assets/Scripts/Utilities/Position.cs | 2 +- Assets/Scripts/Utilities/PositionManager.cs | 60 ++++---- Assets/Scripts/Utilities/Timer.cs | 82 +++++----- 9 files changed, 248 insertions(+), 253 deletions(-) diff --git a/Assets/Scripts/HammerScript/Executable.cs b/Assets/Scripts/HammerScript/Executable.cs index 9fce106..facc40a 100644 --- a/Assets/Scripts/HammerScript/Executable.cs +++ b/Assets/Scripts/HammerScript/Executable.cs @@ -1,93 +1,93 @@ using System.Collections; -using System.Collections.Generic; -using Assets.Scripts; using Assets.Scripts.Utilities; using UnityEngine; -using UnityEngine.UI; -using static MovementGen; using UnityEngine.SceneManagement; +using static Assets.Scripts.MovementGen; -public class Executable : MonoBehaviour +namespace Assets.Scripts.HammerScript { - public Timer timer; - public string NextScene; - public TextMesh text; - public bool noMovementChange = true; - public bool bloquer = false; - public ChoiceOfMovement nextMouv; - - // Si on veut skipper/bypasser le 5-4-3-2-1 - public bool IsQuickTeleport = false; - - void Start() + public class Executable : MonoBehaviour { - //Set the tag of this GameObject to Player - gameObject.tag = Constant.GT_TARGET; - if(noMovementChange) - text.text = ""; - else - text.text = nextMouv.ToString(); - } + public Timer timer; + public string NextScene; + public TextMesh text; + public bool noMovementChange = true; + public bool bloquer = false; + public ChoiceOfMovement nextMouv; - public void Execute() - { - if (!bloquer) { - bloquer = true; - if (timer) - { - timer.Stop(); - } + // Si on veut skipper/bypasser le 5-4-3-2-1 + public bool IsQuickTeleport = false; - if (!noMovementChange) - { - PlayerPrefs.SetInt(Constant.PPK_MOVEMENT_CHOICE, (int)nextMouv); - } - - if (IsQuickTeleport) - { - LoadScene(); - } - else - { - StartCoroutine("TimerExecute"); - } - } - - } - - private int count = 0; - IEnumerator TimerExecute() - { - count = 6; - while (true) + void Start() { - count--; - if (text != null) { - if (count >= 0) - text.text = "" + count; - else - text.text = "Done"; - } - - - yield return new WaitForSeconds(1.0f); - DataSaver.SaveTime(); - if (count <= 0) - { - LoadScene(); - } + //Set the tag of this GameObject to Player + gameObject.tag = Constant.GT_TARGET; + if(noMovementChange) + text.text = ""; + else + text.text = nextMouv.ToString(); } - } + public void Execute() + { + if (!bloquer) { + bloquer = true; + if (timer) + { + timer.Stop(); + } - private void LoadScene() - { - PlayerPrefs.SetString(Constant.PPK_SCENE_NAME, NextScene); - SceneManager.LoadScene(NextScene); - } + if (!noMovementChange) + { + PlayerPrefs.SetInt(Constant.PPK_MOVEMENT_CHOICE, (int)nextMouv); + } - private void OnTriggerEnter(Collider other) - { - Debug.Log("Demon detected the colision"); + if (IsQuickTeleport) + { + LoadScene(); + } + else + { + StartCoroutine("TimerExecute"); + } + } + + } + + private int count = 0; + private IEnumerator TimerExecute() + { + count = 6; + while (true) + { + count--; + if (text != null) { + if (count >= 0) + text.text = "" + count; + else + text.text = "Done"; + } + + + yield return new WaitForSeconds(1.0f); + DataSaver.SaveTime(); + if (count <= 0) + { + LoadScene(); + } + } + + } + + private void LoadScene() + { + PlayerPrefs.SetString(Constant.PPK_SCENE_NAME, NextScene); + SceneManager.LoadScene(NextScene); + } + + private void OnTriggerEnter(Collider other) + { + Debug.Log("Demon detected the colision"); + } } } diff --git a/Assets/Scripts/HammerScript/HammerTrigger.cs b/Assets/Scripts/HammerScript/HammerTrigger.cs index 3879053..ccd6c52 100644 --- a/Assets/Scripts/HammerScript/HammerTrigger.cs +++ b/Assets/Scripts/HammerScript/HammerTrigger.cs @@ -1,29 +1,30 @@ -using System.Collections; -using System.Collections.Generic; -using Assets.Scripts; +using Assets.Scripts.Utilities; using UnityEngine; -public class HammerTrigger : MonoBehaviour +namespace Assets.Scripts.HammerScript { - // Start is called before the first frame update - void Start() + public class HammerTrigger : MonoBehaviour { - gameObject.tag = Constant.GT_HAMMER; - } - - // Update is called once per frame - void Update() - { - - } - - private void OnTriggerEnter(Collider other) - { - Debug.Log("Hammer detected the colision"); - if (other.gameObject.tag == Constant.GT_TARGET) + // Start is called before the first frame update + void Start() { - Executable ex = other.gameObject.GetComponent("Executable") as Executable; - ex.Execute(); + gameObject.tag = Constant.GT_HAMMER; + } + + // Update is called once per frame + void Update() + { + + } + + private void OnTriggerEnter(Collider other) + { + Debug.Log("Hammer detected the colision"); + if (other.gameObject.tag == Constant.GT_TARGET) + { + Executable ex = other.gameObject.GetComponent("Executable") as Executable; + ex.Execute(); + } } } } diff --git a/Assets/Scripts/MovementGen.cs b/Assets/Scripts/MovementGen.cs index 8b363f5..aa9c28f 100644 --- a/Assets/Scripts/MovementGen.cs +++ b/Assets/Scripts/MovementGen.cs @@ -1,67 +1,69 @@ using System; -using System.Collections; using System.Collections.Generic; -using Assets.Scripts; using Assets.Scripts.Movements; +using Assets.Scripts.Utilities; using UnityEngine; -public class MovementGen : MonoBehaviour +namespace Assets.Scripts { - private Dictionary components; - private ChoiceOfMovement currentMovement; - - [SerializeField] private ChoiceOfMovement selectedMovement; - [SerializeField] private String nomDuJoueur = string.Empty; - - // Start is called before the first frame update - void Start() + public class MovementGen : MonoBehaviour { - components = new Dictionary(); - components.Add(ChoiceOfMovement.wasd, this.GetComponent()); - components.Add(ChoiceOfMovement.teleport, this.GetComponent()); - components.Add(ChoiceOfMovement.joystick, this.GetComponent()); - components.Add(ChoiceOfMovement.joycon, this.GetComponent()); - components.Add(ChoiceOfMovement.omni, this.GetComponent()); + private Dictionary components; + private ChoiceOfMovement currentMovement; - selectedMovement = (ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE, 0); - currentMovement = (ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE, 0); - components[currentMovement].enabled = true; + [SerializeField] private ChoiceOfMovement selectedMovement; + [SerializeField] private String nomDuJoueur = string.Empty; - if (nomDuJoueur == string.Empty) + // Start is called before the first frame update + void Start() { - nomDuJoueur = DateTime.Now.ToString("MM-dd HH:mm"); - } - PlayerPrefs.SetString(Constant.PPK_PLAYER_NAME, nomDuJoueur); - } + components = new Dictionary(); + components.Add(ChoiceOfMovement.wasd, this.GetComponent()); + components.Add(ChoiceOfMovement.teleport, this.GetComponent()); + components.Add(ChoiceOfMovement.joystick, this.GetComponent()); + components.Add(ChoiceOfMovement.joycon, this.GetComponent()); + components.Add(ChoiceOfMovement.omni, this.GetComponent()); - // Update is called once per frame - void FixedUpdate() - { - if(selectedMovement != currentMovement) - { - if (components[currentMovement] is IScriptDeMovement) + selectedMovement = (ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE, 0); + currentMovement = (ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE, 0); + components[currentMovement].enabled = true; + + if (nomDuJoueur == string.Empty) { - - ((IScriptDeMovement) components[currentMovement]).BeforeDisable(); + nomDuJoueur = DateTime.Now.ToString("MM-dd HH:mm"); } - - components[currentMovement].enabled = false; - components[selectedMovement].enabled = true; - currentMovement = selectedMovement; + PlayerPrefs.SetString(Constant.PPK_PLAYER_NAME, nomDuJoueur); } - } - public void ChangeMovement(ChoiceOfMovement newChoice) - { - selectedMovement = newChoice; - } + // Update is called once per frame + void FixedUpdate() + { + if(selectedMovement != currentMovement) + { + if (components[currentMovement] is IScriptDeMovement) + { - public enum ChoiceOfMovement - { - wasd = 0, - teleport = 1, - joystick = 2, - joycon = 3, - omni = 4 + ((IScriptDeMovement) components[currentMovement]).BeforeDisable(); + } + + components[currentMovement].enabled = false; + components[selectedMovement].enabled = true; + currentMovement = selectedMovement; + } + } + + public void ChangeMovement(ChoiceOfMovement newChoice) + { + selectedMovement = newChoice; + } + + public enum ChoiceOfMovement + { + wasd = 0, + teleport = 1, + joystick = 2, + joycon = 3, + omni = 4 + } } } diff --git a/Assets/Scripts/RandomDemonSpawn.cs b/Assets/Scripts/RandomDemonSpawn.cs index 33240f5..61704db 100644 --- a/Assets/Scripts/RandomDemonSpawn.cs +++ b/Assets/Scripts/RandomDemonSpawn.cs @@ -1,26 +1,26 @@ -using System; -using System.Collections; -using System.Collections.Generic; using UnityEngine; using Random = System.Random; -public class RandomDemonSpawn : MonoBehaviour +namespace Assets.Scripts { - public GameObject[] listeCommeTuVeux; - - // Start is called before the first frame update - void Start() + public class RandomDemonSpawn : MonoBehaviour { - Random rnd = new Random(); - int card = rnd.Next(1, 3); + public GameObject[] listeCommeTuVeux; - listeCommeTuVeux[0].SetActive(card == 1); - listeCommeTuVeux[1].SetActive(card != 1); - } + // Start is called before the first frame update + void Start() + { + Random rnd = new Random(); + int card = rnd.Next(1, 3); - // Update is called once per frame - void Update() - { + listeCommeTuVeux[0].SetActive(card == 1); + listeCommeTuVeux[1].SetActive(card != 1); + } + + // Update is called once per frame + void Update() + { + } } } diff --git a/Assets/Scripts/Utilities/Constant.cs b/Assets/Scripts/Utilities/Constant.cs index 47564d0..889616b 100644 --- a/Assets/Scripts/Utilities/Constant.cs +++ b/Assets/Scripts/Utilities/Constant.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Assets.Scripts +namespace Assets.Scripts.Utilities { - class Constant + public class Constant { public const string SEPARATOR = "-"; diff --git a/Assets/Scripts/Utilities/DataSaver.cs b/Assets/Scripts/Utilities/DataSaver.cs index e6d9afc..11667bc 100644 --- a/Assets/Scripts/Utilities/DataSaver.cs +++ b/Assets/Scripts/Utilities/DataSaver.cs @@ -1,14 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace Assets.Scripts.Utilities { - class DataSaver + public class DataSaver { public static void SaveTime() { @@ -17,7 +13,7 @@ namespace Assets.Scripts.Utilities string time = PlayerPrefs.GetString(Constant.PPK_TIMER_TIME); string stage = PlayerPrefs.GetString(Constant.PPK_SCENE_NAME); string toSave = movementName + Constant.SEPARATOR + playerName + Constant.SEPARATOR + stage + Constant.SEPARATOR + time; - writeToFile(toSave); + WriteToFile(toSave); } public static void SavePosition(List positions) @@ -25,17 +21,17 @@ namespace Assets.Scripts.Utilities string playerName = PlayerPrefs.GetString(Constant.PPK_PLAYER_NAME); string movementName = ((MovementGen.ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE)).ToString(); string stage = PlayerPrefs.GetString(Constant.PPK_SCENE_NAME); - string fileName = movementName + Constant.SEPARATOR + playerName + Constant.SEPARATOR + stage; - writeToFile(positions, fileName); + string fileName = "position" + Constant.SEPARATOR + movementName + Constant.SEPARATOR + playerName + Constant.SEPARATOR + stage; + WriteToFile(positions, fileName); } - private static async void writeToFile(string toSave) + private static async void WriteToFile(string toSave) { using StreamWriter file = File.AppendText(Constant.FILE_PATH + Constant.FILE_TIME + Constant.FILE_EXTENSION); await file.WriteLineAsync(toSave); } - private static async void writeToFile(List positions, string fileName) + private static async void WriteToFile(List positions, string fileName) { using StreamWriter file = File.AppendText(Constant.FILE_PATH + fileName + Constant.FILE_EXTENSION); diff --git a/Assets/Scripts/Utilities/Position.cs b/Assets/Scripts/Utilities/Position.cs index 10d3b1d..4bad6bf 100644 --- a/Assets/Scripts/Utilities/Position.cs +++ b/Assets/Scripts/Utilities/Position.cs @@ -1,6 +1,6 @@ namespace Assets.Scripts.Utilities { - class Position + public class Position { private float x { get; set; } private float y { get; set; } diff --git a/Assets/Scripts/Utilities/PositionManager.cs b/Assets/Scripts/Utilities/PositionManager.cs index 8d1669f..c2e22a9 100644 --- a/Assets/Scripts/Utilities/PositionManager.cs +++ b/Assets/Scripts/Utilities/PositionManager.cs @@ -1,40 +1,42 @@ -using Assets.Scripts.Utilities; using System.Collections; using System.Collections.Generic; using UnityEngine; -public class PositionManager : MonoBehaviour +namespace Assets.Scripts.Utilities { - public GameObject player; - private List data; - public bool notSended = true; - - // Start is called before the first frame update - void Start() + public class PositionManager : MonoBehaviour { - data = new List(); - StartCoroutine("TackerExecute"); - } + public GameObject player; + private List data; + public bool notSended = true; - // Update is called once per frame - void Update() - { - - } - - - IEnumerator TackerExecute() - { - while (notSended) + // Start is called before the first frame update + void Start() { - data.Add(new Position(player.transform.position.x, player.transform.position.y)); - yield return new WaitForSeconds(1.0f); + data = new List(); + StartCoroutine("TackerExecute"); } - } - public void sendData() - { - notSended = false; - DataSaver.SavePosition(data); - } + // Update is called once per frame + void Update() + { + + } + + + IEnumerator TackerExecute() + { + while (notSended) + { + data.Add(new Position(player.transform.position.x, player.transform.position.y)); + yield return new WaitForSeconds(1.0f); + } + } + public void sendData() + { + notSended = false; + DataSaver.SavePosition(data); + } + + } } diff --git a/Assets/Scripts/Utilities/Timer.cs b/Assets/Scripts/Utilities/Timer.cs index 30e4c7e..c2a304f 100644 --- a/Assets/Scripts/Utilities/Timer.cs +++ b/Assets/Scripts/Utilities/Timer.cs @@ -1,53 +1,53 @@ using System.Collections; -using System.Collections.Generic; -using Assets.Scripts; using UnityEngine; -using UnityEngine.UI; -public class Timer : MonoBehaviour +namespace Assets.Scripts.Utilities { - private float time { get; set; } - private bool timerStop { get; set; } - - // TODO JIMMY : Rename this - [SerializeField] - private TextMesh text; - // TODO JIMMY : ^ Rename this - - private Coroutine timerRoutine; - - // Start is called before the first frame update - void Start() + public class Timer : MonoBehaviour { - time = 0; - timerRoutine = StartCoroutine("TimerExecute"); - } + private float time { get; set; } + private bool timerStop { get; set; } - private void FixedUpdate() - { + // TODO JIMMY : Rename this + [SerializeField] + private TextMesh text; + // TODO JIMMY : ^ Rename this - } + private Coroutine timerRoutine; - public void Stop() - { - timerStop = true; - PlayerPrefs.SetString(Constant.PPK_TIMER_TIME, text.text); - StopCoroutine(timerRoutine); - - } - - IEnumerator TimerExecute() - { - while (true) + // Start is called before the first frame update + void Start() { - if (!timerStop) - { - time += 0.1f; - if (text != null) - text.text = ""+ (Mathf.Round(time * 10) * 0.1f).ToString("F1"); - yield return new WaitForSeconds(.1f); - } + time = 0; + timerRoutine = StartCoroutine("TimerExecute"); } + + private void FixedUpdate() + { + + } + + public void Stop() + { + timerStop = true; + PlayerPrefs.SetString(Constant.PPK_TIMER_TIME, text.text); + StopCoroutine(timerRoutine); + + } + + IEnumerator TimerExecute() + { + while (true) + { + if (!timerStop) + { + time += 0.1f; + if (text != null) + text.text = ""+ (Mathf.Round(time * 10) * 0.1f).ToString("F1"); + yield return new WaitForSeconds(.1f); + } + } - } + } + } }