Skip to content

Commit

Permalink
Merge pull request #167 from redweller/fix/dl-and-page
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGiddyLimit authored May 14, 2023
2 parents 259a951 + da33424 commit 4924966
Show file tree
Hide file tree
Showing 10 changed files with 459 additions and 285 deletions.
60 changes: 49 additions & 11 deletions js/base-art.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@ function d20plusArt () {
}
});

$(`.card-backing-by-url`).live("click", function () {
const cId = $(this).attr("data-card-id");
const url = window.prompt("Enter a URL", d20plus.art.getLastImageUrl());
if (url) {
d20plus.art.setLastImageUrl(url);
const card = d20.Campaign.decks.find(it => it.cards.find(c => c.id === cId)).cards.find(c => c.id === cId);
card.set("card_back", url);
}
});

$(`.deck-mass-cards-by-url`).live("click", function () {
const dId = $(this).attr("data-deck-id");

Expand All @@ -338,31 +348,59 @@ function d20plusArt () {
const $iptTxt = $dialog.find(`textarea`);
const $btnAdd = $dialog.find(`button`).click(() => {
const lines = ($iptTxt.val() || "").split("\n");
const toSaveAll = [];
const addCardsParams = [];
lines.filter(it => it && it.trim()).forEach(l => {
const split = l.split("---").map(it => it.trim()).filter(Boolean);
if (split.length >= 2) {
if (split.length === 2) {
const [name, url] = split;
const toSave = deck.cards.push({
avatar: url,
id: d20plus.ut.generateRowId(),
name,
placement: 99,
});
toSaveAll.push(toSave);
const params = [
name.includes(".") ? name : `${name}.png`,
url,
0,
];
addCardsParams.push(params);
}
});
$dialog.dialog("close");

toSaveAll.forEach(s => s.save());
deck.save();
if (addCardsParams.length) {
deck.uploader.libraryCards = {};
deck.uploader.libraryCardIndex = 0;
addCardsParams.forEach(params => deck.uploader.addCardFromLibrary(...params));
}
});

$dialog.dialog({
width: 800,
height: 650,
});
});

$("tr.card").live("click", event => {
if (!event.target.dataset.cardId) return;
event.preventDefault();
const cId = event.target.dataset.cardId;
const card = d20.Campaign.decks.find(it => it.cards.find(c => c.id === cId)).cards.find(c => c.id === cId)?.editor;
const confirm = $("<div>Are you sure you want to delete this card? This cannot be undone.</div>");
if (!card) return;
card.$el.dialog("destroy");
confirm.dialog({
modal: !0,
title: "Confirm Deletion",
buttons: {
Delete () {
card.model.destroy();
confirm.dialog("destroy").remove();
},
Cancel () {
confirm.dialog("destroy").remove();
},
},
beforeClose () {
confirm.dialog("destroy").remove();
},
})
});
};

d20plus.art._lastImageUrl = "https://example.com/pic.png";
Expand Down
12 changes: 12 additions & 0 deletions js/base-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,16 @@ function baseConfig () {
}
}

d20plus.cfg.HandleCss = () => {
// properly align layer toolbar
const $wrpDmModeSw = $(`.dark-mode-switch`);
const $wrpBtnsMain = $(`#floatingtoolbar`);
const $ulBtns = $(`#floatinglayerbar`);
const darkModeShift = $wrpDmModeSw.css("display") === "none" || $wrpDmModeSw.css("visibility") === "hidden" ? 0 : 54;
$ulBtns.css({top: $wrpBtnsMain.height() + darkModeShift + 40});
$wrpDmModeSw.css({top: $wrpBtnsMain.height() + 40});
}

d20plus.cfg.baseHandleConfigChange = () => {
d20plus.cfg.handleInitiativeShrink();

Expand All @@ -773,6 +783,8 @@ function baseConfig () {
$(`.dark-mode-switch`).toggle(!d20plus.cfg.get("interface", "hideDarkModeSwitch"));
$(`#helpsite`).toggle(!d20plus.cfg.getOrDefault("interface", "hideHelpButton"));
$(`#langpanel`).toggle(d20plus.cfg.getOrDefault("chat", "languages"));

d20plus.cfg.HandleCss();
};

d20plus.cfg.startPlayerConfigHandler = () => {
Expand Down
9 changes: 9 additions & 0 deletions js/base-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,15 @@ function baseCss () {
s: `.actionhelp.js, .commandhelp.js`,
r: `display: none;`,
},
// Deck editor styles
{
s: `tr.card:hover::after`,
r: `background: rgba(200, 200, 200, 0.4);`,
},
{
s: `tr.card::after`,
r: `content: "D";font-family: pictos;display: block;float: right;padding: 3px;border-radius: 5px;background: var(--dark-primary);margin: 10px 3px;`,
},
];

d20plus.css.baseCssRulesPlayer = [
Expand Down
8 changes: 7 additions & 1 deletion js/base-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function d20plusEngine () {
$("#tmpl_handouteditor").html($(d20plus.html.handoutEditor).html());
$("#tmpl_deckeditor").html($(d20plus.html.deckEditor).html());
$("#tmpl_cardeditor").html($(d20plus.html.cardEditor).html());
$("#tmpl_cardupload").html($(d20plus.html.cardUploader).html());
$("#tmpl_macroeditor").html($(d20plus.html.macroEditor).html());
// ensure tokens have editable sight
$("#tmpl_tokeneditor").replaceWith(d20plus.html.tokenEditor);
Expand Down Expand Up @@ -387,6 +388,9 @@ function d20plusEngine () {
width: {id: "page-size-width-input", class: ".width.units.page_setting_item"},
height: {id: "page-size-height-input", class: ".height.units.page_setting_item"},
background_color: {class: ".pagebackground"},
wrapperColor: {class: ".wrappercolor"},
useAutoWrapper: {id: "page-wrapper-color-from-map-toggle", class: ".useautowrapper"},

scale_number: {id: "page-size-height-input", class: ".scale_number"},
scale_units: {id: "page-scale-grid-cell-label-select", class: ".scale_units"},
gridlabels: {id: "page-grid-hex-label-toggle", class: ".gridlabels"},
Expand Down Expand Up @@ -810,7 +814,9 @@ function d20plusEngine () {
}

d20.engine.canvas._renderAll = _.bind(d20plus.mod.renderAll, d20.engine.canvas);
d20.engine.canvas._layerIteratorGenerator = d20plus.mod.layerIteratorGenerator;
d20.engine.canvas.sortTokens = _.bind(d20plus.mod.sortTokens, d20.engine.canvas);
d20.engine.canvas.drawAnyLayer = _.bind(d20plus.mod.drawAnyLayer, d20.engine.canvas);
d20.engine.canvas.drawTokensWithoutAuras = _.bind(d20plus.mod.drawTokensWithoutAuras, d20.engine.canvas);
};

d20plus.engine.removeLinkConfirmation = function () {
Expand Down
Loading

0 comments on commit 4924966

Please sign in to comment.