forked from public/foundryvtt-reve-de-dragon
Réduction de l'espace des TMR
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import { Misc } from "./misc.js";
|
||||
import { Grammar } from "./grammar.js";
|
||||
import { RdDDice } from "./rdd-dice.js";
|
||||
import { tmrConstants } from "./tmr-constants.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
const TMRMapping = {
|
||||
@ -237,8 +236,19 @@ const TMR_MOVE = {
|
||||
"bottom": { even: { row: 1, col: 0 }, odd: { row: 1, col: 0 }, },
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* --------------------------------------------
|
||||
* Pour comprendre les conversions entre coordonnées
|
||||
* - "TMR" A1, ... M15
|
||||
* - oddq: {col, row}
|
||||
* - axial: { q, r )
|
||||
*
|
||||
* Un site intéressant: https://www.redblobgames.com/grids/hexagons/#distances
|
||||
*
|
||||
* Pour être concis, le code TMR lettre(colonne)-ligne correspond à une grille hexagonale en coordonnées "odd-q"
|
||||
* (lettre => col, ligne => row).
|
||||
*
|
||||
* Pour les calculs de distance, les coordonnées axiales sont beaucoup plus pratiques.
|
||||
*/
|
||||
export class TMRUtility {
|
||||
static init() {
|
||||
for (let coord in TMRMapping) {
|
||||
@ -340,7 +350,7 @@ export class TMRUtility {
|
||||
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
|
||||
if (TMRUtility.isOddqInTMR(currentOddq)) { // Sortie de carte ! Ré-insertion aléatoire
|
||||
return TMRUtility.getTMR(TMRUtility.oddqToCoordTMR(currentOddq));
|
||||
} else {
|
||||
return await actor.reinsertionAleatoire('Sortie de carte');
|
||||
@ -377,15 +387,15 @@ export class TMRUtility {
|
||||
*
|
||||
*/
|
||||
static getTMRPortee(coord, portee) {
|
||||
let centerOddq = this.coordTMRToOddq(coord);
|
||||
let centerOddq = TMRUtility.coordTMRToOddq(coord);
|
||||
let caseList = [];
|
||||
for (let dcol = -portee; dcol <= portee; dcol++) { // rows
|
||||
for (let drow = -portee; drow <= portee; drow++) { // columns
|
||||
const currentOddq = { col: centerOddq.col + dcol, row: centerOddq.row + drow };
|
||||
if (this.isOddqInTMR(currentOddq)) {
|
||||
let dist = this.distanceOddq(centerOddq, currentOddq);
|
||||
if (TMRUtility.isOddqInTMR(currentOddq)) {
|
||||
let dist = TMRUtility.distanceOddq(centerOddq, currentOddq);
|
||||
if (dist <= portee) {
|
||||
caseList.push(this.oddqToCoordTMR(currentOddq)); // Inside the area
|
||||
caseList.push(TMRUtility.oddqToCoordTMR(currentOddq)); // Inside the area
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -393,40 +403,6 @@ export class TMRUtility {
|
||||
return caseList;
|
||||
}
|
||||
|
||||
// /* -------------------------------------------- */
|
||||
static computeEventPosition(event) {
|
||||
if (!event.nativeEvent.target.getBoundingClientRect) {
|
||||
return { x: 0, y: 0 }
|
||||
}
|
||||
const canvasRect = event.nativeEvent.target.getBoundingClientRect();
|
||||
return {
|
||||
x: event.nativeEvent.clientX - canvasRect.left,
|
||||
y: event.nativeEvent.clientY - canvasRect.top
|
||||
};
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static computeEventOddq(event) {
|
||||
var { x, y } = TMRUtility.computeEventPosition(event);
|
||||
return TMRUtility.computeOddq(x, y);
|
||||
}
|
||||
|
||||
static computeOddq(x, y) {
|
||||
const col = Math.floor(x / tmrConstants.cellw); // [From 0 -> 12]
|
||||
const decallageColonne = col % 2 == 0 ? tmrConstants.col1_y : tmrConstants.col2_y;
|
||||
const row = Math.floor((y - decallageColonne) / tmrConstants.cellh); // [From 0 -> 14]
|
||||
return { col, row };
|
||||
}
|
||||
|
||||
static computeEventCoord(event) {
|
||||
const oddq = TMRUtility.computeEventOddq(event);
|
||||
return TMRUtility.oddqToCoordTMR(oddq);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// https://www.redblobgames.com/grids/hexagons/#distances
|
||||
// TMR Letter-row correspond to "odd-q" grid (letter => col, numeric => row )
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static coordTMRToOddq(coordTMR) {
|
||||
let col = coordTMR.charCodeAt(0) - 65;
|
||||
@ -453,9 +429,9 @@ export class TMRUtility {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static distanceCoordTMR(coord1, coord2) {
|
||||
let oddq1 = this.coordTMRToOddq(coord1);
|
||||
let oddq2 = this.coordTMRToOddq(coord2);
|
||||
return this.distanceOddq(oddq1, oddq2);
|
||||
let oddq1 = TMRUtility.coordTMRToOddq(coord1);
|
||||
let oddq2 = TMRUtility.coordTMRToOddq(coord2);
|
||||
return TMRUtility.distanceOddq(oddq1, oddq2);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user