fix issues
This commit is contained in:
parent
835efb31b9
commit
6a406db60a
23 changed files with 295 additions and 118 deletions
|
@ -2,38 +2,6 @@
|
|||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
type CSSOMString = string;
|
||||
type FontFaceLoadStatus = "unloaded" | "loading" | "loaded" | "error";
|
||||
type FontFaceSetStatus = "loading" | "loaded";
|
||||
|
||||
interface FontFace {
|
||||
family: CSSOMString;
|
||||
style: CSSOMString;
|
||||
weight: CSSOMString;
|
||||
stretch: CSSOMString;
|
||||
unicodeRange: CSSOMString;
|
||||
variant: CSSOMString;
|
||||
featureSettings: CSSOMString;
|
||||
variationSettings: CSSOMString;
|
||||
display: CSSOMString;
|
||||
readonly status: FontFaceLoadStatus;
|
||||
readonly loaded: Promise<FontFace>;
|
||||
load(): Promise<FontFace>;
|
||||
}
|
||||
|
||||
interface FontFaceSet {
|
||||
readonly status: FontFaceSetStatus;
|
||||
readonly ready: Promise<FontFaceSet>;
|
||||
check(font: string, text?: string): boolean;
|
||||
load(font: string, text?: string): Promise<FontFace[]>;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Document {
|
||||
fonts: FontFaceSet;
|
||||
}
|
||||
}
|
||||
|
||||
const fonts = ["Lora", "Wood Stamp"];
|
||||
|
||||
export async function preloadFonts(): Promise<FontFace[][]> {
|
||||
|
|
|
@ -21,11 +21,11 @@ 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]) => {
|
||||
const localized = Object.entries(obj).map(([key, value]): [string, string] => {
|
||||
return [key, getGame().i18n.localize(value)];
|
||||
});
|
||||
if (sort) localized.sort((a, b) => a[1].localeCompare(b[1]));
|
||||
return Object.fromEntries(localized);
|
||||
return Object.fromEntries(localized) as T;
|
||||
};
|
||||
|
||||
DS4.i18n = Object.fromEntries(
|
||||
|
|
|
@ -58,8 +58,7 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
|
|||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
err.message = `Failed ds4 system migration: ${err.message}`;
|
||||
logger.error(err);
|
||||
logger.error("Failed ds4 system migration:", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ export async function migrateItems(getItemUpdateData: ItemUpdateDataGetter): Pro
|
|||
await item.update(updateData), { enforceTypes: false };
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Item document ${item.name} (${item.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
logger.error(`Error during migration of Item document ${item.name} (${item.id}), continuing anyways.`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +38,10 @@ export async function migrateActors(getActorUpdateData: ActorUpdateDataGetter):
|
|||
await actor.update(updateData);
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Actor document ${actor.name} (${actor.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
logger.error(
|
||||
`Error during migration of Actor document ${actor.name} (${actor.id}), continuing anyways.`,
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +61,10 @@ export async function migrateScenes(getSceneUpdateData: SceneUpdateDataGetter):
|
|||
);
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Scene document ${scene.name} (${scene.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
logger.error(
|
||||
`Error during migration of Scene document ${scene.name} (${scene.id}), continuing anyways.`,
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,8 +173,10 @@ export function getCompendiumMigrator(
|
|||
));
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of document ${doc.name} (${doc.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||
logger.error(err);
|
||||
logger.error(
|
||||
`Error during migration of document ${doc.name} (${doc.id}) in compendium ${compendium.collection}, continuing anyways.`,
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ function assignSubChecksToDice(
|
|||
|
||||
function findIndexOfSmallestNonCoup(dice: number[], maximumCoupResult: number): number {
|
||||
return dice
|
||||
.map((die, index) => [die, index])
|
||||
.map((die, index): [number, number] => [die, index])
|
||||
.filter((indexedDie) => indexedDie[0] > maximumCoupResult)
|
||||
.reduce(
|
||||
(smallestIndexedDie, indexedDie) =>
|
||||
|
@ -77,14 +77,25 @@ function findIndexOfSmallestNonCoup(dice: number[], maximumCoupResult: number):
|
|||
function shouldUseCoupForLastSubCheck(
|
||||
indexOfSmallestNonCoup: number,
|
||||
indexOfFirstCoup: number,
|
||||
dice: number[],
|
||||
dice: readonly number[],
|
||||
checkTargetNumberForLastSubCheck: number,
|
||||
) {
|
||||
if (indexOfFirstCoup !== -1 && indexOfSmallestNonCoup === -1) {
|
||||
return true;
|
||||
}
|
||||
const smallestNonCoup = dice[indexOfSmallestNonCoup];
|
||||
if (
|
||||
!Number.isInteger(indexOfFirstCoup) ||
|
||||
indexOfFirstCoup < -1 ||
|
||||
!Number.isInteger(indexOfSmallestNonCoup) ||
|
||||
smallestNonCoup === undefined
|
||||
) {
|
||||
throw new Error("Received an invalid value for the parameter indexOfSmallestNonCoup or indexOfFirstCoup,");
|
||||
}
|
||||
return (
|
||||
indexOfFirstCoup !== -1 &&
|
||||
(indexOfSmallestNonCoup === -1 ||
|
||||
(dice[indexOfSmallestNonCoup] > checkTargetNumberForLastSubCheck &&
|
||||
dice[indexOfSmallestNonCoup] + checkTargetNumberForLastSubCheck > 20))
|
||||
smallestNonCoup > checkTargetNumberForLastSubCheck &&
|
||||
smallestNonCoup + checkTargetNumberForLastSubCheck > 20
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ async function askGmModifier(
|
|||
}),
|
||||
);
|
||||
} else {
|
||||
const innerForm = html[0].querySelector("form");
|
||||
const innerForm = html[0]?.querySelector("form");
|
||||
if (!innerForm) {
|
||||
throw new Error(
|
||||
getGame().i18n.format("DS4.ErrorCouldNotFindHtmlElement", { htmlElement: "form" }),
|
||||
|
|
|
@ -104,8 +104,8 @@ export class DS4Check extends DiceTerm {
|
|||
canFumble: this.canFumble,
|
||||
});
|
||||
this.results = results;
|
||||
this.coup = results[0].success ?? false;
|
||||
this.fumble = results[0].failure ?? false;
|
||||
this.coup = results[0]?.success ?? false;
|
||||
this.fumble = results[0]?.failure ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue