foundryvtt-reve-de-dragon/module/tmr-constants.js

87 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-11-15 22:14:00 +01:00
export class TMRConstants {
constructor({ size = 64 }) {
// tailles
this.size = size
this.half = this.size / 2
this.quarter = this.size / 4
this.third = this.size / 3
this.twoThird = this.size * 2 / 3
this.full = this.size
// positions
this.col1_y = this.half
this.col2_y = this.size
this.cellw = this.size
this.cellh = this.size
this.gridx = this.half
this.gridy = this.half
// decallages
this.center = { x: 0, y: 0 }
this.top = { x: 0, y: -this.quarter }
this.topLeft = { x: -this.quarter, y: -this.quarter }
this.left = { x: -this.quarter, y: 0 }
this.bottomLeft = { x: -this.quarter, y: this.quarter }
this.bottom = { x: 0, y: this.quarter }
this.bottomRight = { x: this.quarter, y: this.quarter }
this.right = { x: this.quarter, y: 0 }
this.topRight = { x: this.quarter, y: -this.quarter }
this.marginx = 1
this.marginy = 1
}
decallage(x, y) {
return {
x: x * this.third,
y: y * this.third
}
}
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
}
}
computeEventOddq(event) {
var { x, y } = this.computeEventPosition(event);
return this.computeOddq(x, y);
}
computeOddq(x, y) {
const col = Math.floor(x / this.cellw)
const decallageColonne = col % 2 == 0 ? this.col1_y : this.col2_y
const row = Math.floor((y - decallageColonne) / this.cellh)
return { col, row, x, y }
}
}
// couleurs
export const tmrColors = {
sort: 0xFF8800,
tetes: 0xA000FF,
souffle: 0x804040,
queues: 0xAA4040,
trounoir: 0x401060,
demireve: 0x00FFEE,
rencontre: 0xFF0000,
casehumide: 0x1050F0,
}
2023-11-15 22:14:00 +01:00
export const tmrTokenZIndex = {
casehumide: 10,
2023-11-15 22:14:00 +01:00
tetes: 20,
sort: 30,
conquete: 40,
rencontre: 50,
trounoir: 60,
demireve: 70,
tooltip: 100,
}
2023-11-15 22:14:00 +01:00