switch to foundry-vtt-types
This commit is contained in:
parent
6e10d4b093
commit
62cc5a0e7c
13 changed files with 713 additions and 84 deletions
|
@ -1,6 +1,9 @@
|
|||
import { ModifiableData, ResourceData, UsableResource } from "../common/common-data";
|
||||
import { DS4ItemData } from "../item/item-data";
|
||||
|
||||
export type DS4ActorDataType = DS4ActorDataCharacter | DS4ActorDataCreature;
|
||||
export type DS4ActorData = Actor.Data<DS4ActorDataType, DS4ItemData>;
|
||||
|
||||
type DS4ActorDataType = DS4ActorDataCharacter | DS4ActorDataCreature;
|
||||
|
||||
interface DS4ActorDataBase {
|
||||
attributes: DS4ActorDataAttributes;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { ModifiableData } from "../common/common-data";
|
||||
import { DS4Item } from "../item/item";
|
||||
import { DS4Armor, DS4ItemDataType, DS4Shield, ItemType } from "../item/item-data";
|
||||
import { DS4ActorDataType } from "./actor-data";
|
||||
import { DS4Armor, DS4Shield, ItemType } from "../item/item-data";
|
||||
import { DS4ActorData } from "./actor-data";
|
||||
|
||||
export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item> {
|
||||
export class DS4Actor extends Actor<DS4Item, DS4ActorData> {
|
||||
/** @override */
|
||||
prepareDerivedData(): void {
|
||||
const data = this.data;
|
||||
|
@ -96,7 +96,7 @@ export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item>
|
|||
* This only differs from the base implementation by also allowing negative values.
|
||||
* @override
|
||||
*/
|
||||
async modifyTokenAttribute(attribute: string, value: number, isDelta = false, isBar = true): Promise<DS4Actor> {
|
||||
async modifyTokenAttribute(attribute: string, value: number, isDelta = false, isBar = true): Promise<this> {
|
||||
const current = getProperty(this.data.data, attribute);
|
||||
|
||||
// Determine the updates to make to the actor data
|
||||
|
|
|
@ -1,20 +1,39 @@
|
|||
import { DS4Item } from "../../item/item";
|
||||
import { DS4ItemDataType, ItemType } from "../../item/item-data";
|
||||
import { DS4ItemData, ItemType } from "../../item/item-data";
|
||||
import { DS4Actor } from "../actor";
|
||||
import { DS4ActorDataType } from "../actor-data";
|
||||
|
||||
/**
|
||||
* Extend the basic ActorSheet with some very simple modifications
|
||||
* @extends {ActorSheet}
|
||||
*/
|
||||
export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4ItemDataType> {
|
||||
// TODO(types): provide proper types for all generic parameters
|
||||
export class DS4ActorSheet extends ActorSheet<unknown, DS4Actor> {
|
||||
// TODO(types): Improve mergeObject in upstream so that it isn't necessary to provide all parameters
|
||||
/** @override */
|
||||
static get defaultOptions(): FormApplicationOptions {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
static get defaultOptions(): BaseEntitySheet.Options {
|
||||
const superDefaultOptions = super.defaultOptions;
|
||||
return mergeObject(superDefaultOptions, {
|
||||
classes: ["ds4", "sheet", "actor"],
|
||||
width: 745,
|
||||
height: 600,
|
||||
scrollY: [".sheet-body"],
|
||||
template: superDefaultOptions.template,
|
||||
viewPermission: superDefaultOptions.viewPermission,
|
||||
closeOnSubmit: superDefaultOptions.closeOnSubmit,
|
||||
submitOnChange: superDefaultOptions.submitOnChange,
|
||||
submitOnClose: superDefaultOptions.submitOnClose,
|
||||
editable: superDefaultOptions.editable,
|
||||
baseApplication: superDefaultOptions.baseApplication,
|
||||
top: superDefaultOptions.top,
|
||||
left: superDefaultOptions.left,
|
||||
popOut: superDefaultOptions.popOut,
|
||||
minimizable: superDefaultOptions.minimizable,
|
||||
resizable: superDefaultOptions.resizable,
|
||||
id: superDefaultOptions.id,
|
||||
dragDrop: superDefaultOptions.dragDrop,
|
||||
filters: superDefaultOptions.filters,
|
||||
title: superDefaultOptions.title,
|
||||
tabs: superDefaultOptions.tabs,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -32,7 +51,7 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
|
|||
* object itemsByType.
|
||||
* @returns the data fed to the template of the actor sheet
|
||||
*/
|
||||
getData(): ActorSheetData<DS4ActorDataType, DS4Actor> {
|
||||
getData(): ActorSheet.Data<DS4Actor> {
|
||||
const data = {
|
||||
...super.getData(),
|
||||
// Add the localization config to the data:
|
||||
|
@ -82,13 +101,12 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
|
|||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @private
|
||||
*/
|
||||
private _onItemCreate(event: JQuery.ClickEvent): Promise<Item> {
|
||||
private _onItemCreate(event: JQuery.ClickEvent): Promise<DS4ItemData> {
|
||||
event.preventDefault();
|
||||
const header = event.currentTarget;
|
||||
// Get the type of item to create.
|
||||
const type = header.dataset.type;
|
||||
// Grab any data associated with this control.
|
||||
const data = duplicate(header.dataset);
|
||||
const { type, ...data } = duplicate(header.dataset);
|
||||
// Initialize a default name.
|
||||
const name = `New ${type.capitalize()}`;
|
||||
// Prepare the item object.
|
||||
|
@ -97,11 +115,9 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
|
|||
type: type,
|
||||
data: data,
|
||||
};
|
||||
// Remove the type from the dataset since it's in the itemData.type prop.
|
||||
delete itemData.data.type;
|
||||
|
||||
// Finally, create the item!
|
||||
return this.actor.createOwnedItem(itemData);
|
||||
return this.actor.createOwnedItem(itemData as DS4ItemData); // TODO(types) Improve upstream typing of createOwnedItem. It is possible to leave parts out here.
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,7 +132,7 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
|
|||
console.log("Current target:", $(ev.currentTarget).get(0)["name"]);
|
||||
const el: HTMLFormElement = $(ev.currentTarget).get(0);
|
||||
const id = $(ev.currentTarget).parents(".item").data("itemId");
|
||||
const item = duplicate(this.actor.getOwnedItem(id)); // getOwnedItem is typed incorrectly, it actually returns a ItemData<DS4ItemDataType>, not an Item
|
||||
const item = (duplicate(this.actor.getOwnedItem(id)) as unknown) as DS4ItemData; // TODO(types): Possible get better type definition for duplicate into upstream
|
||||
const property: string | undefined = $(ev.currentTarget).data("property");
|
||||
|
||||
// Early return:
|
||||
|
@ -210,7 +226,7 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
|
|||
|
||||
/** @override */
|
||||
async _onDropItem(event: DragEvent, data: Parameters<typeof DS4Item.fromDropData>[0]): Promise<unknown> {
|
||||
const item = await Item.fromDropData(data);
|
||||
const item = ((await Item.fromDropData(data)) as unknown) as DS4Item;
|
||||
if (item && !this.actor.canOwnItemType(item.data.type as ItemType)) {
|
||||
ui.notifications.warn(
|
||||
game.i18n.format("DS4.WarningActorCannotOwnItem", {
|
||||
|
@ -222,6 +238,6 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
|
|||
);
|
||||
return false;
|
||||
}
|
||||
return super._onDropItem(event, data);
|
||||
return super["_onDropItem"](event, data); // TODO(types): Add _onDropItem to upstream
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,30 @@ import { DS4ActorSheet } from "./actor-sheet";
|
|||
|
||||
export class DS4CharacterActorSheet extends DS4ActorSheet {
|
||||
/** @override */
|
||||
static get defaultOptions(): FormApplicationOptions {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
static get defaultOptions(): BaseEntitySheet.Options {
|
||||
const superDefaultOptions = super.defaultOptions;
|
||||
return mergeObject(superDefaultOptions, {
|
||||
classes: ["ds4", "sheet", "actor", "character"],
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "inventory" }],
|
||||
template: superDefaultOptions.template,
|
||||
viewPermission: superDefaultOptions.viewPermission,
|
||||
closeOnSubmit: superDefaultOptions.closeOnSubmit,
|
||||
submitOnChange: superDefaultOptions.submitOnChange,
|
||||
submitOnClose: superDefaultOptions.submitOnClose,
|
||||
editable: superDefaultOptions.editable,
|
||||
baseApplication: superDefaultOptions.baseApplication,
|
||||
top: superDefaultOptions.top,
|
||||
left: superDefaultOptions.left,
|
||||
popOut: superDefaultOptions.popOut,
|
||||
minimizable: superDefaultOptions.minimizable,
|
||||
resizable: superDefaultOptions.resizable,
|
||||
id: superDefaultOptions.id,
|
||||
dragDrop: superDefaultOptions.dragDrop,
|
||||
filters: superDefaultOptions.filters,
|
||||
title: superDefaultOptions.title,
|
||||
width: superDefaultOptions.width,
|
||||
height: superDefaultOptions.height,
|
||||
scrollY: superDefaultOptions.scrollY,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,30 @@ import { DS4ActorSheet } from "./actor-sheet";
|
|||
|
||||
export class DS4CreatureActorSheet extends DS4ActorSheet {
|
||||
/** @override */
|
||||
static get defaultOptions(): FormApplicationOptions {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
static get defaultOptions(): BaseEntitySheet.Options {
|
||||
const superDefaultOptions = super.defaultOptions;
|
||||
return mergeObject(superDefaultOptions, {
|
||||
classes: ["ds4", "sheet", "actor", "creature"],
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "inventory" }],
|
||||
template: superDefaultOptions.template,
|
||||
viewPermission: superDefaultOptions.viewPermission,
|
||||
closeOnSubmit: superDefaultOptions.closeOnSubmit,
|
||||
submitOnChange: superDefaultOptions.submitOnChange,
|
||||
submitOnClose: superDefaultOptions.submitOnClose,
|
||||
editable: superDefaultOptions.editable,
|
||||
baseApplication: superDefaultOptions.baseApplication,
|
||||
top: superDefaultOptions.top,
|
||||
left: superDefaultOptions.left,
|
||||
popOut: superDefaultOptions.popOut,
|
||||
minimizable: superDefaultOptions.minimizable,
|
||||
resizable: superDefaultOptions.resizable,
|
||||
id: superDefaultOptions.id,
|
||||
dragDrop: superDefaultOptions.dragDrop,
|
||||
filters: superDefaultOptions.filters,
|
||||
title: superDefaultOptions.title,
|
||||
width: superDefaultOptions.width,
|
||||
height: superDefaultOptions.height,
|
||||
scrollY: superDefaultOptions.scrollY,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import { migration } from "./migrations";
|
|||
Hooks.once("init", async function () {
|
||||
console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`);
|
||||
|
||||
game.ds4 = {
|
||||
game["ds4"] = {
|
||||
DS4Actor,
|
||||
DS4Item,
|
||||
DS4,
|
||||
|
|
|
@ -3,7 +3,9 @@ import { DS4 } from "../config";
|
|||
|
||||
export type ItemType = keyof typeof DS4.itemTypes;
|
||||
|
||||
export type DS4ItemDataType =
|
||||
export type DS4ItemData = Item.Data<DS4ItemDataType>;
|
||||
|
||||
type DS4ItemDataType =
|
||||
| DS4Weapon
|
||||
| DS4Armor
|
||||
| DS4Shield
|
||||
|
|
|
@ -1,19 +1,37 @@
|
|||
import { DS4Item } from "./item";
|
||||
import { DS4ItemDataType, isDS4ItemDataTypePhysical } from "./item-data";
|
||||
import { isDS4ItemDataTypePhysical } from "./item-data";
|
||||
|
||||
/**
|
||||
* Extend the basic ItemSheet with some very simple modifications
|
||||
* @extends {ItemSheet}
|
||||
*/
|
||||
export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
||||
// TODO(types): provide proper types for all generic parameters
|
||||
export class DS4ItemSheet extends ItemSheet<unknown, DS4Item> {
|
||||
/** @override */
|
||||
static get defaultOptions(): FormApplicationOptions {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
static get defaultOptions(): BaseEntitySheet.Options {
|
||||
const superDefaultOptions = super.defaultOptions;
|
||||
return mergeObject(superDefaultOptions, {
|
||||
width: 530,
|
||||
height: 400,
|
||||
classes: ["ds4", "sheet", "item"],
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
|
||||
scrollY: [".sheet-body"],
|
||||
template: superDefaultOptions.template,
|
||||
viewPermission: superDefaultOptions.viewPermission,
|
||||
closeOnSubmit: superDefaultOptions.closeOnSubmit,
|
||||
submitOnChange: superDefaultOptions.submitOnChange,
|
||||
submitOnClose: superDefaultOptions.submitOnClose,
|
||||
editable: superDefaultOptions.editable,
|
||||
baseApplication: superDefaultOptions.baseApplication,
|
||||
top: superDefaultOptions.top,
|
||||
left: superDefaultOptions.left,
|
||||
popOut: superDefaultOptions.popOut,
|
||||
minimizable: superDefaultOptions.minimizable,
|
||||
resizable: superDefaultOptions.resizable,
|
||||
id: superDefaultOptions.id,
|
||||
dragDrop: superDefaultOptions.dragDrop,
|
||||
filters: superDefaultOptions.filters,
|
||||
title: superDefaultOptions.title,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -26,7 +44,7 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
getData(): ItemSheetData<DS4ItemDataType, DS4Item> {
|
||||
getData(): ItemSheet.Data<DS4Item> {
|
||||
const data = {
|
||||
...super.getData(),
|
||||
config: CONFIG.DS4,
|
||||
|
@ -41,11 +59,11 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
setPosition(options: ApplicationPosition = {}): ApplicationPosition {
|
||||
setPosition(options: Partial<Application.Position> = {}): Application.Position {
|
||||
const position = super.setPosition(options);
|
||||
if ("find" in this.element) {
|
||||
const sheetBody = this.element.find(".sheet-body");
|
||||
const bodyHeight = position.height - 192;
|
||||
const bodyHeight = (position.height as number) - 192; // TODO: remove type cast once https://github.com/kmoschcau/foundry-vtt-types/pull/214 is merged
|
||||
sheetBody.css("height", bodyHeight);
|
||||
} else {
|
||||
console.log("Failure setting position.");
|
||||
|
@ -81,7 +99,7 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
case "create":
|
||||
return this._createActiveEffect();
|
||||
case "edit":
|
||||
const effect = this.item.effects.get(li.data("effectId"));
|
||||
const effect = this.item["effects"].get(li.data("effectId")); // TODO replace with item.effect once https://github.com/kmoschcau/foundry-vtt-types/pull/216 is merged
|
||||
return effect.sheet.render(true);
|
||||
case "delete": {
|
||||
return this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId"));
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import { DS4Actor } from "../actor/actor";
|
||||
import { DS4ActorDataType } from "../actor/actor-data";
|
||||
import { DS4ItemDataType, DS4Talent } from "./item-data";
|
||||
import { DS4ItemData, DS4Talent } from "./item-data";
|
||||
|
||||
/**
|
||||
* Extend the basic Item with some very simple modifications.
|
||||
* @extends {Item}
|
||||
*/
|
||||
export class DS4Item extends Item<DS4ItemDataType, DS4ActorDataType, DS4Actor> {
|
||||
export class DS4Item extends Item<DS4ItemData> {
|
||||
/**
|
||||
* Augment the basic Item data model with additional dynamic data.
|
||||
*/
|
||||
|
|
|
@ -130,41 +130,38 @@ async function askGmModifier(
|
|||
const renderedHtml = await renderTemplate(usedTemplate, templateData);
|
||||
|
||||
const dialogPromise = new Promise<HTMLFormElement>((resolve) => {
|
||||
new Dialog(
|
||||
{
|
||||
title: usedTitle,
|
||||
close: () => {
|
||||
// Don't do anything
|
||||
},
|
||||
content: renderedHtml,
|
||||
buttons: {
|
||||
ok: {
|
||||
label: game.i18n.localize("DS4.RollDialogOkButton"),
|
||||
callback: (html: HTMLElement | JQuery) => {
|
||||
if (!("jquery" in html)) {
|
||||
throw new Error(
|
||||
game.i18n.format("DS4.ErrorUnexpectedHtmlType", {
|
||||
exType: "JQuery",
|
||||
realType: "HTMLElement",
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
const innerForm = html[0].querySelector("form");
|
||||
resolve(innerForm);
|
||||
}
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
label: game.i18n.localize("DS4.RollDialogCancelButton"),
|
||||
callback: () => {
|
||||
// Don't do anything
|
||||
},
|
||||
},
|
||||
},
|
||||
default: "ok",
|
||||
new Dialog({
|
||||
title: usedTitle,
|
||||
close: () => {
|
||||
// Don't do anything
|
||||
},
|
||||
{},
|
||||
).render(true);
|
||||
content: renderedHtml,
|
||||
buttons: {
|
||||
ok: {
|
||||
label: game.i18n.localize("DS4.RollDialogOkButton"),
|
||||
callback: (html: HTMLElement | JQuery) => {
|
||||
if (!("jquery" in html)) {
|
||||
throw new Error(
|
||||
game.i18n.format("DS4.ErrorUnexpectedHtmlType", {
|
||||
exType: "JQuery",
|
||||
realType: "HTMLElement",
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
const innerForm = html[0].querySelector("form");
|
||||
resolve(innerForm);
|
||||
}
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
label: game.i18n.localize("DS4.RollDialogCancelButton"),
|
||||
callback: () => {
|
||||
// Don't do anything
|
||||
},
|
||||
},
|
||||
},
|
||||
default: "ok",
|
||||
}).render(true);
|
||||
});
|
||||
const dialogForm = await dialogPromise;
|
||||
return parseDialogFormData(dialogForm, targetValue);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue