From 8a2af99fd4573a1f42f669dcb912b64f68171d54 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sun, 16 Jun 2024 21:06:35 -0500 Subject: [PATCH] add schema tool, add new world command to editor --- schemas/character.json | 818 ++++++++++++++++++++++++++++ schemas/item.json | 705 ++++++++++++++++++++++++ schemas/room.json | 953 +++++++++++++++++++++++++++++++++ schemas/world.json | 1000 +++++++++++++++++++++++++++++++++++ taleweave/editor.py | 72 ++- taleweave/models/entity.py | 8 +- taleweave/schema.py | 86 +++ taleweave/systems/action.py | 13 +- 8 files changed, 3640 insertions(+), 15 deletions(-) create mode 100644 schemas/character.json create mode 100644 schemas/item.json create mode 100644 schemas/room.json create mode 100644 schemas/world.json create mode 100644 taleweave/schema.py diff --git a/schemas/character.json b/schemas/character.json new file mode 100644 index 0000000..994a279 --- /dev/null +++ b/schemas/character.json @@ -0,0 +1,818 @@ +{ + "$defs": { + "BooleanEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "toggle": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Toggle" + } + }, + "required": [ + "name" + ], + "title": "BooleanEffectPattern", + "type": "object" + }, + "BooleanEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "toggle": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Toggle" + } + }, + "required": [ + "name" + ], + "title": "BooleanEffectResult", + "type": "object" + }, + "Calendar": { + "properties": { + "events": { + "items": { + "$ref": "#/$defs/CalendarEvent" + }, + "title": "Events", + "type": "array" + } + }, + "title": "Calendar", + "type": "object" + }, + "CalendarEvent": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "turn": { + "title": "Turn", + "type": "integer" + } + }, + "required": [ + "name", + "turn" + ], + "title": "CalendarEvent", + "type": "object" + }, + "EffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "application": { + "enum": [ + "permanent", + "temporary" + ], + "title": "Application", + "type": "string" + }, + "attributes": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/StringEffectPattern" + }, + { + "$ref": "#/$defs/FloatEffectPattern" + }, + { + "$ref": "#/$defs/IntEffectPattern" + }, + { + "$ref": "#/$defs/BooleanEffectPattern" + } + ] + }, + "title": "Attributes", + "type": "array" + }, + "cooldown": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Cooldown" + }, + "duration": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Duration" + }, + "last_used": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Last Used" + }, + "uses": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Uses" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "effect_pattern", + "default": "effect_pattern", + "enum": [ + "effect_pattern" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description", + "application" + ], + "title": "EffectPattern", + "type": "object" + }, + "EffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "attributes": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/BooleanEffectResult" + }, + { + "$ref": "#/$defs/FloatEffectResult" + }, + { + "$ref": "#/$defs/IntEffectResult" + }, + { + "$ref": "#/$defs/StringEffectResult" + } + ] + }, + "title": "Attributes", + "type": "array" + }, + "duration": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Duration" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "effect_result", + "default": "effect_result", + "enum": [ + "effect_result" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "EffectResult", + "type": "object" + }, + "FloatEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "FloatEffectPattern", + "type": "object" + }, + "FloatEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "FloatEffectResult", + "type": "object" + }, + "FloatRange": { + "properties": { + "min": { + "title": "Min", + "type": "number" + }, + "max": { + "title": "Max", + "type": "number" + }, + "interval": { + "default": 1.0, + "title": "Interval", + "type": "number" + } + }, + "required": [ + "min", + "max" + ], + "title": "FloatRange", + "type": "object" + }, + "IntEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "IntEffectPattern", + "type": "object" + }, + "IntEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "IntEffectResult", + "type": "object" + }, + "IntRange": { + "properties": { + "min": { + "title": "Min", + "type": "integer" + }, + "max": { + "title": "Max", + "type": "integer" + }, + "interval": { + "default": 1, + "title": "Interval", + "type": "integer" + } + }, + "required": [ + "min", + "max" + ], + "title": "IntRange", + "type": "object" + }, + "Item": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "effects": { + "items": { + "$ref": "#/$defs/EffectPattern" + }, + "title": "Effects", + "type": "array" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "item", + "default": "item", + "enum": [ + "item" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "Item", + "type": "object" + }, + "Planner": { + "properties": { + "calendar": { + "$ref": "#/$defs/Calendar" + }, + "notes": { + "items": { + "type": "string" + }, + "title": "Notes", + "type": "array" + } + }, + "title": "Planner", + "type": "object" + }, + "StringEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "append": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Append" + }, + "prepend": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Prepend" + }, + "set": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + } + }, + "required": [ + "name" + ], + "title": "StringEffectPattern", + "type": "object" + }, + "StringEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "append": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Append" + }, + "prepend": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Prepend" + }, + "set": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + } + }, + "required": [ + "name" + ], + "title": "StringEffectResult", + "type": "object" + } + }, + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "backstory": { + "title": "Backstory", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "planner": { + "$ref": "#/$defs/Planner" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "character", + "default": "character", + "enum": [ + "character" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "backstory", + "description" + ], + "title": "Character", + "type": "object" +} diff --git a/schemas/item.json b/schemas/item.json new file mode 100644 index 0000000..a0172d0 --- /dev/null +++ b/schemas/item.json @@ -0,0 +1,705 @@ +{ + "$defs": { + "BooleanEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "toggle": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Toggle" + } + }, + "required": [ + "name" + ], + "title": "BooleanEffectPattern", + "type": "object" + }, + "BooleanEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "toggle": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Toggle" + } + }, + "required": [ + "name" + ], + "title": "BooleanEffectResult", + "type": "object" + }, + "EffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "application": { + "enum": [ + "permanent", + "temporary" + ], + "title": "Application", + "type": "string" + }, + "attributes": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/StringEffectPattern" + }, + { + "$ref": "#/$defs/FloatEffectPattern" + }, + { + "$ref": "#/$defs/IntEffectPattern" + }, + { + "$ref": "#/$defs/BooleanEffectPattern" + } + ] + }, + "title": "Attributes", + "type": "array" + }, + "cooldown": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Cooldown" + }, + "duration": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Duration" + }, + "last_used": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Last Used" + }, + "uses": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Uses" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "effect_pattern", + "default": "effect_pattern", + "enum": [ + "effect_pattern" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description", + "application" + ], + "title": "EffectPattern", + "type": "object" + }, + "EffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "attributes": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/BooleanEffectResult" + }, + { + "$ref": "#/$defs/FloatEffectResult" + }, + { + "$ref": "#/$defs/IntEffectResult" + }, + { + "$ref": "#/$defs/StringEffectResult" + } + ] + }, + "title": "Attributes", + "type": "array" + }, + "duration": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Duration" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "effect_result", + "default": "effect_result", + "enum": [ + "effect_result" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "EffectResult", + "type": "object" + }, + "FloatEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "FloatEffectPattern", + "type": "object" + }, + "FloatEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "FloatEffectResult", + "type": "object" + }, + "FloatRange": { + "properties": { + "min": { + "title": "Min", + "type": "number" + }, + "max": { + "title": "Max", + "type": "number" + }, + "interval": { + "default": 1.0, + "title": "Interval", + "type": "number" + } + }, + "required": [ + "min", + "max" + ], + "title": "FloatRange", + "type": "object" + }, + "IntEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "IntEffectPattern", + "type": "object" + }, + "IntEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "IntEffectResult", + "type": "object" + }, + "IntRange": { + "properties": { + "min": { + "title": "Min", + "type": "integer" + }, + "max": { + "title": "Max", + "type": "integer" + }, + "interval": { + "default": 1, + "title": "Interval", + "type": "integer" + } + }, + "required": [ + "min", + "max" + ], + "title": "IntRange", + "type": "object" + }, + "Item": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "effects": { + "items": { + "$ref": "#/$defs/EffectPattern" + }, + "title": "Effects", + "type": "array" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "item", + "default": "item", + "enum": [ + "item" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "Item", + "type": "object" + }, + "StringEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "append": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Append" + }, + "prepend": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Prepend" + }, + "set": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + } + }, + "required": [ + "name" + ], + "title": "StringEffectPattern", + "type": "object" + }, + "StringEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "append": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Append" + }, + "prepend": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Prepend" + }, + "set": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + } + }, + "required": [ + "name" + ], + "title": "StringEffectResult", + "type": "object" + } + }, + "allOf": [ + { + "$ref": "#/$defs/Item" + } + ] +} diff --git a/schemas/room.json b/schemas/room.json new file mode 100644 index 0000000..d8de86e --- /dev/null +++ b/schemas/room.json @@ -0,0 +1,953 @@ +{ + "$defs": { + "BooleanEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "toggle": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Toggle" + } + }, + "required": [ + "name" + ], + "title": "BooleanEffectPattern", + "type": "object" + }, + "BooleanEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "toggle": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Toggle" + } + }, + "required": [ + "name" + ], + "title": "BooleanEffectResult", + "type": "object" + }, + "Calendar": { + "properties": { + "events": { + "items": { + "$ref": "#/$defs/CalendarEvent" + }, + "title": "Events", + "type": "array" + } + }, + "title": "Calendar", + "type": "object" + }, + "CalendarEvent": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "turn": { + "title": "Turn", + "type": "integer" + } + }, + "required": [ + "name", + "turn" + ], + "title": "CalendarEvent", + "type": "object" + }, + "Character": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "backstory": { + "title": "Backstory", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "planner": { + "$ref": "#/$defs/Planner" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "character", + "default": "character", + "enum": [ + "character" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "backstory", + "description" + ], + "title": "Character", + "type": "object" + }, + "EffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "application": { + "enum": [ + "permanent", + "temporary" + ], + "title": "Application", + "type": "string" + }, + "attributes": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/StringEffectPattern" + }, + { + "$ref": "#/$defs/FloatEffectPattern" + }, + { + "$ref": "#/$defs/IntEffectPattern" + }, + { + "$ref": "#/$defs/BooleanEffectPattern" + } + ] + }, + "title": "Attributes", + "type": "array" + }, + "cooldown": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Cooldown" + }, + "duration": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Duration" + }, + "last_used": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Last Used" + }, + "uses": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Uses" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "effect_pattern", + "default": "effect_pattern", + "enum": [ + "effect_pattern" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description", + "application" + ], + "title": "EffectPattern", + "type": "object" + }, + "EffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "attributes": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/BooleanEffectResult" + }, + { + "$ref": "#/$defs/FloatEffectResult" + }, + { + "$ref": "#/$defs/IntEffectResult" + }, + { + "$ref": "#/$defs/StringEffectResult" + } + ] + }, + "title": "Attributes", + "type": "array" + }, + "duration": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Duration" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "effect_result", + "default": "effect_result", + "enum": [ + "effect_result" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "EffectResult", + "type": "object" + }, + "FloatEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "FloatEffectPattern", + "type": "object" + }, + "FloatEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "FloatEffectResult", + "type": "object" + }, + "FloatRange": { + "properties": { + "min": { + "title": "Min", + "type": "number" + }, + "max": { + "title": "Max", + "type": "number" + }, + "interval": { + "default": 1.0, + "title": "Interval", + "type": "number" + } + }, + "required": [ + "min", + "max" + ], + "title": "FloatRange", + "type": "object" + }, + "IntEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "IntEffectPattern", + "type": "object" + }, + "IntEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "IntEffectResult", + "type": "object" + }, + "IntRange": { + "properties": { + "min": { + "title": "Min", + "type": "integer" + }, + "max": { + "title": "Max", + "type": "integer" + }, + "interval": { + "default": 1, + "title": "Interval", + "type": "integer" + } + }, + "required": [ + "min", + "max" + ], + "title": "IntRange", + "type": "object" + }, + "Item": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "effects": { + "items": { + "$ref": "#/$defs/EffectPattern" + }, + "title": "Effects", + "type": "array" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "item", + "default": "item", + "enum": [ + "item" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "Item", + "type": "object" + }, + "Planner": { + "properties": { + "calendar": { + "$ref": "#/$defs/Calendar" + }, + "notes": { + "items": { + "type": "string" + }, + "title": "Notes", + "type": "array" + } + }, + "title": "Planner", + "type": "object" + }, + "Portal": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "destination": { + "title": "Destination", + "type": "string" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "portal", + "default": "portal", + "enum": [ + "portal" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description", + "destination" + ], + "title": "Portal", + "type": "object" + }, + "StringEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "append": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Append" + }, + "prepend": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Prepend" + }, + "set": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + } + }, + "required": [ + "name" + ], + "title": "StringEffectPattern", + "type": "object" + }, + "StringEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "append": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Append" + }, + "prepend": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Prepend" + }, + "set": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + } + }, + "required": [ + "name" + ], + "title": "StringEffectResult", + "type": "object" + } + }, + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "characters": { + "items": { + "$ref": "#/$defs/Character" + }, + "title": "Characters", + "type": "array" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "portals": { + "items": { + "$ref": "#/$defs/Portal" + }, + "title": "Portals", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "room", + "default": "room", + "enum": [ + "room" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "Room", + "type": "object" +} diff --git a/schemas/world.json b/schemas/world.json new file mode 100644 index 0000000..040b4f9 --- /dev/null +++ b/schemas/world.json @@ -0,0 +1,1000 @@ +{ + "$defs": { + "BooleanEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "toggle": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Toggle" + } + }, + "required": [ + "name" + ], + "title": "BooleanEffectPattern", + "type": "object" + }, + "BooleanEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "toggle": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Toggle" + } + }, + "required": [ + "name" + ], + "title": "BooleanEffectResult", + "type": "object" + }, + "Calendar": { + "properties": { + "events": { + "items": { + "$ref": "#/$defs/CalendarEvent" + }, + "title": "Events", + "type": "array" + } + }, + "title": "Calendar", + "type": "object" + }, + "CalendarEvent": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "turn": { + "title": "Turn", + "type": "integer" + } + }, + "required": [ + "name", + "turn" + ], + "title": "CalendarEvent", + "type": "object" + }, + "Character": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "backstory": { + "title": "Backstory", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "planner": { + "$ref": "#/$defs/Planner" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "character", + "default": "character", + "enum": [ + "character" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "backstory", + "description" + ], + "title": "Character", + "type": "object" + }, + "EffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "application": { + "enum": [ + "permanent", + "temporary" + ], + "title": "Application", + "type": "string" + }, + "attributes": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/StringEffectPattern" + }, + { + "$ref": "#/$defs/FloatEffectPattern" + }, + { + "$ref": "#/$defs/IntEffectPattern" + }, + { + "$ref": "#/$defs/BooleanEffectPattern" + } + ] + }, + "title": "Attributes", + "type": "array" + }, + "cooldown": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Cooldown" + }, + "duration": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Duration" + }, + "last_used": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Last Used" + }, + "uses": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Uses" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "effect_pattern", + "default": "effect_pattern", + "enum": [ + "effect_pattern" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description", + "application" + ], + "title": "EffectPattern", + "type": "object" + }, + "EffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "attributes": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/BooleanEffectResult" + }, + { + "$ref": "#/$defs/FloatEffectResult" + }, + { + "$ref": "#/$defs/IntEffectResult" + }, + { + "$ref": "#/$defs/StringEffectResult" + } + ] + }, + "title": "Attributes", + "type": "array" + }, + "duration": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Duration" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "effect_result", + "default": "effect_result", + "enum": [ + "effect_result" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "EffectResult", + "type": "object" + }, + "FloatEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "FloatEffectPattern", + "type": "object" + }, + "FloatEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "FloatEffectResult", + "type": "object" + }, + "FloatRange": { + "properties": { + "min": { + "title": "Min", + "type": "number" + }, + "max": { + "title": "Max", + "type": "number" + }, + "interval": { + "default": 1.0, + "title": "Interval", + "type": "number" + } + }, + "required": [ + "min", + "max" + ], + "title": "FloatRange", + "type": "object" + }, + "IntEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/IntRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "$ref": "#/$defs/FloatRange" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "IntEffectPattern", + "type": "object" + }, + "IntEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "set": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + }, + "offset": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Offset" + }, + "multiply": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Multiply" + } + }, + "required": [ + "name" + ], + "title": "IntEffectResult", + "type": "object" + }, + "IntRange": { + "properties": { + "min": { + "title": "Min", + "type": "integer" + }, + "max": { + "title": "Max", + "type": "integer" + }, + "interval": { + "default": 1, + "title": "Interval", + "type": "integer" + } + }, + "required": [ + "min", + "max" + ], + "title": "IntRange", + "type": "object" + }, + "Item": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "effects": { + "items": { + "$ref": "#/$defs/EffectPattern" + }, + "title": "Effects", + "type": "array" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "item", + "default": "item", + "enum": [ + "item" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "Item", + "type": "object" + }, + "Planner": { + "properties": { + "calendar": { + "$ref": "#/$defs/Calendar" + }, + "notes": { + "items": { + "type": "string" + }, + "title": "Notes", + "type": "array" + } + }, + "title": "Planner", + "type": "object" + }, + "Portal": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "destination": { + "title": "Destination", + "type": "string" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "portal", + "default": "portal", + "enum": [ + "portal" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description", + "destination" + ], + "title": "Portal", + "type": "object" + }, + "Room": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "characters": { + "items": { + "$ref": "#/$defs/Character" + }, + "title": "Characters", + "type": "array" + }, + "active_effects": { + "items": { + "$ref": "#/$defs/EffectResult" + }, + "title": "Active Effects", + "type": "array" + }, + "attributes": { + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "title": "Attributes", + "type": "object" + }, + "items": { + "items": { + "$ref": "#/$defs/Item" + }, + "title": "Items", + "type": "array" + }, + "portals": { + "items": { + "$ref": "#/$defs/Portal" + }, + "title": "Portals", + "type": "array" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "room", + "default": "room", + "enum": [ + "room" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "description" + ], + "title": "Room", + "type": "object" + }, + "StringEffectPattern": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "append": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Append" + }, + "prepend": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Prepend" + }, + "set": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + } + }, + "required": [ + "name" + ], + "title": "StringEffectPattern", + "type": "object" + }, + "StringEffectResult": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "append": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Append" + }, + "prepend": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Prepend" + }, + "set": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Set" + } + }, + "required": [ + "name" + ], + "title": "StringEffectResult", + "type": "object" + } + }, + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "order": { + "items": { + "type": "string" + }, + "title": "Order", + "type": "array" + }, + "rooms": { + "items": { + "$ref": "#/$defs/Room" + }, + "title": "Rooms", + "type": "array" + }, + "theme": { + "title": "Theme", + "type": "string" + }, + "id": { + "title": "Id", + "type": "string" + }, + "type": { + "const": "world", + "default": "world", + "enum": [ + "world" + ], + "title": "Type", + "type": "string" + } + }, + "required": [ + "name", + "order", + "rooms", + "theme" + ], + "title": "World", + "type": "object" +} diff --git a/taleweave/editor.py b/taleweave/editor.py index ca3a400..22ed9ee 100644 --- a/taleweave/editor.py +++ b/taleweave/editor.py @@ -5,8 +5,15 @@ from typing import List, Tuple from dotenv import load_dotenv from packit.utils import logger_with_colors -from taleweave.context import get_dungeon_master, get_game_systems, set_game_systems -from taleweave.engine import load_or_initialize_system_data +from taleweave.context import ( + get_dungeon_master, + get_game_config, + get_game_systems, + set_game_config, + set_game_systems, + subscribe, +) +from taleweave.engine import load_or_generate_world, load_or_initialize_system_data from taleweave.game_system import GameSystem from taleweave.generate import ( generate_character, @@ -15,9 +22,11 @@ from taleweave.generate import ( generate_room, link_rooms, ) -from taleweave.main import load_prompt_library +from taleweave.main import get_world_prompt, load_prompt_library from taleweave.models.base import dump_model +from taleweave.models.config import DEFAULT_CONFIG, Config from taleweave.models.entity import World, WorldState +from taleweave.models.event import GenerateEvent from taleweave.plugins import load_plugin from taleweave.utils.file import load_yaml, save_yaml from taleweave.utils.search import ( @@ -41,8 +50,19 @@ logger = logger_with_colors(__name__) load_dotenv(environ.get("TALEWEAVE_ENV", ".env"), override=True) +def generate_listener(event: GenerateEvent): + if event.entity: + logger.info(f"Generating {event.entity.type} named {event.entity.name}") + else: + logger.info(event.name) + + +subscribe(GenerateEvent, generate_listener) + + def parse_args(): - parser = argparse.ArgumentParser(description="Taleweave Editor") + parser = argparse.ArgumentParser(description="TaleWeave AI Editor") + parser.add_argument("--config", type=str, help="Configuration file to load") parser.add_argument("--prompts", type=str, nargs="*", help="Prompt files to load") parser.add_argument("--state", type=str, help="State file to edit") parser.add_argument("--world", type=str, help="World file to edit") @@ -51,6 +71,28 @@ def parse_args(): subparsers = parser.add_subparsers(dest="command", help="Command to execute") subparsers.required = True + # Set up the 'new' command + new_parser = subparsers.add_parser("new", help="Create a new world") + new_parser.add_argument("name", type=str, help="Name of the new world") + new_parser.add_argument("--rooms", type=int, help="Number of rooms to generate") + new_parser.add_argument( + "--world-flavor", + type=str, + default="", + help="Some additional flavor text for the generated world", + ) + new_parser.add_argument( + "--world-template", + type=str, + help="The template file to load the world prompt from", + ) + new_parser.add_argument( + "--world-theme", + type=str, + default="fantasy", + help="The theme of the generated world", + ) + # Set up the 'list' command list_parser = subparsers.add_parser("list", help="List entities of a specific type") list_parser.add_argument( @@ -157,6 +199,19 @@ def save_world(state_file, world_file, world: World, state: WorldState | None): save_yaml(f, dump_model(World, world)) +def command_new(args): + logger.info(f"Creating new world {args.name}") + + config = get_game_config() + systems = get_game_systems() + + prompt = get_world_prompt(args) + world, state_file, _ = load_or_generate_world( + args.name, args.state, config, [], systems, prompt, room_count=args.rooms + ) + save_world(state_file, args.name, world, None) + + def command_list(args): world, _ = load_world(args.state, args.world) logger.info(f"Listing {args.type}s from world {world.name}") @@ -349,6 +404,7 @@ def command_link(args): COMMAND_TABLE = { + "new": command_new, "list": command_list, "describe": command_describe, "create": command_create, @@ -365,6 +421,14 @@ def main(): load_prompt_library(args) + if args.config: + with open(args.config, "r") as f: + config = Config(**load_yaml(f)) + else: + config = DEFAULT_CONFIG + + set_game_config(config) + # load game systems before executing commands systems: List[GameSystem] = [] for system_name in args.systems or []: diff --git a/taleweave/models/entity.py b/taleweave/models/entity.py index ed2ced5..19e3099 100644 --- a/taleweave/models/entity.py +++ b/taleweave/models/entity.py @@ -13,7 +13,7 @@ Actions = Dict[str, Callable] class Item(BaseModel): name: str description: str - actions: Actions = Field(default_factory=dict) + # actions: Actions = Field(default_factory=dict) active_effects: List[EffectResult] = Field(default_factory=list) attributes: Attributes = Field(default_factory=dict) effects: List[EffectPattern] = Field(default_factory=list) @@ -28,7 +28,7 @@ class Character(BaseModel): backstory: str description: str planner: Planner = Field(default_factory=Planner) - actions: Actions = Field(default_factory=dict) + # actions: Actions = Field(default_factory=dict) active_effects: List[EffectResult] = Field(default_factory=list) attributes: Attributes = Field(default_factory=dict) items: List[Item] = Field(default_factory=list) @@ -41,7 +41,7 @@ class Portal(BaseModel): name: str description: str destination: str - actions: Actions = Field(default_factory=dict) + # actions: Actions = Field(default_factory=dict) attributes: Attributes = Field(default_factory=dict) id: str = Field(default_factory=uuid) type: Literal["portal"] = "portal" @@ -52,7 +52,7 @@ class Room(BaseModel): name: str description: str characters: List[Character] = Field(default_factory=list) - actions: Actions = Field(default_factory=dict) + # actions: Actions = Field(default_factory=dict) active_effects: List[EffectResult] = Field(default_factory=list) attributes: Attributes = Field(default_factory=dict) items: List[Item] = Field(default_factory=list) diff --git a/taleweave/schema.py b/taleweave/schema.py new file mode 100644 index 0000000..0ac37b4 --- /dev/null +++ b/taleweave/schema.py @@ -0,0 +1,86 @@ +from argparse import ArgumentParser +from json import dumps + +from pydantic import TypeAdapter + +from taleweave.models.entity import Character, Item, Portal, Room, World +from taleweave.utils.file import load_yaml +from taleweave.utils.world import describe_entity + +MODELS = { + "character": Character, + "item": Item, + "portal": Portal, + "room": Room, + "world": World, +} + + +def parse_args(): + parser = ArgumentParser( + description="Generate or validate a schema for the TaleWeave AI models" + ) + + subparsers = parser.add_subparsers(dest="command", required=True) + subparsers.required = True + + generate_parser = subparsers.add_parser( + "generate", help="Generate a schema for a model" + ) + generate_parser.add_argument( + "model", + type=str, + choices=list(MODELS.keys()), + help="The name of the model to generate a schema for", + ) + + validate_parser = subparsers.add_parser( + "validate", help="Validate a JSON file against a model schema" + ) + validate_parser.add_argument( + "model", + type=str, + choices=list(MODELS.keys()), + help="The name of the model to validate against", + ) + validate_parser.add_argument( + "file", + type=str, + help="The path to the JSON file to validate", + ) + + return parser.parse_args() + + +def command_generate(args): + model = MODELS[args.model] + schema = TypeAdapter(model).json_schema() + print(dumps(schema, indent=2)) + + +def command_validate(args): + model = MODELS[args.model] + with open(args.file, "r") as file: + data = load_yaml(file) + + entity = model(**data) + if isinstance(entity, World): + print(entity) + else: + print(describe_entity(entity)) + + +COMMANDS = { + "generate": command_generate, + "validate": command_validate, +} + + +def main(): + args = parse_args() + command = COMMANDS[args.command] + command(args) + + +if __name__ == "__main__": + main() diff --git a/taleweave/systems/action.py b/taleweave/systems/action.py index bd95d35..611283e 100644 --- a/taleweave/systems/action.py +++ b/taleweave/systems/action.py @@ -42,13 +42,11 @@ def world_result_parser(value, agent, **kwargs): logger.debug(f"parsing action for {agent.name}: {value}") current_character = get_character_for_agent(agent) - current_room = next( - (room for room in current_world.rooms if current_character in room.characters), - None, - ) + if current_character: + current_room = find_containing_room(current_world, current_character) - set_current_room(current_room) - set_current_character(current_character) + set_current_room(current_room) + set_current_character(current_character) return function_result(value, agent=agent, **kwargs) @@ -66,7 +64,7 @@ def prompt_character_action( room_directions = [portal.name for portal in room.portals] character_attributes = format_attributes(character) - # character_effects = [effect.name for effect in character.active_effects] + character_effects = [effect.name for effect in character.active_effects] character_items = [item.name for item in character.items] # set up a result parser for the agent @@ -140,6 +138,7 @@ def prompt_character_action( format_prompt( "world_simulate_character_action", actions=action_names, + character_effects=character_effects, character_items=character_items, attributes=character_attributes, directions=room_directions,