mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-04-30 10:41:40 -04:00
85 lines
2.6 KiB
JavaScript
85 lines
2.6 KiB
JavaScript
/**
|
|
* A simple and flexible system for world-building using an arbitrary collection of character and item attributes
|
|
* Author: Atropos
|
|
* Software License: GNU GPLv3
|
|
*/
|
|
|
|
// Import Modules
|
|
import { SimpleActor } from "./actor.js";
|
|
import { SimpleItemSheet } from "./item-sheet.js";
|
|
import { SimpleActorSheet } from "./actor-sheet.js";
|
|
|
|
/* -------------------------------------------- */
|
|
/* Foundry VTT Initialization */
|
|
/* -------------------------------------------- */
|
|
|
|
Hooks.once("init", async function() {
|
|
console.log(`Initializing Simple Worldbuilding System`);
|
|
|
|
/**
|
|
* 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
|
|
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 });
|
|
|
|
// Register system settings
|
|
game.settings.register("worldbuilding", "macroShorthand", {
|
|
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}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
});
|