aboutsummaryrefslogtreecommitdiff
path: root/src/bt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bt.rs')
-rw-r--r--src/bt.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/bt.rs b/src/bt.rs
index 293e3d4..aac8484 100644
--- a/src/bt.rs
+++ b/src/bt.rs
@@ -377,11 +377,17 @@ impl BuildTemplate {
}
}
-static JSON_PALETTE: &str = include_str!("skill_palette.json");
+lazy_static! {
+ static ref PALETTE_MAPPING: Vec<(u32, u32)> =
+ serde_json::from_str(include_str!("skill_palette.json")).unwrap();
+}
+
+// Those functions do linear searches, but the list only has about 400 items, which should be okay.
+// If performance becomes an issue, we can always create hash tables or do a binary search,
+// however, since we need both directions, we would need double the memory to keep the second map.
fn skill_id_to_palette_id(input: u32) -> u32 {
- let lookup_table: Vec<(u32, u32)> = serde_json::from_str(JSON_PALETTE).unwrap();
- for (skill, palette) in &lookup_table {
+ for (skill, palette) in PALETTE_MAPPING.iter() {
if *skill == input {
return *palette;
}
@@ -390,8 +396,7 @@ fn skill_id_to_palette_id(input: u32) -> u32 {
}
fn palette_id_to_skill_id(input: u32) -> u32 {
- let lookup_table: Vec<(u32, u32)> = serde_json::from_str(JSON_PALETTE).unwrap();
- for (skill, palette) in &lookup_table {
+ for (skill, palette) in PALETTE_MAPPING.iter() {
if *palette == input {
return *skill;
}