Working on data and sztl

This commit is contained in:
2025-11-30 19:32:36 -06:00
parent b1a43d038e
commit 27d3f0b452
16 changed files with 157 additions and 142 deletions

View File

@@ -1,8 +0,0 @@
namespace SessionZero.Data;
public class Datapack
{
public required DatapackMetadata Metadata { get; set; }
}

View File

@@ -1,35 +0,0 @@
using System.Collections.Generic;
using SessionZero.Data.Sztl;
namespace SessionZero.Data;
public class Dataset
{
public required DatasetMetadata Metadata { get; set; }
public Dictionary<string, SztlField> Fields { get; set; } = [];
public Dictionary<string, SztlFieldGroup> Groups { get; set; } = [];
/// <summary>
/// Returns an SzfField from a string path (use dot notation, eg 'stats.damage')
/// </summary>
/// <param name="fieldPath"></param>
/// <returns></returns>
public SztlField? GetField(string fieldPath)
{
var split = fieldPath.Split('.');
var fieldName = split[0];
if (split.Length == 1)
{
return Fields.GetValueOrDefault(fieldName);
}
else
{
// Todo: Recurse into Groups.Fields to find the path
}
return null;
}
}

View File

@@ -1,6 +0,0 @@
namespace SessionZero.Data;
public class DatasetObjectTemplate
{
}

View File

@@ -0,0 +1,11 @@
using SessionZero.Data.Sztl;
namespace SessionZero.Data;
public class SzField
{
public string Id { get; set; }
public object? Value { get; set; }
public SzFieldType Type { get; set; }
public bool IsTextBlock { get; set; }
}

View File

@@ -0,0 +1,34 @@
using System.Collections.Generic;
using SessionZero.Data.Sztl;
namespace SessionZero.Data;
public class SzObject
{
public string Id { get; set; }
public string Uuid { get; set; }
public string TemplateId { get; set; }
public Dictionary<string, SzField> Fields { get; set; } = new();
public Dictionary<string, SzFieldGroup> FieldGroups { get; set; } = new();
public virtual object? GetFieldValue(string fieldPath)
{
throw new System.NotImplementedException();
}
public virtual T GetFieldValue<T>(string fieldPath)
{
throw new System.NotImplementedException();
}
public virtual string GetFieldValueAsString(string fieldPath)
{
throw new System.NotImplementedException();
}
public virtual string SetFieldValue(string fieldPath, object value)
{
throw new System.NotImplementedException();
}
}

View File

@@ -0,0 +1,14 @@
using System.Collections.Generic;
using SessionZero.Data.Sztl;
namespace SessionZero.Data;
public class SzTemplate
{
public string Id { get; set; }
public string Name { get; set; }
public string DataType { get; set; }
public Dictionary<string, SztlField> Fields { get; set; } = new();
public Dictionary<string, SztlFieldGroup> SubGroups { get; set; } = new();
}

View File

@@ -1,6 +1,6 @@
namespace SessionZero.Data; namespace SessionZero.Data;
public class DatasetObject public class SzoFileHandler
{ {
} }

View File

@@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace SessionZero.Data.Sztl;
public class SzFieldGroup
{
public string Id { get; set; }
public Dictionary<string, SzField> Fields { get; set; } = new();
public Dictionary<string, SzFieldGroup> SubGroups { get; set; } = new();
}

View File

@@ -0,0 +1,11 @@
namespace SessionZero.Data.Sztl;
public enum SzFieldType
{
Text,
Textblock,
Number,
Bool,
Formula,
Object
}

View File

@@ -1,25 +1,11 @@
using System;
namespace SessionZero.Data.Sztl; namespace SessionZero.Data.Sztl;
public class SztlField public class SztlField
{ {
public required string Id { get; set; } public required string Id { get; set; }
public required SztlFieldType FieldType { get; set; } public required SzFieldType Type { get; set; }
public object? Value { get; set; } = null; public object? DefaultValue { get; set; }
public string? Description { get; set; }
public bool TrySetValue() public bool IsList { get; set; }
{ public bool IsTextBlock { get; set; }
throw new NotImplementedException();
}
public T TryGetValue<T>()
{
throw new NotImplementedException();
}
}
public enum SztlFieldType
{
Number, Text, Textbox, Bool, Object, Formula
} }

