Public scripting API
The public functions in this namespace (declared with defn-api
) are
provided at runtime to wish-engine Data Source scripts. Data Source scripts
have two modes of operation: compile-time and runtime.
Compile-time, or "top-level," operation occurs when the Data Source is
initially loaded, and is used to declare all the primary entities that might
be used to build a character. As such, all compile-time functions are named
with the declare-
prefix, such as declare-class
. Compile-time
functions may only be used at compile-time.
Runtime operation occurs when a character sheet is in use, with the purpose of building upon a primary entity (such as a Class) based on user-selected options, in order to build up the "current" state of the entity. Runtime functions are invoked on an entity state map, and return the new state, allowing them to be used easily in pipelines to gradually add features, etc.
In general, any feature can have a runtime operation attached to it (also
known as an on-provide
function, using the :!
key) which will be applied
to an entity state when the feature is attached it. Such functions have a
simple signature:
(fn [state] state)
To simplify implementation, the on-state
macro is provided, which
automatically threads the given state
through. It might be used like:
(on-state
(provide-feature :gunslinging)
(provide-to-list :weapons :weapon/captains-pistol))
An extra value of having state
provided at runtime to this function is
that you can access things like :level
in order to dynamically change
the behavior of features, limited-uses, etc.---without requiring special
support from the sheet! For example:
(on-state
(provide-limited-use
{:id :gunslinging/precision-shot
:uses (:level state)))
Note that the on-state
macro provides the state with the implicit name
state
, as in the signature described above.
In general, when providing things to an entity, whether features to an entity, or items to a list, you can use:
state
that returns the value: This enables you to
refer to values that may be declared in other Data Sources, or which
are dynamically added by other features at runtime. Several helpers for
creating these functions exist, such as [options-of] or [items-from-list].by-id
function,
enabling you to easily reference a feature declared elsewhere.In addition, for any provide
or declare
function that allows you to pass
multiple values, you can provide a mix of sequences and values, enabling you
to use strutures like (map)
or list comprehension with (for)
to generate
values.
Public scripting API The public functions in this namespace (declared with `defn-api`) are provided at runtime to wish-engine Data Source scripts. Data Source scripts have two modes of operation: compile-time and runtime. Compile-time, or "top-level," operation occurs when the Data Source is initially loaded, and is used to declare all the primary entities that might be used to build a character. As such, all compile-time functions are named with the `declare-` prefix, such as [[declare-class]]. Compile-time functions may *only* be used at compile-time. Runtime operation occurs when a character sheet is in use, with the purpose of building upon a primary entity (such as a Class) based on user-selected options, in order to build up the "current" state of the entity. Runtime functions are invoked on an entity state map, and return the new state, allowing them to be used easily in pipelines to gradually add features, etc. In general, any feature can have a runtime operation attached to it (also known as an `on-provide` function, using the `:!` key) which will be applied to an entity state when the feature is attached it. Such functions have a simple signature: ```clojure (fn [state] state) ``` To simplify implementation, the `on-state` macro is provided, which automatically threads the given `state` through. It might be used like: ```clojure (on-state (provide-feature :gunslinging) (provide-to-list :weapons :weapon/captains-pistol)) ``` An extra value of having `state` provided at runtime to this function is that you can access things like `:level` in order to dynamically change the behavior of features, limited-uses, etc.---without requiring special support from the sheet! For example: ```clojure (on-state (provide-limited-use {:id :gunslinging/precision-shot :uses (:level state))) ``` Note that the `on-state` macro provides the state with the implicit name `state`, as in the signature described above. In general, when providing things to an entity, whether features to an entity, or items to a list, you can use: 1. A function of `state` that returns the value: This enables you to refer to values that may be declared in other Data Sources, or which are dynamically added by other features at runtime. Several helpers for creating these functions exist, such as [options-of] or [items-from-list]. 2. A map: this represents an inline declaration of the feature at runtime, as you provide it. This is commonly used for class features that won't be referenced by other features. 3. A keyword: this is syntactic sugar for using the [[by-id]] function, enabling you to easily reference a feature declared elsewhere. In addition, for any `provide` or `declare` function that allows you to pass multiple values, you can provide a mix of sequences and values, enabling you to use strutures like `(map)` or list comprehension with `(for)` to generate values.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close