2020-07-05 21:45:25 +02:00
|
|
|
/**
|
|
|
|
* Extend the base Dialog entity by defining a custom window to perform spell.
|
|
|
|
* @extends {Dialog}
|
|
|
|
*/
|
2020-07-06 09:03:21 +02:00
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
2020-07-05 21:45:25 +02:00
|
|
|
|
|
|
|
export class RdDTMRDialog extends Dialog {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
constructor(sort, html, actor) {
|
|
|
|
|
|
|
|
// Common conf
|
|
|
|
let dialogConf = {
|
|
|
|
content: html,
|
|
|
|
buttons:
|
|
|
|
{
|
|
|
|
rollButton:
|
|
|
|
{
|
|
|
|
label: "Lancer",
|
|
|
|
callback: html => this.performRoll(html)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
default: "rollButton"
|
|
|
|
}
|
|
|
|
let dialogOptions = { classes: [ "tmrdialog"] }
|
|
|
|
|
|
|
|
dialogConf.title = "Terres Médianes de Rêve",
|
2020-07-05 22:35:18 +02:00
|
|
|
dialogOptions.width = 740;
|
|
|
|
dialogOptions.height = 960;
|
2020-07-05 21:45:25 +02:00
|
|
|
super(dialogConf, dialogOptions);
|
2020-07-05 22:35:18 +02:00
|
|
|
|
2020-07-06 09:03:21 +02:00
|
|
|
this.col1_y = 30;
|
|
|
|
this.col2_y = 55;
|
|
|
|
this.cellh = 55;
|
|
|
|
this.cellw = 55;
|
2020-07-05 21:45:25 +02:00
|
|
|
this.sort = sort;
|
|
|
|
this.actor = actor;
|
2020-07-06 09:03:21 +02:00
|
|
|
this.TMRimg = new Image();
|
2020-07-05 21:45:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
performRoll (html) {
|
|
|
|
this.actor.performRoll( this.rollData );
|
|
|
|
}
|
2020-07-06 09:03:21 +02:00
|
|
|
|
2020-07-05 21:45:25 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-07-06 09:03:21 +02:00
|
|
|
updateTMR( myself ) {
|
|
|
|
function rads(x) { return Math.PI*x/180; }
|
|
|
|
|
|
|
|
console.log("IMG", this, this.TMRimg);
|
|
|
|
|
|
|
|
let canvas = document.getElementById('canvas_tmr');
|
|
|
|
let ctx = canvas.getContext('2d');
|
|
|
|
ctx.drawImage(myself.TMRimg, 0, 0, 720, 860);
|
|
|
|
|
|
|
|
// Draw current position
|
|
|
|
let coordTMR = myself.actor.data.data.reve.tmrpos.coord;
|
|
|
|
console.log("TMR coord", coordTMR);
|
|
|
|
let coordXY = RdDUtility.convertToCellCoord( coordTMR );
|
|
|
|
let basey = (coordXY.x % 2 == 0) ? this.col1_y : this.col2_y;
|
|
|
|
ctx.globalAlpha = 0.3;
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.arc(28+(coordXY.x * this.cellw), basey+28+(coordXY.y * this.cellh), 15, 0, rads(360), false);
|
|
|
|
ctx.fill();
|
|
|
|
ctx.closePath();
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.globalAlpha = 1;
|
|
|
|
|
|
|
|
setTimeout(myself.updateTMR, 500, myself);
|
2020-07-05 22:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-07-06 09:03:21 +02:00
|
|
|
getCursorPosition(event) {
|
|
|
|
let canvasRect = event.currentTarget.getBoundingClientRect();
|
|
|
|
let x = event.clientX - canvasRect.left;
|
|
|
|
let y = event.clientY - canvasRect.top;
|
|
|
|
|
|
|
|
let cellx = Math.floor( x / this.cellw);// [From 0 -> 12]
|
|
|
|
if (cellx % 2 == 0)
|
|
|
|
y -= this.col1_y;
|
|
|
|
else
|
|
|
|
y -= this.col2_y;
|
|
|
|
let celly = Math.floor( y / this.cellh);// [From 0 -> 14]
|
|
|
|
|
|
|
|
let coordTMR = RdDUtility.convertToTMRCoord(cellx, celly);
|
|
|
|
let cellDescr = RdDUtility.getTMRDescription( coordTMR );
|
|
|
|
this.actor.data.data.reve.tmrpos.coord = coordTMR;
|
|
|
|
console.log("TMR column is", coordTMR, cellx, celly, cellDescr);
|
2020-07-05 22:35:18 +02:00
|
|
|
}
|
2020-07-06 09:03:21 +02:00
|
|
|
|
2020-07-05 22:35:18 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-07-06 09:03:21 +02:00
|
|
|
async activateListeners(html) {
|
2020-07-05 21:45:25 +02:00
|
|
|
super.activateListeners(html);
|
2020-07-05 22:35:18 +02:00
|
|
|
|
2020-07-06 09:03:21 +02:00
|
|
|
this.TMRimg.onload = this.updateTMR(this);
|
|
|
|
this.TMRimg.src = "systems/foundryvtt-reve-de-dragon/styles/ui/tmp_main_r1.webp";
|
|
|
|
|
|
|
|
html.find('#canvas_tmr').click(event => {
|
|
|
|
this.getCursorPosition(event);
|
|
|
|
} );
|
2020-07-05 21:45:25 +02:00
|
|
|
}
|
|
|
|
}
|