foundryvtt-shadows-over-sol/module/sos-flip-dialog.js
2021-01-25 11:16:45 +01:00

84 lines
2.4 KiB
JavaScript

export class SoSFlipDialog extends Dialog {
/* -------------------------------------------- */
constructor(flipData, html) {
let conf = {
title: 'Flip Dialog',
content: html,
buttons: {
'flip-close': { label: 'Cancel and Close', callback: html => this.onFlipClose() }
},
default: 'flip'
};
super(conf, { classes: ["sosdialog"], width: 800, height: 800 });
this.flipData = flipData;
}
/* -------------------------------------------- */
onFlipClose( ) {
this.close();
}
/* -------------------------------------------- */
async updateFlip( flipData ) {
console.log("UPDATE !!!", flipData);
$('.view-deck').remove();
$("#view-deck").append(await flipData.actor.cardDeck.getDeckHTML());
$('.view-edge').remove();
$("#view-edge").append(await flipData.actor.cardDeck.getEdgeHTML());
$('.edge-card').click((event) => {
let flipData = duplicate(this.flipData);
flipData.modifier = $('#modifier').val();
flipData.tn = $('#tn').val();
flipData.edgeName = event.currentTarget.attributes['data-edge-card'].value;
flipData.cardOrigin = "Edge";
if ( flipData.mode == 'skill') {
flipData.stat = duplicate( flipData.statList[ $('#statSelect').val() ] );
}
this.flipData.actor.cardDeck.doFlipFromDeckOrEdge(flipData);
this.onFlipClose();
});
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
this.bringToTop();
var dialog = this;
function onLoad() {
let flipData = dialog.flipData;
//RdDItemSort.setCoutReveReel(rollData.selectedSort);
//$("#diffLibre").val(Misc.toInt(rollData.diffLibre));
//$("#diffConditions").val(Misc.toInt(rollData.diffConditions));
dialog.updateFlip(flipData);
}
// Setup everything onload
$(function () { onLoad(); });
html.find('.class-view-deck').click((event) => {
let flipData = duplicate(this.flipData);
flipData.modifier = html.find('#modifier').val();
flipData.tn = html.find('#tn').val();
if ( flipData.mode == 'skill') {
let statKey = $('#statSelect').val();
flipData.stat = duplicate( flipData.statList[ statKey ] );
}
flipData.cardOrigin = "Deck";
flipData.tn = html.find('#tn').val();
dialog.flipData.actor.cardDeck.doFlipFromDeckOrEdge(flipData);
dialog.onFlipClose();
});
}
}