mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-07-04 13:47:10 -04:00
Add customizable initiative.
This commit is contained in:
parent
c2d939aa1c
commit
ba02ddee4f
6 changed files with 122 additions and 11 deletions
|
@ -16,31 +16,70 @@ import { SimpleActorSheet } from "./actor-sheet.js";
|
|||
Hooks.once("init", async function() {
|
||||
console.log(`Initializing Simple Worldbuilding System`);
|
||||
|
||||
/**
|
||||
* Set an initiative formula for the system
|
||||
* @type {String}
|
||||
*/
|
||||
CONFIG.Combat.initiative = {
|
||||
formula: "1d20",
|
||||
/**
|
||||
* Set an initiative formula for the system. This will be updated later.
|
||||
* @type {String}
|
||||
*/
|
||||
CONFIG.Combat.initiative = {
|
||||
formula: "1d20",
|
||||
decimals: 2
|
||||
};
|
||||
|
||||
// Define custom Entity classes
|
||||
// Define custom Entity classes
|
||||
CONFIG.Actor.entityClass = SimpleActor;
|
||||
|
||||
// Register sheet application classes
|
||||
Actors.unregisterSheet("core", ActorSheet);
|
||||
Actors.registerSheet("worldbuilding", SimpleActorSheet, { makeDefault: true });
|
||||
Items.unregisterSheet("core", ItemSheet);
|
||||
Items.registerSheet("worldbuilding", SimpleItemSheet, {makeDefault: true});
|
||||
Items.registerSheet("worldbuilding", SimpleItemSheet, { makeDefault: true });
|
||||
|
||||
// Register system settings
|
||||
game.settings.register("worldbuilding", "macroShorthand", {
|
||||
name: "Shortened Macro Syntax",
|
||||
hint: "Enable a shortened macro syntax which allows referencing attributes directly, for example @str instead of @attributes.str.value. Disable this setting if you need the ability to reference the full attribute model, for example @attributes.str.label.",
|
||||
name: "SETTINGS.SimpleMacroShorthandN",
|
||||
hint: "SETTINGS.SimpleMacroShorthandL",
|
||||
scope: "world",
|
||||
type: Boolean,
|
||||
default: true,
|
||||
config: true
|
||||
});
|
||||
|
||||
// Register initiative setting.
|
||||
game.settings.register("worldbuilding", "initFormula", {
|
||||
name: "SETTINGS.SimpleInitFormulaN",
|
||||
hint: "SETTINGS.SimpleInitFormulaL",
|
||||
scope: "world",
|
||||
type: String,
|
||||
default: "1d20",
|
||||
config: true,
|
||||
onChange: formula => _simpleUpdateInit(formula, true)
|
||||
});
|
||||
|
||||
// Retrieve and assign the initiative formula setting.
|
||||
const initFormula = game.settings.get("worldbuilding", "initFormula");
|
||||
_simpleUpdateInit(initFormula);
|
||||
|
||||
/**
|
||||
* Update the initiative formula.
|
||||
* @param {string} formula - Dice formula to evaluate.
|
||||
* @param {boolean} notify - Whether or not to post nofications.
|
||||
*/
|
||||
function _simpleUpdateInit(formula, notify = false) {
|
||||
// If the formula is valid, use it.
|
||||
try {
|
||||
new Roll(formula).roll();
|
||||
CONFIG.Combat.initiative.formula = formula;
|
||||
if (notify) {
|
||||
ui.notifications.notify(game.i18n.localize("SIMPLE.NotifyInitFormulaUpdated") + ` ${formula}`);
|
||||
}
|
||||
}
|
||||
// Otherwise, fall back to a d20.
|
||||
catch (error) {
|
||||
CONFIG.Combat.initiative.formula = "1d20";
|
||||
if (notify) {
|
||||
ui.notifications.error(game.i18n.localize("SIMPLE.NotifyInitFormulaInvalid") + ` ${formula}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue