switch to foundry-vtt-types
This commit is contained in:
parent
6e10d4b093
commit
62cc5a0e7c
13 changed files with 713 additions and 84 deletions
|
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue