131 lines
5.1 KiB
JavaScript
131 lines
5.1 KiB
JavaScript
import { ItemSheetKH } from "./items/item-sheet.js";
|
|
import { ItemKH } from "./items/item.js";
|
|
import KHHooks from "./kh-hooks.js";
|
|
import { ActorKH } from "./actors/actor.js";
|
|
import { ActorSheetKH } from "./actors/actor-sheet.js";
|
|
import { KH } from "./kh-config.js";
|
|
|
|
Hooks.once("init", () => {
|
|
CONFIG.Combat.initiative = { formula: "(@combat.init)d6kh2", decimals: 0 };
|
|
|
|
CONFIG.Actor.entityClass = ActorKH;
|
|
CONFIG.Item.entityClass = ItemKH;
|
|
|
|
// Give global access to FFG config.
|
|
CONFIG.KH = KH;
|
|
|
|
//registerFonts();
|
|
registerSheets();
|
|
preloadHandlebarsTemplates();
|
|
registerHandlebarsHelpers();
|
|
game.settings.register("kopparhavet", "worldSchemaVersion", {
|
|
name: "World Version",
|
|
hint: "Used to automatically upgrade worlds data when the system is upgraded.",
|
|
scope: "world",
|
|
config: true,
|
|
default: 0,
|
|
type: Number,
|
|
});
|
|
});
|
|
|
|
Hooks.once("ready", () => {
|
|
//migrateWorld();
|
|
});
|
|
|
|
/* POPULATE CHARACTER WITH DEFAULT SKILLS */
|
|
Hooks.on("createActor", async (actor, options, userId) => KHHooks.onCreateActor(actor, options, userId));
|
|
|
|
function registerSheets() {
|
|
// Register sheet application classes
|
|
console.log("Registerting sheets")
|
|
|
|
Actors.unregisterSheet("core", ActorSheet);
|
|
Actors.registerSheet("kopparhavet", ActorSheetKH, { types: ["character"], makeDefault: true });
|
|
Actors.registerSheet("kopparhavet", ActorSheetKH, { types: ["adversary"], makeDefault: true });
|
|
|
|
Items.unregisterSheet("core", ItemSheet);
|
|
Items.registerSheet("kopparhavet", ItemSheetKH, { types: ["weapon"], makeDefault: true });
|
|
Items.registerSheet("kopparhavet", ItemSheetKH, { types: ["armor"], makeDefault: true });
|
|
Items.registerSheet("kopparhavet", ItemSheetKH, { types: ["gear"], makeDefault: true });
|
|
Items.registerSheet("kopparhavet", ItemSheetKH, { types: ["skill"], makeDefault: true });
|
|
Items.registerSheet("kopparhavet", ItemSheetKH, { types: ["spell"], makeDefault: true });
|
|
Items.registerSheet("kopparhavet", ItemSheetKH, { types: ["talent"], makeDefault: true });
|
|
Items.registerSheet("kopparhavet", ItemSheetKH, { types: ["adversaryAttack"], makeDefault: true });
|
|
}
|
|
|
|
function preloadHandlebarsTemplates() {
|
|
const templatePaths = [
|
|
"systems/kopparhavet/templates/chat/item-card.html",
|
|
"systems/kopparhavet/templates/actors/adversary-sheet.html",
|
|
"systems/kopparhavet/templates/actors/character-sheet.html",
|
|
"systems/kopparhavet/templates/dice/roll.html",
|
|
"systems/kopparhavet/templates/items/adversaryAttack-sheet.html",
|
|
"systems/kopparhavet/templates/items/armor-sheet.html",
|
|
"systems/kopparhavet/templates/items/gear-sheet.html",
|
|
"systems/kopparhavet/templates/items/skill-sheet.html",
|
|
"systems/kopparhavet/templates/items/spell-sheet.html",
|
|
"systems/kopparhavet/templates/items/talent-sheet.html",
|
|
"systems/kopparhavet/templates/items/weapon-sheet.html",
|
|
"systems/kopparhavet/templates/parts/actor/bio.html",
|
|
"systems/kopparhavet/templates/parts/actor/combat.html",
|
|
"systems/kopparhavet/templates/parts/actor/gear.html",
|
|
"systems/kopparhavet/templates/parts/actor/skills.html",
|
|
"systems/kopparhavet/templates/parts/actor/talent.html",
|
|
"systems/kopparhavet/templates/parts/shared/modifications.html",
|
|
];
|
|
return loadTemplates(templatePaths);
|
|
}
|
|
|
|
function normalize(data, defaultValue) {
|
|
if (data) {
|
|
return data.toLowerCase();
|
|
} else {
|
|
return defaultValue;
|
|
}
|
|
}
|
|
|
|
function registerHandlebarsHelpers() {
|
|
Handlebars.registerHelper("weaponCategory", function (category) {
|
|
category = normalize(category, "melee");
|
|
switch (category) {
|
|
case "melee":
|
|
return game.i18n.localize("WEAPON.MELEE");
|
|
case "ranged":
|
|
return game.i18n.localize("WEAPON.RANGED");
|
|
}
|
|
});
|
|
|
|
Handlebars.registerHelper("rollDifficulty", function (difficulty) {
|
|
difficulty = normalize(difficulty, "average");
|
|
switch (difficulty) {
|
|
case "simple":
|
|
return game.i18n.localize("DIFFICULTY.SIMPLE");
|
|
case "easy":
|
|
return game.i18n.localize("DIFFICULTY.EASY");
|
|
case "average":
|
|
return game.i18n.localize("DIFFICULTY.AVERAGE");
|
|
case "hard":
|
|
return game.i18n.localize("DIFFICULTY.HARD");
|
|
case "daunting":
|
|
return game.i18n.localize("DIFFICULTY.DAUNTING");
|
|
}
|
|
});
|
|
|
|
Handlebars.registerHelper("skillType", function (skillType) {
|
|
skillType = normalize(skillType, "base");
|
|
|
|
switch (skillType) {
|
|
case "base":
|
|
return game.i18n.localize("SKILL.BASE");
|
|
case "adventure":
|
|
return game.i18n.localize("SKILL.ADVENTURE");
|
|
case "combat":
|
|
return game.i18n.localize("SKILL.COMBAT");
|
|
}
|
|
});
|
|
|
|
Handlebars.registerHelper('plaintextToHTML', function(value) {
|
|
// strip tags, add <br/> tags
|
|
return new Handlebars.SafeString(value.replace(/(<([^>]+)>)/gi, "").replace(/(?:\r\n|\r|\n)/g, '<br/>'));
|
|
});
|
|
} |