dyslexic-charactersheets / lib-charactersheets

lib-charactersheets
https://www.dyslexic-charactersheets.com
Artistic License 2.0
22 stars 8 forks source link

Dyslexic Character Sheets

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.

Install

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

Use

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) => {});
});

Documentation

Full documentation can be found here:

API

Character objects

create(...)

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:

const CharacterSheets = require('dyslexic-charactersheets');
CharacterSheets.create(request).then(function (characterSheet) {
  ...
});

Global functions

addAssetsDir(...)

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');

addTranslator(...)

Add 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) {
  // ...
});

getFormData(...)

Load 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) {
  // ...
});

The 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
    },
    ...
  ]
}

Events

on('request')

An event emitted when a character is created, before any other actions.

CharacterSheets.on('request', (request => {
  // ...
});

Note that you may not modify the request during the callback.

on('createElementTree')

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}) => {
  // ...
});

Note that you may not modify the element tree during the callback.

on('render')

An event emitted after a character sheet has been rendered into HTML.

CharacterSheets.on('render', ({data, title, mimeType, request}) => {
  // ...
});

on('error')

A hook that is called when an error occurs.

CharacterSheets.on('error', (err, request) => {
  // ...
});

Request format

The 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.

Example character

{
  "version": 0,
  "data": {
    "type": "character",
    "id": "76af3e1",
    "attributes": {
      "game": "pathfinder2",
      "name": "Bob the Destroyer",
      "ancestry": "half-orc",
      "background": "hunter",
      "class": "barbarian",
      "printColor": "#f04312"
    }
  }
}

Example party

{
  "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"
    }
  ]
}

Testing

To test this package, clone the package from source, then run:

$ cd lib-charactersheets
$ npm install
$ npm test

This will:

Translation testing

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.

Bugs

Please raise issues or pull requests on this project.

License

Artistic License 2.0 © Marcus Downing