View File

@@ -4,6 +4,7 @@ namespace SessionZero.Data.Sztl;
public class SztlFieldGroup public class SztlFieldGroup
{ {
public List<SztlField> Fields { get; set; } = []; public string Id { get; set; }
public List<SztlFieldGroup> SubGroups { get; set; } = []; public Dictionary<string, SztlField> Fields { get; set; } = new();
public Dictionary<string, SztlFieldGroup> SubGroups { get; set; } = new();
} }

View File

@@ -0,0 +1,6 @@
namespace SessionZero.Data.Sztl;
public class SztlFileHandler
{
}

View File

@@ -0,0 +1,6 @@
namespace SessionZero.Data.Sztl;
public static class SztlParser
{
}

View File

@@ -1,7 +0,0 @@
namespace SessionZero.Data.Sztl;
public class SztlTemplate
{
}

View File

@@ -1,9 +0,0 @@
namespace SessionZero.Data.Sztl;
public class SztlTokenizer
{
enum TokenType
{
// TODO: Add token types
}
}

View File

@@ -53,41 +53,53 @@ datapack_name/
## DatasetObject Template File ## DatasetObject Template File
- Metadata fields are denoted with a `!` and are required for this template: - Metadata fields required for data object templates:
- `data_type` is an arbitrary value used to denote what kind of dataset type the template is for. - `template_type`: must be `data`.
- The `uuid` field can be left at 0, but when uploading to the SessionZeroDB a uuid will be assigned. - `id`: denotes the template's id; must be unique within the datapack.
- The `id` must be unique within the datapack - `uuid`: can be left at 0, a uuid will be assigned when uploading to the SessionZeroDB.
- `compatible_systems` is arbitrary and only reflects if the template can be used in a datapack according to it's `compatible_systems` value - `version`: must follow semantic versioning.
- Some default fields are required by the default parser: - `data_type`: is an arbitrary value used to denote what kind of dataset type the template is for.
- `name: text` must be present - `compatible_systems`: is arbitrary and only reflects if the template can be used in a datapack according to its own `compatible_systems` value.
- `description`
```ini - Supported Field Types for `data` template types:
!id = "core_item" - text
!uuid = 0 - textblock
!version = "1.0.0" - bool
!data_type = "item" - number
!compatible_systems = "sz_core, d20"
!description = """ ```toml
[metadata]
template_type = "data"
id = "core_item"
uuid = 0
version = "1.0.0"
data_type = "item"
compatible_systems = ["sz_core", "d20"]
description = """
Core SessionZero item template Core SessionZero item template
""" """
[name]
type = "text"
# Top-level fields [description]
name: text type = "textblock"
description: textblock
# Example of a group [consumable]
stats { type = "bool"
value: number default_value = false
weight: number
# Example of a sub-group # -- Stats group --
modifiers { [stats.value]
type = "number"
# Field with a default value
base: number = 1 [stats.weight]
} type = "number"
}
[stats.modifiers.base]
type = "number"
default_value = 1
``` ```
@@ -97,35 +109,24 @@ An instanced DatasetObject should only contain simple fields and values, no obje
```json ```json
{ {
"id": "some_id", "id": "some_id",
"uuid": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "uuid": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
"template_id": "core_item",
"parent_dataset_id": "core_items",
"compatible_systems": ["sz_core", "d20"],
"fields": {
"name": "Human readable name", "name": "Human readable name",
"template_id": "some_template_id",
"parent_dataset_id": "some_dataset_id",
"description": "A description", "description": "A description",
"icon": "path/to/icon", "consumable": false,
"compatible_systems": ["sz_core", "d20"],
"fields": { "stats": {
"groups": [ "value": 10,
{ "weight": 2,
"id": "group_name", "modifiers": {
"fields": [ "base": 1
{ }
"id": "field_name",
"type": "number",
"value": 1
}
],
"sub_groups": []
}
],
"top_level_fields": [
{
"id": "name",
"type": "string",
"value": "something"
}
]
} }
}
} }
``` ```