Skip to content

How plugins fit in

Taflor's core is a table shell: the camera, the object store, selection, access, sync, the loader and the registries, the image, map, token and note objects with the grid and the fog. Almost everything else is a plugin: effects, frames, papers, dice skins, paths, markers, the measure object, GM info, audio and video, the standard dice system. The core uses the same registries a third-party plugin uses, so a bundled plugin and yours are written the same way.

State in 0.3.0

The plugin system is built and the core's own features run on it (see Bundled plugins). A table loads only the bundled plugins so far: installing other plugins (folder, zip, release, catalogue) comes with milestone M2. Until then you can write a plugin and run it against the real loader with @taflor/testkit.

Plugin kinds and tiers

A plugin is a folder with a manifest, table-plugin.json. Its kind says what it contains; the tier says what it can do in the browser, and so how much an admin has to trust it.

kind contains tier
content JSON data and assets only: no entry, no styles, no sheets T0
skin CSS and fonts, plus data, but no JavaScript T1
client an ES module (entry) that runs in the table page, plus data and CSS T3
system a game system: entity schemas, sheets, dice; T2 with sheets in sandboxed frames only, T3 with in-page code T2 or T3

The skin rule. A pack of data and CSS without code is a skin, not a client plugin: the bundled papers and trails plugins are skins. Declare client only when the plugin has a real module. The rule is checked: the manifest schema refuses entry, sheets, frames and csp in a skin (and anything but data in a content plugin), on the server and in the testkit, and the page's loader refuses a content or skin plugin that names an entry, without importing it.

Data files are limited to seven registries, whose defs the core checks and uses as text, numbers, ids and asset URLs, never as markup or code (see Registries, column "data file"); the server and the loader refuse a data file for any other registry. Every other registry takes defs from code only.

Computing the tier from what a plugin's folder actually holds (an entry or any JS outside frames/ is T3, sheets are T2, any CSS is T1), rather than from its manifest, comes with the install pipeline of milestone M2 (SPEC §10.4).

Names and namespaces

A plugin registers short names (glow); the core stores them as <plugin>:<name> (lantern:glow). Its labels, its per-device keys, its Performance switches, its menu entries and tools are namespaced the same way, by the core, so plugin code never writes the prefix and can't write another plugin's names. A name has to be declared in the manifest's contributes before the code registers it; an undeclared name throws.

Bundled plugins keep bare names (classic, marker), because tables stored those ids before the plugins existed. The exception is sea-pack, which stores sea-pack:<name> (D18): a migration renamed its stored ids, and the server and the client still read the old bare ids as the new ones. A plugin object kind is <plugin>.<name> on the wire.

When a table refers to an id whose plugin is gone, the reader falls back to the registry's default (the classic token frame, solid paths, no effect) without changing what is stored. Objects of a missing kind show as a plain fallback object, and their data stays.

Loading and rollback

The server resolves the plugins of a table into a lock (load order: requires and loadAfter, then kind - system, client, skin, content - then id). The page then:

  1. registers every plugin's data (data files, styles, labels, Performance switches) before any code runs, so code that needs a content plugin finds its entries;
  2. imports each entry and calls activate(ctx), one plugin at a time, in lock order. activate has 5 seconds.

If activate throws or times out, everything that plugin registered is rolled back, and the plugins that require it are skipped, with a notice naming both. When a plugin stops (disabled, failed, or in dev reload) its deactivate runs, then every ctx.dispose callback, then the rollback: registry entries, menu entries, HUD buttons, tools, styles, hook handlers.

?safe (GM only) loads the bundled plugins alone, ?safe=all none. If a page stopped while a plugin was activating, the next load skips that plugin, with a notice that a reload starts it again.

Failure isolation

Every call from the core into plugin code goes through a guard: render and frame callbacks, menu builders, tool handlers, hook handlers, mounts. A thrown error is caught, logged with the plugin id and reported to the server (plugin.error, rate-limited). A plugin that throws more than 20 times within 60 seconds is switched off for this page load, and the GM is told. A broken filter is skipped; the chain goes on with the value it was given.

Performance rules

Taflor has to stay smooth on a busy table in Firefox with software rendering, so plugins follow these rules (SPEC §7.10.3):

  • No per-frame events: there is no "camera moved" or "object dragged" hook. camera.settled and object.changed fire after the gesture ends.
  • Per-frame drawing goes through ctx.frame.request(callback, {fps, perfKey}), one shared scheduler that pauses when the page is hidden or the switch is off, caps each callback at its fps and measures it against a budget of 2 ms per frame.
  • Animations run on the compositor where they can (CSS transform and opacity), not by changing styles every frame.
  • Every animated contribution declares a performance key in the manifest. The Performance tab lists it with its cost, and "reduce effects" switches it off unless it says reduced: false.
  • Nothing is added to the hot paths: object rendering on move, the transformer, pointer handling.