Add horrible storage system
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
47985a77d9
commit
86390d27c7
@ -2,8 +2,27 @@
|
|||||||
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 = {
|
||||||
@ -66,12 +85,44 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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} 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} 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}/>
|
||||||
</section>
|
</section>
|
||||||
{#each pages as page}
|
{#each pages as page}
|
||||||
<section class="cards">
|
<section class="cards">
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export let name, type, tags, attributes, description;
|
export let name, type, tags, attributes, description, saved_cards, selected_saved_card;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
@ -76,8 +76,18 @@
|
|||||||
<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>
|
||||||
|
Loading…
Reference in New Issue
Block a user