import { ITEM_TYPES } from "../constants.js" import { CARACS } from "../rdd-carac.js" import { ROLL_TYPE_CUISINE } from "./roll-constants.mjs" import { PART_CARAC } from "./roll-part-carac.mjs" import { PART_COMP } from "./roll-part-comp.mjs" import { RollPartSelect } from "./roll-part-select.mjs" import { ROLLDIALOG_SECTION } from "./roll-part.mjs" export const PART_CUISINE = "cuisine" export class RollPartCuisine extends RollPartSelect { onReady() { foundry.applications.handlebars.loadTemplates({ 'roll-oeuvre-recettecuisine': `systems/foundryvtt-reve-de-dragon/templates/roll/roll-oeuvre-recettecuisine.hbs` }) } get code() { return PART_CUISINE } get section() { return ROLLDIALOG_SECTION.CHOIX } isValid(rollData) { return rollData.active.actor.isPersonnage() } visible(rollData) { return this.isRollType(rollData, ROLL_TYPE_CUISINE) } loadRefs(rollData) { const refs = this.getRefs(rollData) refs.recettes = rollData.active.actor.items .filter(it => it.type == ITEM_TYPES.recettecuisine) .map(it => RollPartCuisine.$extractRecette(it, rollData.active.actor)) if (refs.recettes.length > 0) { this.$selectRecette(rollData) } } choices(refs) { return refs.recettes } static $extractRecette(recette, actor) { return { key: recette.id, label: recette.name, caracs: RollPartCuisine.getCaracs(recette), qualite: recette.system.niveau, value: -recette.system.niveau, recette: recette, comp: actor.getCompetence('Cuisine') } } static getCaracs(recette){ // TODO: permettre différentes caractéristiques pour la cuisine? return [CARACS.ODORATGOUT, CARACS.EMPATHIE, CARACS.DEXTERITE] } $selectRecette(rollData, key) { this.selectByKey(rollData, key, 0) } async _onRender(rollDialog, context, options) { const selectRecette = rollDialog.element.querySelector(`roll-section[name="${this.code}"] select[name="select-recette"]`) selectRecette.addEventListener("change", e => { const selectOptions = e.currentTarget.options const index = selectOptions.selectedIndex this.$selectRecette(rollDialog.rollData, selectOptions[index]?.value) rollDialog.render() }) } impactOtherPart(part, rollData) { if (this.visible(rollData)) { const current = this.getCurrent(rollData) switch (part.code) { case PART_CARAC: return part.filterCaracs(rollData, current.caracs) case PART_COMP: return part.filterComps(rollData, [current.comp?.name]) } } return undefined } }