commit 3ec97851a973002c0f3ee48755afcd086260d220 Author: chrisbell Date: Mon Jan 19 20:44:01 2026 -0600 Init diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..72170d0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch", + "command": "odin run .", + "cwd": "${workspaceFolder}" + }, + ] +} \ No newline at end of file diff --git a/helper_procs.odin b/helper_procs.odin new file mode 100644 index 0000000..4eeac32 --- /dev/null +++ b/helper_procs.odin @@ -0,0 +1,36 @@ +package main + +import sp "core:path/slashpath" +import "core:crypto" +import "core:encoding/uuid" +import "core:os/os2" + +get_data_directory :: proc() -> (result: string, error: os2.Error) { + exe_dir, err := os2.get_executable_directory(context.allocator) + if err != os2.General_Error.None { + return "", error + } + + data_path := sp.join({exe_dir, "data"}) + if (!os2.is_directory(data_path)) + { + mkdir_err := os2.make_directory(data_path) + if mkdir_err != os2.General_Error.None + { + return "", mkdir_err + } + } + + return data_path, os2.General_Error.None +} + +create_uuid :: proc() -> string { + new_uuid: string + + { + context.random_generator = crypto.random_generator() + new_uuid = uuid.to_string_allocated(uuid.generate_v7()) + } + + return new_uuid +} \ No newline at end of file diff --git a/main.odin b/main.odin new file mode 100644 index 0000000..c8e279f --- /dev/null +++ b/main.odin @@ -0,0 +1,27 @@ +package main + +import "core:fmt" +import "core:os" + +json_path :: "test_dataset.json" + + +main :: proc() { + test_dataset := create_test_dataset() + write_dataset_to_json(test_dataset, json_path) + + parsed_dataset, ok := parse_json_to_dataset(json_path) + if !ok { + fmt.eprintfln("Failed to parse json tto dataset") + return + } + + fmt.println("Dataset:", parsed_dataset.name) + for szob in parsed_dataset.objects { + fmt.println("Object:", szob.id) + fmt.println("Fields:") + for field in szob.fields { + fmt.println(" ", field.id, ":", field.type, "=", field.value) + } + } +} \ No newline at end of file diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..e7eeaff --- /dev/null +++ b/schema.json @@ -0,0 +1,5 @@ +{ + "name": "Session Zero Core Items", + "uuid": "12345-12345-12345", + "id": "sz-core" +} diff --git a/sz_parser.odin b/sz_parser.odin new file mode 100644 index 0000000..1e6216d --- /dev/null +++ b/sz_parser.odin @@ -0,0 +1,55 @@ +package main + +import sz "szlib" + +import "core:encoding/json" +import "core:fmt" +import "core:os" + + +write_dataset_to_json :: proc(dataset: sz.Dataset, json_path: string) -> (ok: bool) { + + json_data, err := json.marshal(dataset, {pretty = true, use_enum_names = true}) + if err != nil { + fmt.eprintfln("Unable to marshal JSON: %v", err) + return false + } + + werr := os.write_entire_file_or_err(json_path, json_data) + if werr != nil { + fmt.eprintfln("Unable to write JSON: %v", err) + return false + } + + return true +} + + +parse_json_to_dataset :: proc(json_path: string) -> (result: sz.Dataset, ok: bool) { + dataset: sz.Dataset + + data, data_ok := os.read_entire_file_from_filename(json_path) + if !data_ok { + fmt.eprintln("Failed to load the file") + return dataset, false + } + defer delete(data) + + json_data, err := json.parse(data) + if err != .None { + fmt.eprintln("Failed to parse JSON file.") + fmt.eprintln("Error: ", err) + return dataset, false + } + defer json.destroy_value(json_data) + + root := json_data.(json.Object) + + error := json.unmarshal(data, &dataset) + if error != nil { + fmt.eprintln("Could not unmarshal json data to Dataset:", error) + return dataset, false + } + + return dataset, true +} \ No newline at end of file diff --git a/szlib/data.odin b/szlib/data.odin new file mode 100644 index 0000000..4992d55 --- /dev/null +++ b/szlib/data.odin @@ -0,0 +1,37 @@ +package szlib + +Dataset :: struct { + name: string, + id: string, + uuid: string, + data_object_type: string, + objects: [dynamic]SzDataObject +} + +SzDataObject :: struct { + name: string, + id: string, + fields: [dynamic]SzField +} + +SzField :: struct { + id: string, + type: SzFieldType, + is_list: bool, + value: string, +} + +SzDataObjectTemplate :: struct { + +} + +SzTemplateField :: struct { + id: string, + type: SzFieldType, + is_list: bool, + default_value: string, +} + +SzFieldType :: enum { + TEXT, NUMBER, BOOL, FORMULA, REF +} diff --git a/test_dataset.json b/test_dataset.json new file mode 100644 index 0000000..a781394 --- /dev/null +++ b/test_dataset.json @@ -0,0 +1,26 @@ +{ + "name": "Test Dataset", + "id": "test_dataset", + "uuid": "019bd8f5-7e61-7cac-b4b6-630aba8721a8", + "data_object_type": "items", + "objects": [ + { + "name": "Test Item", + "id": "test-item", + "fields": [ + { + "id": "cost", + "type": "NUMBER", + "is_list": false, + "value": "100" + }, + { + "id": "some_string", + "type": "TEXT", + "is_list": false, + "value": "This is some text" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests.odin b/tests.odin new file mode 100644 index 0000000..63115cf --- /dev/null +++ b/tests.odin @@ -0,0 +1,40 @@ +package main + +import sz "szlib" + +create_test_dataset :: proc() -> sz.Dataset { + + test_dataset: sz.Dataset = { + name = "Test Dataset", + id = "test_dataset", + uuid = create_uuid(), + data_object_type = "items", + objects = make([dynamic]sz.SzDataObject) + } + + test_dataset_object: sz.SzDataObject = { + id = "test-item", + name = "Test Item", + fields = make([dynamic]sz.SzField) + } + + test_field: sz.SzField = { + id = "cost", + type = .NUMBER, + is_list = false, + value = "100" + } + + test_field2: sz.SzField = { + id = "some_string", + type = .TEXT, + is_list = false, + value = "This is some text" + } + + append(&test_dataset_object.fields, test_field) + append(&test_dataset_object.fields, test_field2) + append(&test_dataset.objects, test_dataset_object) + + return test_dataset +} \ No newline at end of file