From ba02ddee4ffb34129502f0c28a871e68e7d39a6f Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Mon, 27 Jul 2020 18:14:08 +0000 Subject: [PATCH] Add customizable initiative. --- .gitignore | 4 ++++ gulpfile.js | 32 ++++++++++++++++++++++++++ lang/en.json | 9 ++++++++ module/simple.js | 59 ++++++++++++++++++++++++++++++++++++++++-------- package.json | 21 +++++++++++++++++ system.json | 8 ++++++- 6 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 gulpfile.js create mode 100644 lang/en.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 8847e16..47906f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ # IDE .idea/ .vs/ + +# Node Modules +node_modules/ +package-lock.json diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..d06b7f7 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,32 @@ +const gulp = require('gulp'); +const less = require('gulp-less'); + +/* ----------------------------------------- */ +/* Compile LESS +/* ----------------------------------------- */ + +const SIMPLE_LESS = ["styles/*.less"]; +function compileLESS() { + return gulp.src("styles/simple.less") + .pipe(less()) + .pipe(gulp.dest("./styles/")) +} +const css = gulp.series(compileLESS); + +/* ----------------------------------------- */ +/* Watch Updates +/* ----------------------------------------- */ + +function watchUpdates() { + gulp.watch(SIMPLE_LESS, css); +} + +/* ----------------------------------------- */ +/* Export Tasks +/* ----------------------------------------- */ + +exports.default = gulp.series( + gulp.parallel(css), + watchUpdates +); +exports.css = css; diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..cf105df --- /dev/null +++ b/lang/en.json @@ -0,0 +1,9 @@ +{ + "SETTINGS.SimpleMacroShorthandN": "Shortened Macro Syntax", + "SETTINGS.SimpleMacroShorthandL": "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.", + "SETTINGS.SimpleInitFormulaN": "Initiative Formula", + "SETTINGS.SimpleInitFormulaL": "Enter an initiative formula, such as d20+@dex", + + "SIMPLE.NotifyInitFormulaUpdated": "Initiative formula was updated to:", + "SIMPLE.NotifyInitFormulaInvalid": "Initiative formula was invalid:" +} \ No newline at end of file diff --git a/module/simple.js b/module/simple.js index becc533..a880059 100644 --- a/module/simple.js +++ b/module/simple.js @@ -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}`); + } + } + } + }); diff --git a/package.json b/package.json new file mode 100644 index 0000000..a0a6dff --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "worldbuilding", + "version": "1.0.0", + "description": "CSS compiler for the Worldbuilding system", + "scripts": { + "css": "gulp css", + "watch": "gulp", + "gulp": "gulp" + }, + "browserslist": [ + "last 3 versions" + ], + "author": "", + "license": "MIT", + "private": true, + "dependencies": { + "gulp": "^4.0.2", + "gulp-less": "^4.0.1" + }, + "devDependencies": {} +} diff --git a/system.json b/system.json index e134ce0..87ab940 100644 --- a/system.json +++ b/system.json @@ -10,7 +10,13 @@ "esmodules": ["module/simple.js"], "styles": ["styles/simple.css"], "packs": [], - "languages": [], + "languages": [ + { + "lang": "en", + "name": "English", + "path": "lang/en.json" + } + ], "gridDistance": 5, "gridUnits": "ft", "primaryTokenAttribute": "health",