This guide describes what each service does.
- Services
type | name | eventing | coupled |
---|---|---|---|
actor | behavior | yes | |
actor | player | yes | |
counter | local | used by state | |
event | node | yes | |
loader | browser fetch | yes | uses a parser |
loader | browser local | yes | uses a parser |
loader | browser page | yes | uses a parser |
loader | node fetch | yes | uses a parser |
loader | node file | yes | uses a parser |
locale | next | yes | used by render, tokenizer |
parser | yaml | used by loader | |
random | alea | used by state | |
random | math | used by state | |
render | browser DOM | yes | uses a locale |
render | node line | yes | uses a locale |
render | node Ink | yes | uses a locale |
script | local | yes | |
state | local | yes | uses a counter, random, template |
template | chain | used by state | |
tokenizer | compromise | yes | uses a locale |
tokenizer | split | yes | uses a locale |
The actor service handles actor command tokenization and output translation.
Batch handling of NPCs.
Singular player client.
Provide unique IDs.
In-memory incrementing integer counter.
Ship events between services, typically within the same process.
In the current architecture, some services are still tightly coupled where eventing would be prohibitively expensive compared to the underlying operator, or it occurs frequently enough that the event flow would be difficult to track. The random number generator and localization service are good examples.
Uses Node's EventEmitter or polyfill for in-process eventing.
The loader service handles file I/O: reading from and writing to paths.
This may wrap a remote server, accept URLs, or load from archives.
Uses the fetch
interface in a browser.
Protocols:
https
http
: usehttps
whenever possible
Uses the localStorage
interface in a browser.
Protocols:
local
session
: alias forlocal
, does not usesessionStorage
Loads from elements on the page.
Protocols:
page
Uses the fetch
interface on the CLI via node-fetch
.
Protocols:
https
http
: usehttps
whenever possible
Uses the Node fs
module on the CLI.
Protocols:
file
Provides translations.
Uses i18next for localization of input verbs and output strings.
The parser service parses data files loaded by the loader service.
Uses js-yaml to parse JSON and YAML, with an extended schema:
!env
includes environment variables!map
produces a JSMap
from a dict
The random generator service generates pseudo-random numbers.
seedrandom-based Alea generator.
Not very random and not recommended for gameplay, good for testing.
The render service handles player I/O, that is, reading from and writing to the screen.
This may wrap a lower-level rendering interface and capture input events.
Uses the React library in the browser to draw an HTML interface.
Uses the Node readline
module on the CLI to draw a basic line-based interface.
Uses the Ink library on the CLI to draw a responsive text interface.
The script service invokes command scripts on behalf of world entities.
Run scripts from modules in the current runtime.
The state service manages world state, creating it from templates and stepping it each turn.
Step state in-memory.
Renders template primitives.
Uses (foo|bar)
chains for input and AND/OR
chains for output.
Use natural language processing to tag parts of speech and build a command.
Simple positional arguments, split on whitespace and with articles removed.
The first word is the verb, and the last word is considered an index if it is numeric.
For example:
move west
becomes a command with the verbmove
and targetwest
hit goblin 2
becomes a command with the verbhit
, targetgoblin
, and index2
This is a small lifecycle manager for the configurable services, creating them from a DI container and calling the
start()
and stop()
lifecycle methods to attach and detach services from the event bus.