import { DS4Actor } from "./actor/actor"; import { DS4Item } from "./item/item"; import { DS4ItemSheet } from "./item/item-sheet"; import { DS4 } from "./config"; import { DS4Check } from "./rolls/check"; import { DS4CharacterActorSheet } from "./actor/sheets/character-sheet"; import { DS4CreatureActorSheet } from "./actor/sheets/creature-sheet"; import { createCheckRoll } from "./rolls/check-factory"; import { registerSystemSettings } from "./settings"; import { migration } from "./migrations"; import handlebarsHelpers from "./handlebars-helpers"; Hooks.once("init", async () => { console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`); game.ds4 = { DS4Actor, DS4Item, DS4, createCheckRoll, migration, }; CONFIG.DS4 = DS4; CONFIG.Actor.entityClass = DS4Actor; CONFIG.Item.entityClass = DS4Item; CONFIG.Actor.typeLabels = DS4.i18n.actorTypes; CONFIG.Item.typeLabels = DS4.i18n.itemTypes; CONFIG.Dice.types.push(DS4Check); CONFIG.Dice.terms.s = DS4Check; registerSystemSettings(); Actors.unregisterSheet("core", ActorSheet); Actors.registerSheet("ds4", DS4CharacterActorSheet, { types: ["character"], makeDefault: true }); Actors.registerSheet("ds4", DS4CreatureActorSheet, { types: ["creature"], makeDefault: true }); Items.unregisterSheet("core", ItemSheet); Items.registerSheet("ds4", DS4ItemSheet, { makeDefault: true }); await registerHandlebarsPartials(); registerHandlebarsHelpers(); }); async function registerHandlebarsPartials() { const templatePaths = [ "systems/ds4/templates/item/partials/sheet-header.hbs", "systems/ds4/templates/item/partials/description.hbs", "systems/ds4/templates/item/partials/details.hbs", "systems/ds4/templates/item/partials/effects.hbs", "systems/ds4/templates/item/partials/body.hbs", "systems/ds4/templates/actor/partials/items-overview.hbs", "systems/ds4/templates/actor/partials/talents-abilities-overview.hbs", "systems/ds4/templates/actor/partials/spells-overview.hbs", "systems/ds4/templates/actor/partials/overview-add-button.hbs", "systems/ds4/templates/actor/partials/overview-control-buttons.hbs", "systems/ds4/templates/actor/partials/attributes-traits.hbs", "systems/ds4/templates/actor/partials/combat-values.hbs", "systems/ds4/templates/actor/partials/profile.hbs", "systems/ds4/templates/actor/partials/character-progression.hbs", "systems/ds4/templates/actor/partials/special-creature-abilities-overview.hbs", "systems/ds4/templates/actor/partials/character-inventory.hbs", "systems/ds4/templates/actor/partials/creature-inventory.hbs", ]; return loadTemplates(templatePaths); } function registerHandlebarsHelpers() { Object.entries(handlebarsHelpers).forEach(([key, helper]) => Handlebars.registerHelper(key, helper)); } /** * This function runs after game data has been requested and loaded from the servers, so entities exist */ Hooks.once("setup", () => { localizeAndSortConfigObjects(); }); Hooks.once("ready", () => { migration.migrate(); }); /** * Select the text of input elements in given sheets via onfocus listener. * The hook names are of the form "render"+sheet_superclassname and are called within * the render() method of the foundry Application class. * Note: The render hooks of all classes in the class hierarchy are called, * so e.g. for a Dialog, both "renderDialog" and "renderApplication" are called * (in this order). */ ["renderApplication", "renderActorSheet", "renderItemSheet"].forEach((hookName: string) => { Hooks.on(hookName, (app: Dialog, html: JQueryStatic) => { $(html) .find("input") .on("focus", (ev: JQuery.FocusEvent) => { ev.currentTarget.select(); }); }); }); /** * Localizes all objects in {@link DS4.i18n} and sorts them unless they are explicitly excluded. */ function localizeAndSortConfigObjects() { const noSort = ["attributes", "traits", "combatValues", "creatureSizeCategories"]; const localizeObject = (obj: T, sort = true): T => { const localized = Object.entries(obj).map(([key, value]) => { return [key, game.i18n.localize(value)]; }); if (sort) localized.sort((a, b) => a[1].localeCompare(b[1])); return Object.fromEntries(localized); }; DS4.i18n = Object.fromEntries( Object.entries(DS4.i18n).map(([key, value]) => { return [key, localizeObject(value, !noSort.includes(key))]; }), ) as typeof DS4.i18n; }