@dicetable/plugin-shell
v0.1.1
Published
Plugin Utilities for VTT-DiceTable Plugins
Downloads
1
Readme
DiceTable Plugin Shell
The plugin shell is used for creating plugins for the DiceTable-VTT.
This repository only exports one real type, the createWebpackConfig
. All other exports are only
included as types. They will be provided by the DiceTable-VTT. This is to ensure that
the plugin itself is as small as possible, as the plugin is also saved inside the
savestate.
Installation
It's a node package!
npm install @dicetable/plugin-shell
Usage
webpack.config.js
After installation, setup webpack to use the plugin shell. Basically add a file
webpack.config.js
to your project with the following content:
const createWebpackConfig = require("packages/plugin-shell/script/createWebpackConfig");
module.exports = createWebpackConfig(__dirname);
This will create a webpack config that will bundle your plugin and replace everything imported from the plugin shell with the global variables on the site.
For this to work, it reads your package.json. The following fields are used:
version
(only in the resulting zip)name
(only in the resulting zip)
package.json
After that add the webpack-command to your package.json:
{
"scripts": {
"build": "webpack"
}
}
You don't need to install webpack, as it is a dependency of the plugin shell.
src/manifest.json
Now add the manifest.json at src/manifest.json
. This file contains infos about
your plugin. The definition of the file can be
found here.
The PluginManifestType is also included inside the plugin-shell.
A simple and complete manifest.json looks like this:
{
"apiVersion": 1,
"id": "com.example.unique.id",
"label": {
"en": "My Plugin",
"de": "Mein Plugin"
},
"version": "1.0.0",
"description": {
"en": "This is my plugin",
"de": "Das ist mein Plugin"
},
"dependencies": {
"com.example.other.plugin.id": "^1.0.0"
},
"author": "My Name"
}
Only the fields apiVersion
, id
, label
and version
are required. All other fields
are optional. The apiVersion is the version of the plugin api that is used. If the
apiVersion of the plugin is not the same as the apiVersion of the DiceTable-VTT,
a warning will be displayed to the user, that the plugin may not be working correctly.
The id is the unique identifier. It must not start with net.dicetable.
, as only
official plugins can start with this prefix. Be sure to pick a unique id, as only
one plugin with the same id can be installed at the same time!
The label is the name shown to the user. It is an object with the language as key.
en
is mandatory, but you can add as many languages as you want, although only
languages that are supported by the DiceTable-VTT will be displayed. At the moment
this is only en
and de
. The same goes for the description, where you can describe
in more detail what your plugin does.
The version is a semver-version. It is used to check dependencies of the other plugins.
The dependencies is an object with the id of the plugin as key and the semver-version. If a plugin your plugin depends on is not installed, the user will get an error message while trying to install your plugin. At the same time, the user cannot uninstall your plugin as long as other plugins depending on your plugin are installed.
The author field is a string with your name. It will be shown to the user inside the plugin list.
src/index.ts
Now you can start writing your plugin. The entry point is src/index.ts
.
The basic structure of the file looks like this:
import { registerPlugin } from "@dicetable/plugin-shell";
import manifest from "./manifest.json";
registerPlugin(manifest.id, (api) => {
});
be sure to set resolveJsonModule
to true
inside your tsconfig.json, otherwise
the manifest.json cannot be imported.
with help of the api
-object you can add own windows, tools, data, token-objects
and many more things to the DiceTable-VTT. The api
-object is defined inside
here
Example
You can find an example plugin here. This plugin adds the amor class to the token sheet and object.