refactor: improve save JSON

This commit is contained in:
Théo LUDWIG 2025-02-09 20:26:05 +01:00
parent 0dbc959c19
commit 3026ea5367
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
12 changed files with 763 additions and 757 deletions

View File

@ -8,8 +8,9 @@ indent_style = space
end_of_line = lf end_of_line = lf
[*.{json,jsonc,asmdef}] [*.{json,jsonc,asmdef}]
indent_size = 2 indent_size = 4
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true
[*.{yml,yaml,sh,puml,md}] [*.{yml,yaml,sh,puml,md}]
indent_size = 2 indent_size = 2

View File

@ -3,6 +3,8 @@ using UnityEngine;
[System.Serializable] [System.Serializable]
public class Level public class Level
{ {
public string JsonName { get; set; }
public string name; public string name;
public string musicName; public string musicName;
public int totalJumps; public int totalJumps;

View File

@ -19,16 +19,17 @@ public class LevelsLoader : MonoBehaviour
TextAsset[] levelFiles = Resources.LoadAll<TextAsset>("Levels"); TextAsset[] levelFiles = Resources.LoadAll<TextAsset>("Levels");
foreach (TextAsset jsonTextFile in levelFiles) foreach (TextAsset jsonTextFile in levelFiles)
{ {
Level loadedLevel = JsonUtility.FromJson<Level>(jsonTextFile.text); Level level = Level.CreateFromJSON(jsonTextFile.text);
levels.Add(loadedLevel); level.JsonName = jsonTextFile.name;
levels.Add(level);
} }
levels.Sort((x, y) => x.order.CompareTo(y.order)); levels.Sort((x, y) => x.order.CompareTo(y.order));
} }
private void SaveLevelCurrent() private void SaveLevelCurrent()
{ {
string json = JsonUtility.ToJson(levelCurrent, true); string json = JsonUtility.ToJson(levelCurrent, true) + "\n";
File.WriteAllText(Path.Combine(Application.dataPath, "Resources", "Levels", levelCurrent.name + ".json"), json); File.WriteAllText(Path.Combine(Application.dataPath, "Resources", "Levels", levelCurrent.JsonName + ".json"), json);
} }
public void NextLevel() public void NextLevel()

View File

@ -1,4 +1,5 @@
{"frames": [ {
"frames": [
{ {
"filename": "1f60a.png", "filename": "1f60a.png",
"frame": { "x": 0, "y": 0, "w": 128, "h": 128 }, "frame": { "x": 0, "y": 0, "w": 128, "h": 128 },
@ -142,7 +143,8 @@
"spriteSourceSize": { "x": 0, "y": 0, "w": 128, "h": 128 }, "spriteSourceSize": { "x": 0, "y": 0, "w": 128, "h": 128 },
"sourceSize": { "w": 128, "h": 128 }, "sourceSize": { "w": 128, "h": 128 },
"pivot": { "x": 0.5, "y": 0.5 } "pivot": { "x": 0.5, "y": 0.5 }
}], }
],
"meta": { "meta": {
"app": "http://www.codeandweb.com/texturepacker", "app": "http://www.codeandweb.com/texturepacker",
"version": "1.0", "version": "1.0",