Activate strict mode
This commit is contained in:
parent
3c47b06f71
commit
09b4117306
9 changed files with 78 additions and 63 deletions
|
@ -221,7 +221,7 @@ export class DS4ActorSheet extends ActorSheet<DS4Actor> {
|
||||||
): Promise<boolean | undefined | ActorSheet.OwnedItemData<DS4Actor>> {
|
): Promise<boolean | undefined | ActorSheet.OwnedItemData<DS4Actor>> {
|
||||||
const item = ((await Item.fromDropData(data)) as unknown) as DS4Item;
|
const item = ((await Item.fromDropData(data)) as unknown) as DS4Item;
|
||||||
if (item && !this.actor.canOwnItemType(item.data.type)) {
|
if (item && !this.actor.canOwnItemType(item.data.type)) {
|
||||||
ui.notifications.warn(
|
ui.notifications?.warn(
|
||||||
game.i18n.format("DS4.WarningActorCannotOwnItem", {
|
game.i18n.format("DS4.WarningActorCannotOwnItem", {
|
||||||
actorName: this.actor.name,
|
actorName: this.actor.name,
|
||||||
actorType: this.actor.data.type,
|
actorType: this.actor.data.type,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { createCheckRoll } from "./rolls/check-factory";
|
||||||
import { registerSystemSettings } from "./settings";
|
import { registerSystemSettings } from "./settings";
|
||||||
import { migration } from "./migrations";
|
import { migration } from "./migrations";
|
||||||
|
|
||||||
Hooks.once("init", async function () {
|
Hooks.once("init", async () => {
|
||||||
console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`);
|
console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`);
|
||||||
|
|
||||||
game.ds4 = {
|
game.ds4 = {
|
||||||
|
@ -68,23 +68,11 @@ async function registerHandlebarsPartials() {
|
||||||
/**
|
/**
|
||||||
* This function runs after game data has been requested and loaded from the servers, so entities exist
|
* This function runs after game data has been requested and loaded from the servers, so entities exist
|
||||||
*/
|
*/
|
||||||
Hooks.once("setup", function () {
|
Hooks.once("setup", () => {
|
||||||
const noSort = ["attributes", "traits", "combatValues", "creatureSizeCategories"];
|
localizeAndSortConfigObjects();
|
||||||
|
|
||||||
// Localize and sort CONFIG objects
|
|
||||||
for (const o of Object.keys(DS4.i18n)) {
|
|
||||||
const localized = Object.entries(DS4.i18n[o]).map((e) => {
|
|
||||||
return [e[0], game.i18n.localize(e[1] as string)];
|
|
||||||
});
|
|
||||||
if (!noSort.includes(o)) localized.sort((a, b) => a[1].localeCompare(b[1]));
|
|
||||||
DS4.i18n[o] = localized.reduce((obj, e) => {
|
|
||||||
obj[e[0]] = e[1];
|
|
||||||
return obj;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Hooks.once("ready", function () {
|
Hooks.once("ready", () => {
|
||||||
migration.migrate();
|
migration.migrate();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -105,3 +93,24 @@ Hooks.once("ready", function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ export class DS4ItemSheet extends ItemSheet<DS4Item> {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (this.item.isOwned) {
|
if (this.item.isOwned) {
|
||||||
return ui.notifications.warn(game.i18n.localize("DS4.WarningManageActiveEffectOnOwnedItem"));
|
return ui.notifications?.warn(game.i18n.localize("DS4.WarningManageActiveEffectOnOwnedItem"));
|
||||||
}
|
}
|
||||||
const a = event.currentTarget;
|
const a = event.currentTarget;
|
||||||
const li = $(a).parents(".effect");
|
const li = $(a).parents(".effect");
|
||||||
|
@ -93,7 +93,7 @@ export class DS4ItemSheet extends ItemSheet<DS4Item> {
|
||||||
return this._createActiveEffect();
|
return this._createActiveEffect();
|
||||||
case "edit":
|
case "edit":
|
||||||
const effect = this.item.effects.get(li.data("effectId"));
|
const effect = this.item.effects.get(li.data("effectId"));
|
||||||
return effect.sheet.render(true);
|
return effect?.sheet.render(true);
|
||||||
case "delete": {
|
case "delete": {
|
||||||
return this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId"));
|
return this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { migrate as migrate001 } from "./migrations/001";
|
import { migrate as migrate001 } from "./migrations/001";
|
||||||
|
|
||||||
async function migrate(): Promise<void> {
|
async function migrate(): Promise<void> {
|
||||||
if (!game.user.isGM) {
|
if (!game.user?.isGM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +18,14 @@ async function migrate(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion: number): Promise<void> {
|
async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion: number): Promise<void> {
|
||||||
if (!game.user.isGM) {
|
if (!game.user?.isGM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const migrationsToExecute = migrations.slice(oldMigrationVersion, targetMigrationVersion);
|
const migrationsToExecute = migrations.slice(oldMigrationVersion, targetMigrationVersion);
|
||||||
|
|
||||||
if (migrationsToExecute.length > 0) {
|
if (migrationsToExecute.length > 0) {
|
||||||
ui.notifications.info(
|
ui.notifications?.info(
|
||||||
game.i18n.format("DS4.InfoSystemUpdateStart", {
|
game.i18n.format("DS4.InfoSystemUpdateStart", {
|
||||||
currentVersion: oldMigrationVersion,
|
currentVersion: oldMigrationVersion,
|
||||||
targetVersion: targetMigrationVersion,
|
targetVersion: targetMigrationVersion,
|
||||||
|
@ -40,7 +40,7 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
|
||||||
await migration();
|
await migration();
|
||||||
game.settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
game.settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ui.notifications.error(
|
ui.notifications?.error(
|
||||||
game.i18n.format("DS4.ErrorDuringMigration", {
|
game.i18n.format("DS4.ErrorDuringMigration", {
|
||||||
currentVersion: oldMigrationVersion,
|
currentVersion: oldMigrationVersion,
|
||||||
targetVersion: targetMigrationVersion,
|
targetVersion: targetMigrationVersion,
|
||||||
|
@ -54,7 +54,7 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.notifications.info(
|
ui.notifications?.info(
|
||||||
game.i18n.format("DS4.InfoSystemUpdateCompleted", {
|
game.i18n.format("DS4.InfoSystemUpdateCompleted", {
|
||||||
currentVersion: oldMigrationVersion,
|
currentVersion: oldMigrationVersion,
|
||||||
targetVersion: targetMigrationVersion,
|
targetVersion: targetMigrationVersion,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export async function migrate(): Promise<void> {
|
export async function migrate(): Promise<void> {
|
||||||
for (const a of game.actors.entities) {
|
for (const a of game.actors?.entities ?? []) {
|
||||||
const updateData = getActorUpdateData();
|
const updateData = getActorUpdateData();
|
||||||
console.log(`Migrating actor ${a.name}`);
|
console.log(`Migrating actor ${a.name}`);
|
||||||
await a.update(updateData, { enforceTypes: false });
|
await a.update(updateData, { enforceTypes: false });
|
||||||
|
@ -18,7 +18,7 @@ function getActorUpdateData(): Record<string, unknown> {
|
||||||
"rangedAttack",
|
"rangedAttack",
|
||||||
"spellcasting",
|
"spellcasting",
|
||||||
"targetedSpellcasting",
|
"targetedSpellcasting",
|
||||||
].reduce((acc, curr) => {
|
].reduce((acc: Partial<Record<string, { "-=base": null }>>, curr) => {
|
||||||
acc[curr] = { "-=base": null };
|
acc[curr] = { "-=base": null };
|
||||||
return acc;
|
return acc;
|
||||||
}, {}),
|
}, {}),
|
||||||
|
|
|
@ -131,7 +131,8 @@ async function askGmModifier(
|
||||||
const renderedHtml = await renderTemplate(usedTemplate, templateData);
|
const renderedHtml = await renderTemplate(usedTemplate, templateData);
|
||||||
|
|
||||||
const dialogPromise = new Promise<HTMLFormElement>((resolve) => {
|
const dialogPromise = new Promise<HTMLFormElement>((resolve) => {
|
||||||
new Dialog({
|
new Dialog(
|
||||||
|
{
|
||||||
title: usedTitle,
|
title: usedTitle,
|
||||||
content: renderedHtml,
|
content: renderedHtml,
|
||||||
buttons: {
|
buttons: {
|
||||||
|
@ -148,6 +149,9 @@ async function askGmModifier(
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const innerForm = html[0].querySelector("form");
|
const innerForm = html[0].querySelector("form");
|
||||||
|
if (!innerForm) {
|
||||||
|
throw new Error(); // TODO: localize
|
||||||
|
}
|
||||||
resolve(innerForm);
|
resolve(innerForm);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -158,7 +162,9 @@ async function askGmModifier(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: "ok",
|
default: "ok",
|
||||||
}).render(true);
|
},
|
||||||
|
{ jQuery: true },
|
||||||
|
).render(true);
|
||||||
});
|
});
|
||||||
const dialogForm = await dialogPromise;
|
const dialogForm = await dialogPromise;
|
||||||
return parseDialogFormData(dialogForm);
|
return parseDialogFormData(dialogForm);
|
||||||
|
|
|
@ -56,8 +56,8 @@ export class DS4Check extends DiceTerm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
success = null;
|
success: boolean | null = null;
|
||||||
failure = null;
|
failure: boolean | null = null;
|
||||||
targetValue = DS4Check.DEFAULT_TARGET_VALUE;
|
targetValue = DS4Check.DEFAULT_TARGET_VALUE;
|
||||||
minCritFailure = DS4Check.DEFAULT_MIN_CRIT_FAILURE;
|
minCritFailure = DS4Check.DEFAULT_MIN_CRIT_FAILURE;
|
||||||
maxCritSuccess = DS4Check.DEFAULT_MAX_CRIT_SUCCESS;
|
maxCritSuccess = DS4Check.DEFAULT_MAX_CRIT_SUCCESS;
|
||||||
|
@ -94,15 +94,15 @@ export class DS4Check extends DiceTerm {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Term Modifiers */
|
/** Term Modifiers */
|
||||||
noop(): this {
|
noop(): void {
|
||||||
return this;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DS4 only allows recursive explosions
|
// DS4 only allows recursive explosions
|
||||||
explode(modifier: string): this {
|
explode(modifier: string): void {
|
||||||
const rgx = /[xX]/;
|
const rgx = /[xX]/;
|
||||||
const match = modifier.match(rgx);
|
const match = modifier.match(rgx);
|
||||||
if (!match) return this;
|
if (!match) return;
|
||||||
|
|
||||||
this.results = (this.results as Array<RollResult>)
|
this.results = (this.results as Array<RollResult>)
|
||||||
.map((r) => {
|
.map((r) => {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { calculateRollResult, isDiceSwapNecessary, isSlayingDiceRepetition, sepa
|
||||||
export function ds4roll(
|
export function ds4roll(
|
||||||
checkTargetValue: number,
|
checkTargetValue: number,
|
||||||
rollOptions: Partial<RollOptions> = {},
|
rollOptions: Partial<RollOptions> = {},
|
||||||
dice: Array<number> = null,
|
dice: Array<number> = [],
|
||||||
): RollResult {
|
): RollResult {
|
||||||
if (checkTargetValue <= 20) {
|
if (checkTargetValue <= 20) {
|
||||||
return rollCheckSingleDie(checkTargetValue, rollOptions, dice);
|
return rollCheckSingleDie(checkTargetValue, rollOptions, dice);
|
||||||
|
@ -36,11 +36,11 @@ export function ds4roll(
|
||||||
export function rollCheckSingleDie(
|
export function rollCheckSingleDie(
|
||||||
checkTargetValue: number,
|
checkTargetValue: number,
|
||||||
rollOptions: Partial<RollOptions>,
|
rollOptions: Partial<RollOptions>,
|
||||||
dice: Array<number> = null,
|
dice: Array<number> = [],
|
||||||
): RollResult {
|
): RollResult {
|
||||||
const usedOptions = new DefaultRollOptions().mergeWith(rollOptions);
|
const usedOptions = new DefaultRollOptions().mergeWith(rollOptions);
|
||||||
|
|
||||||
if (dice?.length != 1) {
|
if (dice.length != 1) {
|
||||||
dice = [new DS4RollProvider().getNextRoll()];
|
dice = [new DS4RollProvider().getNextRoll()];
|
||||||
}
|
}
|
||||||
const usedDice = dice;
|
const usedDice = dice;
|
||||||
|
@ -75,13 +75,13 @@ export function rollCheckSingleDie(
|
||||||
export function rollCheckMultipleDice(
|
export function rollCheckMultipleDice(
|
||||||
targetValue: number,
|
targetValue: number,
|
||||||
rollOptions: Partial<RollOptions>,
|
rollOptions: Partial<RollOptions>,
|
||||||
dice: Array<number> = null,
|
dice: Array<number> = [],
|
||||||
): RollResult {
|
): RollResult {
|
||||||
const usedOptions = new DefaultRollOptions().mergeWith(rollOptions);
|
const usedOptions = new DefaultRollOptions().mergeWith(rollOptions);
|
||||||
const remainderTargetValue = targetValue % 20;
|
const remainderTargetValue = targetValue % 20;
|
||||||
const numberOfDice = Math.ceil(targetValue / 20);
|
const numberOfDice = Math.ceil(targetValue / 20);
|
||||||
|
|
||||||
if (!dice || dice.length != numberOfDice) {
|
if (dice.length != numberOfDice) {
|
||||||
dice = new DS4RollProvider().getNextRolls(numberOfDice);
|
dice = new DS4RollProvider().getNextRolls(numberOfDice);
|
||||||
}
|
}
|
||||||
const usedDice = dice;
|
const usedDice = dice;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"strict": false
|
"strict": true
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue