From 56b13b49619e79a79c1e95321ffda842531c676b Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Fri, 20 Oct 2023 07:12:39 +0200 Subject: [PATCH] Add GDD Type invoke-action A second attempt, following the dicussion in #11 --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 99a5e12..fdd11df 100644 --- a/README.md +++ b/README.md @@ -422,6 +422,40 @@ Example: } ``` +### Special GDD Type: "Invoke Action" + +Some templates support invoking custom functions during their life-time. +This GDD Type should be rendered as a Button in the GUI so that the user can click it to invoke the action. + + +Example: +```typescript +{ + "title": string, // [Mandatory] A short title / label of the action + "description": "", // [Optional] A longer description of the action + "type": "null", + "gddType": "invoke-action", + "gddOptions": { + // [mandatory] Name of the function to execute/invoke in the template. Example: "triggerGoalAnimation" + "invokeFunction": string + // [optional] An array containing arguments provided to the function. Example: "myCustomHello(\"world\", $path)" + "invokeArguments": ["Zlatan Ibrahimovic", 11, "$$path", "$$data"] + } +} +``` +There are certain _special tokens_ that can be used in the `invokeArguments` array: + +* `"$$data"` is a special token which will be substituted at runtime with the full template data object. + + This is useful when an action needs the latest data. + +* `"$$path"` is a special token which will be substituted at runtime with the [JSONPath](https://goessner.net/articles/JsonPath/) of the action. + + This is useful when having an action inside an array, since this would cause multiple actions to render (one per row in the data). + An example of a path would be `myData.people[2]` for the action in the 3rd row of an array called `people` in an object called `myData`. + + + ## For GUI Developers When implementing a GUI to support the GDD definitions, you don't have to implement support for all GDD Types - since the GDD Types are designed to degrade gracefully. The only types that are mandatory to implement are the basic types `"boolean"`, `"string"`, `"number"`, `"integer"`, `"array"`and `"object"`.