Moved the test command to a seperate "TestingCommands" class
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using Cogwheel;
|
||||
using SessionZero.Cogwheel;
|
||||
using SessionZero.Data;
|
||||
@@ -31,98 +33,4 @@ public static class AppManager
|
||||
{
|
||||
MainWindow.ChangePage(pageName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[Command(Name = "test")]
|
||||
public static void TestParseTemplate()
|
||||
{
|
||||
string toml = @"
|
||||
[metadata]
|
||||
template_type = ""data""
|
||||
id = ""core_item""
|
||||
uuid = ""0""
|
||||
data_type = ""item""
|
||||
version = ""1.0.0""
|
||||
description = ""Core SessionZero item template""
|
||||
|
||||
[name]
|
||||
type = ""text""
|
||||
|
||||
[description]
|
||||
type = ""textblock""
|
||||
|
||||
[consumable]
|
||||
type = ""bool""
|
||||
default_value = false
|
||||
|
||||
[stats.value]
|
||||
type = ""number""
|
||||
|
||||
[stats.weight]
|
||||
type = ""number""
|
||||
|
||||
[stats.modifiers.base]
|
||||
type = ""number""
|
||||
default_value = 1
|
||||
";
|
||||
|
||||
try
|
||||
{
|
||||
// Parse template
|
||||
var template = SztlParser.ParseTemplate(toml);
|
||||
|
||||
COGWHEEL.Log($"Template ID: {template.Id}");
|
||||
|
||||
COGWHEEL.Log("\nTop-Level Fields:");
|
||||
foreach (var f in template.Fields)
|
||||
{
|
||||
COGWHEEL.Log($"- {f.Key}: Type={f.Value.Type}, Default={f.Value}, TextBlock={f.Value.IsTextBlock}");
|
||||
}
|
||||
|
||||
COGWHEEL.Log("\nGroups:");
|
||||
foreach (var g in template.SubGroups)
|
||||
{
|
||||
PrintGroup(g.Value, "");
|
||||
}
|
||||
|
||||
// --- Instantiate SzDataObject ---
|
||||
var obj = SzObjectFactory.CreateObject(template);
|
||||
|
||||
// Set some values
|
||||
obj.SetFieldValue("name", "Excalibur");
|
||||
obj.SetFieldValue("consumable", true);
|
||||
obj.SetFieldValue("stats.value", 10);
|
||||
obj.SetFieldValue("stats.weight", 2);
|
||||
obj.SetFieldValue("stats.modifiers.base", 5);
|
||||
|
||||
// Get and log values
|
||||
COGWHEEL.Log("\nInstanced Object Field Values:");
|
||||
COGWHEEL.Log($"name = {obj.GetFieldValueAsString("name")}");
|
||||
COGWHEEL.Log($"consumable = {obj.GetFieldValue<bool>("consumable")}");
|
||||
COGWHEEL.Log($"stats.value = {obj.GetFieldValue<int>("stats.value")}");
|
||||
COGWHEEL.Log($"stats.weight = {obj.GetFieldValue<int>("stats.weight")}");
|
||||
COGWHEEL.Log($"stats.modifiers.base = {obj.GetFieldValue<int>("stats.modifiers.base")}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
COGWHEEL.Log($"Error parsing template: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintGroup(SztlFieldGroup group, string indent)
|
||||
{
|
||||
COGWHEEL.Log($"{indent}Group: {group.Id}");
|
||||
|
||||
foreach (var f in group.Fields)
|
||||
{
|
||||
COGWHEEL.Log($"{indent} Field: {f.Key}, Type={f.Value.Type}, Default={f.Value}");
|
||||
}
|
||||
|
||||
foreach (var sg in group.SubGroups)
|
||||
{
|
||||
PrintGroup(sg.Value, indent + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user