diff --git a/module/actor.js b/module/actor.js index fe8eea8c..ebdc2e7d 100644 --- a/module/actor.js +++ b/module/actor.js @@ -46,7 +46,7 @@ import { PAS_DE_DRACONIC, POSSESSION_SANS_DRACONIC } from "./item/base-items.js" import { RdDRollResult } from "./rdd-roll-result.js"; import { RdDInitiative } from "./initiative.mjs"; import RollDialog from "./roll/roll-dialog.mjs"; -import { OptionsAvancees, ROLL_DIALOG_V2 } from "./settings/options-avancees.js"; +import { OptionsAvancees, ROLL_DIALOG_V2, ROLL_DIALOG_V2_TEST } from "./settings/options-avancees.js"; export const MAINS_DIRECTRICES = ['Droitier', 'Gaucher', 'Ambidextre'] @@ -3049,7 +3049,7 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ - async _rollArtV2(oeuvreId, callbackAction = async (rd) => await this._resultArtV2(rd)) { + async _rollArtV2(oeuvreId) { const oeuvre = this.items.get(oeuvreId) const rollData = { title: `Interpretation de ${oeuvre.name} par ${this.name}`, @@ -3066,23 +3066,12 @@ export class RdDActor extends RdDBaseActorSang { } await RollDialog.create(rollData, { onRollDone: (dialog) => { - this._onCloseRollDialog() - dialog.close() - }, - customChatMessage: true, - callbacks: [callbackAction] + if (!OptionsAvancees.isUsing(ROLL_DIALOG_V2_TEST)) + dialog.close() + } }) } - // TODO: move vers ChatRollResult - async _resultArtV2(artData) { - const niveau = artData.oeuvre.system.niveau ?? 0 - const baseQualite = (artData.rolled.isSuccess ? niveau : artData.competence.system.niveau) - artData.qualiteFinale = Math.min(baseQualite, niveau) + artData.rolled.ptQualite - //this.$onRollCompetence(artData) - await RdDRollResult.displayRollData(artData, this.name, `chat-resultat-${artData.art}.hbs`) - } - /* -------------------------------------------- */ async rollOeuvre(id) { if (OptionsAvancees.isUsing(ROLL_DIALOG_V2)) { diff --git a/module/chat-utility.js b/module/chat-utility.js index 83a749c1..c1649e3c 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -197,8 +197,12 @@ export class ChatUtility { static async onCreateChatMessage(chatMessage, options, id) { if (chatMessage.isAuthor) { - await chatMessage.setFlag(SYSTEM_RDD, 'rdd-timestamp', game.system.rdd.calendrier.getTimestamp()); + await ChatUtility.setTimestamp(chatMessage) await chatMessage.update({ content: await RdDTextEditor.enrichHTML(chatMessage.content, undefined, { showLink: false }) }) } } + + static async setTimestamp(chatMessage) { + await chatMessage.setFlag(SYSTEM_RDD, 'rdd-timestamp', game.system.rdd.calendrier.getTimestamp()); + } } diff --git a/module/misc.js b/module/misc.js index 9b43636d..ac0e933a 100644 --- a/module/misc.js +++ b/module/misc.js @@ -34,6 +34,9 @@ export class Misc { return ((n % m) + m) % m; } + static inRange(value, min,max){ + return Math.max(min, Math.min(value, max)) + } static sum() { return (a, b) => Number(a) + Number(b); } diff --git a/module/rdd-bonus.js b/module/rdd-bonus.js index 8fa1a4d0..54dbadca 100644 --- a/module/rdd-bonus.js +++ b/module/rdd-bonus.js @@ -36,7 +36,7 @@ export class RdDBonus { /* -------------------------------------------- */ static dmg(rollData, actor, isEntiteIncarnee = false) { const dmgArme = RdDBonus.dmgArme(rollData.arme, rollData.arme?.system.dommagesReels) - const forceRequise = RdDItemArme.valeurMain(rollData.arme?.system.force ?? 0, RdDItemArme.getMainAttaque(rollData.competence)) + const forceRequise = rollData.arme ? RdDItemArme.valeurMain(rollData.arme.system.force ?? 0, RdDItemArme.getMainAttaque(rollData.competence)) : 0 let dmg = { total: 0, dmgArme: dmgArme, diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 026285de..08b35d61 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -18,7 +18,8 @@ import { RdDInitiative } from "./initiative.mjs"; import RollDialog from "./roll/roll-dialog.mjs"; import { PART_DEFENSE } from "./roll/roll-part-defense.mjs"; import { RollDialogAdapter } from "./roll/roll-dialog-adapter.mjs"; -import { DIFF, ROLL_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE } from "./roll/roll-constants.mjs"; +import { ROLL_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE } from "./roll/roll-constants.mjs"; +import { OptionsAvancees, ROLL_DIALOG_V2_TEST } from "./settings/options-avancees.js"; /* -------------------------------------------- */ const premierRoundInit = [ @@ -402,19 +403,19 @@ export class RdDCombat { /* -------------------------------------------- */ static registerChatCallbacks(html) { for (let button of [ - '.defense-button', - '.parer-button', - '.esquiver-button', + '.button-defense', + '.button-parade', + '.button-esquive', + '.button-encaisser', '.particuliere-attaque', - '.encaisser-button', '.appel-chance-defense', '.appel-destinee-defense', '.appel-chance-attaque', '.appel-destinee-attaque', '.echec-total-attaque', - '.appel-chance', - '.chat-encaissement', - '.resister-recul', + // '.appel-chance', + // '.chat-encaissement', + // '.resister-recul', ]) { $(html).on("click", button, event => { const rddCombat = RdDCombat.rddCombatForAttackerAndDefender( @@ -474,11 +475,11 @@ export class RdDCombat { switch (button) { case '.particuliere-attaque': return await this.choixParticuliere(attackerRoll, event.currentTarget.attributes['data-mode'].value); - case '.defense-button': return this.defenseV2(attackerRoll); + case '.button-defense': return this.defenseV2(attackerRoll); - case '.parer-button': return this.parade(attackerRoll, armeParadeId); - case '.esquiver-button': return this.esquive(attackerRoll, compId, competence); - case '.encaisser-button': return this.encaisser(attackerRoll, defenderRoll); + case '.button-parade': return this.parade(attackerRoll, armeParadeId); + case '.button-esquive': return this.esquive(attackerRoll, compId, competence); + case '.button-encaisser': return this.encaisser(attackerRoll, defenderRoll); case '.echec-total-attaque': return this._onEchecTotal(attackerRoll); case '.appel-chance-attaque': return this.attacker.rollAppelChance( @@ -488,11 +489,9 @@ export class RdDCombat { () => this.defenseChanceuse(attackerRoll, defenderRoll), () => this.afficherOptionsDefense(attackerRoll, defenderRoll, { defenseChance: true })); case '.appel-destinee-attaque': return this.attacker.appelDestinee( - () => this.attaqueSignificative(attackerRoll), - () => { }); + () => this.attaqueSignificative(attackerRoll)); case '.appel-destinee-defense': return this.defender.appelDestinee( - () => this.defenseDestinee(defenderRoll), - () => { }); + () => this.defenseDestinee(defenderRoll)); } } @@ -969,10 +968,8 @@ export class RdDCombat { } async defenseV2(attackerRoll) { - // this._prepareParade(attackerRoll, arme, competence); - const rollData = - { + await this.doRollDefense({ ids: { actorId: this.defender.id, actorTokenId: this.defenderTokenId, @@ -982,24 +979,26 @@ export class RdDCombat { type: { allowed: ['defense'], current: 'defense' }, attackerRoll: RollDialogAdapter.mapActionAttaque(attackerRoll), passeArme: attackerRoll.passeArme, - } - - await RollDialog.create(rollData, { - onRollDone: (dialog) => { - // dialog.close() - }, - customChatMessage: true, - callbacks: [async (roll) => { - this.removeChatMessageActionsPasseArme(roll.passeArme) - // defense: esquive / arme de parade / competence de défense - if (!RdDCombat.isParticuliere(roll)) { - await roll.active.actor.incDecItemUse(roll.current[PART_DEFENSE].defense?.id,) - } - await this._onDefense(roll) - }] }) } + async doRollDefense(rollData) { + await RollDialog.create(rollData, { + onRollDone: (dialog) => { + if (!OptionsAvancees.isUsing(ROLL_DIALOG_V2_TEST)) + dialog.close() + }, + customChatMessage: true, + callbacks: [async (roll) => { + this.removeChatMessageActionsPasseArme(roll.passeArme); + // defense: esquive / arme de parade / competence de défense + if (!RdDCombat.isParticuliere(roll)) { + await roll.active.actor.incDecItemUse(roll.current[PART_DEFENSE].defense?.id); + } + await this._onDefense(roll); + }] + }) + } /* -------------------------------------------- */ _prepareParade(attackerRoll, armeParade, competenceParade) { @@ -1369,6 +1368,3 @@ export class RdDCombat { } } -function newFunction(attackerRoll) { - return attackerRoll.diffLibre; -} diff --git a/module/rdd-main.js b/module/rdd-main.js index e08389af..4408de30 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -86,6 +86,7 @@ import { RdDCombatManager, RdDCombat } from "./rdd-combat.js" import { Migrations } from './migrations.js' import RollDialog from "./roll/roll-dialog.mjs" +import ChatRollResult from "./roll/chat-roll-result.mjs" /** * RdD system @@ -292,6 +293,7 @@ export class SystemReveDeDragon { TMRRencontres.init() ExportScriptarium.init() RollDialog.init() + ChatRollResult.init() } initSettings() { @@ -346,18 +348,7 @@ export class SystemReveDeDragon { }) } - static async setupAccueil() { - let exists = game.scenes.find(j => j.name == "Accueil RdD"); - if (!exists) { - const scenes = await SystemCompendiums.loadCompendium("foundryvtt-reve-de-dragon.scenes-rdd") - let newDocuments = scenes.filter(i => i.name == "Accueil RdD"); - await game.scenes.documentClass.create(newDocuments); - game.scenes.find(i => i.name == "Accueil RdD").activate(); - } - } - async onReady() { - /* -------------------------------------------- */ /* Foundry VTT Initialization */ /* -------------------------------------------- */ @@ -376,7 +367,8 @@ export class SystemReveDeDragon { StatusEffects.onReady() RdDDice.onReady() RollDialog.onReady() - RdDStatBlockParser.parseStatBlock() + ChatRollResult.onReady() + /* -------------------------------------------- */ /* Affiche/Init le calendrier */ game.system.rdd.calendrier.display() @@ -389,7 +381,17 @@ export class SystemReveDeDragon { }) } - SystemReveDeDragon.setupAccueil() + this.setupAccueil() + } + + async setupAccueil() { + let exists = game.scenes.find(j => j.name == "Accueil RdD"); + if (!exists) { + const scenes = await SystemCompendiums.loadCompendium("foundryvtt-reve-de-dragon.scenes-rdd") + let newDocuments = scenes.filter(i => i.name == "Accueil RdD"); + await game.scenes.documentClass.create(newDocuments); + game.scenes.find(i => i.name == "Accueil RdD").activate(); + } } /* -------------------------------------------- */ diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 83d5b783..99d51688 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -157,7 +157,7 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static significativeRequise(chances) { - chances.roll = Math.floor(chances.score / 2); + chances.roll = Math.min(chances.part + 1, chances.sign) foundry.utils.mergeObject(chances, reussites.find(x => x.code == 'sign'), { overwrite: true }); } @@ -188,7 +188,7 @@ export class RdDResolutionTable { static computeReussite(chances, roll, diviseur) { const reussite = reussites.find(x => x.condition(chances, roll)) if (diviseur > 1 && reussite.isSuccess) { - if (chances > roll * diviseur){ + if (chances > roll * diviseur) { return reussiteInsuffisante } } diff --git a/module/roll/chat-roll-result.mjs b/module/roll/chat-roll-result.mjs index 270785bf..7eedd29e 100644 --- a/module/roll/chat-roll-result.mjs +++ b/module/roll/chat-roll-result.mjs @@ -1,8 +1,16 @@ import { ChatUtility } from "../chat-utility.js" import RollDialog from "./roll-dialog.mjs" -import { RdDCarac } from "../rdd-carac.js"; +import { RdDCarac } from "../rdd-carac.js" +import { RdDCombat } from "../rdd-combat.js" +import { ROLL_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE } from "./roll-constants.mjs" +import { RdDResolutionTable } from "../rdd-resolution-table.js" -export class ChatRollResult { +export default class ChatRollResult { + static init() { + ChatRollResult.instance = new ChatRollResult() + + Hooks.on('renderChatLog', (log, html, chatLog) => ChatRollResult.instance.chatListeners(html)) + } static onReady() { foundry.applications.handlebars.loadTemplates({ @@ -14,10 +22,7 @@ export class ChatRollResult { } async display(roll) { - roll.show = roll.show || {}; - roll.show.chance = this.isAppelChancePossible(roll) - roll.show.encaissement = this.isShowEncaissement(roll) - roll.show.recul = this.isShowReculChoc(roll) + this.prepareDisplay(roll) const chatMessage = await ChatUtility.createChatWithRollMode( { @@ -26,14 +31,18 @@ export class ChatRollResult { roll.active.actor, roll.current?.rollmode?.key ) - if (roll.show.chance) { - const save = RollDialog.saveParts(roll) - console.log("Store message roll", save) - ChatUtility.setMessageData(chatMessage, 'rollData', save) - } + const save = RollDialog.saveParts(roll) + ChatUtility.setMessageData(chatMessage, 'rollData', save) return chatMessage } + prepareDisplay(roll) { + roll.show = roll.show || {} + roll.show.chance = this.isAppelChancePossible(roll) + roll.show.encaissement = this.isShowEncaissement(roll) + roll.show.recul = this.isShowReculChoc(roll) + } + isAppelChancePossible(roll) { return roll.active.actor.isPersonnage() && roll.rolled.isEchec && @@ -46,14 +55,87 @@ export class ChatRollResult { } isShowReculChoc(roll) { - return roll.rolled.isEchec && - roll.attackerRoll && - !roll.current.defense.isEsquive && - (roll.attackerRoll.particuliere == 'force' || 'charge' == attackerRoll.tactique?.key) + const attaque = roll.attackerRoll + return attaque && + (roll.rolled.isEchec || !roll.current.defense.isEsquive) && + (attaque.particuliere == 'force' || 'charge' == attaque.tactique?.key) } async buildRollHtml(roll) { const template = `systems/foundryvtt-reve-de-dragon/templates/roll/result/chat-${roll.type.current}.hbs` return await foundry.applications.handlebars.renderTemplate(template, roll) } + + async chatListeners(html) { + $(html).on("click", '.appel-chance', event => this.onClickAppelChance(event)) + $(html).on("click", '.appel-destinee', event => this.onClickAppelDestinee(event)) + } + + onClickAppelChance(event) { + const chatMessage = ChatUtility.getChatMessage(event) + const savedRoll = ChatUtility.getMessageData(chatMessage, 'rollData') + const actor = game.actors.get(savedRoll.ids.actorId) + actor.rollAppelChance( + () => this.onAppelChanceSuccess(savedRoll, chatMessage), + () => this.onAppelChanceEchec(savedRoll, chatMessage)) + event.preventDefault() + } + + getCombat(roll) { + switch (roll.type.current) { + case ROLL_TYPE_DEFENSE: + return RdDCombat.rddCombatForAttackerAndDefender(roll.ids.opponentId, roll.ids.opponentTokenId, roll.ids.actorId) + case ROLL_TYPE_ATTAQUE: + return RdDCombat.rddCombatForAttackerAndDefender(roll.ids.actorId, roll.ids.actorTokenId, roll.ids.opponentId) + } + return undefined + } + + onAppelChanceSuccess(savedRoll, chatMessage) { + const reRoll = foundry.utils.duplicate(savedRoll) + reRoll.type.retry = true + // TODO: annuler les effets + switch (reRoll.type.current) { + case ROLL_TYPE_DEFENSE: + this.getCombat(reRoll)?.doRollDefense(reRoll) + break + case ROLL_TYPE_ATTAQUE: + this.getCombat(reRoll)?.doRollAttaque(reRoll) + break + default: { + RollDialog.create(reRoll) + } + } + ChatUtility.removeChatMessageId(chatMessage.id) + } + + async onAppelChanceEchec(savedRoll, chatMessage) { + savedRoll.type.retry = true + await this.updateChatMessage(chatMessage, savedRoll) + } + + async updateChatMessage(chatMessage, savedRoll) { + ChatUtility.setMessageData(chatMessage, 'rollData', savedRoll) + const copy = foundry.utils.duplicate(savedRoll) + RollDialog.loadRollData(copy) + this.prepareDisplay(copy) + chatMessage.update({ content: await this.buildRollHtml(copy) }) + chatMessage.render(true) + } + + onClickAppelDestinee(event) { + const chatMessage = ChatUtility.getChatMessage(event) + const savedRoll = ChatUtility.getMessageData(chatMessage, 'rollData') + const actor = game.actors.get(savedRoll.ids.actorId) + + actor.appelDestinee(async () => { + const reRoll = foundry.utils.duplicate(savedRoll) + reRoll.type.retry = true + RdDResolutionTable.significativeRequise(reRoll.rolled) + await this.updateChatMessage(chatMessage, savedRoll) + }) + event.preventDefault() + } + + } \ No newline at end of file diff --git a/module/roll/roll-basic-parts.mjs b/module/roll/roll-basic-parts.mjs index 212462b5..3a1c5746 100644 --- a/module/roll/roll-basic-parts.mjs +++ b/module/roll/roll-basic-parts.mjs @@ -41,9 +41,7 @@ export class RollBasicParts { initFrom(rollData) { return { selected: {}, - type: { - current: rollData.type.current - }, + type: rollData.type, ids: { sceneId: rollData.ids.sceneId, actorId: rollData.active.id, diff --git a/module/roll/roll-dialog.mjs b/module/roll/roll-dialog.mjs index 1bd6b6b4..0e9df824 100644 --- a/module/roll/roll-dialog.mjs +++ b/module/roll/roll-dialog.mjs @@ -25,7 +25,7 @@ import { RollPartMeditation } from "./roll-part-meditation.mjs"; import { RollPartMoral } from "./roll-part-moral.mjs"; import { RollPartOpponent } from "./roll-part-opponent.mjs"; import { RollPartSurEnc } from "./roll-part-surenc.mjs"; -import { RollPartTricher } from "./roll-part-tricher.mjs"; +import { PART_TRICHER, RollPartTricher } from "./roll-part-tricher.mjs"; import { RollPartTache } from "./roll-part-tache.mjs"; import { RollPartOeuvre } from "./roll-part-oeuvre.mjs"; import { RollPartSort } from "./roll-part-sort.mjs"; @@ -38,7 +38,7 @@ import { RollPartDefense } from "./roll-part-defense.mjs"; import { RollDialogAdapter } from "./roll-dialog-adapter.mjs"; import { ROLLDIALOG_SECTION } from "./roll-part.mjs"; import { ROLL_TYPE_COMP } from "./roll-constants.mjs"; -import { ChatRollResult } from "./chat-roll-result.mjs"; +import ChatRollResult from "./chat-roll-result.mjs"; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api @@ -286,6 +286,8 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 ROLL_PARTS.filter(p => p.isActive(rollData)) .forEach(p => p.storeClean(rollData, target)) target.attackerRoll = rollData.attackerRoll + target.rolled = rollData.rolled + target.result = rollData.result return target } @@ -317,8 +319,8 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 } - getActiveParts() { - return ROLL_PARTS.filter(p => p.isActive(this.rollData)) + static getActiveParts(rollData) { + return ROLL_PARTS.filter(p => p.isActive(rollData)) } // get title() { @@ -353,12 +355,12 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 )) Promise.all( - this.getActiveParts().map(async p => await p._onRender(this, context, options)) + RollDialog.getActiveParts(this.rollData).map(async p => await p._onRender(this, context, options)) ) } - getAjustements(rollData = this.rollData) { - return this.getActiveParts() + static getAjustements(rollData) { + return RollDialog.getActiveParts(rollData) .map(p => p.getAjustements(rollData)) .reduce((a, b) => a.concat(b)) .sort((a, b) => a.diff == undefined ? 1 : b.diff == undefined ? -1 : 0) @@ -373,19 +375,19 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 const types = ALL_ROLL_TYPES.filter(m => m.isAllowed(rollData) && m.visible(rollData)) .map(m => m.toTypeData(rollData)) - BASIC_PARTS.loadSurprises(this.rollData, this.getSelectedType().code) - this.rollData.type.label = this.getSelectedType()?.title(this.rollData) + BASIC_PARTS.loadSurprises(rollData, this.getSelectedType().code) + rollData.type.label = this.getSelectedType()?.title(rollData) //TOCHECK: set type.label ? - const visibleRollParts = this.getActiveParts() + const visibleRollParts = RollDialog.getActiveParts(rollData) visibleRollParts.forEach(p => p.applyExternalImpacts(visibleRollParts, rollData)) this.setSpecialComp(visibleRollParts); visibleRollParts.forEach(p => p.prepareContext(rollData)) - this.calculAjustements() + RollDialog.calculAjustements(rollData) - const templates = this.getActiveParts().map(p => p.toTemplateData()) + const templates = RollDialog.getActiveParts(rollData).map(p => p.toTemplateData()) const context = await super._prepareContext() return foundry.utils.mergeObject( { @@ -399,14 +401,14 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 const specialComp = visibleRollParts.map(p => p.getSpecialComp(this.rollData)) .reduce((a, b) => a.concat(b)) if (specialComp.length > 0) { - const rollPartComp = this.getActiveParts() + const rollPartComp = RollDialog.getActiveParts(this.rollData) .find(it => it.code == PART_COMP); rollPartComp?.setSpecialComp(this.rollData, specialComp) } } - calculAjustements(rollData = this.rollData) { - rollData.ajustements = this.getAjustements(rollData) + static calculAjustements(rollData) { + rollData.ajustements = RollDialog.getAjustements(rollData) rollData.ajustements.forEach(it => it.isDiff = it.diff != undefined) rollData.current.totaldiff = rollData.ajustements .map(adj => adj.diff) @@ -419,12 +421,12 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 } async roll() { + // ROLL_PARTS.filter(p => p.isActive(this.rollData)) + // .forEach(p => p.validate(this.rollData)) const roll = RollDialog.saveParts(this.rollData) - RollDialog.$prepareRollData(roll) - this.calculAjustements(roll) - roll.current.resultat = this.rollData.current.resultat - roll.v2 = true + RollDialog.loadRollData(roll) + roll.current.resultat = this.rollData.current[PART_TRICHER]?.resultat ?? -1 roll.rolled = await this.$rollDice(roll) roll.result = this.getSelectedType(roll).getResult(roll) console.info('RollDialog.roll:', roll) @@ -434,12 +436,18 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 this.rollOptions.onRollDone(this) } + static loadRollData(roll) { + RollDialog.$prepareRollData(roll) + RollDialog.calculAjustements(roll) + roll.v2 = true + } + async defaultCallback(rollData, rolled) { await rollData.active.actor.appliquerAjoutExperience(rollData) await rollData.active.actor.appliquerAppelMoral(rollData) } async $rollDice(rollData) { - return await RollDialogAdapter.rollDice(rollData, this.rollTitle(rollData)); + return await RollDialogAdapter.rollDice(rollData, this.rollTitle(rollData)) } } diff --git a/module/roll/roll-part-conditions.mjs b/module/roll/roll-part-conditions.mjs index d686b047..909d7233 100644 --- a/module/roll/roll-part-conditions.mjs +++ b/module/roll/roll-part-conditions.mjs @@ -1,4 +1,5 @@ import { SYSTEM_RDD } from "../constants.js"; +import { Misc } from "../misc.js"; import { ROLLDIALOG_SECTION, RollPart } from "./roll-part.mjs"; const CONDITIONS = "conditions" @@ -50,7 +51,7 @@ export class RollPartConditions extends RollPart { const current = this.getCurrent(rollData) current.min = game.settings.get(SYSTEM_RDD, this.settingMin()) current.max = game.settings.get(SYSTEM_RDD, this.settingMax()) - current.value = current.value ?? 0 + current.value = Misc.inRange(current.value ?? 0, current.min, current.max) } getAjustements(rollData) { @@ -63,12 +64,13 @@ export class RollPartConditions extends RollPart { async _onRender(rollDialog, context, options) { const input = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="${this.code}"]`) - - input?.addEventListener("change", e => { - const current = this.getCurrent(rollDialog.rollData) - current.value = parseInt(e.currentTarget.value) - rollDialog.render() - }) + + input?.addEventListener("input", e => this.onInputChange(e, rollDialog)) + } + + onInputChange(event, rollDialog) { + this.getCurrent(rollDialog.rollData).value = parseInt(event.currentTarget.value) + rollDialog.render() } } \ No newline at end of file diff --git a/module/roll/roll-part-diff.mjs b/module/roll/roll-part-diff.mjs index d4af6449..8ec99049 100644 --- a/module/roll/roll-part-diff.mjs +++ b/module/roll/roll-part-diff.mjs @@ -1,5 +1,6 @@ import { DIFF, DIFFS, ROLL_TYPE_MEDITATION, ROLL_TYPE_OEUVRE, ROLL_TYPE_SORT, ROLL_TYPE_TACHE } from "./roll-constants.mjs"; import { ROLLDIALOG_SECTION, RollPart } from "./roll-part.mjs"; +import { Misc } from "../misc.js"; export const PART_DIFF = "diff" @@ -41,8 +42,8 @@ export class RollPartDiff extends RollPart { { type: diffType.key, label: diffType?.label ?? '', - value: current.value ?? 0, disabled: !diffType.libre, + value: Misc.inRange(current.value ?? 0, -10, diffType.max), min: -10, max: diffType.max }, @@ -67,11 +68,12 @@ export class RollPartDiff extends RollPart { async _onRender(rollDialog, context, options) { const input = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="${this.code}"]`) - input?.addEventListener("change", e => { - this.getCurrent(rollDialog.rollData).value = parseInt(e.currentTarget.value) - rollDialog.render() - }) + input?.addEventListener("input", e => this.onInputChange(e, rollDialog)) } + onInputChange(event, rollDialog) { + this.getCurrent(rollDialog.rollData).value = parseInt(event.currentTarget.value) + rollDialog.render() + } } \ No newline at end of file diff --git a/module/roll/roll-part-tricher.mjs b/module/roll/roll-part-tricher.mjs index 9ea83617..c0e869c8 100644 --- a/module/roll/roll-part-tricher.mjs +++ b/module/roll/roll-part-tricher.mjs @@ -1,3 +1,4 @@ +import { Misc } from "../misc.js" import { ROLLDIALOG_SECTION, RollPart } from "./roll-part.mjs" export const PART_TRICHER = "tricher" @@ -11,21 +12,20 @@ export class RollPartTricher extends RollPart { prepareContext(rollData) { const current = this.getCurrent(rollData) - if (current.resultat == undefined) { - current.resultat = -1 - } + current.resultat = Misc.inRange(current.resultat == undefined ? -1 : current.resultat, -1, 100) } getAjustements(rollData) { - rollData.current.resultat = this.getCurrent(rollData).resultat return [] } async _onRender(rollDialog, context, options) { const input = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="${this.code}"]`) - input?.addEventListener("change", e => { - this.getCurrent(rollDialog.rollData).resultat = parseInt(e.currentTarget.value) - }) + input?.addEventListener("input", e => this.onInputChange(e, rollDialog)) + } + + onInputChange(event, rollDialog) { + this.getCurrent(rollDialog.rollData).resultat = parseInt(event.currentTarget.value) } } diff --git a/module/roll/roll-part.mjs b/module/roll/roll-part.mjs index 94481559..3543dd72 100644 --- a/module/roll/roll-part.mjs +++ b/module/roll/roll-part.mjs @@ -1,5 +1,3 @@ -import { Misc } from "../misc.js" - export const ROLLDIALOG_SECTION = { ACTION: 'action', CARAC: 'carac', @@ -86,6 +84,9 @@ export class RollPart { loadRefs(rollData) { } prepareContext(rollData) { } + + /** permet de sauvegarder dans rollData les informations (cas des champs edit) */ + validate(rollData) {} /** ---- cross roll-part filtering ---- */ applyImpact(rollData, filter) { } @@ -108,14 +109,4 @@ export class RollPart { async _onRender(rollDialog, context, options) { } - addResult(rollData) { - const result = this.getResult(rollData) - if (result){ - rollData.result[this.code] = result - } - } - - getResult(rollData){ - return undefined - } } \ No newline at end of file diff --git a/module/settings/options-avancees.js b/module/settings/options-avancees.js index 90d9f37d..720a3923 100644 --- a/module/settings/options-avancees.js +++ b/module/settings/options-avancees.js @@ -3,9 +3,11 @@ import { Misc } from "../misc.js" export const EXPORT_CSV_SCRIPTARIUM = 'export-csv-scriptarium' export const ROLL_DIALOG_V2 = 'roll-dialog-v2' +export const ROLL_DIALOG_V2_TEST = 'roll-dialog-v2-test' const OPTIONS_AVANCEES = [ { group: 'Fenêtres', name: ROLL_DIALOG_V2, descr: "Utiliser les nouvelles fenêtres de jet", default: false }, + { group: 'Fenêtres', name: ROLL_DIALOG_V2_TEST, descr: "Mode de test des nouvelles fenêtres", default: false }, { group: 'Menus', name: EXPORT_CSV_SCRIPTARIUM, descr: "Proposer le menu d'export csv Scriptarium", default: false }, ] @@ -56,7 +58,7 @@ export class OptionsAvancees extends FormApplication { return formData } - static getSettingKey(name){ + static getSettingKey(name) { return `${SYSTEM_RDD}.${this._getId(name)}` } diff --git a/templates/chat-demande-defense.hbs b/templates/chat-demande-defense.hbs index 6a813946..718e86dc 100644 --- a/templates/chat-demande-defense.hbs +++ b/templates/chat-demande-defense.hbs @@ -36,7 +36,7 @@ {{/unless}} {{else}} {{#if (settings-get 'rdd-advanced-roll-dialog-v2')}} - {{else}} {{#each armes as |arme key|}} - Parer avec {{arme.name}} @@ -67,7 +67,7 @@
{{/each}} {{#if mainsNues}} -
Parer à mains nues à {{diffLibre}}{{#if arme.nbUsage}} (Utilisations : {{arme.nbUsage}}){{/if}} @@ -76,7 +76,7 @@ {{/if}} {{#if (ne attaqueCategorie 'tir')}} {{#each esquives as |esquive key|}} - {{esquive.name}} @@ -92,7 +92,7 @@ {{/if}} {{/if}} {{/unless}} - Encaisser à {{plusMoins dmg.total}} {{#if (eq dmg.mortalite 'non-mortel')~}} diff --git a/templates/roll/result/chat-defense.hbs b/templates/roll/result/chat-defense.hbs index 65c66787..b9c078a1 100644 --- a/templates/roll/result/chat-defense.hbs +++ b/templates/roll/result/chat-defense.hbs @@ -1,3 +1,4 @@ + {{log this}}
diff --git a/templates/roll/result/partial-encaissement.hbs b/templates/roll/result/partial-encaissement.hbs index 098ed21c..3d59faad 100644 --- a/templates/roll/result/partial-encaissement.hbs +++ b/templates/roll/result/partial-encaissement.hbs @@ -1,9 +1,9 @@ {{#if show.encaissement}} - Encaisser à {{plusMoins attackerRoll.dmg.total}} diff --git a/templates/roll/roll-part-appelmoral.hbs b/templates/roll/roll-part-appelmoral.hbs index 865f8070..015901f1 100644 --- a/templates/roll/roll-part-appelmoral.hbs +++ b/templates/roll/roll-part-appelmoral.hbs @@ -1,4 +1,6 @@ - + diff --git a/templates/roll/roll-part-astrologique.hbs b/templates/roll/roll-part-astrologique.hbs index 31a00ac4..5c1ae5a6 100644 --- a/templates/roll/roll-part-astrologique.hbs +++ b/templates/roll/roll-part-astrologique.hbs @@ -1,2 +1,4 @@ - + diff --git a/templates/roll/roll-part-checkbox.hbs b/templates/roll/roll-part-checkbox.hbs index 7c0fea04..4418bd52 100644 --- a/templates/roll/roll-part-checkbox.hbs +++ b/templates/roll/roll-part-checkbox.hbs @@ -1,3 +1,5 @@ - + {{#if current.icon}}{{{current.icon}}}{{/if}} diff --git a/templates/roll/roll-part-enctotal.hbs b/templates/roll/roll-part-enctotal.hbs index bdf0235e..fe726e2e 100644 --- a/templates/roll/roll-part-enctotal.hbs +++ b/templates/roll/roll-part-enctotal.hbs @@ -1,4 +1,6 @@ - +