107 lines
4.9 KiB
C#
107 lines
4.9 KiB
C#
/*
|
|
* WARNING:
|
|
* This tool was created by an LLM based on the SessionZero shared lib project, therefore it is subject to errors and does not reflect the architecture of the SessionZero project.
|
|
* It was created to be used as a quick and dirty validation tool for the szpack format.
|
|
*/
|
|
|
|
using SessionZero.Shared.Models;
|
|
using SessionZero.Shared.Services;
|
|
using Spectre.Console;
|
|
using Spectre.Console.Cli;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace SessionZero.Tools.Packer;
|
|
|
|
// Settings class defines the command-line arguments
|
|
public class CreateSettings : CommandSettings
|
|
{
|
|
[CommandArgument(0, "<name>")]
|
|
[Description("The display name of the datapack (e.g., 'My Fantasy Spells').")]
|
|
public required string Name { get; init; }
|
|
|
|
[CommandArgument(1, "[author]")]
|
|
[Description("The author's name.")]
|
|
[DefaultValue("Test Author")]
|
|
public string Author { get; init; } = "Test Author";
|
|
|
|
[CommandOption("-o|--output")]
|
|
[Description("The parent directory where the new pack folder will be created.")]
|
|
[DefaultValue(".")]
|
|
public string Output { get; init; } = Environment.CurrentDirectory;
|
|
}
|
|
|
|
public class CreateCommand : AsyncCommand<CreateSettings>
|
|
{
|
|
public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [NotNull] CreateSettings settings, CancellationToken cancellationToken)
|
|
{
|
|
AnsiConsole.MarkupLine($"\n[bold white on blue] --- Creating Datapack: '{settings.Name}' --- [/]");
|
|
|
|
try
|
|
{
|
|
// 1. Create the top-level model and save szpack.json
|
|
var newPack = DatapackService.CreateEmptyDatapack(settings.Name, "1.0.0", settings.Author, "MIT");
|
|
var szpackPath = await DatapackService.SaveDatapackMetadataAsync(newPack, settings.Output);
|
|
var packRootDirectory = Path.GetDirectoryName(szpackPath)!;
|
|
|
|
AnsiConsole.MarkupLine($"[green]✅ Created metadata file at: {szpackPath}[/]");
|
|
|
|
// 2. Create the standard directory structure
|
|
var structure = DatapackService.CreateDatapackDirectoryStructure(packRootDirectory);
|
|
AnsiConsole.MarkupLine($"[green]✅ Created standard directories at: {packRootDirectory}[/]");
|
|
|
|
// 3. Create and save test objects
|
|
await CreateTestObjects(packRootDirectory, structure);
|
|
|
|
AnsiConsole.MarkupLine("\n[bold]Creation Complete![/] Use 'szpack pack' to compress it.");
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
AnsiConsole.MarkupLine($"\n[bold white on red]❌ ERROR:[/] Failed to create datapack. Details: {ex.Message}");
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
// Helper method for creating test objects (copied from previous Program.cs)
|
|
private static async Task CreateTestObjects(string rootPath, Dictionary<string, string> structure)
|
|
{
|
|
// ... (Test object creation logic remains the same, ensure you have the necessary usings in this file)
|
|
|
|
// --- Test object creation logic (omitted for brevity, assume the previous logic is here) ---
|
|
var testDataset = new Dataset { /* ... test data ... */ Id = "basic-attributes", Name = "Basic Character Attributes", SzType = "Dataset", Version = "1.0.0", SchemaVersion = "1.0.0", DatasetType = "Attribute", Entries = new() };
|
|
var dsPath = await DatapackService.SaveSzObjectAsync(testDataset, structure["datasets"]);
|
|
AnsiConsole.MarkupLine($" -> Saved Test Dataset: [yellow]{Path.GetFileName(dsPath)}[/]");
|
|
|
|
var testCharTemplate = new CharacterTemplate { /* ... test data ... */ Id = "default-char-sheet", Name = "Default Character Template", SzType = "Template", Version = "1.0.0", SchemaVersion = "1.0.0", Sections = new() };
|
|
var charPath = await DatapackService.SaveSzObjectAsync(testCharTemplate, structure["character_templates"]);
|
|
AnsiConsole.MarkupLine($" -> Saved Test Character Template: [yellow]{Path.GetFileName(charPath)}[/]");
|
|
|
|
var testSessionTemplate = new SessionTemplate
|
|
{
|
|
/* ... test data ... */ Id = "basic-encounter",
|
|
Name = "Basic Encounter Template",
|
|
SzType = "Template",
|
|
Version = "1.0.0",
|
|
SchemaVersion = "1.0.0",
|
|
CharacterTemplateLink = new()
|
|
{
|
|
DatapackId = Guid.Empty,
|
|
TemplateId = testCharTemplate.Id,
|
|
Version = testCharTemplate.Version
|
|
},
|
|
RequiredDatasets = new()
|
|
{
|
|
new()
|
|
{
|
|
DatapackId = Guid.Empty,
|
|
DatasetId = testDataset.Id,
|
|
Version = testDataset.Version
|
|
}
|
|
},
|
|
Sections = new()
|
|
};
|
|
var sessionPath = await DatapackService.SaveSzObjectAsync(testSessionTemplate, structure["session_templates"]);
|
|
AnsiConsole.MarkupLine($" -> Saved Test Session Template: [yellow]{Path.GetFileName(sessionPath)}[/]");
|
|
}
|
|
} |