fvtt-wasteland/modules/wasteland-actor-sheet.js

195 lines
7.3 KiB
JavaScript
Raw Permalink Normal View History

2023-11-26 16:18:04 +01:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { WastelandUtility } from "./wasteland-utility.js";
import { WastelandRollDialog } from "./wasteland-roll-dialog.js";
/* -------------------------------------------- */
export class WastelandActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
2024-05-23 11:36:03 +02:00
return foundry.utils.mergeObject(super.defaultOptions, {
2023-11-26 16:18:04 +01:00
classes: ["fvtt-wasteland", "sheet", "actor"],
template: "systems/fvtt-wasteland/templates/actor-sheet.html",
width: 640,
height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: false
});
}
/* -------------------------------------------- */
async getData() {
2024-05-23 11:36:03 +02:00
const objectData = foundry.utils.duplicate(this.object)
2023-11-26 16:18:04 +01:00
let actorData = objectData
let formData = {
title: this.title,
id: objectData.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: actorData.system,
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
limited: this.object.limited,
skills: this.actor.getSkills(),
2024-05-23 11:36:03 +02:00
armes: foundry.utils.duplicate(this.actor.getWeapons()),
protections: foundry.utils.duplicate(this.actor.getArmors()),
pouvoirs:foundry.utils.duplicate(this.actor.getPouvoirs()),
dons: foundry.utils.duplicate(this.actor.getDons()),
hubrises: foundry.utils.duplicate(this.actor.getHubris()),
tours:foundry.utils.duplicate(this.actor.getTours()),
artifex: foundry.utils.duplicate(this.actor.getArtifex()),
charmes:foundry.utils.duplicate(this.actor.getCharmes()),
peuple: foundry.utils.duplicate(this.actor.getPeuple() || {}),
origine: foundry.utils.duplicate(this.actor.getOrigine() || {}),
heritage: foundry.utils.duplicate(this.actor.getHeritage() || {}),
metier: foundry.utils.duplicate(this.actor.getMetier() || {}),
2023-11-26 16:18:04 +01:00
combat: this.actor.getCombatValues(),
2024-05-23 11:36:03 +02:00
config: foundry.utils.duplicate(game.system.wasteland.config),
capacites: foundry.utils.duplicate(this.actor.getCapacites()),
equipements: foundry.utils.duplicate(this.actor.getEquipments()),
monnaies: foundry.utils.duplicate(this.actor.getMonnaies()),
mutations: foundry.utils.duplicate(this.actor.getMutations()),
2023-11-26 16:18:04 +01:00
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
2023-12-02 09:03:58 +01:00
comportement: await TextEditor.enrichHTML(this.object.system.biodata.comportement, {async: true}),
habitat: await TextEditor.enrichHTML(this.object.system.biodata.habitat, {async: true}),
2023-11-26 16:18:04 +01:00
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
2024-05-23 11:36:03 +02:00
isGM: game.user.isGM,
config: game.system.wasteland.config
2023-11-26 16:18:04 +01:00
}
this.formData = formData;
console.log("PC : ", formData, this.object);
return formData;
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
const item = this.actor.items.get( itemId )
item.sheet.render(true)
})
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
WastelandUtility.confirmDelete(this, li);
})
html.find('.edit-item-data').change(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
let itemType = li.data("item-type")
let itemField = $(ev.currentTarget).data("item-field")
let dataType = $(ev.currentTarget).data("dtype")
let value = ev.currentTarget.value
this.actor.editItemField(itemId, itemType, itemField, dataType, value)
})
html.find('.quantity-minus').click(event => {
const li = $(event.currentTarget).parents(".item");
this.actor.incDecQuantity( li.data("item-id"), -1 );
} );
html.find('.quantity-plus').click(event => {
const li = $(event.currentTarget).parents(".item");
this.actor.incDecQuantity( li.data("item-id"), +1 );
} );
html.find('.roll-attribut').click((event) => {
const li = $(event.currentTarget).parents(".item")
let attrKey = li.data("attr-key")
this.actor.rollAttribut(attrKey)
})
html.find('.roll-competence').click((event) => {
const li = $(event.currentTarget).parents(".item")
let attrKey = $(event.currentTarget).data("attr-key")
let compId = li.data("item-id")
this.actor.rollCompetence(attrKey, compId)
})
2023-11-29 22:04:17 +01:00
html.find('.roll-charme').click((event) => {
const li = $(event.currentTarget).parents(".item")
let charmeId = li.data("item-id")
this.actor.rollCharme(charmeId)
})
2023-11-26 17:00:12 +01:00
html.find('.roll-pouvoir').click((event) => {
2023-11-26 16:18:04 +01:00
const li = $(event.currentTarget).parents(".item")
2023-11-26 17:00:12 +01:00
let pouvoirId = li.data("item-id")
this.actor.rollPouvoir(pouvoirId)
2023-11-26 16:18:04 +01:00
})
html.find('.roll-arme-offensif').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollArmeOffensif(armeId)
})
html.find('.roll-arme-degats').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollArmeDegats(armeId)
})
html.find('.quantity-modify').click(event => {
const li = $(event.currentTarget).parents(".item")
const value = Number($(event.currentTarget).data("quantite-value"))
this.actor.incDecQuantity( li.data("item-id"), value );
})
html.find('.item-add').click((event) => {
const itemType = $(event.currentTarget).data("type")
this.actor.createEmbeddedDocuments('Item', [{ name: `Nouveau ${itemType}`, type: itemType }], { renderSheet: true })
})
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);
});
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.equipItem( li.data("item-id") );
this.render(true);
});
}
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {
const position = super.setPosition(options);
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
/*async _onDropItem(event, dragData) {
let item = await WastelandUtility.searchItem( dragData)
this.actor.preprocessItem( event, item, true )
super._onDropItem(event, dragData)
}*/
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
}