diff --git a/Assets/Levels/back-on-track.json b/Assets/Levels/back-on-track.json deleted file mode 100644 index c881349..0000000 --- a/Assets/Levels/back-on-track.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "Name": "Back on Track", - "MusicName": "BackOnTrack.mp3", - "TotalJumps": 0, - "TotalAttempts": 0, - "KilledCount": 0, - "elements": [ - { - "type": "Spike", - "position": { - "x": 0, - "y": 0 - } - } - ] -} diff --git a/Assets/Levels.meta b/Assets/Resources/Levels.meta similarity index 100% rename from Assets/Levels.meta rename to Assets/Resources/Levels.meta diff --git a/Assets/Resources/Levels/BackOnTrack.json b/Assets/Resources/Levels/BackOnTrack.json new file mode 100644 index 0000000..89275bf --- /dev/null +++ b/Assets/Resources/Levels/BackOnTrack.json @@ -0,0 +1,16 @@ +{ + "name": "Back on Track", + "musicName": "BackOnTrack", + "totalJumps": 0, + "totalAttempts": 0, + "killedCount": 0, + "elements": [ + { + "type": "Spike", + "position": { + "x": 0, + "y": 0 + } + } + ] +} diff --git a/Assets/Levels/back-on-track.json.meta b/Assets/Resources/Levels/BackOnTrack.json.meta similarity index 100% rename from Assets/Levels/back-on-track.json.meta rename to Assets/Resources/Levels/BackOnTrack.json.meta diff --git a/Assets/Scripts/Level.cs b/Assets/Scripts/Level.cs index 4cb84dc..b9b93b1 100644 --- a/Assets/Scripts/Level.cs +++ b/Assets/Scripts/Level.cs @@ -1,20 +1,16 @@ -using System.Runtime.Serialization; +using UnityEngine; -[DataContract] +[System.Serializable] public class Level { - [DataMember] - public string Name { get; set; } + public string name; + public string musicName; + public int totalJumps; + public int totalAttempts; + public int killedCount; - [DataMember] - public string MusicName { get; set; } - - [DataMember] - public int TotalJumps { get; set; } - - [DataMember] - public int TotalAttempts { get; set; } - - [DataMember] - public int KilledCount { get; set; } + public static Level CreateFromJSON(string jsonString) + { + return JsonUtility.FromJson(jsonString); + } } diff --git a/Assets/Scripts/LevelsLoader.cs b/Assets/Scripts/LevelsLoader.cs index aba5a94..297609f 100644 --- a/Assets/Scripts/LevelsLoader.cs +++ b/Assets/Scripts/LevelsLoader.cs @@ -1,5 +1,4 @@ using System.IO; -using System.Runtime.Serialization.Json; using UnityEngine; public class LevelsLoader : MonoBehaviour @@ -10,22 +9,7 @@ public class LevelsLoader : MonoBehaviour { DontDestroyOnLoad(gameObject); - // var jsonTextFile = Resources.Load("Text/jsonFile01"); - //Then use JsonUtility.FromJson() to deserialize jsonTextFile into an object - - string path = Path.Combine(Application.dataPath, "Levels", "back-on-track.json"); - if (File.Exists(path)) - { - string json = File.ReadAllText(path); - using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json))) - { - DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Level)); - level = (Level)serializer.ReadObject(stream); - } - } - else - { - Debug.LogError("Level file not found: " + path); - } + TextAsset jsonTextFile = Resources.Load(Path.Combine("Levels", "BackOnTrack")); + level = JsonUtility.FromJson(jsonTextFile.text); } } diff --git a/Assets/Scripts/LevelsSelect/LevelNameText.cs b/Assets/Scripts/LevelsSelect/LevelNameText.cs index 9165507..60fa19e 100644 --- a/Assets/Scripts/LevelsSelect/LevelNameText.cs +++ b/Assets/Scripts/LevelsSelect/LevelNameText.cs @@ -10,6 +10,6 @@ public class LevelNameText : MonoBehaviour public void Start() { levelsLoader = GameObject.FindGameObjectWithTag("LevelsLoader").GetComponent(); - levelNameText.text = levelsLoader.level.Name; + levelNameText.text = levelsLoader.level.name; } } diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 07afdc3..846b4ce 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -1,7 +1,6 @@ using UnityEngine; using UnityEngine.SceneManagement; using System.IO; -using UnityEngine.Audio; public class Player : MonoBehaviour { @@ -20,17 +19,8 @@ public class Player : MonoBehaviour { levelsLoader = GameObject.FindGameObjectWithTag("LevelsLoader").GetComponent(); - string musicPath = Path.Combine("Musics", Path.GetFileNameWithoutExtension(levelsLoader.level.MusicName)); - AudioClip clip = Resources.Load(musicPath); - if (clip == null) - { - Debug.LogError("Music file not found at: " + musicPath); - } - else - { - audioSource.clip = clip; - audioSource.Play(); - } + audioSource.clip = Resources.Load(Path.Combine("Musics", levelsLoader.level.musicName)); + audioSource.Play(); var mainModule = particle.main; mainModule.simulationSpace = ParticleSystemSimulationSpace.World; diff --git a/Documentation/UML/class-diagram.puml b/Documentation/UML/class-diagram.puml index 586944d..7c46b46 100644 --- a/Documentation/UML/class-diagram.puml +++ b/Documentation/UML/class-diagram.puml @@ -17,7 +17,7 @@ class GameManager { class Level { - name: String - - musicPath: String + - musicName: String + StartLevel() + EndLevel() + CheckCompletion(): Boolean