forked from public/foundryvtt-reve-de-dragon
Fix: saisie des bonus de cases
This commit is contained in:
@ -13,6 +13,7 @@ import { Misc } from "./misc.js";
|
||||
import { RdDTimestamp } from "./time/rdd-timestamp.js";
|
||||
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
|
||||
import { ITEM_TYPES, RdDItem } from "./item.js";
|
||||
import { FLEUVE_COORD, TMRUtility } from "./tmr-utility.js";
|
||||
|
||||
/**
|
||||
* Extend the basic ItemSheet for RdD specific items
|
||||
@ -100,55 +101,59 @@ export class RdDItemSheet extends ItemSheet {
|
||||
descriptionmj: await TextEditor.enrichHTML(this.item.system.descriptionmj, { async: true }),
|
||||
isComestible: this.item.getUtilisationCuisine(),
|
||||
options: RdDSheetUtility.mergeDocumentRights(this.options, this.item, this.isEditable),
|
||||
competences: await SystemCompendiums.getCompetences('personnage'),
|
||||
categories: RdDItem.getCategories(this.item.type),
|
||||
}
|
||||
|
||||
if (this.item.type == ITEM_TYPES.competencecreature) {
|
||||
formData.isparade = RdDItemCompetenceCreature.isParade(this.item)
|
||||
formData.isdommages = RdDItemCompetenceCreature.isDommages(this.item)
|
||||
}
|
||||
|
||||
const competences = await SystemCompendiums.getCompetences('personnage');
|
||||
formData.categories = RdDItem.getCategories(this.item.type)
|
||||
if (this.item.type == 'tache' || this.item.type == 'livre' || this.item.type == 'meditation' || this.item.type == 'oeuvre') {
|
||||
if (this.item.type == ITEM_TYPES.tache ||
|
||||
this.item.type == ITEM_TYPES.livre ||
|
||||
this.item.type == ITEM_TYPES.meditation ||
|
||||
this.item.type == ITEM_TYPES.oeuvre) {
|
||||
formData.caracList = foundry.utils.duplicate(game.model.Actor.personnage.carac)
|
||||
formData.caracList["reve-actuel"] = foundry.utils.duplicate(game.model.Actor.personnage.reve.reve)
|
||||
formData.competences = competences;
|
||||
}
|
||||
if (this.item.type == 'arme') {
|
||||
formData.competences = competences.filter(it => it.isCompetenceArme())
|
||||
if (this.item.type == ITEM_TYPES.arme) {
|
||||
formData.competences = formData.competences.filter(it => it.isCompetenceArme())
|
||||
}
|
||||
if (['sort', 'sortreserve'].includes(this.item.type)) {
|
||||
formData.competences = competences.filter(it => RdDItemCompetence.isDraconic(it));
|
||||
}
|
||||
if (this.item.type == 'recettecuisine') {
|
||||
if (this.item.type == ITEM_TYPES.recettecuisine) {
|
||||
formData.ingredients = await TextEditor.enrichHTML(this.object.system.ingredients, { async: true })
|
||||
}
|
||||
if (this.item.type == 'extraitpoetique') {
|
||||
if (this.item.type == ITEM_TYPES.extraitpoetique) {
|
||||
formData.extrait = await TextEditor.enrichHTML(this.object.system.extrait, { async: true })
|
||||
formData.texte = await TextEditor.enrichHTML(this.object.system.texte, { async: true })
|
||||
}
|
||||
if (this.item.type == 'recettealchimique') {
|
||||
RdDAlchimie.processManipulation(this.item, this.actor && this.actor.id);
|
||||
if (this.item.type == ITEM_TYPES.recettealchimique) {
|
||||
RdDAlchimie.processManipulation(this.item, this.actor?.id);
|
||||
formData.manipulation_update = await TextEditor.enrichHTML(this.object.system.manipulation_update, { async: true })
|
||||
formData.utilisation = await TextEditor.enrichHTML(this.object.system.utilisation, { async: true })
|
||||
formData.enchantement = await TextEditor.enrichHTML(this.object.system.enchantement, { async: true })
|
||||
formData.sureffet = await TextEditor.enrichHTML(this.object.system.sureffet, { async: true })
|
||||
}
|
||||
if (this.item.type == 'gemme') {
|
||||
if (this.item.type == ITEM_TYPES.gemme) {
|
||||
formData.gemmeTypeList = RdDGemme.getGemmeTypeOptionList();
|
||||
RdDGemme.calculDataDerivees(this.item);
|
||||
RdDGemme.calculDataDerivees(this.item)
|
||||
}
|
||||
if (this.item.type == 'potion') {
|
||||
await RdDHerbes.addPotionFormData(formData);
|
||||
if (this.item.type == ITEM_TYPES.potion) {
|
||||
RdDHerbes.calculFormData(formData, this.item)
|
||||
}
|
||||
if (formData.options.isOwned && this.item.type == 'herbe' && (formData.system.categorie == 'Soin' || formData.system.categorie == 'Repos')) {
|
||||
formData.isIngredientPotionBase = true;
|
||||
if (this.item.type == ITEM_TYPES.herbe) {
|
||||
if (formData.options.isOwned && ['Soin', 'Repos'].includes(formData.system.categorie)) {
|
||||
formData.isIngredientPotionBase = true;
|
||||
}
|
||||
}
|
||||
if (this.item.type == 'sortreserve') {
|
||||
if (this.item.type == ITEM_TYPES.sortreserve) {
|
||||
const sortId = this.item.system.sortid;
|
||||
formData.competences = formData.competences.filter(it => RdDItemCompetence.isDraconic(it));
|
||||
formData.sort = formData.options.isOwned ? this.item.actor.items.get(sortId) : game.items.get(sortId);
|
||||
}
|
||||
formData.bonusCaseList = RdDItemSort.getBonusCaseList(formData, true);
|
||||
|
||||
if (this.item.type == ITEM_TYPES.sort) {
|
||||
formData.competences = formData.competences.filter(it => RdDItemCompetence.isDraconic(it));
|
||||
formData.bonusCaseList = RdDItemSort.getBonusCaseList(this.item);
|
||||
}
|
||||
return formData;
|
||||
}
|
||||
|
||||
@ -185,6 +190,9 @@ export class RdDItemSheet extends ItemSheet {
|
||||
}
|
||||
}
|
||||
})
|
||||
this.html.find('.delete-bonus-case').click((event) => {
|
||||
this.supprimerBonusCase(event.currentTarget.attributes['data-deleteCoord'].value)
|
||||
})
|
||||
|
||||
this.html.find('.date-enchantement').change((event) => {
|
||||
const jour = Number(this.html.find('input.date-enchantement[name="enchantement.jour"]').val());
|
||||
@ -264,23 +272,66 @@ export class RdDItemSheet extends ItemSheet {
|
||||
}
|
||||
}
|
||||
|
||||
async supprimerBonusCase(deleteCoord){
|
||||
if (this.item.type == ITEM_TYPES.sort) {
|
||||
const oldList = RdDItemSort.getBonusCaseList(this.item)
|
||||
const newList = oldList.filter(it => it.case != deleteCoord);
|
||||
if (newList.length != oldList.length) {
|
||||
await this.item.update({
|
||||
'system.bonuscase': RdDItemSort.bonuscasesToString(newList)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
_updateObject(event, formData) {
|
||||
switch (this.item.type) {
|
||||
case ITEM_TYPES.sort:
|
||||
// Données de bonus de cases ?
|
||||
formData['system.bonuscase'] = RdDItemSort.buildBonuscaseFromArrays(formData.bonusValue, formData.caseValue)
|
||||
formData['system.bonuscase'] = RdDItemSort.bonuscasesToString(RdDItemSheet._listCaseTmr(
|
||||
formData.caseTmrCoord,
|
||||
formData.caseTmrBonus,
|
||||
formData.caseTmrAdd
|
||||
))
|
||||
break
|
||||
case ITEM_TYPES.competence:
|
||||
if (formData['system.niveau'] == undefined) {
|
||||
formData['system.niveau'] = formData['system.base']
|
||||
}
|
||||
formData['system.niveau'] = formData.system.niveau ?? formData.system.base
|
||||
break
|
||||
}
|
||||
|
||||
return this.item.update(formData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/**
|
||||
* reconstruit les bonus de cases
|
||||
* @param {*} caseTmrCoord tableau des coordonées
|
||||
* @param {*} caseTmrBonus tableau des bonus
|
||||
* @param {*} caseTmrAdd case à ajouter
|
||||
* @returns list d'objets {coord, bonus}
|
||||
*/
|
||||
static _listCaseTmr(caseTmrCoord, caseTmrBonus, caseTmrAdd) {
|
||||
const listCaseTmrCoord = caseTmrCoord == undefined ? [] : Array.isArray(caseTmrCoord) ? caseTmrCoord : [caseTmrCoord]
|
||||
const listCaseTmrBonus = caseTmrBonus == undefined ? [] : Array.isArray(caseTmrBonus) ? caseTmrBonus : [caseTmrBonus]
|
||||
if (caseTmrAdd != undefined && caseTmrAdd != '' && TMRUtility.verifyTMRCoord(caseTmrAdd) && !listCaseTmrCoord.includes(caseTmrAdd)) {
|
||||
listCaseTmrCoord.push(TMRUtility.getTMR(caseTmrAdd).coord)
|
||||
listCaseTmrBonus.push(1)
|
||||
}
|
||||
|
||||
const list = [];
|
||||
const caseChecked = {};
|
||||
for (let i = 0; i < listCaseTmrBonus.length && i < listCaseTmrCoord.length; i++) {
|
||||
const coord = listCaseTmrCoord[i] == FLEUVE_COORD ? FLEUVE_COORD : (listCaseTmrCoord[i]?.toUpperCase() ?? 'A1')
|
||||
const bonus = listCaseTmrBonus[i] ?? 0
|
||||
if (TMRUtility.verifyTMRCoord(coord) && bonus >= 0 && !caseChecked[coord]) {
|
||||
caseChecked[coord] = coord
|
||||
list.push({ case: coord, bonus: bonus })
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDragStart(event) {
|
||||
}
|
||||
|
Reference in New Issue
Block a user