Implement load and save UI

This commit is contained in:
Stone_Red
2023-07-30 17:28:36 +02:00
parent 6d0ca85b7f
commit 8b8e4c48e3
22 changed files with 364 additions and 166 deletions
+81
View File
@@ -0,0 +1,81 @@
using Myra.Utility;
using System;
using System.IO;
namespace StoneRed.LogicSimulator.Misc;
internal static class Paths
{
public static string GetAppDataPath()
{
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string srlsAppDataPath = Path.Combine(appDataPath, "StoneRed", "LogicSimulator");
if (!Directory.Exists(srlsAppDataPath))
{
_ = Directory.CreateDirectory(srlsAppDataPath);
}
return srlsAppDataPath;
}
public static string GetAppDataPath(string fileName)
{
return Path.Combine(GetAppDataPath(), fileName);
}
public static string GetAppDataPath(params string[] paths)
{
return Path.Combine(GetAppDataPath(), Path.Combine(paths));
}
public static string GetContentPath()
{
return Path.Combine(PathUtils.ExecutingAssemblyDirectory, "Content");
}
public static string GetContentPath(string fileName)
{
return Path.Combine(GetContentPath(), fileName);
}
public static string GetContentPath(params string[] paths)
{
return Path.Combine(GetContentPath(), Path.Combine(paths));
}
public static string GetSettingsPath()
{
return Path.Combine(GetAppDataPath(), "settings.json");
}
public static string GetWorldSavesPath()
{
string savesPath = Path.Combine(GetAppDataPath(), "Saves");
if (!Directory.Exists(savesPath))
{
_ = Directory.CreateDirectory(savesPath);
}
return savesPath;
}
public static string GetWorldSaveDirectoryPath(string saveName)
{
string savePath = Path.Combine(GetWorldSavesPath(), saveName);
if (!Directory.Exists(savePath))
{
_ = Directory.CreateDirectory(savePath);
}
return savePath;
}
public static string GetWorldSaveFilePath(string saveName)
{
return Path.Combine(GetWorldSaveDirectoryPath(saveName), saveName + ".srls");
}
}
+27
View File
@@ -0,0 +1,27 @@
using System.IO;
using System.Text.Json;
using StoneRed.LogicSimulator.Utilities;
namespace StoneRed.LogicSimulator.Misc;
internal class Settings
{
public Resolution Resolution { get; set; } = new(0, 0);
public float Scale { get; set; } = 1;
public bool Fullscreen { get; set; } = false;
public static Settings? Load(string path)
{
if (!File.Exists(path))
{
return null;
}
return JsonSerializer.Deserialize<Settings>(File.ReadAllText(path));
}
public void Save(string path)
{
File.WriteAllText(path, JsonSerializer.Serialize(this));
}
}