Add deck legality checking, deck/library import-export, and a command palette
Threads Scryfall's per-format legalities through the reference db and adds a deck-page indicator (structural rules + banned/restricted lists) that lists violation reasons inline. Decks and selected library cards can now be exported to/imported from plain-text decklists, with best-effort name resolution and a report of anything that didn't match. Also adds a shuffle- and-draw sample hand modal, and an Alt+/ command palette for jumping to a tab, deck, or card without leaving the keyboard. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -220,3 +220,48 @@ pub fn card_decks(db: Db, oracle_id: String) -> Res<Vec<Deck>> {
|
||||
let s = db.lock().unwrap();
|
||||
s.catalog()?.card_decks(&oracle_id).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct DeckImportResult {
|
||||
pub deck: Deck,
|
||||
pub unresolved: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct LibraryImportResult {
|
||||
pub added: Vec<(String, i64)>,
|
||||
pub unresolved: Vec<String>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn export_deck(db: Db, deck_id: i64, path: String) -> Res<()> {
|
||||
let s = db.lock().unwrap();
|
||||
let text = s.catalog()?.export_deck_text(deck_id).map_err(|e| e.to_string())?;
|
||||
std::fs::write(&path, text).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn import_deck(db: Db, path: String, name: String) -> Res<DeckImportResult> {
|
||||
let s = db.lock().unwrap();
|
||||
let text = std::fs::read_to_string(&path).map_err(|e| e.to_string())?;
|
||||
let (deck, unresolved) = s.catalog()?.import_deck(&name, &text).map_err(|e| e.to_string())?;
|
||||
Ok(DeckImportResult { deck, unresolved })
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn export_library_cards(db: Db, oracle_ids: Vec<String>, path: String) -> Res<()> {
|
||||
let s = db.lock().unwrap();
|
||||
let text = s
|
||||
.catalog()?
|
||||
.export_library_text(&oracle_ids)
|
||||
.map_err(|e| e.to_string())?;
|
||||
std::fs::write(&path, text).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn import_library_cards(db: Db, path: String) -> Res<LibraryImportResult> {
|
||||
let s = db.lock().unwrap();
|
||||
let text = std::fs::read_to_string(&path).map_err(|e| e.to_string())?;
|
||||
let (added, unresolved) = s.catalog()?.import_library_list(&text).map_err(|e| e.to_string())?;
|
||||
Ok(LibraryImportResult { added, unresolved })
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ pub fn run() {
|
||||
commands::set_deck_card,
|
||||
commands::deck_contents,
|
||||
commands::card_decks,
|
||||
commands::export_deck,
|
||||
commands::import_deck,
|
||||
commands::export_library_cards,
|
||||
commands::import_library_cards,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user