Merge branch '1-add-init-system-setting' into 'master'

Resolve "Add a system setting to configure the preferred initiative formula that should be used"

Closes #1

See merge request foundrynet/worldbuilding!2
This commit is contained in:
Andrew 2020-07-27 18:14:08 +00:00
commit 3e2a95f5f1
6 changed files with 122 additions and 11 deletions

4
.gitignore vendored
View file

@ -1,3 +1,7 @@
# IDE
.idea/
.vs/
# Node Modules
node_modules/
package-lock.json

32
gulpfile.js Normal file
View file

@ -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;

9
lang/en.json Normal file
View file

@ -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:"
}

View file

@ -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}`);
}
}
}
});

21
package.json Normal file
View file

@ -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": {}
}

View file

@ -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",