Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "decklist"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
authors = ["Seth <bajablastoise@protonmail.com>"]
license = "Unlicense"
Expand Down
58 changes: 55 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
collection::{check_legality, check_missing, FormatLegal},
database::scryfall::{get_min_price, match_card, min_price_fmt},
database::scryfall::{get_min_price, match_card, min_price_fmt, serialize_database},
startup::{
config_check, database_check, database_management, directory_check, dl_scryfall_latest,
load_database_file, ConfigCheck, DatabaseCheck, DirectoryCheck,
load_database_file, ConfigCheck, DatabaseCheck, DatabaseType, DirectoryCheck,
},
};
use arboard::Clipboard;
Expand Down Expand Up @@ -77,6 +77,8 @@ pub struct App {
pub dl_done: bool,
pub load_started: bool,
pub load_done: bool,
pub short_started: bool,
pub short_done: bool, // shorter JSON w/ single copy and lowest price
pub os: SupportedOS,
pub directory_exist: bool,
pub data_directory_exist: bool,
Expand All @@ -100,6 +102,10 @@ pub struct App {
std::sync::mpsc::Receiver<DatabaseCheck>,
),
pub dc: DatabaseCheck,
pub short_channel: (
std::sync::mpsc::Sender<String>,
std::sync::mpsc::Receiver<String>,
),
pub collection: Option<Vec<CollectionCard>>,
pub collection_file_name: Option<String>,
pub collection_file: Option<File>,
Expand Down Expand Up @@ -168,6 +174,7 @@ pub struct App {
pub legal_counter: u64,
pub missing_counter: u64,
pub price_counter: u64,
pub short_counter: u64,
}

impl Default for App {
Expand All @@ -184,6 +191,8 @@ impl Default for App {
dl_done: false,
load_started: false,
load_done: false,
short_started: false,
short_done: false,
os: SupportedOS::default(),
directory_exist: false,
data_directory_exist: false,
Expand All @@ -198,6 +207,7 @@ impl Default for App {
config_channel: std::sync::mpsc::channel(),
database_channel: std::sync::mpsc::channel(),
dc: DatabaseCheck::default(),
short_channel: std::sync::mpsc::channel(),
collection: None,
collection_file_name: None,
collection_file: None,
Expand Down Expand Up @@ -245,6 +255,7 @@ impl Default for App {
legal_counter: 0,
missing_counter: 0,
price_counter: 0,
short_counter: 0,
}
}
}
Expand Down Expand Up @@ -383,6 +394,7 @@ impl App {
self.dc.need_dl = dc.need_dl;
self.dc.ready_load = dc.ready_load;
self.dc.filename = dc.filename;
self.dc.db_type = dc.db_type;
if dc.database_exists {
self.database_ok = true;
}
Expand Down Expand Up @@ -431,9 +443,10 @@ impl App {
self.dc.database_status = format!("Loading {} ...", self.dc.filename);
let database_channel = self.database_channel.0.clone();
let dc_clone = self.dc.clone();
let currency = self.config.currency.clone();
self.database_counter += 1;
thread::spawn(move || {
let database_results = task::block_on(load_database_file(dc_clone));
let database_results = task::block_on(load_database_file(dc_clone, currency));
if let Ok(()) = database_channel.send(database_results) {};
});
self.dc.ready_load = false;
Expand All @@ -448,6 +461,45 @@ impl App {
self.redraw = true;
}
}
// if a Scryfall database is loaded and the hashmap is done, serialize and save as a
// custom database JSON with a single copy of each card with the lowest price so the
// hashmap doesn't have to be filtered each time the program starts
// only do it if loading a Scryfall JSON
if self.load_done
&& !self.short_started
&& !self.short_done
&& self.dc.db_type == DatabaseType::Scryfall
&& self.dc.database_cards.len() > 10
// don't overwrite database if loading fails
{
let map = self.dc.database_cards.clone();
let path = self.dc.database_path.clone();
// TODO: reset this when loading a new database
self.short_started = true;
// TODO: eventually make another condition for when the short database has been
// loaded instead of a Scryfall file
let short_channel = self.short_channel.0.clone();
self.short_counter += 1;
thread::spawn(
move || match task::block_on(serialize_database(&map, path)) {
Ok(()) => short_channel.send(
"Compact decklist database generated successfully.\n".to_string(),
),
Err(e) => short_channel.send(e.to_string()),
},
);
}
if self.short_started && !self.short_done {
if let Ok(s) = self.debug_channel.1.try_recv() {
self.debug_string += &s;
}
// TODO: eventually move this behind a different boolean
if let Ok(s) = self.short_channel.1.try_recv() {
self.debug_string += &s;
// TODO: reset this when reloading database
self.short_done = true;
}
}
if self.loading_collection {
if let Ok(msg) = self.collection_channel.1.try_recv() {
self.debug_string += &msg.debug;
Expand Down
Loading