Fix livre

This commit is contained in:
2020-07-06 09:03:21 +02:00
parent 7d9f6fd6c3
commit f6c81fd68d
4 changed files with 87 additions and 17 deletions

View File

@ -2,6 +2,7 @@
* Extend the base Dialog entity by defining a custom window to perform spell.
* @extends {Dialog}
*/
import { RdDUtility } from "./rdd-utility.js";
export class RdDTMRDialog extends Dialog {
@ -28,32 +29,74 @@ export class RdDTMRDialog extends Dialog {
dialogOptions.height = 960;
super(dialogConf, dialogOptions);
this.col1_y = 30;
this.col2_y = 55;
this.cellh = 55;
this.cellw = 55;
this.sort = sort;
this.actor = actor;
this.TMRimg = new Image();
}
/* -------------------------------------------- */
performRoll (html) {
this.actor.performRoll( this.rollData );
}
/* -------------------------------------------- */
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);
}
/* -------------------------------------------- */
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);
}
/* -------------------------------------------- */
loadImage(url) {
return new Promise(r => { let i = new Image(); i.onload = (() => r(i)); i.src = url; });
}
/* -------------------------------------------- */
async init_canvas() {
var ctx = document.getElementById('canvas_tmr');
ctx = ctx.getContext('2d');
let img = await this.loadImage("systems/foundryvtt-reve-de-dragon/styles/ui/tmp_main_r1.webp");
await ctx.drawImage(img, 0, 0, 720, 860);
}
/* -------------------------------------------- */
activateListeners(html) {
async activateListeners(html) {
super.activateListeners(html);
this.init_canvas();
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);
} );
}
}