Skip to content

Commit

Permalink
Merge pull request #35 from spacemandev-git/decksettings
Browse files Browse the repository at this point in the history
Deck Settings 1.5.0 Release
  • Loading branch information
spacemandev-git authored Sep 4, 2020
2 parents 299f27e + 2fc2e91 commit e6a5309
Show file tree
Hide file tree
Showing 17 changed files with 598 additions and 37 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ At a high level, this module abuses the setFlag() and getFlag() operators on fol

A FolderID refers to the DeckID, and the JournalEntry ID refers to the Card ID.

### Hooks
Calls ```decks.ready``` hook when it's finished initalizing decks

### game.decks

```game.decks.get(deckId:string)```
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.5.0
- Added Deck Img field when importing via SDF and Images to specify what the deck image should be
- Added per player setting configuration to allow them to view/draw/discard cards from any given deck

1.4.6
- Bugfix for chbDrawFaceUp to chbDrawFaceUpHand

Expand Down
3 changes: 3 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ At a high level, this module abuses the setFlag() and getFlag() operators on fol

A FolderID refers to the DeckID, and the JournalEntry ID refers to the Card ID.

### Hooks
Calls ```decks.ready``` hook when it's finished initalizing decks

### game.decks

```game.decks.get(deckId:string)```
Expand Down
11 changes: 6 additions & 5 deletions dist/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
"title": "Card Support (Unofficial)",
"description": "Unofficial deck support for foundry that allows you to have cards and player hands and the like.",
"author": "Spacemandev, Norc",
"version": "1.4.6",
"version": "1.5.0-dev",
"minimumCoreVersion": "0.6.0",
"compatibleCoreVersion": "0.7.0",
"url": "https://github.com/Brownie79/fvtt-card-support",
"manifest": "https://github.com/Brownie79/fvtt-card-support/releases/download/latest/module.json",
"download": "https://github.com/Brownie79/fvtt-card-support/releases/download/latest/module.zip",
"compatibleCoreVersion": "0.7.2",
"url": "https://github.com/spacemandev-git/fvtt-card-support",
"manifest": "https://github.com/spacemandev-git/fvtt-card-support/releases/download/latest/module.json",
"download": "https://github.com/spacemandev-git/fvtt-card-support/releases/download/latest/module.zip",
"esmodules": [
"./scripts/decksupport.js",
"./scripts/tileHud.js",
"./scripts/tokenHUD.js",
"./scripts/drop.js",
"./scripts/socketListener.js",
"./scripts/decksettings.js",
"./lib/js-yaml.js",
"./lib/jszip.js",
"./cardhotbar/index.js"
Expand Down
14 changes: 13 additions & 1 deletion dist/scripts/DeckForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class DeckForm extends FormApplication {
let deck = d;
//Draw Card Listener
html.find(`#${deck.deckID}-draw`).click(() => {
if (!game.user.isGM && !game.settings.get('cardsupport', `${deck.deckID}-settings`)['drawCards'].includes(game.user.id)) {
ui.notifications.error("You don't have permission to do that.");
return;
}
let takeDialogTemplate = `
<div style="display:flex; flex-direction:column">
<div style="display:flex; flex-direction:row">
Expand Down Expand Up @@ -74,11 +78,15 @@ export class DeckForm extends FormApplication {
});
//View Cards Listener
html.find(`#${deck.deckID}-view`).click(() => {
if (!game.user.isGM && !game.settings.get('cardsupport', `${deck.deckID}-settings`)['viewDeck'].includes(game.user.id)) {
ui.notifications.error("You don't have permission to do that.");
return;
}
let template = `
<div>
<p>
<h3> How many cards do you want to view? </h3>
<h3> Deck has ${deck._state.length} cards </h3>
<h3> Deck has ${game.decks.get(deck.deckID)._state.length} cards </h3>
<input id="numCards" value=1 type="number" style='width:50px;'/>
</p>
</div>
Expand Down Expand Up @@ -115,6 +123,10 @@ export class DeckForm extends FormApplication {
});
//Discard Listener
html.find(`#${deck.deckID}-discard`).click(() => {
if (!game.user.isGM && !game.settings.get('cardsupport', `${deck.deckID}-settings`)['viewDiscard'].includes(game.user.id)) {
ui.notifications.error("You don't have permission to do that.");
return;
}
if (game.user.isGM) {
let discardPile = [];
for (let card of deck._discard) {
Expand Down
33 changes: 31 additions & 2 deletions dist/scripts/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,13 @@ export class Decks {
else {
this.decks = JSON.parse(game.settings.get("cardsupport", "decks"));
}
Hooks.call("decks.ready");
}
/**
*
* @param sdf A Zip Object from JSZip
*/
create(deckfile) {
create(deckfile, deckImg) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
//If DeckFolder doesn't exist create it
Expand Down Expand Up @@ -363,6 +364,20 @@ export class Decks {
if (result.target != target) {
yield FilePicker.createDirectory(src, target, {});
}
//Deal with Deck Img
let deckImgPath = yield uploadFile(target, deckImg);
//Register the setting for the new deck
game.settings.register("cardsupport", `${deckfolderId}-settings`, {
config: false,
scope: "world",
type: Object,
default: {
"deckImg": deckImgPath,
"drawCards": [],
"viewDeck": [],
"viewDiscard": []
}
});
//Create a new deck object
//Read deck.yaml
const deckyaml = jsyaml.safeLoadAll(yield deckZip.file('deck.yaml').async('string'));
Expand Down Expand Up @@ -405,7 +420,7 @@ export class Decks {
/**
* #param files A list of img files
*/
createByImages(deckName, files, cardBack) {
createByImages(deckName, files, cardBack, deckImg) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
var _a;
//If DeckFolder doesn't exist create it
Expand All @@ -425,6 +440,20 @@ export class Decks {
if (result.target != target) {
yield FilePicker.createDirectory(src, target, {});
}
//Deal with Deck Img
let deckImgPath = yield uploadFile(target, deckImg);
//Register the setting for the new deck
game.settings.register("cardsupport", `${deckfolderId}-settings`, {
config: false,
scope: "world",
type: Object,
default: {
"deckImg": deckImgPath,
"drawCards": [],
"viewDeck": [],
"viewDiscard": []
}
});
//uplaod CardBack
let cardBackPath = yield uploadFile(target, cardBack);
//Make Cards
Expand Down
217 changes: 217 additions & 0 deletions dist/scripts/decksettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Hooks.on("decks.ready", () => {
//Go through game.decks and make and register a setting for each one
for (let deckID of Object.keys(game.decks.decks)) {
game.settings.register("cardsupport", `${deckID}-settings`, {
config: false,
scope: "world",
type: Object,
default: {
"deckImg": "",
"drawCards": [],
"viewDeck": [],
"viewDiscard": []
}
});
}
game.settings.registerMenu('cardsupport', 'decksettings', {
name: "Deck Settings for Players",
label: "Deck Settings",
type: DeckSettingsForm,
restricted: true
});
});
class DeckSettingsForm extends FormApplication {
constructor(object, options = {}) {
super(object, options);
}
getData() {
return {
decks: game.decks.decks
};
}
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
id: "decksettingsform",
title: "Deck Settings",
template: "modules/cardsupport/templates/decksettingsform.hbs"
});
}
activateListeners(html) {
return __awaiter(this, void 0, void 0, function* () {
for (let deckID of Object.keys(game.decks.decks)) {
html.find(`#${deckID}-draw`).click((ev) => {
let playersettings = '';
for (let player of Array.from(game.users)) {
if (player['isGM']) {
continue;
}
let playerID = player['_id'];
if (game.settings.get('cardsupport', `${deckID}-settings`)['drawCards'].includes(playerID)) {
playersettings += `
<p style="display:flex">
<span style="flex: 2">${game.users.get(playerID).name}</span>
<input style="flex: 1" id=${playerID} type="checkbox" checked/>
</p>`;
}
else {
playersettings += `
<p style="display:flex">
<span style="flex: 2">${game.users.get(playerID).name}</span>
<input style="flex: 1" id=${playerID} type="checkbox" />
</p>`;
}
}
let diaglogTemplate = `
${playersettings}
`;
new Dialog({
title: `${game.decks.get(deckID).deckName} Draw Settings`,
content: diaglogTemplate,
buttons: {
save: {
label: "Save",
callback: (html) => __awaiter(this, void 0, void 0, function* () {
let oldSettings = game.settings.get('cardsupport', `${deckID}-settings`);
let drawCardsSettings = [];
for (let player of Array.from(game.users)) {
if (player['isGM']) {
continue;
}
if (html.find(`#${player['_id']}`)[0].checked) {
drawCardsSettings.push(player['_id']);
}
}
game.settings.set('cardsupport', `${deckID}-settings`, {
drawCards: drawCardsSettings,
deckImg: oldSettings.deckImg,
viewDeck: oldSettings.viewDeck,
viewDiscard: oldSettings.viewDiscard
});
})
}
}
}).render(true);
});
html.find(`#${deckID}-view`).click((ev) => {
let playersettings = '';
for (let player of Array.from(game.users)) {
if (player['isGM']) {
continue;
}
let playerID = player['_id'];
if (game.settings.get('cardsupport', `${deckID}-settings`)['viewDeck'].includes(playerID)) {
playersettings += `
<p style="display:flex">
<span style="flex: 2">${game.users.get(playerID).name}</span>
<input style="flex: 1" id=${playerID} type="checkbox" checked/>
</p>`;
}
else {
playersettings += `
<p style="display:flex">
<span style="flex: 2">${game.users.get(playerID).name}</span>
<input style="flex: 1" id=${playerID} type="checkbox" />
</p>`;
}
}
let diaglogTemplate = `
${playersettings}
`;
new Dialog({
title: `${game.decks.get(deckID).deckName} View Settings`,
content: diaglogTemplate,
buttons: {
save: {
label: "Save",
callback: (html) => __awaiter(this, void 0, void 0, function* () {
let oldSettings = game.settings.get('cardsupport', `${deckID}-settings`);
let viewCardsSettings = [];
for (let player of Array.from(game.users)) {
if (player['isGM']) {
continue;
}
if (html.find(`#${player['_id']}`)[0].checked) {
viewCardsSettings.push(player['_id']);
}
}
game.settings.set('cardsupport', `${deckID}-settings`, {
drawCards: oldSettings.drawCards,
deckImg: oldSettings.deckImg,
viewDeck: viewCardsSettings,
viewDiscard: oldSettings.viewDiscard
});
})
}
}
}).render(true);
});
html.find(`#${deckID}-discard`).click((ev) => {
let playersettings = '';
for (let player of Array.from(game.users)) {
let playerID = player['_id'];
if (player['isGM']) {
continue;
}
if (game.settings.get('cardsupport', `${deckID}-settings`)['viewDiscard'].includes(playerID)) {
playersettings += `
<p style="display:flex">
<span style="flex: 2">${game.users.get(playerID).name}</span>
<input style="flex: 1" id=${playerID} type="checkbox" checked/>
</p>`;
}
else {
playersettings += `
<p style="display:flex">
<span style="flex: 2">${game.users.get(playerID).name}</span>
<input style="flex: 1" id=${playerID} type="checkbox" />
</p>`;
}
}
let diaglogTemplate = `
${playersettings}
`;
new Dialog({
title: `${game.decks.get(deckID).deckName} Discard Settings`,
content: diaglogTemplate,
buttons: {
save: {
label: "Save",
callback: (html) => __awaiter(this, void 0, void 0, function* () {
let oldSettings = game.settings.get('cardsupport', `${deckID}-settings`);
let discardCardsSettings = [];
for (let player of Array.from(game.users)) {
if (player['isGM']) {
continue;
}
if (html.find(`#${player['_id']}`)[0].checked) {
discardCardsSettings.push(player['_id']);
}
}
game.settings.set('cardsupport', `${deckID}-settings`, {
drawCards: oldSettings.drawCards,
deckImg: oldSettings.deckImg,
viewDeck: oldSettings.viewDeck,
viewDiscard: discardCardsSettings
});
})
}
}
}).render(true);
});
}
});
}
}
// Default Image
// Draw Cards
// View Deck
// View Discard
Loading

0 comments on commit e6a5309

Please sign in to comment.