fvtt-rolemaster-frp/rmss.js

155 lines
6.9 KiB
JavaScript
Raw Permalink Normal View History

2024-07-26 09:20:48 +02:00
// Import Configuration Object
import { rmss } from "./module/config.js";
2024-07-26 14:15:51 +02:00
//import { registerGetSceneControlButtonsHook } from "./module/controls.js";
2024-07-26 09:20:48 +02:00
// Import document classes.
import { RMSSActor } from "./module/documents/actor.js";
import { RMSSItem } from "./module/documents/item.js";
// Import Sheets
import RMSSItemSheet from "./module/sheets/items/rmss_item_sheet.js";
import RMSSArmorSheet from "./module/sheets/items/rmss_armor_sheet.js";
import RMSSTransportSheet from "./module/sheets/items/rmss_transport_sheet.js";
import RMSSWeaponSheet from "./module/sheets/items/rmss_weapon_sheet.js";
import RMSSHerbOrPoisonSheet from "./module/sheets/items/rmss_herb_or_poison_sheet.js";
import RMSSSpellSheet from "./module/sheets/spells/rmss_spell_sheet.js";
import RMSSSkillCategorySheet from "./module/sheets/skills/rmss_skill_category_sheet.js";
import RMSSSkillSheet from "./module/sheets/skills/rmss_skill_sheet.js";
import RMSSPlayerSheet from "./module/sheets/actors/rmss_player_sheet.js";
2024-07-26 14:15:51 +02:00
import RMSSToolsSCImporter from "./module/sheets/apps/rmss_import_skill_categories.js";
import RMSSToolsDiceRoller from "./module/sheets/apps/rmss_dice_roller.js";
2024-07-26 09:20:48 +02:00
/** Preload handlebars templates for character sheets */
async function preloadHandlebarsTemplates() {
const templatePaths = [
2024-07-26 12:51:32 +02:00
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-stats.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fixed-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-armor-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-resistance.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-race-stat-fixed-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-role-traits.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-background-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skill-categories.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-items.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-weapons.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-money.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skill-categories.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-armor.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-herbs.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-spells.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-spells.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-items.html",
2024-07-26 14:15:51 +02:00
"systems/fvtt-rolemaster-frp/templates/sheets/apps/app_skill_category_importer.html"
2024-07-26 09:20:48 +02:00
];
return loadTemplates(templatePaths);
}
2024-07-26 14:15:51 +02:00
// Register Scene Controls
// registerGetSceneControlButtonsHook();
2024-07-26 09:20:48 +02:00
// Hook the init function and set up our system
2024-07-29 09:28:42 +02:00
Hooks.once("init", function () {
2024-07-26 09:20:48 +02:00
console.log("rmss | Initialising Rolemaster Standard System");
// Load our custom actor and item classes
console.log("rmss | Loading Rolemaster Actor and Item classes");
game.rmss = {
RMSSActor,
RMSSItem,
applications: {
2024-07-26 14:15:51 +02:00
RMSSToolsSCImporter,
RMSSToolsDiceRoller
2024-07-26 09:20:48 +02:00
}
};
// Define custom Document classes
CONFIG.Actor.documentClass = RMSSActor;
CONFIG.Item.documentClass = RMSSItem;
2024-07-26 14:15:51 +02:00
// Add PragRoman Font
CONFIG.fontDefinitions["PragRoman"] = {
editor: true,
fonts: [
2024-07-29 09:28:42 +02:00
{ urls: ["systems/fvtt-rolemaster-frp/assets/fonts/PragRoman.woff2"] }
2024-07-26 14:15:51 +02:00
]
};
2024-07-26 09:20:48 +02:00
// Make Config Data Available
CONFIG.rmss = rmss;
// Unregister Default Sheets
console.log("rmss | Unregistering core sheets");
Items.unregisterSheet("core", ItemSheet);
Actors.unregisterSheet("core", ActorSheet);
// Register RMSS Sheets
console.log("rmss | Registering RMSS sheets");
// Items
2024-07-29 09:28:42 +02:00
Items.registerSheet("fvtt-rolemaster-frp", RMSSItemSheet, { makeDefault: true, label: "rmss.entity_sheet.item", types: ["item"] });
Items.registerSheet("fvtt-rolemaster-frp", RMSSArmorSheet, { makeDefault: true, label: "rmss.entity_sheet.armor", types: ["armor"] });
Items.registerSheet("fvtt-rolemaster-frp", RMSSTransportSheet, { makeDefault: true, label: "rmss.entity_sheet.transport", types: ["transport"] });
Items.registerSheet("fvtt-rolemaster-frp", RMSSWeaponSheet, { makeDefault: true, label: "rmss.entity_sheet.weapon", types: ["weapon"] });
Items.registerSheet("fvtt-rolemaster-frp", RMSSHerbOrPoisonSheet, { makeDefault: true, label: "rmss.entity_sheet.herb_or_poison", types: ["herb_or_poison"] });
2024-07-26 09:20:48 +02:00
// Spells
2024-07-29 09:28:42 +02:00
Items.registerSheet("fvtt-rolemaster-frp", RMSSSpellSheet, { makeDefault: true, label: "rmss.entity_sheet.spell", types: ["spell"] });
2024-07-26 09:20:48 +02:00
// Skills
2024-07-29 09:28:42 +02:00
Items.registerSheet("fvtt-rolemaster-frp", RMSSSkillCategorySheet, { makeDefault: true, label: "rmss.entity_sheet.skill_category", types: ["skill_category"] });
Items.registerSheet("fvtt-rolemaster-frp", RMSSSkillSheet, { makeDefault: true, label: "rmss.entity_sheet.skill", types: ["skill"] });
2024-07-26 09:20:48 +02:00
// Actors
2024-07-29 09:28:42 +02:00
Actors.registerSheet("fvtt-rolemaster-frp", RMSSPlayerSheet, { makeDefault: true, label: "rmss.entity_sheet.player_characrer", types: ["character"] });
2024-07-26 09:20:48 +02:00
// Preload Handlebars Templates
console.log("rmss | Preloading Handlebars Templates");
preloadHandlebarsTemplates();
// Handlebars Helpers
Handlebars.registerHelper('count', function (list) {
return list.length;
})
Handlebars.registerHelper('includes', function (array, val) {
return array.includes(val);
})
Handlebars.registerHelper('upper', function (text) {
return text.toUpperCase();
})
Handlebars.registerHelper('lower', function (text) {
return text.toLowerCase()
})
Handlebars.registerHelper('upperFirst', function (text) {
if (typeof text !== 'string') return text
return text.charAt(0).toUpperCase() + text.slice(1)
})
Handlebars.registerHelper('notEmpty', function (list) {
return list.length > 0;
})
Handlebars.registerHelper('mul', function (a, b) {
return parseInt(a) * parseInt(b);
})
2024-07-29 09:28:42 +02:00
Handlebars.registerHelper("switch", function (value, options) {
2024-07-26 09:20:48 +02:00
this.switch_value = value;
return options.fn(this);
});
2024-07-29 09:28:42 +02:00
Handlebars.registerHelper("case", function (value, options) {
2024-07-26 09:20:48 +02:00
if (value === this.switch_value) {
return options.fn(this);
}
});
2024-07-29 09:28:42 +02:00
// Handle v12 removal of this helper
Handlebars.registerHelper('select', function (selected, options) {
const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected));
const rgx = new RegExp(' value=[\"\']' + escapedValue + '[\"\']');
const html = options.fn(this);
return html.replace(rgx, "$& selected");
});
2024-07-26 09:20:48 +02:00
});