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";
|
2020-04-24 15:30:51 +00:00
|
|
|
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";
|
2020-04-24 15:30:51 +00:00
|
|
|
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 });
|
2020-04-24 15:30:51 +00:00
|
|
|
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.
|
2020-04-28 12:19:50 +00:00
|
|
|
Handlebars.registerHelper('eq', (a, b, options) => {
|
2020-04-21 06:51:49 +00:00
|
|
|
return (a === b) ? options.fn(this) : '';
|
|
|
|
});
|
|
|
|
|
2020-04-24 15:30:51 +00:00
|
|
|
// NotEquals handlebar.
|
2020-04-28 12:19:50 +00:00
|
|
|
Handlebars.registerHelper('noteq', (a, b, options) => {
|
2020-04-24 15:30:51 +00:00
|
|
|
return (a !== b) ? options.fn(this) : '';
|
|
|
|
});
|
|
|
|
|
2020-04-27 13:58:52 +00:00
|
|
|
// ReputationTurf handlebar.
|
2020-04-28 12:19:50 +00:00
|
|
|
Handlebars.registerHelper('repturf', (turfs_amount, options) => {
|
2020-04-27 13:58:52 +00:00
|
|
|
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-28 12:19:50 +00:00
|
|
|
Handlebars.registerHelper('crew_vault_coins', (max_coins, options) => {
|
|
|
|
|
|
|
|
let html = options.fn(this);
|
|
|
|
for (let i = 1; i <= max_coins; i++) {
|
|
|
|
|
|
|
|
html += "<input type=\"radio\" id=\"crew-coins-vault-" + i + "\" name=\"data.vault.value\" value=\"" + i + "\"><label for=\"crew-coins-vault-" + i + "\"></label>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return html;
|
|
|
|
});
|
|
|
|
|
2020-04-28 14:10:14 +00:00
|
|
|
Handlebars.registerHelper('crew_experience', (options) => {
|
|
|
|
|
|
|
|
let html = options.fn(this);
|
|
|
|
for (let i = 1; i <= 10; i++) {
|
|
|
|
|
|
|
|
html += '<input type="radio" id="crew-experience-' + i + '" name="data.experience" value="' + i + '" dtype="Radio"><label for="crew-experience-' + i + '"></label>';
|
|
|
|
}
|
|
|
|
|
|
|
|
return html;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Enrich the HTML replace /n with <br>
|
|
|
|
Handlebars.registerHelper('html', (options) => {
|
|
|
|
|
|
|
|
let text = options.hash['text'].replace(/\n/g, "<br />");
|
|
|
|
|
|
|
|
return new Handlebars.SafeString(text);;
|
|
|
|
});
|
|
|
|
|
2020-04-17 21:23:57 +00:00
|
|
|
});
|
2020-04-28 10:46:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hooks
|
|
|
|
*/
|
2020-04-28 10:52:30 +00:00
|
|
|
Hooks.on("preCreateOwnedItem", (parent_entity, child_data, options, userId) => {
|
2020-04-28 12:19:50 +00:00
|
|
|
|
|
|
|
BladesHelpers.removeDuplicatedItemType(child_data, parent_entity);
|
|
|
|
|
|
|
|
return true;
|
2020-04-28 10:46:04 +00:00
|
|
|
});
|
|
|
|
|
2020-04-28 10:52:30 +00:00
|
|
|
Hooks.on("createOwnedItem", (parent_entity, child_data, options, userId) => {
|
2020-04-28 12:19:50 +00:00
|
|
|
|
2020-04-28 10:52:30 +00:00
|
|
|
BladesHelpers.callItemLogic(child_data, parent_entity);
|
2020-04-28 12:19:50 +00:00
|
|
|
return true;
|
2020-04-28 10:52:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Hooks.on("deleteOwnedItem", (parent_entity, child_data, options, userId) => {
|
2020-04-28 12:19:50 +00:00
|
|
|
|
2020-04-28 10:52:30 +00:00
|
|
|
BladesHelpers.undoItemLogic(child_data, parent_entity);
|
2020-04-28 12:19:50 +00:00
|
|
|
return true;
|
2020-04-28 10:46:04 +00:00
|
|
|
});
|