adding saving to Datapacks and datasets
This commit is contained in:
46
SessionZero/Data/Dataset.cs
Normal file
46
SessionZero/Data/Dataset.cs
Normal file
@@ -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<string, SzDataObject> _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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user