-
Notifications
You must be signed in to change notification settings - Fork 12
Module Structure
Lavaeolous edited this page Apr 20, 2021
·
2 revisions
Welcome to the PF1-StatBlock-Converter-Module wiki!
Here i will try to document how SBC works, so that contributors have an easier time to understand the code. There will be a lot of inconsistencies and i am pretty sure i am not really following any best practices, so, sorry for that.
Here is a general overview over SBCs structure und function:
Folder | File | General Function |
---|---|---|
/scripts/ | sbc.js | Gets initialized when Foundry is ready and registers the sbc button in the actor directory. While initializing a temporary actor is created and stored in an object provided by sbcData.js. Provides a general call to reset sbc (which should really be in sbcUtils.js instead of in here now that i think of it) |
/scripts/ | sbcConfig.js | Exposes data thats used for a range of things, e.g. default options (used in the module settings), objects to hold keys of compendia entries, system-specific data (damage types and special effects of attacks/weapons for example) |
/scripts/ | sbcContent.js | Contains additional system specific data like names of wizarding schools, data for prestige classes and descriptions of senses. This and the system-specific data in sbcConfig.js should really be collated to get a good separation between config data and system data |
/scripts/ | sbcData.js | Exposes a class scbData that holds multiple objects for temporary data, input and parsed data as well as the main characterData object, which includes the temporary actor that gets initialized in sbc.js. It further provides a class for custom error messages (and the configuration data for that, which ... should be in sbcConfig.js ...) |
/scripts/ | sbcInput.js | Provides everything needed for the modal dialog, the highlighting of lines containing errors, the toggle to switch between pc and npc actor generation as well as fields for the preview statblock and the error console. It uses sbcModal.html (styled with sbc.css) for this. While data is being input, it parses this into the temporary actor (which gets initialized then the modal is opened) and generates the input. This input is delayed by the amout specified in the module settings and sent to the general parser in sbcParser.js. It also handles the conversion of the temporary actor into a permanent actor and kicks of the conversion validation. **A main issue i am unable to solve is, that i need to fire multiple actor.updates({}) after the conversion into a permanent actor as well as after the conversion validation to get correct data in the created actors. Any help here would be deeply appreciated. |
/scripts/ | sbcParser.js | Performs an initial clean-up of input data (in prepareInput()), splits the input at newlines and saves the prepared data into sbcData.preparedInput. Prepared data then gets split into separate dataChunks for the main categories of a pathfinder statblock (e.g. offense, defense, ...) by slicing the array containing the prepared data. This general parser then sends these chunks to specific parsers in sbcParsers.js. When all categories are parsed, this creates embeddedEntities in the temporary actors, checks optional flags which may be set while parsing (e.g. for undead creatures) and generates the notes section of the actor (which in turn is used as a preview in the modal dialog. |
/scripts/ | sbcParsers.js | Here the main parsing happens, with specific parsers for each category (e.g. parseDefense()) which in turn further split and parse this data according to a general template of data most often found in pathfinder statblocks. Which data this is and which specific parser should be used for any given case is contained in sbcMapping.map, which gets initialization function is exposed by sbcParsers.js as well. Most simple data found in statblocks gets parsed by taking a keyword and putting the value right next to it into a specific path of the temporary actor (via singleValueParser(). More specialized parsers exist for stuff that needs to calculated or is in some other way not usable by the singleValueParser(). |
/scripts/ | sbcSettings.js | Handles everything needed for the module settings, which get matched with the options set in sbcConfig.options |
/scripts/ | sbcUtils.js | Contains a lot of helper and worker functions to, for example: Create custom error messages; Find Entities in Compendia; Reset SBC or specific temporary data objects (for example when the input is changed); generate placeholder embeddedEntities for objects that could not be found in compendia; validate the conversion and create a permanent conversion buff. |
--- | --- | --- |
/styles/ | sbc.css | Styling of the sbcModal.html (the preview is styled inline) |
--- | --- | --- |
/templates/ | sbcModal.html | Markup of the sbc modal dialog containing the input, preview and error area. |
/templates/ | sbcPreview.hbs | Handlebar template for the statblock preview |