Global
Those functions must be defined in the global scope. If you do not want to use one of there features, simply don't define the function.
init(sheet)
sheet
, type: Sheet
,
The sheet to initialize Return void
Initialize a sheet, as a character sheet or a craft. You can see what
type of sheet it is via sheet.id
. Tabs entries are not initialized
individually, and should be initialized as if they were part of the
parent view.
Example:
init = function(sheet) {
if (sheet.id() === "main") {
initMain(sheet);
} else if (sheet.id() === "weapon") {
initWeapon(sheet);
}
};
const initMain = function(sheet) {
// initialize the main sheet
sheet.get("hp"); //...
};
const initWeapon = function(sheet) {
// initialize the weapon sheet
}
drop(from, to)
from
, type: Sheet
,
Source's sheet to
, type:
Sheet
, Target's sheet
Return void|string
Called when dropping a craft onto a character sheet. If you simply want to append the data to a repeater, return the repeater's id. Otherwise, you'll have to manipulate the target sheet data.
For now, it is only possible to drop craft into character sheet.
Examples:
drop = function(from, to) {
if (from.id() === "weapon" && to.id() === "main") {
return "weapons"; // "weapons" is a repeater id
}
};
drop = function(from, to) {
if (from.id() === "heal" && to.id() === "main") {
to.get("hp").value(
from.get("maxhp").value()
); // set the target's hp to the source maxhp
}
};
dropDice(result, to)
result
, type:
DiceResult
, A dice
result from the dice log. sheet
, type:
Sheet
, Target's sheet
For some systems, it can be useful to drag'n drop a dice result onto the sheet. With this function, you can create interaction between the dice log and a character sheet or craft.
Example:
dropDice = function(result, sheet) {
if (result.containsTag("heal")) {
let hp = sheet.get("hp");
hp.value(hp.value() + result.total); // the character is healed by the total of the roll
}
}
initRoll(result, callback)
result
, type:
DiceResult
, A dice
result from the dice log. callback
,type: Function
, A callback to
render the dice result.
This function allows you to customize the rendering of a dice result. You should call the callback with two arguments :
view
:string
the id of the view you want to use to render the dice resultonRender
:Function
a function called when rendering the view, where you can change the view values. Please note the view is also initialized in the globalinit
function.
Example:
initRoll = function(result, callback) {
callback('diceresult', function(sheet) { // diceresult is the id of the view you want to use
sheet.get('total').text(result.total); // apply various changes to the view
if (result.total > 20) {
sheet.get('total').addClass('text-large');
}
});
};
getBarAttributes(sheet)
sheet
, type: Sheet
,
The sheet Return Object
Players can connect bars to some attributes with this method. It is
required to have a value, and a maximum value. The method should return
an Object
with the titles as keys, and an Array(2)
, with the first
element being the value, and the second the max value.
The bar updates when the sheet is changed, and the sheet updates when the bar value is changed.
Example:
getBarAttributes = function(sheet) {
if (sheet.id() === "main") {
return {
"HP": ["hp", "hpmax"],
"Quick Resource": ["quickResource", "quickResourceMax"]
};
}
if (sheet.id() === "monster") {
return {
"HP": ["hp", "hpmax"],
"Mana": ["mana", 30] // you can use numbers directly for maximums
};
}
return {};
};
getCriticalHits(result)
result
, type: DiceResult
This global function allows you to customise the colours of the die roll results.
It must return an object, with another object for each die dimension that associates a colour with the possible values.
Here's an example:
getCriticalHits = function(result) {
return {
"20": {
"critical": [20, 19],
"fumble": [1],
},
"6": {
"critical": [],
"fumble": [],
"cyan": [2, 3],
"pink": [1]
}
}
}
In this example, the dice will be displayed in green for "critical" on 19 and 20, and in red for "fumble" on 1s, only on d20s. On d6s, the colours don't change for criticals and fumbles, but 2s and 3s are blue, and 1s are pink.
result
is an object of type DiceResult
which allows you to modify the behaviour according to the results or tags associated with the throw, for example.
The different colours available are as follows:
critical
fumble
red
orange
yellow
green
cyan
magenta
pink