-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Moral Code
offers two ways to visualize an Actor's moral code
The Moral Code viewer is a FormApplication
that has been deposited in the API. See the example below;
const actor = game.actors.getName("MyCoolActor");
const viewer = game.modules.get("moral-code")?.api?.MoralCodeViewer;
new viewer(actor).render(true);
The module also provides a handy function that assembles a given actor's moral code into text form, alternatively posting it directly to chat!
const actor = game.actors.getName("MyCoolActor");
//returns the constructed string
game.modules.get("moral-code")?.api?.getMoralCodeSummary(actor);
// posts the string directly to chat and returns a promise
await game.modules.get("moral-code")?.api?.getMoralCodeSummary(actor, true);
Moral Code fires the moralCodeReady
which provides 2 functions
- registerTheme
- registerSheet
Registering a theme can either be done in the moralCodeReady
hook or any time after Foundry's setup
hook is finished
Example:
Hooks.on('moralCodeReady', (api) => {
const myCoolTheme = {
label: 'Some Cool Theme',
class: 'cool-theme',
};
api.registerTheme(myCoolTheme);
});
To avoid CSS collisions please always scope your theme under the parent class moral-code
.moral-code.cool-theme {
//add CSS here
}
Any themes registered that way can then be selected in the Module Settings with the Theme dropdown
Registering a theme can either be done in the moralCodeReady
hook or any time after Foundry's setup
hook is finished
Sheet registration data:
Name | Type | Description |
---|---|---|
system | string | The system that this sheet is used in |
sheetClass | string | The sheet class to look for |
target | string | The selector used to select the element that will be replaced by the moral code button |
classes | string[] (optional) | The class(es) to apply to the button to make it look good. Defaults to ["btn-moral-code"]
|
insert | boolean (optional) | If true , the Moral Code button will be inserted as a standalone button instead of replacing an element |
prepend | boolean (optional) | If true the Moral Code button will be prepended to the target on insert, otherwise it is appended |
Please keep in mind that you need to provide your own css rules. The module only applies the class you have defined.
Example:
Hooks.on('moralCodeReady', (api) => {
const myCoolSheet = {
system: 'my-cool-system',
sheetClass: 'MyCoolSheet',
target: 'some.css.selector',
};
api.registerSheet(myCoolSheet);
});