Skip to content

Commit

Permalink
Add text icons for HQ items and collectables (#77)
Browse files Browse the repository at this point in the history
* Ignore collectable and HQ character during search

* Add text icon font

* Use HQ character in item name instead of "(HQ)"

* Use collectable character in item name of collectables

* Use `AlwaysCollectable` instead of `IsCollectable` entry from item game data

* Move collectable name formating to `locales.rs` to make it global

* Do not ignore collectable character since it is unnecessary to do so

* Update tests using item names to account for changed behaviour

* Use more readable way of removing null bytes from the search text

* Do not ignore HQ character for food items and potions

This makes the search more "correct" and consistent to the recipe search. Additionally the search for all HQ items of a category is now possible.

* Replace "(HQ)" and "(CL)" with the HQ and collectable character respecively in the search text

This allows for easy input of those special characters without pasting them directly.
  • Loading branch information
augenfrosch authored Aug 23, 2024
1 parent b04627e commit 2c48381
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 20 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions game_data/build/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ pub fn import_item_records(
.filter(|item| relevant_items.contains(&item.id))
{
item_stats.entry(item.id, &format!(
"Item {{ item_level: {item_level}, can_be_hq: {can_be_hq}, is_collectable: {is_collectable} }}",
"Item {{ item_level: {item_level}, can_be_hq: {can_be_hq}, always_collectable: {always_collectable} }}",
item_level = item.item_level,
can_be_hq = item.can_be_hq,
is_collectable = item.is_collectable,
always_collectable = item.always_collectable,
));
}
let out_path = Path::new(&std::env::var("OUT_DIR")?).join("items.rs");
Expand Down
4 changes: 2 additions & 2 deletions game_data/build/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ pub struct ItemRecord {
#[serde(rename = "CanBeHq")]
#[serde(deserialize_with = "bool_string")]
pub can_be_hq: bool,
#[serde(rename = "IsCollectable")]
#[serde(rename = "AlwaysCollectable")]
#[serde(deserialize_with = "bool_string")]
pub is_collectable: bool,
pub always_collectable: bool,
}

#[derive(Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions game_data/src/consumables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod tests {

#[test]
fn test_u16_overflow() {
let consumable = find_consumable("Rroneek Steak (HQ)").unwrap();
let consumable = find_consumable("Rroneek Steak \u{e03c}").unwrap();
// 13108 * 5 mod 1<<16 = 4
// 2521 * 26 mod 1<<16 = 10
assert_eq!(
Expand All @@ -114,7 +114,7 @@ mod tests {

#[test]
fn test_rroneek_steak_hq() {
let consumable = find_consumable("Rroneek Steak (HQ)").unwrap();
let consumable = find_consumable("Rroneek Steak \u{e03c}").unwrap();
assert_eq!(
consumable.effect_string(4021, 4023, 550),
"Control +5% (97), CP +26% (92)"
Expand Down
2 changes: 1 addition & 1 deletion game_data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use simulator::{Action, ActionMask, Settings};
pub struct Item {
pub item_level: u16,
pub can_be_hq: bool,
pub is_collectable: bool,
pub always_collectable: bool,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
Expand Down
16 changes: 13 additions & 3 deletions game_data/src/locales.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::ITEMS;
use serde::{Deserialize, Serialize};
use simulator::Action;

Expand Down Expand Up @@ -61,9 +62,18 @@ pub fn get_item_name(item_id: u32, hq: bool, locale: Locale) -> String {
.copied()
.unwrap_or("Unknown item"),
};
match hq {
true => format!("{} (HQ)", item_name),
false => item_name.to_string(),
let item_entry = ITEMS.get(&item_id);
let always_collectable = match item_entry {
Some(item) => item.always_collectable,
None => false,
};
if !always_collectable {
match hq {
true => format!("{} \u{e03c}", item_name),
false => item_name.to_string(),
}
} else {
format!("{} \u{e03d}", item_name)
}
}

Expand Down
30 changes: 25 additions & 5 deletions game_data/tests/test_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,28 @@ fn test_item_name_2341() {
}

#[test]
fn test_item_name_44232_hq() {
fn test_item_name_44232_collectable() {
let item_id = 44232;
let item_names = [
get_item_name(item_id, false, Locale::EN),
get_item_name(item_id, true, Locale::DE),
get_item_name(item_id, false, Locale::FR),
get_item_name(item_id, true, Locale::JP),
];
assert_eq!(
item_names,
[
"Rarefied Tacos de Carne Asada \u{e03d}",
"Tacos de Carne Asada (Sammlerstück) \u{e03d}",
"Tacos de carne asada collectionnables \u{e03d}",
"収集用のタコス・カルネ・アサーダ \u{e03d}"
]
);
}

#[test]
fn test_item_name_44104_hq() {
let item_id = 44104;
let item_names = [
get_item_name(item_id, true, Locale::EN),
get_item_name(item_id, true, Locale::DE),
Expand All @@ -44,10 +64,10 @@ fn test_item_name_44232_hq() {
assert_eq!(
item_names,
[
"Rarefied Tacos de Carne Asada (HQ)",
"Tacos de Carne Asada (Sammlerstück) (HQ)",
"Tacos de carne asada collectionnables (HQ)",
"収集用のタコス・カルネ・アサーダ (HQ)"
"Tacos de Carne Asada \u{e03c}",
"Tacos mit Carne Asada \u{e03c}",
"Tacos de carne asada \u{e03c}",
"タコス・カルネ・アサーダ \u{e03c}"
]
);
}
13 changes: 13 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ impl MacroSolverApp {
.get_mut(&FontFamily::Monospace)
.unwrap()
.push("japanese_monospace".to_owned());

fonts.font_data.insert(
String::from("FFXIV_Lodestone_SSF"),
FontData::from_static(include_bytes!(
"../assets/fonts/XIV_Icon_Recreations/XIV_Icon_Recreations.ttf"
)),
);
fonts
.families
.get_mut(&FontFamily::Proportional)
.unwrap()
.push("FFXIV_Lodestone_SSF".to_owned());

ctx.set_fonts(fonts);
}
}
4 changes: 3 additions & 1 deletion src/widgets/food_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl<'a> Widget for FoodSelect<'a> {

ui.horizontal(|ui| {
ui.label("Search:");
ui.text_edit_singleline(&mut search_text);
if ui.text_edit_singleline(&mut search_text).changed() {
search_text = search_text.replace("\0", "").replace("(HQ)", "\u{e03c}");
}
});
ui.separator();

Expand Down
4 changes: 3 additions & 1 deletion src/widgets/potion_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl<'a> Widget for PotionSelect<'a> {

ui.horizontal(|ui| {
ui.label("Search:");
ui.text_edit_singleline(&mut search_text);
if ui.text_edit_singleline(&mut search_text).changed() {
search_text = search_text.replace("\0", "").replace("(HQ)", "\u{e03c}");
}
});
ui.separator();

Expand Down
7 changes: 5 additions & 2 deletions src/widgets/recipe_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ impl<'a> RecipeSelect<'a> {

ui.horizontal(|ui| {
ui.label("Search:");
ui.text_edit_singleline(&mut search_text);
if ui.text_edit_singleline(&mut search_text).changed() {
search_text = search_text.replace("\0", "").replace("(CL)", "\u{e03d}");
}
});
ui.separator();

let mut search_result = Vec::new();
ui.ctx().memory_mut(|mem| {
let search_cache = mem.caches.cache::<SearchCache<'_>>();
search_result = search_cache.get((&search_text.to_lowercase(), self.locale));
let cache_search_string = search_text.trim_end_matches('\u{e03c}').to_lowercase();
search_result = search_cache.get((&cache_search_string, self.locale));
});

ui.ctx().data_mut(|data| {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<'a> Widget for Simulator<'a> {
egui::RichText::new("Synthesis failed".to_string())
.strong(),
);
} else if self.item.is_collectable {
} else if self.item.always_collectable {
let t1 = QualityTarget::CollectableT1
.get_target(self.settings.max_quality);
let t2 = QualityTarget::CollectableT2
Expand Down

0 comments on commit 2c48381

Please sign in to comment.