diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js index 4bec890c..cda22f09 100644 --- a/module/rdd-tmr-dialog.js +++ b/module/rdd-tmr-dialog.js @@ -19,7 +19,6 @@ import { RdDTimestamp } from "./time/rdd-timestamp.js"; import { TYPES } from "./item.js"; /* -------------------------------------------- */ - export class RdDTMRDialog extends Dialog { static async create(actor, tmrData) { @@ -188,36 +187,23 @@ export class RdDTMRDialog extends Dialog { } forceDemiRevePositionView() { - this.notifierResonanceSigneDraconique(this._getActorCoord()); + this.notifierResonanceSigneDraconique(this._getCoordActor()); this._trackToken(this.demiReve); } - _getActorCoord() { + _getCoordActor() { return this.actor.system.reve.tmrpos.coord; } /* -------------------------------------------- */ - async moveFromKey(move) { + async deplacementTMR(move) { if (this.subdialog) { return this.forceTMRContinueAction(); } - let oddq = TMRUtility.coordTMRToOddq(this._getActorCoord()); - - if (move == 'top') oddq.row -= 1; - if (move == 'bottom') oddq.row += 1; - if (move.includes('left')) oddq.col -= 1; - if (move.includes('right')) oddq.col += 1; - if (oddq.col % 2 == 1) { - if (move == 'top-left') oddq.row -= 1; - if (move == 'top-right') oddq.row -= 1; - } else { - if (move == 'bottom-left') oddq.row += 1; - if (move == 'bottom-right') oddq.row += 1; - } - - let targetCoord = TMRUtility.oddqToCoordTMR(oddq); - await this._deplacerDemiReve(targetCoord, 'normal'); + const coordOrig = this._getCoordActor(); + const coordTarget = TMRUtility.deplacement(coordOrig, move); + await this._deplacerDemiReve(coordTarget, 'normal'); this.checkQuitterTMR(); } @@ -238,36 +224,36 @@ export class RdDTMRDialog extends Dialog { } HtmlUtility.showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionnelles.isUsing("appliquer-fatigue")); - HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(this._getActorCoord())); + HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(this._getCoordActor())); this.html.find('tr.tmr-row *').click(event => this.subdialog?.bringToTop()); // Roll Sort - this.html.find('.lancer-sort').click(event => this.actor.rollUnSort(this._getActorCoord())); - this.html.find('.lire-signe-draconique').click(event => this.actor.rollLireSigneDraconique(this._getActorCoord())); - this.html.find('#dir-top').click(event=> this.moveFromKey("top")); - this.html.find('#dir-top-left').click(event=> this.moveFromKey("top-left")); - this.html.find('#dir-top-right').click(event=> this.moveFromKey("top-right")); - this.html.find('#dir-bottom-left').click(event=> this.moveFromKey("bottom-left")); - this.html.find('#dir-bottom-right').click(event=> this.moveFromKey("bottom-right")); - this.html.find('#dir-bottom').click(event=> this.moveFromKey("bottom")); + this.html.find('.lancer-sort').click(event => this.actor.rollUnSort(this._getCoordActor())); + this.html.find('.lire-signe-draconique').click(event => this.actor.rollLireSigneDraconique(this._getCoordActor())); + + this.html.find('img.tmr-move').click(event => this.deplacementTMR(this.html.find(event.currentTarget)?.data('move'))); // Gestion du cout de montée en points de rêve - let reveCout = ((this.tmrdata.isRapide && !EffetsDraconiques.isDeplacementAccelere(this.actor)) ? -2 : -1) - this.actor.countMonteeLaborieuse(); - await this.actor.reveActuelIncDec(reveCout); + await this.actor.reveActuelIncDec(this.calculCoutMonteeTMR()); this.cumulFatigue += this.fatigueParCase; + // Le reste... this.updateValuesDisplay(); - let tmr = TMRUtility.getTMR(this._getActorCoord()); + let tmr = TMRUtility.getTMR(this._getCoordActor()); await this.manageRencontre(tmr); } + calculCoutMonteeTMR() { + return ((this.tmrdata.isRapide && !EffetsDraconiques.isDeplacementAccelere(this.actor)) ? -2 : -1) - this.actor.countMonteeLaborieuse(); + } + /* -------------------------------------------- */ async updateValuesDisplay() { if (!this.rendered) { return; } - const coord = this._getActorCoord(); + const coord = this._getCoordActor(); HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(coord)); @@ -425,7 +411,7 @@ export class RdDTMRDialog extends Dialog { nbRounds: 1, canClose: false, selectedCarac: { label: "reve-actuel" }, - tmr: TMRUtility.getTMR(this._getActorCoord()) + tmr: TMRUtility.getTMR(this._getCoordActor()) } await this._tentativeMaitrise(rencontreData); @@ -608,19 +594,18 @@ export class RdDTMRDialog extends Dialog { if (rencontre) { return game.system.rdd.rencontresTMR.calculRencontre(rencontre, tmr); } - let locTMR = (this.isDemiReveCache() + const coordTMR = (this.isDemiReveCache() ? TMRUtility.getTMRType(tmr.coord) + " ??" : tmr.label + " (" + tmr.coord + ")"); - const fakeDialogRencontre = { bringToTop: () => { } }; - this.setTMRPendingAction(fakeDialogRencontre) - let myRoll = await RdDDice.rollTotal("1dt", { showDice: SHOW_DICE }); + this.setTMRPendingAction({ bringToTop: () => { } }) + const myRoll = await RdDDice.rollTotal("1dt", { showDice: SHOW_DICE }); this.restoreTMRAfterAction() if (myRoll == 7) { - this._tellToUser(myRoll + ": Rencontre en " + locTMR); + this._tellToUser(myRoll + ": Rencontre en " + coordTMR); return await game.system.rdd.rencontresTMR.getRencontreAleatoire(tmr, this.actor.isMauvaiseRencontre()) } else { - this._tellToUser(myRoll + ": Pas de rencontre en " + locTMR); + this._tellToUser(myRoll + ": Pas de rencontre en " + coordTMR); return undefined; } } @@ -935,7 +920,7 @@ export class RdDTMRDialog extends Dialog { return this.forceTMRContinueAction() } let clickOddq = TMRUtility.computeEventOddq(event); - let currentOddq = TMRUtility.coordTMRToOddq(this._getActorCoord()); + let currentOddq = TMRUtility.coordTMRToOddq(this._getCoordActor()); let targetCoord = TMRUtility.oddqToCoordTMR(clickOddq); let currentCoord = TMRUtility.oddqToCoordTMR(currentOddq); diff --git a/module/tmr-utility.js b/module/tmr-utility.js index 32522a11..4414b43c 100644 --- a/module/tmr-utility.js +++ b/module/tmr-utility.js @@ -228,14 +228,15 @@ export const TMRType = { } /* -------------------------------------------- */ -const tmrRandomMovePatten = - [{ name: 'top', col: 0, row: -1 }, - { name: 'topright', col: 1, row: -1 }, - { name: 'botright', col: 1, row: 1 }, - { name: 'bot', col: 0, row: 1 }, - { name: 'botleft', col: -1, row: 1 }, - { name: 'topleft', col: -1, row: -1 } - ] +const TMR_MOVE = { + "top": { even: { row: -1, col: 0 }, odd: { row: -1, col: 0 }, }, + "topleft": { even: { row: -1, col: -1 }, odd: { row: 0, col: -1 }, }, + "topright": { even: { row: -1, col: 1 }, odd: { row: 0, col: 1 }, }, + "bottomleft": { even: { row: 0, col: -1 }, odd: { row: 1, col: -1 }, }, + "bottomright": { even: { row: 0, col: 1 }, odd: { row: 1, col: 1 }, }, + "bottom": { even: { row: 1, col: 0 }, odd: { row: 1, col: 0 }, }, +} + /* -------------------------------------------- */ export class TMRUtility { @@ -313,16 +314,32 @@ export class TMRUtility { } /* -------------------------------------------- */ - static async getDirectionPattern() { - return await RdDDice.rollOneOf(tmrRandomMovePatten); + static deplacement(coordOrig, moveName) { + const tmrMove = TMR_MOVE[moveName]; + if (! tmrMove) { + ui.notifications.error(`Le déplacement dans les TMR '${moveName}' est inconnu`) + return coordOrig + } + const fromOddq = TMRUtility.coordTMRToOddq(coordOrig); + const move = TMRUtility.getOddqMove(tmrMove, fromOddq); + const toOddq = TMRUtility.addOddq(fromOddq, move); + return TMRUtility.oddqToCoordTMR(toOddq); + } + + static getOddqMove(tmrMove, oddq) { + return oddq.col % 2 == 1 ? tmrMove.odd : tmrMove.even; + } + + static async getDirectionPattern(oddq) { + const tmrMove = await RdDDice.rollOneOf(Object.values(TMR_MOVE)); + return TMRUtility.getOddqMove(tmrMove, oddq); } /* -------------------------------------------- */ static async deplaceTMRAleatoire(actor, coord) { - const currentOddq = TMRUtility.coordTMRToOddq(coord); - const direction = await TMRUtility.getDirectionPattern(); - currentOddq.col = currentOddq.col + direction.col; - currentOddq.row = currentOddq.row + direction.row; + const oddq = TMRUtility.coordTMRToOddq(coord); + const direction = await TMRUtility.getDirectionPattern(oddq); + const currentOddq = TMRUtility.addOddq(oddq, direction) if (this.isOddqInTMR(currentOddq)) { // Sortie de carte ! Ré-insertion aléatoire return TMRUtility.getTMR(TMRUtility.oddqToCoordTMR(currentOddq)); } else { @@ -432,12 +449,8 @@ export class TMRUtility { row >= 0 && (row + col % 2 <= 14) ); - // if (x >= 0 && x < 13 && y >= 0 && y < 14) return true; - // if (x >= 0 && x < 13 && x % 2 == 0 && y == 14) return true; - // return false; } - /* -------------------------------------------- */ static distanceCoordTMR(coord1, coord2) { let oddq1 = this.coordTMRToOddq(coord1); @@ -450,13 +463,13 @@ export class TMRUtility { const axial1 = TMRUtility.oddqToAxial(oddq1); const axial2 = TMRUtility.oddqToAxial(oddq2); return TMRUtility.distanceAxial(axial1, axial2); + } - // const dx = oddq2.col - oddq1.col; - // const dy = oddq2.row - oddq1.row; - // const abs_dx = Math.abs(dx); - // const abs_dy = Math.abs(dy); - // const distance = Math.sign(dx) == Math.sign(dy) ? Math.max(abs_dx, abs_dy) : (abs_dx + abs_dy); - // return distance; + static addOddq(move, oddq) { + return { + row: oddq.row + move.row, + col: oddq.col + move.col + } } static oddqToAxial(pos) { @@ -480,20 +493,4 @@ export class TMRUtility { }; } - // function axial_to_cube(hex): - // var q = hex.q - // var r = hex.r - // var s = -q - r - // return Cube(q, r, s) - // } - - - // /* -------------------------------------------- */ - // static computeRealPictureCoordinates(coordOddq) { - // let decallagePairImpair = (coordOddq.col % 2 == 0) ? tmrConstants.col1_y : tmrConstants.col2_y; - // return { - // x: tmrConstants.gridx + (coordOddq.col * tmrConstants.cellw), - // y: tmrConstants.gridy + (coordOddq.row * tmrConstants.cellh) + decallagePairImpair - // } - // } } \ No newline at end of file diff --git a/styles/img/ui/dir-bottom-left.svg b/styles/img/ui/dir-bottomleft.svg similarity index 100% rename from styles/img/ui/dir-bottom-left.svg rename to styles/img/ui/dir-bottomleft.svg diff --git a/styles/img/ui/dir-bottom-right.svg b/styles/img/ui/dir-bottomright.svg similarity index 100% rename from styles/img/ui/dir-bottom-right.svg rename to styles/img/ui/dir-bottomright.svg diff --git a/styles/img/ui/dir-top-left.svg b/styles/img/ui/dir-topleft.svg similarity index 100% rename from styles/img/ui/dir-top-left.svg rename to styles/img/ui/dir-topleft.svg diff --git a/styles/img/ui/dir-top-right.svg b/styles/img/ui/dir-topright.svg similarity index 100% rename from styles/img/ui/dir-top-right.svg rename to styles/img/ui/dir-topright.svg diff --git a/templates/dialog-tmr.html b/templates/dialog-tmr.html index 6ca5ed09..f5c736dd 100644 --- a/templates/dialog-tmr.html +++ b/templates/dialog-tmr.html @@ -1,5 +1,4 @@
-
@@ -14,14 +13,14 @@ {{/if}}
- - - + + +
- - - + + +