Compare commits

..

No commits in common. "86390d27c7b375ab63c2eebbe11e38e43578a71a" and "2be16753bc26a6ce49198c79c99351ca732c53ad" have entirely different histories.

2 changed files with 10 additions and 71 deletions

View File

@ -2,27 +2,8 @@
import Card from './Card.svelte'; import Card from './Card.svelte';
import CardInput from './CardInput.svelte'; import CardInput from './CardInput.svelte';
import { writable } from 'svelte/store';
import LZString from 'lz-string'; import LZString from 'lz-string';
const NO_CARD_MAGIC_STRING = "---";
let saved_cards = {};
let saved_cards_keys = [NO_CARD_MAGIC_STRING];
let selected_saved_card = NO_CARD_MAGIC_STRING;
const saved_cards_store = writable<object>(JSON.parse(localStorage.getItem("saved_cards")) || {} );
saved_cards_store.subscribe(v => {
if (Object.keys(v).length > 0) {
saved_cards = v;
saved_cards_keys = Object.keys(v).sort();
} else {
saved_cards = {};
saved_cards_keys = [NO_CARD_MAGIC_STRING]
}
selected_saved_card = saved_cards_keys[0];
})
saved_cards_store.update(n => n); // Dummy update
saved_cards_store.subscribe((value) => localStorage.setItem("saved_cards", JSON.stringify(value)));
const MAX_CARDS = 9; const MAX_CARDS = 9;
let cards = []; let cards = [];
let mhp = { let mhp = {
@ -43,7 +24,7 @@
function get_idx_by_id(id) { function get_idx_by_id(id) {
for(let idx = 0; idx < cards.length; idx++) { for(let idx = 0; idx < cards.length; idx++) {
if(id === cards[idx].id) { if(id === cards[idx].id) {
return idx; return idx
} }
} }
} }
@ -79,50 +60,18 @@
if (cards.length > 1) { // remove only if there is more than 1 card if (cards.length > 1) { // remove only if there is more than 1 card
cards = cards.filter(x => x.id != selector); cards = cards.filter(x => x.id != selector);
if (selected_idx >= cards.length) { if (selected_idx >= cards.length) {
selector = cards[cards.length-1].id; selector = cards[cards.length-1].id;
} else { } else {
selector = cards[selected_idx].id; selector = cards[selected_idx].id;
} }
} }
} }
function save_card() {
saved_cards_store.update(n => {
let to_save = {};
for (let key in selected_card) {
if (key !== "id") {
to_save[key] = selected_card[key];
}
}
n[to_save["name"]] = to_save;
return n;
});
}
function load_card() {
if (selected_saved_card !== NO_CARD_MAGIC_STRING) {
let new_card = saved_cards[selected_saved_card];
selected_card.name = new_card.name;
selected_card.type = new_card.type;
selected_card.tags = new_card.tags;
selected_card.attributes = new_card.attributes;
selected_card.description = new_card.description;
cards = cards;
}
}
function delete_card() {
saved_cards_store.update(n => {
delete n[selected_saved_card];
return n;
})
}
</script> </script>
<main> <main>
<section class="controls"> <section class="controls">
<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} bind:saved_cards={saved_cards_keys} bind:selected_saved_card={selected_saved_card} on:change_tags={change_tags} on:add_card={add_card} on:remove_card={remove_card} on:save_card={save_card} on:load_card={load_card} on:delete_card={delete_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} {#each pages as page}
<section class="cards"> <section class="cards">

View File

@ -17,10 +17,10 @@
input.setAttribute('accept', 'image/*'); input.setAttribute('accept', 'image/*');
input.onchange = function () { input.onchange = function () {
var file = this.files[0]; var file = this.files[0];
var reader = new FileReader(); var reader = new FileReader();
reader.onload = function () { reader.onload = function () {
/* /*
Note: Now we need to register the blob in TinyMCEs image blob Note: Now we need to register the blob in TinyMCEs image blob
registry. In the next release this part hopefully won't be registry. In the next release this part hopefully won't be
@ -34,15 +34,15 @@
/* call the callback and populate the Title field with the file name */ /* call the callback and populate the Title field with the file name */
cb(blobInfo.blobUri(), { title: file.name }); cb(blobInfo.blobUri(), { title: file.name });
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
}; };
input.click(); input.click();
}, },
}; };
export let name, type, tags, attributes, description, saved_cards, selected_saved_card; export let name, type, tags, attributes, description;
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
@ -76,18 +76,8 @@
<div class="row">Description: <div class="row">Description:
<Editor {apiKey} {conf} bind:value={description}/> <Editor {apiKey} {conf} bind:value={description}/>
</div> </div>
<div class="row">
<select bind:value={selected_saved_card}>
{#each saved_cards as card}
<option value={card}>{card}</option>
{/each}
</select>
</div>
<div class="row"> <div class="row">
<button on:click={e => dispatch('add_card')}>+</button> <button on:click={e => dispatch('add_card')}>+</button>
<button on:click={e => dispatch('remove_card')}>-</button> <button on:click={e => dispatch('remove_card')}>-</button>
<button on:click={e => dispatch('save_card')}>Save</button>
<button on:click={e => dispatch('load_card')}>Load</button>
<button on:click={e => dispatch('delete_card')}>Delete selected</button>
</div> </div>
</div> </div>