add eslint and prettier

This commit is contained in:
Johannes Loher 2020-12-23 18:23:26 +01:00
parent 618146226b
commit 2ba687eb14
10 changed files with 775 additions and 37 deletions

View file

@ -0,0 +1,2 @@
// TODO: Actually add a type for data
export type DS4ActorDataType = unknown;

View file

@ -1,12 +1,13 @@
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<{
/* TODO: add actual type for data */
}> {
export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor> {
/** @override */
static get defaultOptions() {
static get defaultOptions(): FormApplicationOptions {
return mergeObject(super.defaultOptions, {
classes: ["ds4", "sheet", "actor"],
template: "systems/ds4/templates/actor/actor-sheet.html",
@ -19,11 +20,11 @@ export class DS4ActorSheet extends ActorSheet<{
/* -------------------------------------------- */
/** @override */
getData() {
getData(): ActorSheetData<DS4ActorDataType> {
// TODO: replace ["..."] access with .
const data = super.getData();
data["dtypes"] = ["String", "Number", "Boolean"];
for (let attr of Object.values(data.data["attributes"])) {
for (const attr of Object.values(data.data["attributes"])) {
attr["isCheckbox"] = attr["dtype"] === "Boolean";
}
console.log(data);
@ -31,7 +32,7 @@ export class DS4ActorSheet extends ActorSheet<{
}
/** @override */
activateListeners(html) {
activateListeners(html: JQuery): void {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
@ -65,7 +66,7 @@ export class DS4ActorSheet extends ActorSheet<{
* @param {Event} event The originating click event
* @private
*/
_onItemCreate(event) {
_onItemCreate(event: JQuery.ClickEvent): Promise<Item> {
event.preventDefault();
const header = event.currentTarget;
// Get the type of item to create.
@ -92,14 +93,14 @@ export class DS4ActorSheet extends ActorSheet<{
* @param {Event} event The originating click event
* @private
*/
_onRoll(event) {
_onRoll(event: JQuery.ClickEvent): void {
event.preventDefault();
const element = event.currentTarget;
const dataset = element.dataset;
if (dataset.roll) {
let roll = new Roll(dataset.roll, this.actor.data.data);
let label = dataset.label ? `Rolling ${dataset.label}` : "";
const roll = new Roll(dataset.roll, this.actor.data.data as Record<string, unknown>);
const label = dataset.label ? `Rolling ${dataset.label}` : "";
roll.roll().toMessage({
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
flavor: label,

View file

@ -1,34 +1,39 @@
import { DS4ActorDataType } from "./actor-data";
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class DS4Actor extends Actor {
export class DS4Actor extends Actor<DS4ActorDataType> {
/** @override */
prepareDerivedData() {
prepareDerivedData(): void {
const data = this.data;
this._prepareCombatValues(data);
}
_prepareCombatValues(data) {
_prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
setProperty(
data,
"data.combatValues.hitPoints.max",
data.data.attributes.body.initial + data.data.traits.constitution.initial + 10 + hitPointsModifier
data.data["attributes"]["body"].initial + // TODO: replace ["..."]
data.data["traits"]["constitution"].initial + // TODO: replace ["..."]
10 +
hitPointsModifier,
);
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0;
setProperty(
data,
"data.combatValues.defense.value",
data.data.attributes.body.initial +
data.data.traits.constitution.initial +
data.data["attributes"]["body"].initial + // TODO: replace ["..."]
data.data["traits"]["constitution"].initial + // TODO: replace ["..."]
this._getArmorValue() +
defenseModifier
defenseModifier,
);
}
_getArmorValue() {
_getArmorValue(): number {
return this.data["items"]
.filter((item) => ["armor", "shield"].includes(item.type))
.filter((item) => item.data.equipped)

View file

@ -18,8 +18,8 @@ Hooks.once("init", async function () {
CONFIG.DS4 = DS4;
// Define custom Entity classes
CONFIG.Actor.entityClass = DS4Actor;
CONFIG.Item.entityClass = DS4Item;
CONFIG.Actor.entityClass = DS4Actor as typeof Actor; // TODO: Can we remove the casts?
CONFIG.Item.entityClass = DS4Item as typeof Item; // TODO: Can we remove the casts?
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
@ -50,7 +50,7 @@ Hooks.once("setup", function () {
const noSort = [];
// Localize and sort CONFIG objects
for (let o of toLocalize) {
for (const o of toLocalize) {
const localized = Object.entries(CONFIG.DS4[o]).map((e) => {
return [e[0], game.i18n.localize(e[1] as string)];
});

View file

@ -0,0 +1,2 @@
// TODO: Actually add a type for data
export type DS4ItemDataType = unknown;

View file

@ -1,10 +1,14 @@
import { DS4ActorDataType } from "../actor/actor-data";
import { DS4Item } from "./item";
import { DS4ItemDataType } from "./item-data";
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class DS4ItemSheet extends ItemSheet {
export class DS4ItemSheet extends ItemSheet<DS4ActorDataType, DS4Item> {
/** @override */
static get defaultOptions() {
static get defaultOptions(): FormApplicationOptions {
return mergeObject(super.defaultOptions, {
width: 530,
height: 400,
@ -14,7 +18,7 @@ export class DS4ItemSheet extends ItemSheet {
}
/** @override */
get template() {
get template(): string {
const path = "systems/ds4/templates/item";
return `${path}/${this.item.data.type}-sheet.hbs`;
}
@ -22,7 +26,7 @@ export class DS4ItemSheet extends ItemSheet {
/* -------------------------------------------- */
/** @override */
getData() {
getData(): ItemSheetData<DS4ItemDataType> {
const data = { ...super.getData(), config: CONFIG.DS4 };
console.log(data);
return data;
@ -31,7 +35,7 @@ export class DS4ItemSheet extends ItemSheet {
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {
setPosition(options = {}): unknown {
const position = super.setPosition(options);
const sheetBody = (this.element as JQuery).find(".sheet-body"); // TODO: Why is the cast necessary?
const bodyHeight = position.height - 192;
@ -42,7 +46,7 @@ export class DS4ItemSheet extends ItemSheet {
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
activateListeners(html: JQuery): void {
super.activateListeners(html);
if (!this.options.editable) return;
@ -52,7 +56,7 @@ export class DS4ItemSheet extends ItemSheet {
html.find(".effect-edit").click((ev) => {
const li = $(ev.currentTarget).parents(".effect");
console.log(li.data("effectId"));
const effect = this.item.effects.get(li.data("effectId"));
const effect = this.item["effects"].get(li.data("effectId")); // TODO: replace ["..."]
effect.sheet.render(true);
});
@ -67,7 +71,7 @@ export class DS4ItemSheet extends ItemSheet {
* @param {Event} event The originating click event
* @private
*/
async _onEffectCreate(event) {
async _onEffectCreate(event: JQuery.ClickEvent): Promise<unknown> {
event.preventDefault();
const label = `New Effect`;

View file

@ -1,17 +1,19 @@
import { DS4ItemDataType } from "./item-data";
/**
* Extend the basic Item with some very simple modifications.
* @extends {Item}
*/
export class DS4Item extends Item {
export class DS4Item extends Item<DS4ItemDataType> {
/**
* Augment the basic Item data model with additional dynamic data.
*/
prepareData() {
prepareData(): void {
super.prepareData();
// Get the Item's data
const itemData = this.data;
const actorData = this.actor ? this.actor.data : {};
const data = itemData.data;
// const itemData = this.data;
// const actorData = this.actor ? this.actor.data : {};
// const data = itemData.data;
}
}