1
Fork 0
mirror of https://github.com/Steffo99/patched-porobot.git synced 2024-12-23 01:54:22 +00:00

Load setbundles dynamically

This commit is contained in:
Steffo 2022-08-22 19:56:21 +02:00
parent f5456980f6
commit 54fc192b6e
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 19 additions and 23 deletions

View file

@ -16,7 +16,6 @@ use crate::data::setbundle::supertype::CardSupertype;
use crate::data::deckcode::deck::Deck; use crate::data::deckcode::deck::Deck;
use itertools::Itertools; use itertools::Itertools;
use teloxide::utils::html::escape; use teloxide::utils::html::escape;
use crate::data::deckcode::format::DeckCodeFormat;
/// Render a [Card] in [Telegram Bot HTML]. /// Render a [Card] in [Telegram Bot HTML].
/// ///

View file

@ -6,6 +6,7 @@ use crate::data::setbundle::card::{Card, CardIndex};
use crate::data::setbundle::SetBundle; use crate::data::setbundle::SetBundle;
use crate::search::cardsearch::CardSearchEngine; use crate::search::cardsearch::CardSearchEngine;
use crate::telegram::handler::{inline_query_handler, message_handler}; use crate::telegram::handler::{inline_query_handler, message_handler};
use glob::glob;
use log::*; use log::*;
use std::path::PathBuf; use std::path::PathBuf;
use teloxide::prelude::*; use teloxide::prelude::*;
@ -15,35 +16,31 @@ pub async fn main() {
pretty_env_logger::init(); pretty_env_logger::init();
debug!("Logger initialized successfully!"); debug!("Logger initialized successfully!");
debug!("Loading bundles..."); debug!("Loading core bundle...");
let core = CoreBundle::load(&*PathBuf::from("./data/core-en_us")) let core = CoreBundle::load(&*PathBuf::from("./data/core-en_us"))
.expect("to be able to load `core-en_us` bundle"); .expect("to be able to load `core-en_us` bundle");
let set1 = SetBundle::load(&*PathBuf::from("./data/set1-en_us")) debug!("Loaded core bundle successfully!");
.expect("to be able to load `set1-en_us` bundle");
let set2 = SetBundle::load(&*PathBuf::from("./data/set2-en_us")) debug!("Loading set bundles...");
.expect("to be able to load `set2-en_us` bundle"); let setpaths = glob("./data/set*-*")
let set3 = SetBundle::load(&*PathBuf::from("./data/set3-en_us")) .expect("setglob to be a valid glob")
.expect("to be able to load `set3-en_us` bundle"); .into_iter()
let set4 = SetBundle::load(&*PathBuf::from("./data/set4-en_us")) .filter(|sp| sp.is_ok())
.expect("to be able to load `set4-en_us` bundle"); .map(|sp| sp.unwrap());
let set5 = SetBundle::load(&*PathBuf::from("./data/set5-en_us")) let mut cards: Vec<Card> = vec![];
.expect("to be able to load `set5-en_us` bundle"); for setpath in setpaths {
let set6 = SetBundle::load(&*PathBuf::from("./data/set6-en_us")) debug!("Loading {:?}...", &setpath);
.expect("to be able to load `set6-en_us` bundle"); let set = SetBundle::load(&setpath)
let set6cde = SetBundle::load(&*PathBuf::from("./data/set6cde-en_us")) .expect(&*format!("to be able to load {:?} as a set bundle", &setpath));
.expect("to be able to load `set6cde-en_us` bundle"); let mut setcards = set.cards;
debug!("Loaded all bundles!"); cards.append(&mut setcards);
}
debug!("Loaded {} cards!", &cards.len());
debug!("Indexing globals..."); debug!("Indexing globals...");
let globals = LocalizedGlobalsIndexes::from(core.globals); let globals = LocalizedGlobalsIndexes::from(core.globals);
debug!("Indexed globals!"); debug!("Indexed globals!");
debug!("Indexing cards...");
let cards: Vec<Card> = [
set1.cards, set2.cards, set3.cards, set4.cards, set5.cards, set6.cards, set6cde.cards,
]
.concat();
let mut index = CardIndex::new(); let mut index = CardIndex::new();
for card in cards { for card in cards {
index.insert(card.code.clone(), card); index.insert(card.code.clone(), card);