fvtt-les-heritiers/modules/heritiers-actor-sheet.js

255 lines
9.3 KiB
JavaScript
Raw Normal View History

2022-12-26 00:33:13 +01:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { HeritiersUtility } from "./heritiers-utility.js";
/* -------------------------------------------- */
export class HeritiersActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
2024-05-23 11:25:51 +02:00
return foundry.utils.mergeObject(super.defaultOptions, {
2022-12-26 00:33:13 +01:00
classes: ["fvtt-les-heritiers", "sheet", "actor"],
template: "systems/fvtt-les-heritiers/templates/actor-sheet.html",
2023-03-11 12:11:27 +01:00
width: 780,
height: 840,
2022-12-26 00:33:13 +01:00
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: false
})
}
/* -------------------------------------------- */
async getData() {
2024-05-23 11:25:51 +02:00
const objectData = foundry.utils.duplicate(this.object)
2022-12-26 00:33:13 +01:00
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",
system: objectData.system,
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
limited: this.object.limited,
skills: this.actor.getSkills(),
2023-03-11 12:11:27 +01:00
utileSkillsMental :this.actor.organizeUtileSkills("mental"),
utileSkillsPhysical :this.actor.organizeUtileSkills("physical"),
2023-01-18 16:16:18 +01:00
futileSkills :this.actor.organizeFutileSkills(),
2023-03-08 16:58:11 +01:00
contacts: this.actor.organizeContacts(),
2024-05-23 11:25:51 +02:00
armes: foundry.utils.duplicate(this.actor.getWeapons()),
monnaies: foundry.utils.duplicate(this.actor.getMonnaies()),
pouvoirs: foundry.utils.duplicate(this.actor.getPouvoirs()),
fee: foundry.utils.duplicate(this.actor.getFee() || {} ),
protections: foundry.utils.duplicate(this.actor.getArmors()),
2022-12-26 00:33:13 +01:00
combat: this.actor.getCombatValues(),
2024-05-23 11:25:51 +02:00
equipements: foundry.utils.duplicate(this.actor.getEquipments()),
avantages: foundry.utils.duplicate(this.actor.getAvantages()),
atouts: foundry.utils.duplicate(this.actor.getAtouts()),
capacites: foundry.utils.duplicate(this.actor.getCapacites()),
desavantages: foundry.utils.duplicate(this.actor.getDesavantages()),
profils: foundry.utils.duplicate(this.actor.getProfils()),
2023-01-20 15:19:04 +01:00
pvMalus: this.actor.getPvMalus(),
heritage: game.settings.get("fvtt-les-heritiers", "heritiers-heritage"),
2022-12-26 00:33:13 +01:00
initiative: this.actor.getFlag("world", "last-initiative") || -1,
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
2023-03-08 16:58:11 +01:00
revesetranges: await TextEditor.enrichHTML(this.object.system.biodata.revesetranges, {async: true}),
secretsdecouverts: await TextEditor.enrichHTML(this.object.system.biodata.secretsdecouverts, {async: true}),
questions: await TextEditor.enrichHTML(this.object.system.biodata.questions, {async: true}),
2022-12-26 00:33:13 +01:00
habitat: await TextEditor.enrichHTML(this.object.system.biodata.habitat, {async: true}),
2023-04-08 09:55:08 +02:00
playernotes: await TextEditor.enrichHTML(this.object.system.biodata.playernotes, {async: true}),
2024-11-17 22:45:48 +01:00
magieList: this.actor.prepareMagie(),
2022-12-26 00:33:13 +01:00
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
2023-03-13 20:39:38 +01:00
config: game.system.lesheritiers.config,
2023-03-13 09:00:49 +01:00
isGM: game.user.isGM,
isPNJ: (this.actor.type == "pnj")
2022-12-26 00:33:13 +01:00
}
this.formData = formData;
console.log("PC : ", formData, this.object);
return formData;
}
/* -------------------------------------------- */
2024-03-23 11:37:15 +01:00
dialogRecupUsage() {
new Dialog({
title: "Récupération des Points d'Usage",
content: "<p>Combien de Points d'Usage souhaitez-vous récupérer ?</p>",
buttons: {
one: {
icon: '<i class="fas fa-check"></i>',
label: "1 Point",
callback: () => {
this.actor.recupUsage(1)
}
},
two: {
icon: '<i class="fas fa-check"></i>',
label: "2 Points",
callback: () => {
this.actor.recupUsage(2)
}
},
four: {
icon: '<i class="fas fa-check"></i>',
label: "4 Points",
callback: () => {
this.actor.recupUsage(4)
}
},
all: {
icon: '<i class="fas fa-check"></i>',
label: "Tous les Points",
callback: () => {
this.actor.recupUsage(100)
}
2022-12-26 00:33:13 +01:00
}
}
2024-03-23 11:37:15 +01:00
}).render(true)
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
/** @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");
HeritiersUtility.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('.adversite-modify').click(event => {
const li = $(event.currentTarget).parents(".item")
let adv = li.data("adversite")
let value = Number($(event.currentTarget).data("adversite-value"))
this.actor.incDecAdversite(adv, value)
})
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('.roll-initiative').click((event) => {
2023-03-01 22:12:27 +01:00
this.actor.rollInitiative()
2022-12-26 00:33:13 +01:00
})
2023-01-20 15:19:04 +01:00
html.find('.roll-carac').click((event) => {
const key = $(event.currentTarget).data("key")
this.actor.rollCarac(key, false)
2022-12-26 00:33:13 +01:00
})
2023-03-11 12:11:27 +01:00
html.find('.roll-rang').click((event) => {
const key = $(event.currentTarget).data("rang-key")
this.actor.rollRang(key, false)
})
2023-03-13 09:00:49 +01:00
html.find('.roll-root-competence').click((event) => {
const compKey = $(event.currentTarget).data("attr-key")
this.actor.rollRootCompetence(compKey)
})
2022-12-26 00:33:13 +01:00
html.find('.roll-competence').click((event) => {
const li = $(event.currentTarget).parents(".item")
let compId = li.data("item-id")
2023-01-18 16:16:18 +01:00
this.actor.rollCompetence(compId)
2022-12-26 00:33:13 +01:00
})
2024-11-17 22:45:48 +01:00
html.find('.roll-sort').click((event) => {
const li = $(event.currentTarget).parents(".item")
let sortId = li.data("item-id")
this.actor.rollSort(sortId)
})
2023-03-09 00:26:52 +01:00
html.find('.roll-attaque-arme').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollAttaqueArme(armeId)
})
2023-04-09 21:45:46 +02:00
html.find('.roll-attaque-brutale-arme').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollAttaqueBrutaleArme(armeId)
})
html.find('.roll-attaque-charge-arme').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollAttaqueChargeArme(armeId)
})
html.find('.roll-assomer-arme').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollAssomerArme(armeId)
})
2023-03-09 13:16:19 +01:00
html.find('.roll-pouvoir').click((event) => {
const li = $(event.currentTarget).parents(".item")
let pouvoirId = li.data("item-id")
this.actor.rollPouvoir(pouvoirId)
})
2024-03-23 11:37:15 +01:00
html.find('.dialog-recup-usage').click((event) => {
this.dialogRecupUsage()
})
2022-12-26 00:33:13 +01:00
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;
}
/* -------------------------------------------- */
2023-01-20 15:19:04 +01:00
/*async _onDropItem(event, dragData) {
2022-12-26 00:33:13 +01:00
let data = event.dataTransfer.getData('text/plain')
let dataItem = JSON.parse( data)
let item = fromUuidSync(dataItem.uuid)
if (item.pack) {
item = await HeritiersUtility.searchItem(item)
}
2023-01-20 15:19:04 +01:00
super._onDropItem(event, dragData)
}*/
2022-12-26 00:33:13 +01:00
}