-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move string search to game_data crate & Ignore HQ/CL icons
- Loading branch information
1 parent
8025bd6
commit 62a5d7f
Showing
7 changed files
with
82 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::{ | ||
get_item_name, Consumable, Locale, CL_ICON_CHAR, HQ_ICON_CHAR, MEALS, POTIONS, RECIPES, | ||
}; | ||
|
||
fn contains_noncontiguous(string: &str, pattern: &str) -> bool { | ||
let mut it = string.split_whitespace(); | ||
for c in pattern.split_whitespace() { | ||
loop { | ||
let Some(c2) = it.next() else { | ||
return false; | ||
}; | ||
if c2.contains(c) { | ||
break; | ||
} | ||
} | ||
} | ||
true | ||
} | ||
|
||
fn preprocess_pattern(pattern: &str) -> String { | ||
pattern | ||
.to_lowercase() | ||
.replace([HQ_ICON_CHAR, CL_ICON_CHAR], "") | ||
} | ||
|
||
pub fn find_recipes(search_string: &str, locale: Locale) -> Vec<usize> { | ||
let pattern = preprocess_pattern(search_string); | ||
RECIPES | ||
.iter() | ||
.enumerate() | ||
.filter_map(|(index, recipe)| { | ||
let item_name = get_item_name(recipe.item_id, false, locale); | ||
match contains_noncontiguous(&item_name.to_lowercase(), &pattern) { | ||
true => Some(index), | ||
false => None, | ||
} | ||
}) | ||
.collect() | ||
} | ||
|
||
fn find_consumables(search_string: &str, locale: Locale, consumables: &[Consumable]) -> Vec<usize> { | ||
let pattern = preprocess_pattern(search_string); | ||
consumables | ||
.iter() | ||
.enumerate() | ||
.filter_map(|(index, consumable)| { | ||
let item_name = get_item_name(consumable.item_id, false, locale); | ||
match contains_noncontiguous(&item_name.to_lowercase(), &pattern) { | ||
true => Some(index), | ||
false => None, | ||
} | ||
}) | ||
.collect() | ||
} | ||
|
||
pub fn find_meals(search_string: &str, locale: Locale) -> Vec<usize> { | ||
find_consumables(search_string, locale, MEALS) | ||
} | ||
|
||
pub fn find_potions(search_string: &str, locale: Locale) -> Vec<usize> { | ||
find_consumables(search_string, locale, POTIONS) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,5 @@ pub use app::MacroSolverApp; | |
pub use worker::Worker; | ||
|
||
mod config; | ||
mod utils; | ||
mod widgets; | ||
mod worker; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters