Roll V2: cuisine
This commit is contained in:
@@ -19,55 +19,153 @@ export class RollPartCuisine extends RollPartSelect {
|
||||
isValid(rollData) { return rollData.active.actor.isPersonnage() }
|
||||
visible(rollData) { return this.isRollType(rollData, ROLL_TYPE_CUISINE) }
|
||||
|
||||
restore(rollData) {
|
||||
super.restore(rollData)
|
||||
this.$restoreSavedOptions(rollData)
|
||||
}
|
||||
|
||||
store(rollData, targetData) {
|
||||
const current = this.getCurrent(rollData)
|
||||
this.setSaved(targetData, {
|
||||
key: current.key,
|
||||
fabriquer: current.fabriquer,
|
||||
proportions: current.proportions,
|
||||
value: current.value,
|
||||
})
|
||||
}
|
||||
|
||||
loadRefs(rollData) {
|
||||
const refs = this.getRefs(rollData)
|
||||
refs.recettes = rollData.active.actor.items
|
||||
const actor = rollData.active.actor
|
||||
refs.cuisine = actor.getCompetence('Cuisine')
|
||||
|
||||
const recettes = 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)
|
||||
.map(RollPartCuisine.$extractPreparationRecette)
|
||||
|
||||
const ingredientsBruts = actor.items
|
||||
.filter(it => it.getUtilisationCuisine() == 'brut')
|
||||
.map(RollPartCuisine.$extractPreparationBrut)
|
||||
|
||||
refs.preparations = [RollPartCuisine.$preparationBasique(), ...recettes, ...ingredientsBruts]
|
||||
refs.preparations.forEach(p => p.comp = refs.cuisine)
|
||||
if (refs.preparations.length > 0) {
|
||||
this.$selectPreparation(rollData)
|
||||
this.$restoreSavedOptions(rollData)
|
||||
}
|
||||
}
|
||||
|
||||
choices(refs) { return refs.recettes }
|
||||
$restoreSavedOptions(rollData) {
|
||||
const saved = this.getSaved(rollData)
|
||||
const current = this.getCurrent(rollData)
|
||||
if (saved.fabriquer != undefined) {
|
||||
current.fabriquer = saved.fabriquer
|
||||
}
|
||||
if (saved.proportions != undefined) {
|
||||
current.proportions = saved.proportions
|
||||
}
|
||||
if (saved.value != undefined) {
|
||||
current.value = saved.value
|
||||
}
|
||||
}
|
||||
|
||||
static $extractRecette(recette, actor) {
|
||||
choices(refs) { return refs.preparations }
|
||||
|
||||
static $preparationBasique() {
|
||||
return {
|
||||
key: '',
|
||||
label: "Improvisation du moment",
|
||||
img: RollPartCuisine.$getImgIngredient(),
|
||||
sust: 1,
|
||||
exotisme: 0,
|
||||
ingredients: "Ce qu'il y a sous la main",
|
||||
proportions: 8,
|
||||
proportionsMax: 50,
|
||||
value: 0,
|
||||
fabriquer: false,
|
||||
}
|
||||
}
|
||||
|
||||
static $extractPreparationRecette(recette) {
|
||||
const proportions = recette.system.sust ?? 1
|
||||
return {
|
||||
key: recette.id,
|
||||
label: recette.name,
|
||||
caracs: RollPartCuisine.getCaracs(recette),
|
||||
qualite: recette.system.niveau,
|
||||
img: 'systems/foundryvtt-reve-de-dragon/icons/cuisine/ragout.svg',
|
||||
sust: 1,
|
||||
exotisme: recette.system.exotisme,
|
||||
ingredients: recette.system.ingredients,
|
||||
proportions: proportions,
|
||||
proportionsMax: proportions * 10,
|
||||
value: -recette.system.niveau,
|
||||
recette: recette,
|
||||
comp: actor.getCompetence('Cuisine')
|
||||
fabriquer: true,
|
||||
}
|
||||
}
|
||||
static getCaracs(recette){
|
||||
// TODO: permettre différentes caractéristiques pour la cuisine?
|
||||
return [CARACS.ODORATGOUT, CARACS.EMPATHIE, CARACS.DEXTERITE]
|
||||
|
||||
static $extractPreparationBrut(ingredient) {
|
||||
return {
|
||||
key: ingredient.id,
|
||||
label: ingredient.name + ' cuisiné',
|
||||
img: RollPartCuisine.$getImgIngredient(ingredient.type),
|
||||
sust: ingredient.system.sust ?? 1,
|
||||
exotisme: ingredient.system.exotisme,
|
||||
ingredients: ingredient.name,
|
||||
proportions: Math.min(10, ingredient.system.quantite),
|
||||
proportionsMax: Math.min(50, ingredient.system.quantite),
|
||||
value: 0,
|
||||
ingredient: ingredient,
|
||||
fabriquer: true,
|
||||
}
|
||||
}
|
||||
|
||||
$selectRecette(rollData, key) {
|
||||
static $getImgIngredient(type = ITEM_TYPES.ingredient) {
|
||||
switch (type) {
|
||||
case ITEM_TYPES.herbe:
|
||||
case ITEM_TYPES.plante:
|
||||
return `systems/foundryvtt-reve-de-dragon/icons/cuisine/${type}.svg`
|
||||
case ITEM_TYPES.faune:
|
||||
return 'systems/foundryvtt-reve-de-dragon/icons/cuisine/gibier.svg'
|
||||
}
|
||||
return 'systems/foundryvtt-reve-de-dragon/icons/cuisine/ragout.svg'
|
||||
}
|
||||
|
||||
$selectPreparation(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"]`)
|
||||
const current = this.getCurrent(rollDialog.rollData)
|
||||
|
||||
selectRecette.addEventListener("change", e => {
|
||||
const selectPreparation = rollDialog.element.querySelector(`roll-section[name="${this.code}"] select[name="select-preparation"]`)
|
||||
const inputDiff = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="diff-var"]`)
|
||||
const checkboxFabriquer = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="fabriquer"]`)
|
||||
const inputProportions = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="proportions"]`)
|
||||
|
||||
selectPreparation.addEventListener("change", e => {
|
||||
const selectOptions = e.currentTarget.options
|
||||
const index = selectOptions.selectedIndex
|
||||
this.$selectRecette(rollDialog.rollData, selectOptions[index]?.value)
|
||||
this.$selectPreparation(rollDialog.rollData, selectOptions[index]?.value)
|
||||
rollDialog.render()
|
||||
})
|
||||
|
||||
checkboxFabriquer?.addEventListener("change", e => {
|
||||
current.fabriquer = e.currentTarget.checked
|
||||
})
|
||||
inputDiff?.addEventListener("change", e => {
|
||||
current.value = parseInt(e.currentTarget.value)
|
||||
})
|
||||
inputProportions?.addEventListener("change", e => {
|
||||
current.proportions = parseInt(e.currentTarget.value)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
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])
|
||||
case PART_CARAC: return part.filterCaracs(rollData, [CARACS.ODORATGOUT])
|
||||
case PART_COMP: return part.filterComps(rollData, [this.getRefs(rollData).cuisine.name])
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
|
Reference in New Issue
Block a user