diff --git a/SessionZero/AppManager.cs b/SessionZero/AppManager.cs index 14b64b0..0562964 100644 --- a/SessionZero/AppManager.cs +++ b/SessionZero/AppManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Text.Json; using Cogwheel; using SessionZero.Cogwheel; @@ -15,6 +16,27 @@ public static class AppManager public static CommandsManager CommandsManager { get; } = new(); public static ConsoleControl ConsoleControl { get; } = new(); public static AppSettings Settings { get; } = new(); + + public static string DataDirectory => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "data"); + public static string DatapacksDirectory => Path.Combine(DataDirectory, "datapacks"); + + public static void Init() + { + VerifyDataDirs(); + } + + public static void VerifyDataDirs() + { + if (!Directory.Exists(DataDirectory)) + { + Directory.CreateDirectory(DataDirectory); + } + + if (!Directory.Exists(DatapacksDirectory)) + { + Directory.CreateDirectory(DatapacksDirectory); + } + } public static void ShowConsole() { diff --git a/SessionZero/Data/Datapack.cs b/SessionZero/Data/Datapack.cs new file mode 100644 index 0000000..a128b5c --- /dev/null +++ b/SessionZero/Data/Datapack.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Avalonia.Markup.Xaml.Templates; + +namespace SessionZero.Data; + +public class Datapack +{ + public DatapackMetadata Metadata { get; set; } + + private readonly string _path; + private Dictionary _datasetLookup = []; + private Dictionary _templateLookup = []; + + + public Datapack(string name, string id, string version = "1.0.0", string[]? compatibleSystems = null, string description = "") + { + Metadata = new() + { + Name = name, + Id = id, + Version = version, + CompatibleSystems = compatibleSystems, + Description = description, + Uuid = Guid.NewGuid().ToString() + }; + + _path = Path.Combine(AppManager.DatapacksDirectory, Metadata.Id); + } + + public void SavePack() + { + + if (!Directory.Exists(_path)) + { + Directory.CreateDirectory(_path); + Directory.CreateDirectory($"{_path}/resources"); + Directory.CreateDirectory($"{_path}/datasets"); + Directory.CreateDirectory($"{_path}/templates"); + } + + if (!File.Exists($"{_path}/datapack.meta")) + { + File.WriteAllText($"{_path}/datapack.meta", Metadata.ToString()); + } + } + + public void AddDataset(Dataset dataset) + { + dataset.Save(); + _datasetLookup.TryAdd(dataset.Metadata.Id, dataset); + } + + public void AddTemplate(SzTemplate template) + { + _templateLookup.TryAdd(template.Id, template); + } +} \ No newline at end of file diff --git a/SessionZero/Data/DatapackMetadata.cs b/SessionZero/Data/DatapackMetadata.cs index 0c01dda..d2cad7a 100644 --- a/SessionZero/Data/DatapackMetadata.cs +++ b/SessionZero/Data/DatapackMetadata.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; namespace SessionZero.Data; @@ -10,4 +12,10 @@ public class DatapackMetadata public required string Version { get; set; } public required string[] CompatibleSystems { get; set; } public string Uuid { get; set; } = string.Empty; + + + public override string ToString() + { + return JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); + } } \ No newline at end of file diff --git a/SessionZero/Data/Dataset.cs b/SessionZero/Data/Dataset.cs new file mode 100644 index 0000000..42f9576 --- /dev/null +++ b/SessionZero/Data/Dataset.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.IO; + +namespace SessionZero.Data; + +public class Dataset +{ + public DatasetMetadata Metadata { get; private set; } + + private Dictionary _objectLookup = []; + private readonly string _path; + + public Dataset(string name, string id, string dataType, string templateId, string iconPath = "", string description = "") + { + Metadata = new() + { + Name = name, + Id = id, + DatasetType = dataType, + Description = description, + ObjectTemplateId = templateId, + Icon = iconPath + }; + + _path = Path.Combine(AppManager.DatapacksDirectory, "datasets", id); + } + + public void Save() + { + if (!Directory.Exists(_path)) + { + Directory.CreateDirectory(_path); + Directory.CreateDirectory($"{_path}/objects"); + } + + if (!File.Exists($"{_path}/dataset.meta")) + { + File.WriteAllText($"{_path}/dataset.meta", Metadata.ToString()); + } + } + + public void AddObject(SzDataObject obj) + { + _objectLookup.TryAdd(obj.Id, obj); + } +} \ No newline at end of file diff --git a/SessionZero/Data/DatasetMetadata.cs b/SessionZero/Data/DatasetMetadata.cs index c73adce..89e35e7 100644 --- a/SessionZero/Data/DatasetMetadata.cs +++ b/SessionZero/Data/DatasetMetadata.cs @@ -1,3 +1,5 @@ +using System.Text.Json; + namespace SessionZero.Data; public class DatasetMetadata @@ -6,6 +8,11 @@ public class DatasetMetadata public required string Id { get; set; } public required string Description { get; set; } public required string DatasetType { get; set; } - public required string Icon { get; set; } - public required string ObjectTemplate { get; set; } + public string Icon { get; set; } + public required string ObjectTemplateId { get; set; } + + public override string ToString() + { + return JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); + } } \ No newline at end of file diff --git a/SessionZero/TestingCommands.cs b/SessionZero/TestingCommands.cs index e30dc9b..cd8ffef 100644 --- a/SessionZero/TestingCommands.cs +++ b/SessionZero/TestingCommands.cs @@ -9,8 +9,16 @@ namespace SessionZero; public static class TestingCommands { + [Command(Name = "createpack")] + private static void CreateTestPack() + { + var pack = new Datapack("SessionZero Core", "sz_core"); + pack.SavePack(); + } + + // TODO: Remove this after testing - [Command(Name = "test")] + [Command(Name = "testdata")] private static void TestParseTemplate() { string toml = @"