diff --git a/img/cards/hearth.webp b/img/cards/hearth.webp new file mode 100644 index 0000000..46ece2d Binary files /dev/null and b/img/cards/hearth.webp differ diff --git a/img/icons/injury_generic.svg b/img/icons/injury_generic.svg new file mode 100644 index 0000000..2225ed8 --- /dev/null +++ b/img/icons/injury_generic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/module/actor.js b/module/actor.js index ab284c5..1623188 100644 --- a/module/actor.js +++ b/module/actor.js @@ -54,8 +54,12 @@ export class SoSActor extends Actor { super.prepareData(); if ( !this.cardDeck ) { - this.cardDeck = new SoSCardDeck(); - this.cardDeck.initCardDeck( this, this.data.data.internals.deck ); + if ( this.hasPlayerOwner) { + this.cardDeck = new SoSCardDeck(); + this.cardDeck.initCardDeck( this, this.data.data.internals.deck ); + } else { + this.cardDeck = game.system.sos.gmDeck; + } } this.controlScores(); } @@ -100,10 +104,14 @@ export class SoSActor extends Actor { /* -------------------------------------------- */ saveDeck( ) { let deck = { deck: duplicate(this.cardDeck.data.deck), - discard: duplicate(this.cardDeck.data.discard), - cardEdge: duplicate(this.cardDeck.data.cardEdge) - } - this.update( { 'data.internals.deck': deck }); + discard: duplicate(this.cardDeck.data.discard), + cardEdge: duplicate(this.cardDeck.data.cardEdge) + } + if ( this.hasPlayerOwner ) { + this.update( { 'data.internals.deck': deck }); + } else { + game.settings.set("foundryvtt-shadows-over-sol", "gmDeck", deck ); + } } /* -------------------------------------------- */ diff --git a/module/sos-flip-dialog.js b/module/sos-flip-dialog.js index 16a7daf..77ad360 100644 --- a/module/sos-flip-dialog.js +++ b/module/sos-flip-dialog.js @@ -89,19 +89,19 @@ export class SoSFlipDialog extends Dialog { this.updateScoreBase(); } - /* -------------------------------------------- */ - updateConsequenceBonus(event) { - this.flipData.consequencesSelected = $('#consequenceSelectBonus').val(); - let bonusConsequence = 0; - for (let consequenceId of this.flipData.consequencesSelected) { - let consequence = this.flipData.consequencesList.find( item => item._id == consequenceId); - console.log(consequence, consequenceId); - bonusConsequence += SoSUtility.getConsequenceBonus( consequence.data.severity ); - } - $('#consequence-bonus').text(bonusConsequence); - this.flipData.bonusConsequence = bonusConsequence; - this.updateScoreBase(); + /* -------------------------------------------- */ + updateConsequenceBonus(event) { + this.flipData.consequencesSelected = $('#consequenceSelectBonus').val(); + let bonusConsequence = 0; + for (let consequenceId of this.flipData.consequencesSelected) { + let consequence = this.flipData.consequencesList.find( item => item._id == consequenceId); + console.log(consequence, consequenceId); + bonusConsequence += SoSUtility.getConsequenceBonus( consequence.data.severity ); } + $('#consequence-bonus').text(bonusConsequence); + this.flipData.bonusConsequence = bonusConsequence; + this.updateScoreBase(); + } /* -------------------------------------------- */ activateListeners(html) { diff --git a/module/sos-gm-deck.js b/module/sos-gm-deck.js new file mode 100644 index 0000000..8831e87 --- /dev/null +++ b/module/sos-gm-deck.js @@ -0,0 +1,124 @@ +/* -------------------------------------------- */ +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: { + 'flip-close': { label: 'Cancel and Close', callback: html => this.onFlipClose() } + }, + 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() { + this.close(); + } + + /* -------------------------------------------- */ + saveDeck( ) { + let deck = { + deck: duplicate(this.GMdeck.data.deck), + discard: duplicate(this.GMdeck.data.discard), + cardEdge: duplicate(this.GMdeck.data.cardEdge) + } + 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 ); + ChatMessage.create( { content: html, whisper: [ ChatMessage.getWhisperRecipients("GM") ] }); + //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); + }); + + } + +} \ No newline at end of file diff --git a/module/sos-main.js b/module/sos-main.js index 91f77ca..d882870 100644 --- a/module/sos-main.js +++ b/module/sos-main.js @@ -14,6 +14,7 @@ import { SoSActorSheet } from "./actor-sheet.js"; import { SoSUtility } from "./sos-utility.js"; import { SoSCombat } from "./sos-combat.js"; import { gearConverter } from "./gears_convert.js"; +import { SoSGMDeck } from "./sos-gm-deck.js"; /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -23,10 +24,24 @@ import { gearConverter } from "./gears_convert.js"; Hooks.once("init", async function () { console.log(`Initializing Shadows Over Sol System`); + /* -------------------------------------------- */ + game.settings.register("foundryvtt-shadows-over-sol", "gmDeck", { + name: "gmDeck", + scope: "world", + config: false, + type: Object + }); + + /* -------------------------------------------- */ // preload handlebars templates SoSUtility.preloadHandlebarsTemplates(); // Create useful storage space - game.system.sos = { } + let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/gm-deck.html', {} ); + let gmDeck = new SoSGMDeck(html); + gmDeck.render(true); + game.system.sos = { + gmDeck: gmDeck, + } /* -------------------------------------------- */ // Set an initiative formula for the system diff --git a/system.json b/system.json index 785e64a..b782801 100644 --- a/system.json +++ b/system.json @@ -2,11 +2,11 @@ "name": "foundryvtt-shadows-over-sol", "title": "Shadows over Sol", "description": "Shadows over Sol for FoundryVTT", - "version": "0.1.2", + "version": "0.1.4", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9", - "templateVersion": 17, + "templateVersion": 18, "author": "LeRatierBretonnien", "esmodules": [ "module/sos-main.js" ], "styles": ["styles/simple.css"], diff --git a/template.json b/template.json index f602ce4..81f75b3 100644 --- a/template.json +++ b/template.json @@ -1,6 +1,6 @@ { "Actor": { - "types": ["character", "npc"], + "types": ["character"], "templates": { "subactors": { "subactors": { @@ -133,9 +133,6 @@ }, "character": { "templates": [ "background", "common", "subactors" ] - }, - "npc": { - "templates": [ "background", "common" ] } }, "Item": { diff --git a/templates/chat-card.html b/templates/chat-card.html new file mode 100644 index 0000000..17acdbb --- /dev/null +++ b/templates/chat-card.html @@ -0,0 +1,2 @@ +

GM draws a card from its deck !

+ diff --git a/templates/gm-deck.html b/templates/gm-deck.html new file mode 100644 index 0000000..b904fec --- /dev/null +++ b/templates/gm-deck.html @@ -0,0 +1,21 @@ +
+ +
+
+ +
+ +
+ + +
+
+ +
+
+ +
\ No newline at end of file