Skip to content

Commit 56ef19f

Browse files
authored
exclude card backs option on the export (#171)
1 parent c02ad0a commit 56ef19f

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

cider-app/src/app/export-cards/export-cards.component.html

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,25 @@
121121
<input type="number" pInputText [id]="cardsPerPage" [(ngModel)]="cardsPerPage" required autofocus
122122
(ngModelChange)="updateSlices()" [disabled]="selectedPaper.name.includes('Tabletop Simulator')" />
123123
</div>
124-
<div class="p-field p-d-flex p-flex-row">
125-
<div class="p-field p-d-inline-flex p-flex-row p-mr-2">
124+
<div class="p-field checkbox-group">
125+
<div class="checkbox-item">
126126
<p-checkbox name="lowInk" class="p-mr-2" [binary]="true" [(ngModel)]="lowInk" inputId="lowInk"></p-checkbox>
127-
<label for="lowInk" class="ml-2">{{'export.low-ink-mode' | translate}}</label>
127+
<label for="lowInk">{{'export.low-ink-mode' | translate}}</label>
128+
</div>
129+
<div class="checkbox-item">
130+
<p-checkbox name="excludeCardBacks" class="p-mr-2" [binary]="true" [(ngModel)]="excludeCardBacks"
131+
(onChange)="changePaperType()" inputId="excludeCardBacks"></p-checkbox>
132+
<label for="excludeCardBacks">Exclude Card Backs</label>
128133
</div>
129-
<div class="p-field p-d-inline-flex p-flex-row p-mr-2">
134+
<div class="checkbox-item">
130135
<p-checkbox name="mirrorBacksX" class="p-mr-2" [binary]="true" [(ngModel)]="mirrorBacksX"
131136
inpudId="mirrorBacksX"></p-checkbox>
132-
<label for="mirrorBacksX" class="ml-2">{{'export.mirror-backs-x' | translate}}</label>
137+
<label for="mirrorBacksX">{{'export.mirror-backs-x' | translate}}</label>
133138
</div>
134-
<div class="p-field p-d-inline-flex p-flex-row p-mr-2">
139+
<div class="checkbox-item">
135140
<p-checkbox name="mirrorBacksY" class="p-mr-2" [binary]="true" [(ngModel)]="mirrorBacksY"
136141
inputId="mirrorBacksY"></p-checkbox>
137-
<label for="mirrorBacksY" class="ml-2">{{'export.mirror-backs-y' | translate}}</label>
142+
<label for="mirrorBacksY">{{'export.mirror-backs-y' | translate}}</label>
138143
</div>
139144
</div>
140145
<div class="p-d-flex p-flex-row">

cider-app/src/app/export-cards/export-cards.component.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ $preview-individual-scale: 0.08;
6363
div.p-d-flex div.p-field {
6464
flex: 1
6565
}
66+
67+
.checkbox-group {
68+
display: flex;
69+
flex-direction: row;
70+
flex-wrap: wrap;
71+
gap: 1.5rem;
72+
align-items: center;
73+
74+
.checkbox-item {
75+
flex: initial !important; // Override the general rule
76+
display: flex;
77+
align-items: center;
78+
white-space: nowrap; // Prevent label wrapping for short items
79+
}
80+
}
6681
}
6782

