foundryvtt-beam-saber/module/blades.js

104 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-04-17 21:23:57 +00:00
/**
* 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
2020-04-21 06:51:49 +00:00
import { preloadHandlebarsTemplates } from "./templates.js";
import { BladesHelpers } from "./blades-helpers.js";
2020-04-23 16:11:04 +00:00
import { BladesItem } from "./item.js";
2020-04-21 16:06:33 +00:00
import { BladesItemSheet } from "./item-sheet.js";
2020-04-17 21:48:29 +00:00
import { BladesActorSheet } from "./actor-sheet.js";
import { BladesCrewSheet } from "./crew-sheet.js";
window.BladesHelpers = BladesHelpers;
2020-04-17 21:23:57 +00:00
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("init", async function() {
2020-04-17 21:48:29 +00:00
console.log(`Initializing Blades In the Dark System`);
2020-04-17 21:23:57 +00:00
/**
* Set an initiative formula for the system
* @type {String}
*/
2020-04-23 16:11:04 +00:00
CONFIG.Item.entityClass = BladesItem;
2020-04-17 21:23:57 +00:00
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
2020-04-23 16:11:04 +00:00
Actors.registerSheet("blades", BladesActorSheet, { types: ["character"], makeDefault: true });
Actors.registerSheet("blades", BladesCrewSheet, { types: ["crew"], makeDefault: true });
2020-04-21 16:06:33 +00:00
Items.unregisterSheet("core", ItemSheet);
2020-04-23 16:11:04 +00:00
Items.registerSheet("blades", BladesItemSheet, {makeDefault: true});
2020-04-21 06:51:49 +00:00
preloadHandlebarsTemplates();
2020-04-17 21:23:57 +00:00
// Multiboxes.
Handlebars.registerHelper('multiboxes', function(selected, options) {
let html = options.fn(this);
selected.forEach(selected_value => {
if (selected_value !== false) {
const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected_value));
const rgx = new RegExp(' value=\"' + escapedValue + '\"');
html = html.replace(rgx, "$& checked=\"checked\"");
}
});
return html;
});
// Trauma Counter
Handlebars.registerHelper('traumacounter', function(selected, options) {
let html = options.fn(this);
var count = selected.length;
if (count > 4) count = 4;
const rgx = new RegExp(' value=\"' + count + '\"');
return html.replace(rgx, "$& checked=\"checked\"");
2020-04-17 21:48:29 +00:00
2020-04-17 21:23:57 +00:00
});
2020-04-21 06:51:49 +00:00
// Equals handlebar.
Handlebars.registerHelper('eq', function (a, b, options) {
return (a === b) ? options.fn(this) : '';
});
// NotEquals handlebar.
Handlebars.registerHelper('noteq', function (a, b, options) {
return (a !== b) ? options.fn(this) : '';
});
// ReputationTurf handlebar.
Handlebars.registerHelper('repturf', function (turfs_amount, options) {
let html = options.fn(this);
var turfs_amount_int = parseInt(turfs_amount);
// Can't be more than 6.
if (turfs_amount_int > 6) {
turfs_amount_int = 6;
}
for (let i = 13 - turfs_amount_int; i <= 12; i++) {
const rgx = new RegExp(' value=\"' + i + '\"');
html = html.replace(rgx, "$& disabled=\"disabled\"");
}
return html;
});
2020-04-17 21:23:57 +00:00
});
/*
* Hooks
*/
Hooks.on("createOwnedItem", (parent, child, options, userId) => {
BladesHelpers.callItemLogic(child, parent);
});
Hooks.on("deleteOwnedItem", (parent, child, options, userId) => {
BladesHelpers.undoItemLogic(child, parent);
});