This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SessionZero-Client/SessionZero/Data/Datapack.cs

59 lines
1.6 KiB
C#

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<string, Dataset> _datasetLookup = [];
private Dictionary<string, SzTemplate> _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);
}
}