A library to generate character sheets for Pathfinder 2nd Edition and other games.
See the website: https://www.dyslexic-charactersheets.com/.
This project is a Node.js module: https://npmjs.com/package/dyslexic-charactersheets
You can follow progress on the project's Patreon page.
To install this library in another project:
$ npm install dyslexic-charactersheets
To clone this library for development:
$ git clone https://github.com/dyslexic-charactersheets/lib-charactersheets.git
$ cd lib-charactersheets
$ npm install # install dependencies
You can make changes, then import your version of this module into another project with:
$ npm test # compile and run the code
$ sudo npm link -g # export this library folder
$ cd ../your-project
$ npm link dyslexic-charactersheets # import the library into your project
The library expects to be given a character's details in the form of a plain JavaScript object (details in the documentation)
let request = {
data: {
type: 'character',
id: '76af3e1',
attributes: {
game: 'pathfinder2',
name: 'Valeros',
class: 'druid',
...a lot more details...
}
}
};
const CharacterSheets = require('dyslexic-charactersheets');
CharacterSheets.create(request).then(characterSheet => {
fs.writeFile(characterSheet.filename, characterSheet.data, (err) => {});
});
Full documentation can be found here:
Creates a character sheet.
This function returns a Promise representing the data. The result is either an array of objects or a single object, each containing:
data
- the result, generally as HTMLfilename
- the preferred name of the filemimeType
- the MIME type of the result, typically text/html
const CharacterSheets = require('dyslexic-charactersheets');
CharacterSheets.create(request).then(function (characterSheet) {
...
});
create()
request
\<Object> - The request object (see below).Register a directory with asset files. Do this before calling create
, and it will refer to this directory when looking for portraits, logos and background images.
CharacterSheets.addAssetsDir('./assets');
addAssetsDir()
dir
\<String> - A directoryAdd a callback that supplies translations. The callback accepts a message
, a language
and an object with metadata; it returns either a translation, or null
.
CharacterSheets.addTranslator(function (message, language, meta) {
// ...
});
addTranslator(callback)
callback
\<Function> - A callbackmessage
\<String> - A string to translatelanguage
\<String> - A locale code, en
or en-GB
context
\<Object> - Metadata for that messageLoad the data needed to render a selection form with all the options. Takes a callback that will process the data.
CharacterSheets.getFormData(system).then(function (data) {
// ...
});
getFormData(system, callback)
system
\<String> - for example, pathfinder2
data
\<Object> - The form dataThe form data is in the format:
{
selects: [
{
select: "class",
name: "Class",
max: 1,
base: true,
units: {
"class/alchemist": {
id: "class/alchemist",
name: "Alchemist"
},
"class/fighter": {
id: "class/fighter",
name: "Fighter"
},
...
},
groups: [
{
group: "crb",
name: "Core Rulebook",
units: [
"class/alchemist",
"class/fighter",
...
]
},
...
]
},
...
],
options: [
{
option: "permission",
name: "Permission to Print",
unit: "option/permission",
base: true
},
...
]
}
An event emitted when a character is created, before any other actions.
CharacterSheets.on('request', (request => {
// ...
});
on
'request'
callback
\<Function>request
\<Object> - The requested character.Note that you may not modify the request during the callback.
An event emitted after the element tree has been processed, but before it's rendered into HTML. Used for debugging the resulting element tree.
CharacterSheets.on('createElementTree', ({elementTree, title, request}) => {
// ...
});
on
'createElementTree'
callback
\<Function>params
\<Object>
elementTree
\<Object> - The element treetitle
\<String> - The character or party's namerequest
\<Object> - The requested characterNote that you may not modify the element tree during the callback.
An event emitted after a character sheet has been rendered into HTML.
CharacterSheets.on('render', ({data, title, mimeType, request}) => {
// ...
});
on
'render'
callback
\<Function>params
\<Object>
data
\<String> - The rendered outputtitle
\<String> - The character or party's namemimeType
\<String> - The MIME type of the resultrequest
\<Object> - The requested characterA hook that is called when an error occurs.
CharacterSheets.on('error', (err, request) => {
// ...
});
on
'error'
callback
\<Function>err
\<Error> - Error objectrequest
\<Object> - The requested characterThe request object describes a character, a party, or various other things you may want the library to produce.
For a detailed description of the format, see the character sheets schema repo.
{
"version": 0,
"data": {
"type": "character",
"id": "76af3e1",
"attributes": {
"game": "pathfinder2",
"name": "Bob the Destroyer",
"ancestry": "half-orc",
"background": "hunter",
"class": "barbarian",
"printColor": "#f04312"
}
}
}
{
"version": 0,
"data": {
"type": "party",
"game": "pathfinder2",
"attributes": {
"name": "The Gravy Bunch"
},
"relationships": {
"members": {
"data": [
{ "type": "character", "id": "76af3e1" },
]
}
}
},
"included": [
{
"type": "character",
"id": "76af3e1",
"game": "pathfinder2",
"name": "Bob the Destroyer",
"ancestry": "half-orc",
"background": "hunter",
"class": "barbarian",
"printColor": "#f04312"
}
]
}
To test this package, clone the package from source, then run:
$ cd lib-charactersheets
$ npm install
$ npm test
This will:
src
to create the files in lib
test/in
test/out
To properly test translations, enough character sheets need to be created to expose every single unit.
$ npm run test:i18n
The files will be placed in test/out/i18n
.
Please raise issues or pull requests on this project.
Artistic License 2.0 © Marcus Downing