Fix calculs coordonnées et distances
Utiliser les différents repères de cases: - coordonnées TMR A5 - oddq pour les coordonnées de case (ligne, colonne) - axial (q,r) pour effectuer les calculs de distance utiliser x, y rend la distinction de positions de pixels vs position dans la grille parfois ardue. Utilisation des coordonnées axiales pour le calcul de distance.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { RollDataAjustements } from "./rolldata-ajustements.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
import { TMRUtility, tmrConstants } from "./tmr-utility.js";
|
||||
import { TMRUtility } from "./tmr-utility.js";
|
||||
import { tmrConstants } from "./tmr-constants.js";
|
||||
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
||||
import { RdDTMRRencontreDialog } from "./rdd-tmr-rencontre-dialog.js";
|
||||
import { TMRRencontres } from "./tmr-rencontres.js";
|
||||
@ -14,8 +15,8 @@ import { Misc } from "./misc.js";
|
||||
import { HtmlUtility } from "./html-utility.js";
|
||||
import { ReglesOptionelles } from "./regles-optionelles.js";
|
||||
import { RdDDice } from "./rdd-dice.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
export class RdDTMRDialog extends Dialog {
|
||||
|
||||
static async create(html, actor, tmrData) {
|
||||
@ -163,21 +164,21 @@ export class RdDTMRDialog extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async moveFromKey(move) {
|
||||
let pos = TMRUtility.convertToCellPos(this._getActorCoord());
|
||||
let oddq = TMRUtility.coordTMRToOddq(this._getActorCoord());
|
||||
|
||||
if (move == 'top') pos.y -= 1;
|
||||
if (move == 'bottom') pos.y += 1;
|
||||
if (move.includes('left')) pos.x -= 1;
|
||||
if (move.includes('right')) pos.x += 1;
|
||||
if (pos.x % 2 == 1) {
|
||||
if (move == 'top-left') pos.y -= 1;
|
||||
if (move == 'top-right') pos.y -= 1;
|
||||
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') pos.y += 1;
|
||||
if (move == 'bottom-right') pos.y += 1;
|
||||
if (move == 'bottom-left') oddq.row += 1;
|
||||
if (move == 'bottom-right') oddq.row += 1;
|
||||
}
|
||||
|
||||
let targetCoord = TMRUtility.convertToTMRCoord(pos);
|
||||
let targetCoord = TMRUtility.oddqToCoordTMR(oddq);
|
||||
await this._deplacerDemiReve(targetCoord, 'normal');
|
||||
this.checkQuitterTMR();
|
||||
}
|
||||
@ -310,11 +311,11 @@ export class RdDTMRDialog extends Dialog {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
colorierZoneRencontre(locList) {
|
||||
colorierZoneRencontre(listCoordTMR) {
|
||||
this.currentRencontre.graphics = []; // Keep track of rectangles to delete it
|
||||
this.currentRencontre.locList = duplicate(locList); // And track of allowed location
|
||||
for (let loc of locList) {
|
||||
let rect = this._getCaseRectangleCoord(loc);
|
||||
this.currentRencontre.locList = duplicate(listCoordTMR); // And track of allowed location
|
||||
for (let coordTMR of listCoordTMR) {
|
||||
let rect = this._getCaseRectangleCoord(coordTMR);
|
||||
var rectDraw = new PIXI.Graphics();
|
||||
rectDraw.beginFill(0xFFFF00, 0.3);
|
||||
// set the line style to have a width of 5 and set the color to red
|
||||
@ -863,24 +864,21 @@ export class RdDTMRDialog extends Dialog {
|
||||
return;
|
||||
}
|
||||
|
||||
let origEvent = event.data.originalEvent;
|
||||
let tmrObject = this;
|
||||
|
||||
let eventPos = RdDTMRDialog._computeEventPos(origEvent);
|
||||
await tmrObject._onClickTMRPos(eventPos); // Vérifier l'état des compteurs reve/fatigue/vie
|
||||
let clickOddq = RdDTMRDialog._computeEventOddq(event.data.originalEvent);
|
||||
await this._onClickTMRPos(clickOddq); // Vérifier l'état des compteurs reve/fatigue/vie
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onClickTMRPos(eventPos) {
|
||||
let currentPos = TMRUtility.convertToCellPos(this._getActorCoord());
|
||||
async _onClickTMRPos(clickOddq) {
|
||||
let currentOddq = TMRUtility.coordTMRToOddq(this._getActorCoord());
|
||||
|
||||
console.log("deplacerDemiReve >>>>", currentPos, eventPos);
|
||||
console.log("deplacerDemiReve >>>>", currentOddq, clickOddq);
|
||||
|
||||
let targetCoord = TMRUtility.convertToTMRCoord(eventPos);
|
||||
let currentCoord = TMRUtility.convertToTMRCoord(currentPos);
|
||||
let targetCoord = TMRUtility.oddqToCoordTMR(clickOddq);
|
||||
let currentCoord = TMRUtility.oddqToCoordTMR(currentOddq);
|
||||
|
||||
// Validation de la case de destination (gestion du cas des rencontres qui peuvent téléporter)
|
||||
let deplacementType = this._calculDeplacement(targetCoord, currentCoord, currentPos, eventPos);
|
||||
let deplacementType = this._calculDeplacement(targetCoord, currentCoord, currentOddq, clickOddq);
|
||||
|
||||
// Si le deplacement est valide
|
||||
if (deplacementType == 'normal' || deplacementType == 'saut') {
|
||||
@ -895,9 +893,9 @@ export class RdDTMRDialog extends Dialog {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_calculDeplacement(targetCoord, currentCoord, currentPos, eventPos) {
|
||||
let isInArea = this.rencontreState == 'aucune'
|
||||
? this.isTerreAttache(targetCoord) || this.isConnaissanceFleuve(currentCoord, targetCoord) || !RdDTMRDialog._horsDePortee(currentPos, eventPos)
|
||||
_calculDeplacement(targetCoord, currentCoord, fromOddq, toOddq) {
|
||||
const isInArea = this.rencontreState == 'aucune'
|
||||
? (this.isTerreAttache(targetCoord) || this.isConnaissanceFleuve(currentCoord, targetCoord) || TMRUtility.distanceOddq(fromOddq, toOddq) <= 1)
|
||||
: this.currentRencontre?.locList.find(coord => coord == targetCoord) ?? false
|
||||
if (isInArea) {
|
||||
switch (this.rencontreState) {
|
||||
@ -1000,35 +998,26 @@ export class RdDTMRDialog extends Dialog {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static _computeEventPos(origEvent) {
|
||||
static _computeEventOddq(origEvent) {
|
||||
let canvasRect = origEvent.target.getBoundingClientRect();
|
||||
let x = origEvent.clientX - canvasRect.left;
|
||||
let y = origEvent.clientY - canvasRect.top;
|
||||
let cellx = Math.floor(x / tmrConstants.cellw); // [From 0 -> 12]
|
||||
y -= (cellx % 2 == 0) ? tmrConstants.col1_y : tmrConstants.col2_y;
|
||||
let celly = Math.floor(y / tmrConstants.cellh); // [From 0 -> 14]
|
||||
return { x: cellx, y: celly };
|
||||
let col = Math.floor(x / tmrConstants.cellw); // [From 0 -> 12]
|
||||
y -= (col % 2 == 0) ? tmrConstants.col1_y : tmrConstants.col2_y;
|
||||
let row = Math.floor(y / tmrConstants.cellh); // [From 0 -> 14]
|
||||
return { col: col, row: row };
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static _horsDePortee(origin, target) {
|
||||
return Math.abs(target.x - origin.x) > 1
|
||||
|| Math.abs(target.y - origin.y) > 1
|
||||
|| (origin.y == 0 && target.y > origin.y && target.x != origin.x && origin.x % 2 == 0)
|
||||
|| (target.y == 0 && target.y < origin.y && target.x != origin.x && origin.x % 2 == 1);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Retourne les coordonnées x, h, w, h du rectangle d'une case donnée */
|
||||
_getCaseRectangleCoord(coord) {
|
||||
return this.pixiTMR.getCaseRectangle(TMRUtility.convertToCellPos(coord));
|
||||
return this.pixiTMR.getCaseRectangle(TMRUtility.coordTMRToOddq(coord));
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_setTokenPosition(token) {
|
||||
if (!this.cacheTMR) {
|
||||
this.pixiTMR.setPosition(token.sprite, TMRUtility.convertToCellPos(token.coordTMR()));
|
||||
this.pixiTMR.setPosition(token.sprite, TMRUtility.coordTMRToOddq(token.coordTMR()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1046,5 +1035,3 @@ export class RdDTMRDialog extends Dialog {
|
||||
this._setTokenPosition(token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user