Skip to content

Commit

Permalink
art description export to clipboard
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-src-components-widgets-ubg-cards.html,AUTO-COMMIT-src-components-widgets-ubg-cards.js,
  • Loading branch information
onsetsu committed Sep 23, 2023
1 parent d7f3ced commit 5e35fcd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/widgets/ubg-cards.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<button id="sortById" title="sort cards by id"><i class="fa fa-sort" aria-hidden="true"></i>by id</button>
<button id="sortByName" title="sort cards by name"><i class="fa fa-sort" aria-hidden="true"></i>by name</button>
<button id="import new cards" class="shortcut-supported" title="import new cards (Ctrl+I)">import <i class="fa fa-download"></i></button>
<button id="artDesc" class="shortcut-supported" title="copy to clipboard art descriptions of card that do not have art yet">art <i class="fa fa-clipboard"></i></button>
<button id="printAll" title="print all cards (Ctrl+Shift+P)">all <i class="fa fa-print"></i></button>
<button id="printChanges" title="print changed cards (Ctrl+P)">changes <i class="fa fa-print"></i></button>
<button id="saveJSON" class="shortcut-supported" title="save json (Ctrl+S)">json <i class="fa fa-floppy-o"></i></button>
Expand Down
54 changes: 52 additions & 2 deletions src/components/widgets/ubg-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ContextMenu from 'src/client/contextmenu.js';
import { Paper } from 'src/client/literature.js';
import Bibliography from "src/client/bibliography.js";
import pdf from "src/external/pdf.js";
import { shake } from 'utils';

import { serialize, deserialize } from 'src/client/serialize.js';
import Card from 'demos/stefan/untitled-board-game/ubg-card.js';
Expand Down Expand Up @@ -588,6 +589,10 @@ export default class Cards extends Morph {
return this.buildCards(doc, cards); // .slice(0,12)
}

async fetchAssetsInfo() {
return (await this.assetsFolder.fetchStats()).contents;
}

async buildCards(doc, cardsToPrint) {
const GAP = lively.pt(.2, .2);

Expand All @@ -603,8 +608,7 @@ export default class Cards extends Morph {
const progress = await lively.showProgress(progressLabel(0));

try {
const ASSET_FOLDER = this.assetsFolder;
const assetsInfo = (await ASSET_FOLDER.fetchStats()).contents;
const assetsInfo = await this.fetchAssetsInfo();

let i = 0;
let currentPage = 0;
Expand Down Expand Up @@ -1645,6 +1649,52 @@ width: ${ruleTextBox.width}mm; min-height: ${ruleTextBox.height}mm;`}></div>;
}
}

async onArtDesc(evt) {
const text = do {
const assetsInfo = await this.fetchAssetsInfo();
let ids = []
for (let entry of assetsInfo) {
if (entry.type !== 'file') {
continue
}

const match = entry.name.match(/^(.+)\.jpg$/)
if (!match) {
continue
}

// const id = parseInt(match[1])
// if (_.isInteger(id)) {
// ids.push(id)
// }
ids.push(match[1])
}

let cards = this.cards;
cards = cards
.filter(c => !c.getIsBad())
// we just use a string match for now
.filter(c => !ids.includes(c.getId() + '')).sortBy('id')
cards.map(c => {
const artDesc = c.getArtDirection() || c.getName();
return `[${c.getId()}, '${artDesc}'],`
}).join('\n')
};

const type = "text/plain";
const blob = new Blob([text], { type });
// evt.clipboardData.setData('text/html', html);
const data = [new ClipboardItem({ [type]: blob })];

try {
await navigator.clipboard.write(data);
lively.success('copied art description!');
} catch (e) {
shake(this.get('#artDesc'));
lively.error('copying failed', e.message);
}
}

async onPrintAll(evt) {
if (!this.cards) {
return;
Expand Down

0 comments on commit 5e35fcd

Please sign in to comment.