Add support for more than 9 cards, with multi-page
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michal Kunc 2022-04-06 21:39:54 +02:00
parent c9cd9f0da5
commit 8cd26c971a

View File

@ -29,11 +29,16 @@
} }
} }
//let card_selected = 0; function chunk(arr) {
//$: selected_card = cards[card_selected]; let larr = [...arr], out = [];
while(larr.length) {
out = [...out, (larr.splice(0,MAX_CARDS))];
};
return out;
}
$: pages = chunk(cards);
let selector = cards[0].id; let selector = cards[0].id;
//$: selector = cards[card_selected].id;
$: selected_card = cards.filter(x => x.id === selector)[0]; $: selected_card = cards.filter(x => x.id === selector)[0];
$: selected_idx = get_idx_by_id(selector); $: selected_idx = get_idx_by_id(selector);
@ -45,10 +50,8 @@
} }
function add_card() { function add_card() {
if (cards.length < MAX_CARDS) { cards = [...cards, {id: cards[cards.length-1].id+1, ...mhp}];
cards = [...cards, {id: cards[cards.length-1].id+1, ...mhp}]; selector = cards[cards.length-1].id;
selector = cards[cards.length-1].id;
}
} }
function remove_card() { function remove_card() {
@ -70,20 +73,22 @@
<h1>PF2e card generator</h1> <h1>PF2e card generator</h1>
<CardInput bind:name={selected_card.name} bind:type={selected_card.type} tags={selected_card.tags} bind:attributes={selected_card.attributes} bind:description={selected_card.description} on:change_tags={change_tags} on:add_card={add_card} on:remove_card={remove_card}/> <CardInput bind:name={selected_card.name} bind:type={selected_card.type} tags={selected_card.tags} bind:attributes={selected_card.attributes} bind:description={selected_card.description} on:change_tags={change_tags} on:add_card={add_card} on:remove_card={remove_card}/>
</section> </section>
{#each pages as page}
<section class="cards"> <section class="cards">
{#each cards as card, idx (card.id)} {#each page as card, idx (card.id)}
<div class="card"> <div class="card" style="break-after:avoid;">
<Card {...card}/> <Card {...card}/>
<input class="card-selector" type="radio" bind:group={selector} value={card.id}/> <input class="card-selector" type="radio" bind:group={selector} value={card.id}/>
</div> </div>
{/each} {/each}
</section> </section>
{/each}
</main> </main>
<style> <style>
@media print { @media print {
@page { @page {
margin: 0; margin: 7mm;
} }
.controls { .controls {
display: none; display: none;
@ -95,6 +100,7 @@
.cards { .cards {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
break-after: always;
} }
h1 { h1 {
text-transform: uppercase; text-transform: uppercase;