refactor: use noImplicitOverride option

This commit is contained in:
Johannes Loher 2022-05-29 17:47:27 +02:00
parent c9a3818571
commit 12bc76ba54
18 changed files with 45 additions and 85 deletions

View file

@ -59,8 +59,7 @@ export class DS4ActiveEffect extends ActiveEffect {
return this.originatingItem?.activeEffectFactor ?? 1;
}
/** @override */
apply(actor: DS4Actor, change: foundry.data.ActiveEffectData["changes"][number]): unknown {
override apply(actor: DS4Actor, change: foundry.data.ActiveEffectData["changes"][number]): unknown {
change.value = Roll.replaceFormulaData(change.value, actor.data);
try {
change.value = Roll.safeEval(change.value).toString();

View file

@ -21,8 +21,7 @@ import type { DS4Item } from "../item/item";
* The base sheet class for all {@link DS4Actor}s.
*/
export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetData> {
/** @override */
static get defaultOptions(): ActorSheet.Options {
static override get defaultOptions(): ActorSheet.Options {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["sheet", "ds4-actor-sheet"],
height: 625,
@ -37,14 +36,12 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
});
}
/** @override */
get template(): string {
override get template(): string {
const basePath = "systems/ds4/templates/sheets/actor";
return `${basePath}/${this.actor.data.type}-sheet.hbs`;
}
/** @override */
async getData(): Promise<DS4ActorSheetData> {
override async getData(): Promise<DS4ActorSheetData> {
const itemsByType = Object.fromEntries(
Object.entries(this.actor.itemTypes).map(([itemType, items]) => {
return [itemType, items.map((item) => item.data).sort((a, b) => (a.sort || 0) - (b.sort || 0))];
@ -96,8 +93,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
}`;
}
/** @override */
activateListeners(html: JQuery): void {
override activateListeners(html: JQuery): void {
super.activateListeners(html);
if (!this.options.editable) return;
@ -327,8 +323,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
this.actor.rollCheck(check).catch((e) => notifications.error(e, { log: true }));
}
/** @override */
_onDragStart(event: DragEvent): void {
override _onDragStart(event: DragEvent): void {
const target = event.currentTarget as HTMLElement;
if (!(target instanceof HTMLElement)) return super._onDragStart(event);
@ -391,8 +386,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
this.actor.updateEmbeddedDocuments("Item", updates);
}
/** @override */
protected async _onDropItem(event: DragEvent, data: ActorSheet.DropData.Item): Promise<unknown> {
protected override async _onDropItem(event: DragEvent, data: ActorSheet.DropData.Item): Promise<unknown> {
const item = await Item.fromDropData(data);
if (item && !this.actor.canOwnItemType(item.data.type)) {
notifications.warn(

View file

@ -25,8 +25,7 @@ declare global {
* The Actor class for DS4
*/
export class DS4Actor extends Actor {
/** @override */
prepareData(): void {
override prepareData(): void {
this.data.reset();
this.prepareBaseData();
this.prepareEmbeddedDocuments();
@ -36,8 +35,7 @@ export class DS4Actor extends Actor {
this.prepareFinalDerivedData();
}
/** @override */
prepareBaseData(): void {
override prepareBaseData(): void {
const data = this.data;
data.data.rolling = {
@ -57,11 +55,10 @@ export class DS4Actor extends Actor {
}
/**
* @override
* We override this with an empty implementation because we have our own custom way of applying
* {@link ActiveEffect}s and {@link Actor#prepareEmbeddedDocuments} calls this.
*/
applyActiveEffects(): void {
override applyActiveEffects(): void {
return;
}
@ -117,9 +114,8 @@ export class DS4Actor extends Actor {
/**
* Apply transformations to the Actor data after effects have been applied to the base data.
* @override
*/
prepareDerivedData(): void {
override prepareDerivedData(): void {
this.prepareCombatValues();
this.prepareChecks();
}
@ -281,9 +277,8 @@ export class DS4Actor extends Actor {
/**
* Handle how changes to a Token attribute bar are applied to the Actor.
* This only differs from the base implementation by also allowing negative values.
* @override
*/
async modifyTokenAttribute(
override async modifyTokenAttribute(
attribute: string,
value: number,
isDelta = false,

View file

@ -8,8 +8,7 @@ import { DS4ActorSheet } from "../actor-sheet";
* The Sheet class for DS4 Character Actors
*/
export class DS4CharacterActorSheet extends DS4ActorSheet {
/** @override */
static get defaultOptions(): ActorSheet.Options {
static override get defaultOptions(): ActorSheet.Options {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["sheet", "ds4-actor-sheet", "ds4-character-sheet"],
});

View file

@ -7,19 +7,16 @@ import { DS4Actor } from "../actor";
import type { ItemType } from "../../item/item-data-source";
export class DS4Character extends DS4Actor {
/** @override */
prepareFinalDerivedData(): void {
override prepareFinalDerivedData(): void {
super.prepareFinalDerivedData();
this.data.data.slayerPoints.max = 3;
}
/** @override */
get finalDerivedDataProperties(): string[] {
override get finalDerivedDataProperties(): string[] {
return [...super.finalDerivedDataProperties, "data.slayerPoints.max"];
}
/** @override */
get ownableItemTypes(): Array<ItemType> {
override get ownableItemTypes(): Array<ItemType> {
return [...super.ownableItemTypes, "talent", "racialAbility", "language", "alphabet"];
}
}

View file

@ -8,8 +8,7 @@ import { DS4ActorSheet } from "../actor-sheet";
* The Sheet class for DS4 Creature Actors
*/
export class DS4CreatureActorSheet extends DS4ActorSheet {
/** @override */
static get defaultOptions(): ActorSheet.Options {
static override get defaultOptions(): ActorSheet.Options {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["sheet", "ds4-actor-sheet", "ds4-creature-sheet"],
});

View file

@ -7,8 +7,7 @@ import { DS4Actor } from "../actor";
import type { ItemType } from "../../item/item-data-source";
export class DS4Creature extends DS4Actor {
/** @override */
get ownableItemTypes(): Array<ItemType> {
override get ownableItemTypes(): Array<ItemType> {
return [...super.ownableItemTypes, "specialCreatureAbility"];
}
}

View file

@ -6,8 +6,7 @@
* A simple extension to the {@link Dialog} class that allows attaching additional listeners.
*/
export class DialogWithListeners extends Dialog<DialogWithListenersOptions> {
/** @inheritdoc */
activateListeners(html: JQuery): void {
override activateListeners(html: JQuery): void {
super.activateListeners(html);
if (this.options.activateAdditionalListeners !== undefined) {
this.options.activateAdditionalListeners(html, this);

View file

@ -15,8 +15,7 @@ declare global {
}
export class DS4ChatMessage extends ChatMessage {
/** @override */
prepareData(): void {
override prepareData(): void {
super.prepareData();
if (this.data.flavor) {
const game = getGame();

View file

@ -15,8 +15,7 @@ import { isDS4ItemDataTypePhysical } from "./item-data-source-base";
* The Sheet class for DS4 Items
*/
export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData> {
/** @override */
static get defaultOptions(): ItemSheet.Options {
static override get defaultOptions(): ItemSheet.Options {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["sheet", "ds4-item-sheet"],
height: 400,
@ -26,14 +25,12 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
});
}
/** @override */
get template(): string {
override get template(): string {
const basePath = "systems/ds4/templates/sheets/item";
return `${basePath}/${this.item.data.type}-sheet.hbs`;
}
/** @override */
async getData(): Promise<DS4ItemSheetData> {
override async getData(): Promise<DS4ItemSheetData> {
const data = {
...(await super.getData()),
config: DS4,
@ -44,8 +41,9 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
return data;
}
/** @override */
setPosition(options: Partial<Application.Position> = {}): (Application.Position & { height: number }) | void {
override setPosition(
options: Partial<Application.Position> = {},
): (Application.Position & { height: number }) | void {
const position = super.setPosition(options);
if (position) {
const sheetBody = this.element.find(".sheet-body");
@ -56,8 +54,7 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
return position;
}
/** @override */
activateListeners(html: JQuery): void {
override activateListeners(html: JQuery): void {
super.activateListeners(html);
if (!this.options.editable) return;

View file

@ -24,13 +24,7 @@ declare global {
* The Item class for DS4
*/
export class DS4Item extends Item {
/** @override */
prepareData(): void {
super.prepareData();
}
/** @override */
prepareDerivedData(): void {
override prepareDerivedData(): void {
this.data.data.rollable = false;
}

View file

@ -9,14 +9,12 @@ import { DS4Item } from "../item";
import { calculateSpellPrice } from "./calculate-spell-price";
export class DS4Spell extends DS4Item {
/** @override */
prepareDerivedData(): void {
override prepareDerivedData(): void {
this.data.data.rollable = this.data.data.equipped;
this.data.data.price = calculateSpellPrice(this.data.data);
}
/** @override */
async roll(options: { speaker?: { token?: TokenDocument; alias?: string } } = {}): Promise<void> {
override async roll(options: { speaker?: { token?: TokenDocument; alias?: string } } = {}): Promise<void> {
const game = getGame();
if (!this.data.data.equipped) {

View file

@ -5,15 +5,13 @@
import { DS4Item } from "../item";
export class DS4Talent extends DS4Item {
/** @override */
prepareDerivedData(): void {
override prepareDerivedData(): void {
super.prepareDerivedData();
const data = this.data.data;
data.rank.total = data.rank.base + data.rank.mod;
}
/** @override */
get activeEffectFactor(): number | undefined {
override get activeEffectFactor(): number | undefined {
return this.data.data.rank.total;
}
}

View file

@ -11,13 +11,11 @@ import { DS4Item } from "../item";
import type { AttackType } from "./weapon-data-source";
export class DS4Weapon extends DS4Item {
/** @override */
prepareDerivedData(): void {
override prepareDerivedData(): void {
this.data.data.rollable = this.data.data.equipped;
}
/** @override */
async roll(options: { speaker?: { token?: TokenDocument; alias?: string } } = {}): Promise<void> {
override async roll(options: { speaker?: { token?: TokenDocument; alias?: string } } = {}): Promise<void> {
const game = getGame();
if (!this.data.data.equipped) {
return notifications.warn(

View file

@ -72,26 +72,22 @@ export class DS4Check extends DiceTerm {
minimumFumbleResult = DS4Check.DEFAULT_MINIMUM_FUMBLE_RESULT;
maximumCoupResult = DS4Check.DEFAULT_MAXIMUM_COUP_RESULT;
/** @override */
get expression(): string {
override get expression(): string {
return `ds${this.modifiers.join("")}`;
}
/** @override */
get total(): string | number | null | undefined {
override get total(): string | number | null | undefined {
if (this.fumble) return 0;
return super.total;
}
/** @override */
_evaluateSync({ minimize = false, maximize = false } = {}): this {
override _evaluateSync({ minimize = false, maximize = false } = {}): this {
super._evaluateSync({ minimize, maximize });
this.evaluateResults();
return this;
}
/** @override */
roll({ minimize = false, maximize = false } = {}): DiceTerm.Result {
override roll({ minimize = false, maximize = false } = {}): DiceTerm.Result {
// Swap minimize / maximize because in DS4, the best possible roll is a 1 and the worst possible roll is a 20
return super.roll({ minimize: maximize, maximize: minimize });
}
@ -109,20 +105,19 @@ export class DS4Check extends DiceTerm {
}
/**
* @override
* @remarks "min" and "max" are filtered out because they are irrelevant for
* {@link DS4Check}s and only result in some dice rolls being highlighted
* incorrectly.
*/
getResultCSS(result: DiceTerm.Result): (string | null)[] {
override getResultCSS(result: DiceTerm.Result): (string | null)[] {
return super.getResultCSS(result).filter((cssClass) => cssClass !== "min" && cssClass !== "max");
}
static readonly DEFAULT_CHECK_TARGET_NUMBER = 10;
static readonly DEFAULT_MAXIMUM_COUP_RESULT = 1;
static readonly DEFAULT_MINIMUM_FUMBLE_RESULT = 20;
static DENOMINATION = "s";
static MODIFIERS = {
static override DENOMINATION = "s";
static override MODIFIERS = {
c: (): void => undefined, // Modifier is consumed in constructor for maximumCoupResult / minimumFumbleResult
v: (): void => undefined, // Modifier is consumed in constructor for checkTargetNumber
n: (): void => undefined, // Modifier is consumed in constructor for canFumble

View file

@ -6,15 +6,14 @@ import { getGame } from "../helpers";
import { DS4Check } from "./check";
export class DS4Roll<D extends Record<string, unknown> = Record<string, unknown>> extends Roll<D> {
static CHAT_TEMPLATE = "systems/ds4/templates/dice/roll.hbs";
static override CHAT_TEMPLATE = "systems/ds4/templates/dice/roll.hbs";
/**
* @override
* @remarks
* This only differs from {@link Roll#render} in that it provides `isCoup` and `isFumble` properties to the roll
* template if the first dice term is a ds4 check.
*/
async render({
override async render({
flavor,
template = (this.constructor as typeof DS4Roll).CHAT_TEMPLATE,
isPrivate = false,

View file

@ -21,7 +21,7 @@ function getFallbackData() {
}
export class DS4TokenDocument extends TokenDocument {
static getTrackedAttributes(data?: foundry.data.ActorData["data"], _path: string[] = []) {
static override getTrackedAttributes(data?: foundry.data.ActorData["data"], _path: string[] = []) {
if (!data) {
data = getFallbackData();
}

View file

@ -8,6 +8,7 @@
"forceConsistentCasingInFileNames": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"resolveJsonModule": true,
"importsNotUsedAsValues": "error"
},