Merge branch '068-enable-strict-mode' into 050-basic-active-effects
This commit is contained in:
commit
b74ee5ec7c
45 changed files with 3088 additions and 2119 deletions
|
@ -1,37 +1,53 @@
|
|||
import { ModifiableData } from "../common/common-data";
|
||||
import { DS4 } from "../config";
|
||||
|
||||
export type ItemType = keyof typeof DS4.itemTypes;
|
||||
export type ItemType = keyof typeof DS4.i18n.itemTypes;
|
||||
|
||||
export type DS4ItemDataType =
|
||||
| DS4Weapon
|
||||
| DS4Armor
|
||||
| DS4Shield
|
||||
| DS4Spell
|
||||
| DS4Trinket
|
||||
| DS4Equipment
|
||||
| DS4Talent
|
||||
| DS4RacialAbility
|
||||
| DS4Language
|
||||
| DS4Alphabet
|
||||
| DS4SpecialCreatureAbility;
|
||||
export type DS4ItemData =
|
||||
| DS4WeaponData
|
||||
| DS4ArmorData
|
||||
| DS4ShieldData
|
||||
| DS4SpellData
|
||||
| DS4TrinketData
|
||||
| DS4EquipmentData
|
||||
| DS4TalentData
|
||||
| DS4RacialAbilityData
|
||||
| DS4LanguageData
|
||||
| DS4AlphabetData
|
||||
| DS4SpecialCreatureAbilityData;
|
||||
|
||||
export type DS4EquippableItemDataType = DS4Weapon | DS4Armor | DS4Shield | DS4Trinket;
|
||||
interface DS4ItemDataHelper<T, U extends ItemType> extends Item.Data<T> {
|
||||
type: U;
|
||||
}
|
||||
|
||||
// types
|
||||
type DS4WeaponData = DS4ItemDataHelper<DS4WeaponDataData, "weapon">;
|
||||
type DS4ArmorData = DS4ItemDataHelper<DS4ArmorDataData, "armor">;
|
||||
type DS4ShieldData = DS4ItemDataHelper<DS4ShieldDataData, "shield">;
|
||||
type DS4SpellData = DS4ItemDataHelper<DS4SpellDataData, "spell">;
|
||||
type DS4TrinketData = DS4ItemDataHelper<DS4TrinketDataData, "trinket">;
|
||||
type DS4EquipmentData = DS4ItemDataHelper<DS4EquipmentDataData, "equipment">;
|
||||
type DS4TalentData = DS4ItemDataHelper<DS4TalentDataData, "talent">;
|
||||
type DS4RacialAbilityData = DS4ItemDataHelper<DS4RacialAbilityDataData, "racialAbility">;
|
||||
type DS4LanguageData = DS4ItemDataHelper<DS4LanguageDataData, "language">;
|
||||
type DS4AlphabetData = DS4ItemDataHelper<DS4AlphabetDataData, "alphabet">;
|
||||
type DS4SpecialCreatureAbilityData = DS4ItemDataHelper<DS4SpecialCreatureAbilityDataData, "specialCreatureAbility">;
|
||||
|
||||
interface DS4Weapon extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable {
|
||||
interface DS4WeaponDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical, DS4ItemDataDataEquipable {
|
||||
attackType: "melee" | "ranged" | "meleeRanged";
|
||||
weaponBonus: number;
|
||||
opponentDefense: number;
|
||||
}
|
||||
|
||||
export interface DS4Armor extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable, DS4ItemProtective {
|
||||
interface DS4ArmorDataData
|
||||
extends DS4ItemDataDataBase,
|
||||
DS4ItemDataDataPhysical,
|
||||
DS4ItemDataDataEquipable,
|
||||
DS4ItemDataDataProtective {
|
||||
armorMaterialType: "cloth" | "leather" | "chain" | "plate";
|
||||
armorType: "body" | "helmet" | "vambrace" | "greaves" | "vambraceGreaves";
|
||||
}
|
||||
|
||||
export interface DS4Talent extends DS4ItemBase {
|
||||
interface DS4TalentDataData extends DS4ItemDataDataBase {
|
||||
rank: DS4TalentRank;
|
||||
}
|
||||
|
||||
|
@ -39,7 +55,7 @@ interface DS4TalentRank extends ModifiableData<number> {
|
|||
max: number;
|
||||
}
|
||||
|
||||
interface DS4Spell extends DS4ItemBase, DS4ItemEquipable {
|
||||
interface DS4SpellDataData extends DS4ItemDataDataBase, DS4ItemDataDataEquipable {
|
||||
spellType: "spellcasting" | "targetedSpellcasting";
|
||||
bonus: string;
|
||||
spellCategory:
|
||||
|
@ -59,37 +75,41 @@ interface DS4Spell extends DS4ItemBase, DS4ItemEquipable {
|
|||
scrollPrice: number;
|
||||
}
|
||||
|
||||
export interface DS4Shield extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable, DS4ItemProtective {}
|
||||
interface DS4Trinket extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable {}
|
||||
interface DS4Equipment extends DS4ItemBase, DS4ItemPhysical {}
|
||||
type DS4RacialAbility = DS4ItemBase;
|
||||
type DS4Language = DS4ItemBase;
|
||||
type DS4Alphabet = DS4ItemBase;
|
||||
interface DS4SpecialCreatureAbility extends DS4ItemBase {
|
||||
interface DS4ShieldDataData
|
||||
extends DS4ItemDataDataBase,
|
||||
DS4ItemDataDataPhysical,
|
||||
DS4ItemDataDataEquipable,
|
||||
DS4ItemDataDataProtective {}
|
||||
interface DS4TrinketDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical, DS4ItemDataDataEquipable {}
|
||||
interface DS4EquipmentDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical {}
|
||||
type DS4RacialAbilityDataData = DS4ItemDataDataBase;
|
||||
type DS4LanguageDataData = DS4ItemDataDataBase;
|
||||
type DS4AlphabetDataData = DS4ItemDataDataBase;
|
||||
interface DS4SpecialCreatureAbilityDataData extends DS4ItemDataDataBase {
|
||||
experiencePoints: number;
|
||||
}
|
||||
|
||||
// templates
|
||||
|
||||
interface DS4ItemBase {
|
||||
interface DS4ItemDataDataBase {
|
||||
description: string;
|
||||
}
|
||||
interface DS4ItemPhysical {
|
||||
interface DS4ItemDataDataPhysical {
|
||||
quantity: number;
|
||||
price: number;
|
||||
availability: "hamlet" | "village" | "city" | "elves" | "dwarves" | "nowhere" | "unset";
|
||||
storageLocation: string;
|
||||
}
|
||||
|
||||
export function isDS4ItemDataTypePhysical(input: DS4ItemDataType): boolean {
|
||||
export function isDS4ItemDataTypePhysical(input: DS4ItemData["data"]): boolean {
|
||||
return "quantity" in input && "price" in input && "availability" in input && "storageLocation" in input;
|
||||
}
|
||||
|
||||
interface DS4ItemEquipable {
|
||||
interface DS4ItemDataDataEquipable {
|
||||
equipped: boolean;
|
||||
}
|
||||
|
||||
interface DS4ItemProtective {
|
||||
interface DS4ItemDataDataProtective {
|
||||
armorValue: number;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,36 @@
|
|||
import { DS4 } from "../config";
|
||||
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}
|
||||
* The Sheet class for DS4 Items
|
||||
*/
|
||||
export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
||||
export class DS4ItemSheet extends ItemSheet<ItemSheet.Data<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,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -23,13 +40,11 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
return `${path}/${this.item.data.type}-sheet.hbs`;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
getData(): ItemSheetData<DS4ItemDataType, DS4Item> {
|
||||
async getData(): Promise<ItemSheet.Data<DS4Item>> {
|
||||
const data = {
|
||||
...super.getData(),
|
||||
config: CONFIG.DS4,
|
||||
...(await super.getData()),
|
||||
config: DS4,
|
||||
isOwned: this.item.isOwned,
|
||||
actor: this.item.actor,
|
||||
isPhysical: isDS4ItemDataTypePhysical(this.item.data.data),
|
||||
|
@ -37,10 +52,8 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
return data;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @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");
|
||||
|
@ -52,8 +65,6 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
return position;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
activateListeners(html: JQuery): void {
|
||||
super.activateListeners(html);
|
||||
|
@ -65,13 +76,13 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
|
||||
/**
|
||||
* Handle management of ActiveEffects.
|
||||
* @param {Event} event The originating click event
|
||||
* @param event - he originating click event
|
||||
*/
|
||||
private async _onManageActiveEffect(event: JQuery.ClickEvent): Promise<unknown> {
|
||||
protected async _onManageActiveEffect(event: JQuery.ClickEvent): Promise<unknown> {
|
||||
event.preventDefault();
|
||||
|
||||
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 li = $(a).parents(".effect");
|
||||
|
@ -81,7 +92,7 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
return this._createActiveEffect();
|
||||
case "edit":
|
||||
const effect = this.item.effects.get(li.data("effectId"));
|
||||
return effect.sheet.render(true);
|
||||
return effect?.sheet.render(true);
|
||||
case "delete": {
|
||||
return this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId"));
|
||||
}
|
||||
|
@ -91,7 +102,7 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
/**
|
||||
* Create a new ActiveEffect for the item using default data.
|
||||
*/
|
||||
private async _createActiveEffect(): Promise<unknown> {
|
||||
protected async _createActiveEffect(): Promise<ActiveEffect.Data> {
|
||||
const label = `New Effect`;
|
||||
|
||||
const createData = {
|
||||
|
@ -101,7 +112,7 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
|
|||
transfer: true,
|
||||
};
|
||||
|
||||
const effect = await ActiveEffect.create(createData, this.item);
|
||||
const effect = ActiveEffect.create(createData, this.item);
|
||||
return effect.create({});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,20 @@
|
|||
import { DS4Actor } from "../actor/actor";
|
||||
import { DS4ActorDataType } from "../actor/actor-data";
|
||||
import { DS4ItemDataType, DS4Talent } from "./item-data";
|
||||
import { DS4ItemData } from "./item-data";
|
||||
|
||||
/**
|
||||
* Extend the basic Item with some very simple modifications.
|
||||
* @extends {Item}
|
||||
* The Item class for DS4
|
||||
*/
|
||||
export class DS4Item extends Item<DS4ItemDataType, DS4ActorDataType, DS4Actor> {
|
||||
export class DS4Item extends Item<DS4ItemData> {
|
||||
/**
|
||||
* Augment the basic Item data model with additional dynamic data.
|
||||
* @override
|
||||
*/
|
||||
prepareData(): void {
|
||||
super.prepareData();
|
||||
this.prepareDerivedData();
|
||||
|
||||
// Get the Item's data
|
||||
// const itemData = this.data;
|
||||
// const actorData = this.actor ? this.actor.data : {};
|
||||
// const data = itemData.data;
|
||||
}
|
||||
|
||||
prepareDerivedData(): void {
|
||||
if (this.type === "talent") {
|
||||
const data = this.data.data as DS4Talent;
|
||||
if (this.data.type === "talent") {
|
||||
const data = this.data.data;
|
||||
data.rank.total = data.rank.base + data.rank.mod;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue