Open acpennington opened 3 years ago
import { cards, fusions } from "databases/cardDB";
function exportDeck(main, side) { const buf = ["#created by ..."]; const add = (id, n) => { for (let i = 0; i < n; i++) buf.push(id); }; buf.push("#main"); for (const name in main) { add(cards[name].id, main[name]); } buf.push("#extra"); for (const name in fusions) { add(fusions[name].id, 3); } buf.push("!side"); for (const name in side) { add(cards[name].id, side[name]); } return buf.join("\n"); }
- deck sizes are likely problematic - testing is required to figure out what DB/YGOPro/etc does with main decks > 60 or extra decks with > 15 cards. if both of these result in errors, we probably want to:
1. not export an extra deck at all (and make it clear in the UI that this is the case)
1. grey out the export functionality if the main deck is too large (or display an error when the export button is clicked)
- in order to import we need to dynamically create a map from id => card name (maybe when the 'Import' button is first clicked we can iterate over the cards DB and build this lookup table)
---
I'm not super interested in the rest of the wiring required here, so I'll assign back to @acpennington to finish this.
Confirmed via experimentation that DB will import a deck with > 60 cards/>15 in extra deck, but appears to silently drop them, as when you re-export the deck you just imported the cards are gone.
For export, see: https://stackoverflow.com/questions/43135852/javascript-export-to-text-file For import, see: https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications