From 8b8e4c48e3c3499712316e448b65b13c87356723 Mon Sep 17 00:00:00 2001
From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com>
Date: Sun, 30 Jul 2023 17:28:36 +0200
Subject: [PATCH] Implement load and save UI
---
.../Content/LoadWorldWindow.xmmp | 9 ++
.../Content/SaveWorldWindow.xmmp | 12 +++
StoneRed.LogicSimulator/Misc/Paths.cs | 81 ++++++++++++++
.../{Utilities => Misc}/Settings.cs | 3 +-
StoneRed.LogicSimulator/Srls.cs | 17 +--
.../StoneRed.LogicSimulator.csproj | 6 ++
.../UserInterface/Screens/LoadingScreen.cs | 101 ++----------------
.../UserInterface/Screens/SrlsScreen.cs | 4 +-
.../UserInterface/Screens/StartScreen.cs | 20 +---
.../UserInterface/Screens/WorldScreen.cs | 12 ++-
.../UserInterface/Windows/LoadWorldWindow.cs | 43 ++++++++
.../UserInterface/Windows/QuickMenu.cs | 12 ++-
.../UserInterface/Windows/SaveWorldWindow.cs | 78 ++++++++++++++
.../UserInterface/Windows/SettingsWindow.cs | 3 +-
.../UserInterface/Windows/SrlsWindow.cs | 4 +-
.../WorldSaveSystem/WorldData.cs | 21 ++++
.../WorldSaveSystem/WorldLoader.cs | 11 +-
.../WorldReaders/IWorldReader.cs | 5 +-
.../WorldReaders/WorldReaderV1.cs | 30 ++++--
.../WorldSaveSystem/WorldSaver.cs | 31 +++++-
.../WorldWriters/IWorldWriter.cs | 5 +-
.../WorldWriters/WorldWriterV1.cs | 22 ++--
22 files changed, 364 insertions(+), 166 deletions(-)
create mode 100644 StoneRed.LogicSimulator/Content/LoadWorldWindow.xmmp
create mode 100644 StoneRed.LogicSimulator/Content/SaveWorldWindow.xmmp
create mode 100644 StoneRed.LogicSimulator/Misc/Paths.cs
rename StoneRed.LogicSimulator/{Utilities => Misc}/Settings.cs (87%)
create mode 100644 StoneRed.LogicSimulator/UserInterface/Windows/LoadWorldWindow.cs
create mode 100644 StoneRed.LogicSimulator/UserInterface/Windows/SaveWorldWindow.cs
create mode 100644 StoneRed.LogicSimulator/WorldSaveSystem/WorldData.cs
diff --git a/StoneRed.LogicSimulator/Content/LoadWorldWindow.xmmp b/StoneRed.LogicSimulator/Content/LoadWorldWindow.xmmp
new file mode 100644
index 0000000..f1536dc
--- /dev/null
+++ b/StoneRed.LogicSimulator/Content/LoadWorldWindow.xmmp
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/StoneRed.LogicSimulator/Content/SaveWorldWindow.xmmp b/StoneRed.LogicSimulator/Content/SaveWorldWindow.xmmp
new file mode 100644
index 0000000..8ce91e9
--- /dev/null
+++ b/StoneRed.LogicSimulator/Content/SaveWorldWindow.xmmp
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/StoneRed.LogicSimulator/Misc/Paths.cs b/StoneRed.LogicSimulator/Misc/Paths.cs
new file mode 100644
index 0000000..51f6f3a
--- /dev/null
+++ b/StoneRed.LogicSimulator/Misc/Paths.cs
@@ -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");
+ }
+}
\ No newline at end of file
diff --git a/StoneRed.LogicSimulator/Utilities/Settings.cs b/StoneRed.LogicSimulator/Misc/Settings.cs
similarity index 87%
rename from StoneRed.LogicSimulator/Utilities/Settings.cs
rename to StoneRed.LogicSimulator/Misc/Settings.cs
index 4609098..3269233 100644
--- a/StoneRed.LogicSimulator/Utilities/Settings.cs
+++ b/StoneRed.LogicSimulator/Misc/Settings.cs
@@ -1,7 +1,8 @@
using System.IO;
using System.Text.Json;
+using StoneRed.LogicSimulator.Utilities;
-namespace StoneRed.LogicSimulator.Utilities;
+namespace StoneRed.LogicSimulator.Misc;
internal class Settings
{
diff --git a/StoneRed.LogicSimulator/Srls.cs b/StoneRed.LogicSimulator/Srls.cs
index 9e6ab88..57e4828 100644
--- a/StoneRed.LogicSimulator/Srls.cs
+++ b/StoneRed.LogicSimulator/Srls.cs
@@ -8,8 +8,8 @@ using MonoGame.Extended.Screens;
using Myra;
using Myra.Assets;
using Myra.Graphics2D.UI;
-using Myra.Utility;
+using StoneRed.LogicSimulator.Misc;
using StoneRed.LogicSimulator.UserInterface.Screens;
using StoneRed.LogicSimulator.UserInterface.Windows;
using StoneRed.LogicSimulator.Utilities;
@@ -36,18 +36,11 @@ internal class Srls : Game
public Settings Settings { get; set; }
- public string ContentPath { get; }
-
- public string SettingsPath { get; }
-
public Srls()
{
Content.RootDirectory = "Content";
- ContentPath = Path.Combine(PathUtils.ExecutingAssemblyDirectory, "Content");
- SettingsPath = Path.Combine(PathUtils.ExecutingAssemblyDirectory, "settings.json");
-
- Settings = Settings.Load(SettingsPath) ?? new Settings()
+ Settings = Settings.Load(Paths.GetSettingsPath()) ?? new Settings()
{
Resolution = new Resolution(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height),
Scale = 1
@@ -101,7 +94,7 @@ internal class Srls : Game
public TextButton ShowContextMenu(string title, Point position, MenuItem[] menuItems, bool showButton = false)
{
- string data = File.ReadAllText(Path.Combine(ContentPath, "ContextMenu.xmmp"));
+ string data = File.ReadAllText(Paths.GetContentPath("ContextMenu.xmmp"));
VerticalStackPanel contextMenu = (VerticalStackPanel)Project.LoadFromXml(data, AssetManager).Root;
contextMenu.FindChildById