directive: better parameter representation

This commit is contained in:
Branden J Brown 2024-10-14 11:12:56 -04:00
parent 6b1fb10717
commit fff67316bb
2 changed files with 69 additions and 24 deletions

View File

@ -2,27 +2,22 @@
"types": [ "types": [
{ {
"name": "text", "name": "text",
"doc": "Arbitrary text.",
"kind": "text" "kind": "text"
}, },
{ {
"name": "speech", "name": "speech",
"doc": "Formatted speech text with emphasis, shout, and whisper markers.",
"kind": "speech" "kind": "speech"
}, },
{ {
"name": "character", "name": "character",
"doc": "Name of a character in the current scene.",
"kind": "character" "kind": "character"
}, },
{ {
"name": "duration", "name": "duration",
"doc": "Time duration.",
"kind": "duration" "kind": "duration"
}, },
{ {
"name": "scene", "name": "scene",
"doc": "Scene asset.",
"kind": "asset", "kind": "asset",
"tags": [ "tags": [
"scene" "scene"
@ -30,7 +25,6 @@
}, },
{ {
"name": "background", "name": "background",
"doc": "Background image or environment model.",
"kind": "asset", "kind": "asset",
"tags": [ "tags": [
"background" "background"
@ -38,7 +32,6 @@
}, },
{ {
"name": "stage position", "name": "stage position",
"doc": "Default positions on the stage.\n- close: front and center, much zoomed in.\n- left third, right third: rule of thirds, slightly zoomed in.\n- left, center, right: middle distance, dividing the horizontal space into four.\n- far left, mid left, mid right, far right: middle distance, dividing the horizontal space into five.\n- far: center, zoomed out.",
"kind": "enum", "kind": "enum",
"enum": [ "enum": [
"close", "close",
@ -58,26 +51,43 @@
"directives": [ "directives": [
{ {
"name": "page", "name": "page",
"doc": "Prepare a new page, resetting static text, speaker, &c.\nNormally not used directly; script speech lines call this directive implicitly.", "doc": "Start showing the current static speaker, text, &c.\nNormally not used directly; script speech lines call this directive implicitly.",
"prefix": "page" "prefix": "page"
}, },
{ {
"name": "set static text", "name": "set static text _",
"doc": "Set the current page's text.\nNormally not used directly; script speech lines call this directive implicitly.", "doc": "Set the current page's text.\nNormally not used directly; script speech lines call this directive implicitly.",
"prefix": "set static text", "prefix": "set static text",
"prefix_param": "speech" "prefix_param": {
"name": "text",
"doc": "Line content.",
"type": "speech"
}
}, },
{ {
"name": "set static speaker", "name": "set static speaker _",
"doc": "Set the current page's speaker.\nNormally not used directly; script speech lines call this directive implicitly.", "doc": "Set the current page's speaker.\nNormally not used directly; script speech lines call this directive implicitly.",
"prefix": "set static speaker", "prefix": "set static speaker",
"prefix_param": "character" "prefix_param": {
"name": "name",
"doc": "Speaker name.",
"type": "text"
}
}, },
{ {
"name": "characters", "name": "characters",
"doc": "Set the names of characters in the current scene.", "doc": "Set the names of characters in the current scene.",
"prefix": "characters", "prefix": "characters",
"list_param": "text" "list_param": {
"name": "characters",
"doc": "Name of the character to include.",
"type": "text",
"nuance": {
"name": "variant",
"doc": "Variant of this character.",
"type": "text"
}
}
}, },
{ {
"name": "scene", "name": "scene",
@ -88,27 +98,47 @@
"name": "background", "name": "background",
"doc": "Set the background image.", "doc": "Set the background image.",
"prefix": "background", "prefix": "background",
"prefix_param": "background" "prefix_param": {
"name": "asset",
"doc": "Background image asset.",
"type": "background"
}
}, },
{ {
"name": "enter _ stage _", "name": "enter _ stage _",
"doc": "Bring a character onto the stage at a given position.", "doc": "Bring a character onto the stage at a given position.",
"prefix": "enter", "prefix": "enter",
"prefix_param": "character", "prefix_param": {
"name": "character",
"doc": "Character to enter.",
"type": "character"
},
"suffix": "stage", "suffix": "stage",
"suffix_param": "stage position" "suffix_param": {
"name": "position",
"doc": "Position on the stage where the character enters.",
"type": "stage position"
}
}, },
{ {
"name": "enter _", "name": "enter _",
"doc": "Bring a character onto the stage at a default position.", "doc": "Bring a character onto the stage at a default position.",
"prefix": "enter", "prefix": "enter",
"prefix_param": "character" "prefix_param": {
"name": "character",
"doc": "Character to enter.",
"type": "character"
}
}, },
{ {
"name": "exit _", "name": "exit _",
"doc": "Remove a character from the stage.", "doc": "Remove a character from the stage.",
"prefix": "exit", "prefix": "exit",
"prefix_param": "character" "prefix_param": {
"name": "character",
"doc": "Character to exit.",
"type": "character"
}
}, },
{ {
"name": "exeunt", "name": "exeunt",

View File

@ -28,9 +28,14 @@ pub struct Directive {
/// Directive parameter. /// Directive parameter.
pub struct Param { pub struct Param {
/// Name to which the compiler maps the argument.
name: String, name: String,
doc: String, /// Description of the parameter's meaning in the context of the directive.
doc: Option<String>,
/// Type required for the argument.
typ: Type, typ: Type,
/// Nuance parameter for list parameters.
nuance: Option<Box<Param>>,
} }
/// Types expected by directive arguments. /// Types expected by directive arguments.
@ -61,7 +66,7 @@ mod serial {
} }
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)] #[serde(rename_all = "snake_case", deny_unknown_fields, tag = "kind")]
enum TypeKind { enum TypeKind {
Text, Text,
Speech, Speech,
@ -84,18 +89,28 @@ mod serial {
kind: TypeKind, kind: TypeKind,
} }
#[derive(Deserialize)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
struct Param {
name: String,
doc: Option<String>,
#[serde(rename = "type")]
typ: String,
nuance: Option<Box<Param>>,
}
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(rename_all = "snake_case", deny_unknown_fields)] #[serde(rename_all = "snake_case", deny_unknown_fields)]
struct Directive { struct Directive {
name: String, name: String,
doc: String, doc: String,
prefix: String, prefix: String,
prefix_param: Option<String>, prefix_param: Option<Param>,
infix: Option<String>, infix: Option<String>,
infix_param: Option<String>, infix_param: Option<Param>,
suffix: Option<String>, suffix: Option<String>,
suffix_param: Option<String>, suffix_param: Option<Param>,
list_param: Option<String>, list_param: Option<Param>,
} }
} }