6883
.card-controls {

cider-app/src/app/export-cards/export-cards.component.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class ExportCardsComponent implements OnInit {
7272
public maxTtsPixels: number = 4096;
7373
public scale: number = 0.1;
7474
public exportSelectionDialogVisible: boolean = false;
75+
public excludeCardBacks: boolean = false;
7576
public someCardsMissingTemplates: boolean = false;
7677
renderCache: boolean = false;
7778
zoomOptions: any[] = [
@@ -88,7 +89,7 @@ export class ExportCardsComponent implements OnInit {
8889
private confirmationService: ConfirmationService) {
8990
cardsService.getAll().then(cards => {
9091
// check cards for front/back templates being defined
91-
const cardsWithTemplatesDefined = cards.filter(card => card.backCardTemplateId && card.frontCardTemplateId);
92+
const cardsWithTemplatesDefined = cards.filter(card => card.frontCardTemplateId);
9293
this.someCardsMissingTemplates = cards.length != cardsWithTemplatesDefined.length;
9394
this.originalCards = cardsWithTemplatesDefined;
9495
this.cards = cardsWithTemplatesDefined;
@@ -184,7 +185,7 @@ export class ExportCardsComponent implements OnInit {
184185
this.cardsPerPage = 6;
185186
this.pixelRatio = 1;
186187
this.showFront = true;
187-
this.showBack = true;
188+
this.showBack = !this.excludeCardBacks;
188189
this.updateSlices();
189190
}
190191
// console.log('change paper type', this.selectedPaper.name, this.mirrorBacksX, this.mirrorBacksY);
@@ -235,7 +236,7 @@ export class ExportCardsComponent implements OnInit {
235236
const renderSlices = this.sliceIntoChunks(this.cards, sliceSize);
236237
const hardLimit = pLimit(1);
237238
this.showFront = true;
238-
this.showBack = true;
239+
this.showBack = !this.excludeCardBacks;
239240
this.renderCache = true;
240241
this.loadingPercent = 0;
241242
const preRenders$ = renderSlices.map((slice, index) => {
@@ -269,8 +270,10 @@ export class ExportCardsComponent implements OnInit {
269270
await this.prerenderCardImages();
270271
this.loadingPercent = 0;
271272

273+
const exportSides = this.excludeCardBacks ? [true] : [true, false];
274+
272275
const promisedSheetImages$ = this.slicedCards.map((sheet, sheetIndex) => {
273-
return Promise.all([true, false].map(async (showFront) => {
276+
return Promise.all(exportSides.map(async (showFront) => {
274277
return await hardLimit(async () => {
275278
this.sheet = sheet;
276279
this.showFront = showFront;
@@ -397,18 +400,23 @@ export class ExportCardsComponent implements OnInit {
397400
const imgName = 'front-' + imgIdentifier + '.png';
398401
return this.dataUrlToFile(imgUri, imgName);
399402
});
400-
const backCards$ = this.backCards.map(async cardPreview => {
401-
await lastValueFrom(cardPreview.isCacheLoaded()).catch(() => {
402-
return Promise.reject('Failed to render card "' + cardPreview.card.name + '" with template "' + cardPreview.template.name + '".');
403+
404+
let backCards$: Promise<File>[] = [];
405+
if (!this.excludeCardBacks) {
406+
backCards$ = this.backCards.map(async cardPreview => {
407+
await lastValueFrom(cardPreview.isCacheLoaded()).catch(() => {
408+
return Promise.reject('Failed to render card "' + cardPreview.card.name + '" with template "' + cardPreview.template.name + '".');
409+
});
410+
const imgUri = await limit(() => this.imageRendererService.toPng((<any>cardPreview).element.nativeElement,
411+
{ pixelRatio: this.individualExportPixelRatio }));
412+
const imgIdentifier = this.individualExportUseCardName
413+
? StringUtils.toKebabCase(cardPreview.card?.name)
414+
: cardPreview.card?.id;
415+
const imgName = 'back-' + imgIdentifier + '.png';
416+
return this.dataUrlToFile(imgUri, imgName);
403417
});
404-
const imgUri = await limit(() => this.imageRendererService.toPng((<any>cardPreview).element.nativeElement,
405-
{ pixelRatio: this.individualExportPixelRatio }));
406-
const imgIdentifier = this.individualExportUseCardName
407-
? StringUtils.toKebabCase(cardPreview.card?.name)
408-
: cardPreview.card?.id;
409-
const imgName = 'back-' + imgIdentifier + '.png';
410-
return this.dataUrlToFile(imgUri, imgName);
411-
});
418+
}
419+
412420
const allCards$ = frontCards$.concat(backCards$);
413421
return Promise.all(this.promisesProgress(allCards$, () => this.loadingPercent += 100.0 / (allCards$.length + 1)))
414422
.then(promisedImages => {

0 commit comments

Comments
 (0)