2020-12-23 17:05:12 +01:00
|
|
|
import { DS4Actor } from "./actor/actor";
|
|
|
|
import { DS4Item } from "./item/item";
|
|
|
|
import { DS4ItemSheet } from "./item/item-sheet";
|
|
|
|
import { DS4 } from "./config";
|
2021-01-08 23:18:01 +01:00
|
|
|
import { DS4Check } from "./rolls/check";
|
2021-01-13 17:20:25 +01:00
|
|
|
import { DS4CharacterActorSheet } from "./actor/sheets/character-sheet";
|
|
|
|
import { DS4CreatureActorSheet } from "./actor/sheets/creature-sheet";
|
2021-01-09 23:14:31 +01:00
|
|
|
import { createCheckRoll } from "./rolls/check-factory";
|
2021-01-19 03:31:40 +01:00
|
|
|
import { registerSystemSettings } from "./settings";
|
2021-01-20 22:11:53 +01:00
|
|
|
import { migration } from "./migrations";
|
2021-02-20 22:41:33 +01:00
|
|
|
import handlebarsHelpers from "./handlebars-helpers";
|
2020-12-23 16:52:20 +01:00
|
|
|
|
2021-02-07 13:51:20 +01:00
|
|
|
Hooks.once("init", async () => {
|
2020-12-23 16:52:20 +01:00
|
|
|
console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`);
|
|
|
|
|
2021-02-05 02:56:13 +01:00
|
|
|
game.ds4 = {
|
2020-12-23 16:52:20 +01:00
|
|
|
DS4Actor,
|
|
|
|
DS4Item,
|
|
|
|
DS4,
|
2021-01-09 23:14:31 +01:00
|
|
|
createCheckRoll,
|
2021-01-20 22:11:53 +01:00
|
|
|
migration,
|
2020-12-23 16:52:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CONFIG.DS4 = DS4;
|
|
|
|
|
2021-02-05 02:52:55 +01:00
|
|
|
CONFIG.Actor.entityClass = DS4Actor;
|
|
|
|
CONFIG.Item.entityClass = DS4Item;
|
2020-12-23 16:52:20 +01:00
|
|
|
|
2021-01-26 20:47:28 +01:00
|
|
|
CONFIG.Actor.typeLabels = DS4.i18n.actorTypes;
|
|
|
|
CONFIG.Item.typeLabels = DS4.i18n.itemTypes;
|
2021-01-10 02:35:48 +01:00
|
|
|
|
2021-02-05 20:37:52 +01:00
|
|
|
CONFIG.Dice.types.push(DS4Check);
|
2021-02-05 03:47:54 +01:00
|
|
|
CONFIG.Dice.terms.s = DS4Check;
|
2021-01-06 19:15:56 +01:00
|
|
|
|
2021-01-19 03:31:40 +01:00
|
|
|
registerSystemSettings();
|
|
|
|
|
2020-12-23 16:52:20 +01:00
|
|
|
Actors.unregisterSheet("core", ActorSheet);
|
2021-01-13 17:20:25 +01:00
|
|
|
Actors.registerSheet("ds4", DS4CharacterActorSheet, { types: ["character"], makeDefault: true });
|
|
|
|
Actors.registerSheet("ds4", DS4CreatureActorSheet, { types: ["creature"], makeDefault: true });
|
2020-12-23 16:52:20 +01:00
|
|
|
Items.unregisterSheet("core", ItemSheet);
|
|
|
|
Items.registerSheet("ds4", DS4ItemSheet, { makeDefault: true });
|
|
|
|
|
2021-02-20 22:41:33 +01:00
|
|
|
await registerHandlebarsPartials();
|
|
|
|
registerHandlebarsHelpers();
|
2020-12-23 16:52:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
async function registerHandlebarsPartials() {
|
2020-12-28 20:38:02 +01:00
|
|
|
const templatePaths = [
|
2021-01-08 23:23:53 +01:00
|
|
|
"systems/ds4/templates/item/partials/sheet-header.hbs",
|
2020-12-28 20:38:02 +01:00
|
|
|
"systems/ds4/templates/item/partials/description.hbs",
|
2020-12-28 18:49:55 +01:00
|
|
|
"systems/ds4/templates/item/partials/details.hbs",
|
|
|
|
"systems/ds4/templates/item/partials/effects.hbs",
|
2020-12-28 18:58:01 +01:00
|
|
|
"systems/ds4/templates/item/partials/body.hbs",
|
2021-01-03 00:08:21 +01:00
|
|
|
"systems/ds4/templates/actor/partials/items-overview.hbs",
|
2021-01-13 17:23:06 +01:00
|
|
|
"systems/ds4/templates/actor/partials/talents-abilities-overview.hbs",
|
2021-01-09 23:39:35 +01:00
|
|
|
"systems/ds4/templates/actor/partials/spells-overview.hbs",
|
2021-01-06 16:29:02 +01:00
|
|
|
"systems/ds4/templates/actor/partials/overview-add-button.hbs",
|
|
|
|
"systems/ds4/templates/actor/partials/overview-control-buttons.hbs",
|
2021-01-04 00:55:44 +01:00
|
|
|
"systems/ds4/templates/actor/partials/attributes-traits.hbs",
|
2021-01-04 01:11:05 +01:00
|
|
|
"systems/ds4/templates/actor/partials/combat-values.hbs",
|
2021-01-03 20:54:45 +01:00
|
|
|
"systems/ds4/templates/actor/partials/profile.hbs",
|
2021-01-04 21:51:58 +01:00
|
|
|
"systems/ds4/templates/actor/partials/character-progression.hbs",
|
2021-02-07 11:51:36 +01:00
|
|
|
"systems/ds4/templates/actor/partials/special-creature-abilities-overview.hbs",
|
2021-01-18 19:59:25 +01:00
|
|
|
"systems/ds4/templates/actor/partials/character-inventory.hbs",
|
|
|
|
"systems/ds4/templates/actor/partials/creature-inventory.hbs",
|
2021-02-25 22:22:05 +01:00
|
|
|
"systems/ds4/templates/actor/partials/talent-rank-equation.hbs",
|
2020-12-28 20:38:02 +01:00
|
|
|
];
|
2020-12-23 16:52:20 +01:00
|
|
|
return loadTemplates(templatePaths);
|
|
|
|
}
|
|
|
|
|
2021-02-20 22:41:33 +01:00
|
|
|
function registerHandlebarsHelpers() {
|
|
|
|
Object.entries(handlebarsHelpers).forEach(([key, helper]) => Handlebars.registerHelper(key, helper));
|
|
|
|
}
|
|
|
|
|
2020-12-23 16:52:20 +01:00
|
|
|
/**
|
|
|
|
* This function runs after game data has been requested and loaded from the servers, so entities exist
|
|
|
|
*/
|
2021-02-07 13:51:20 +01:00
|
|
|
Hooks.once("setup", () => {
|
|
|
|
localizeAndSortConfigObjects();
|
2020-12-23 16:52:20 +01:00
|
|
|
});
|
2021-01-19 03:31:40 +01:00
|
|
|
|
2021-02-07 13:51:20 +01:00
|
|
|
Hooks.once("ready", () => {
|
2021-01-20 22:11:53 +01:00
|
|
|
migration.migrate();
|
2021-01-19 03:31:40 +01:00
|
|
|
});
|
2021-01-24 13:11:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) => {
|
2021-01-27 01:38:47 +01:00
|
|
|
Hooks.on(hookName, (app: Dialog, html: JQueryStatic) => {
|
2021-01-24 13:11:08 +01:00
|
|
|
$(html)
|
|
|
|
.find("input")
|
|
|
|
.on("focus", (ev: JQuery.FocusEvent<HTMLInputElement>) => {
|
|
|
|
ev.currentTarget.select();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-07 13:51:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = <T extends { [s: string]: string }>(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;
|
|
|
|
}
|