Skip to main content

ygopro_data/data/
strings.rs

1//! Loading of the `strings.conf` localization file.
2//!
3//! Provides [`load_strings_conf`], which parses the conf into a category → id → string
4//! map.
5
6use std::collections::HashMap;
7use std::fs;
8
9pub fn load_strings_conf(path: &str) -> HashMap<String, HashMap<i32, String>> {
10    let mut map: HashMap<String, HashMap<i32, String>> = HashMap::new();
11    let Ok(content) = fs::read_to_string(path) else { return map; };
12
13    for line in content.lines() {
14        let line = line.trim();
15        if line.is_empty() || line.starts_with('#') || !line.starts_with('!') {
16            continue;
17        }
18        let rest = &line[1..];
19        let mut parts = rest.splitn(3, ' ');
20        let Some(category) = parts.next() else { continue };
21        let Some(id_str) = parts.next() else { continue };
22        let Ok(id) = id_str.parse::<i32>() else { continue };
23        let value = parts.next().unwrap_or("");
24
25        map.entry(category.to_string())
26            .or_default()
27            .insert(id, value.to_string());
28    }
29
30    map
31}