foundryvtt-shadows-over-sol/module/sos-gm-deck.js

124 lines
3.4 KiB
JavaScript
Raw Permalink Normal View History

2021-03-08 22:46:33 +01:00
/* -------------------------------------------- */
import { SoSUtility } from "./sos-utility.js";
import { SoSCardDeck } from "./sos-card-deck.js";
/* -------------------------------------------- */
export class SoSGMDeck extends Dialog {
/* -------------------------------------------- */
constructor(html) {
let conf = {
title: 'GM Deck Dialog',
content: html,
buttons: {
2021-03-08 23:26:56 +01:00
'flip-close': { label: 'Close', callback: html => this.onFlipClose() }
2021-03-08 22:46:33 +01:00
},
default: 'flip'
};
super(conf, { classes: ["sosdialog"], width: 640 });
let deckData = game.settings.get("foundryvtt-shadows-over-sol", "gmDeck" );
if ( deckData == undefined || deckData.deck == undefined) {
deckData = {deck:[], discard: [], cardEdge:[] };
}
this.name = "GM Deck";
this.GMdeck = new SoSCardDeck();
this.GMdeck.initCardDeck( this, deckData );
}
/* -------------------------------------------- */
onFlipClose() {
2021-03-08 23:42:38 +01:00
this.minimize();
2021-03-08 22:46:33 +01:00
}
/* -------------------------------------------- */
saveDeck( ) {
let deck = {
2024-06-07 11:26:46 +02:00
deck: foundry.utils.duplicate(this.GMdeck.data.deck),
discard: foundry.utils.duplicate(this.GMdeck.data.discard),
cardEdge: foundry.utils.duplicate(this.GMdeck.data.cardEdge)
2021-03-08 22:46:33 +01:00
}
game.settings.set("foundryvtt-shadows-over-sol", "gmDeck", deck );
}
/* -------------------------------------------- */
async updateFlip( deckData) {
$('.view-deck').remove();
$("#view-gm-deck").append(await this.GMdeck.getDeckHTML());
$('.view-edge').remove();
$("#view-gm-edge").append(await this.GMdeck.getEdgeHTMLForFlip());
//this.flipData.GMdeck.drawFromDeck();
}
/* -------------------------------------------- */
async drawCard() {
let card = this.GMdeck.drawFromDeck();
let cardPath = `systems/foundryvtt-shadows-over-sol/img/cards/${card.cardName}.webp`;
let cardData = { card: card, cardPath: cardPath };
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-card.html', cardData );
2022-07-17 20:53:25 +02:00
ChatMessage.create( { content: html, whisper: ChatMessage.getWhisperRecipients("GM") } );
2021-03-08 22:46:33 +01:00
//dialog.onFlipClose();
}
/* -------------------------------------------- */
resetDeckFull( ) {
this.GMdeck.shuffleDeck();
this.GMdeck.drawEdge( 3 );
this.saveDeck();
}
/* -------------------------------------------- */
drawNewEdge( ) {
this.GMdeck.drawEdge( 1 );
this.saveDeck();
}
/* -------------------------------------------- */
discardEdge( cardName ) {
this.GMdeck.discardEdge( cardName );
this.saveDeck();
}
/* -------------------------------------------- */
resetDeck( ) {
this.GMdeck.resetDeck();
this.saveDeck();
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
this.bringToTop();
var dialog = this;
function onLoad() {
dialog.updateFlip();
}
// Setup everything onload
$(function () { onLoad(); });
html.find('.class-view-deck').click((event) => {
this.drawCard();
});
html.find('.reset-deck-full').click((event) => {
this.resetDeckFull();
this.render(true);
});
html.find('.draw-new-edge').click((event) => {
this.drawNewEdge();
this.render(true);
});
html.find('.reset-deck').click((event) => {
this.resetDeck();
this.render(true);
});
}
}