use std::sync::LazyLock;
use crate::helpers::{TigerHashMap, expand_scopes_hoi4};
use crate::scopes::{ArgumentValue, Scopes};
#[inline]
pub fn scope_to_scope(name: &str) -> Option<(Scopes, Scopes)> {
SCOPE_TO_SCOPE_MAP.get(name).copied()
}
static SCOPE_TO_SCOPE_MAP: LazyLock<TigerHashMap<&'static str, (Scopes, Scopes)>> =
LazyLock::new(|| {
let mut hash = TigerHashMap::default();
for (from, s, to) in SCOPE_TO_SCOPE.iter().copied() {
hash.insert(s, (expand_scopes_hoi4(from), to));
}
hash
});
const SCOPE_TO_SCOPE: &[(Scopes, &str, Scopes)] = &[
(Scopes::Country, "capital", Scopes::State), (Scopes::Country, "capital_scope", Scopes::State), (Scopes::State, "controller", Scopes::Country),
(Scopes::Country, "faction_leader", Scopes::Country),
(Scopes::None, "no", Scopes::Bool),
(Scopes::Country, "overlord", Scopes::Country),
(
Scopes::State
.union(Scopes::Character)
.union(Scopes::Division)
.union(Scopes::IndustrialOrg)
.union(Scopes::Ace),
"owner",
Scopes::Country,
),
(Scopes::None, "yes", Scopes::Bool),
];
#[inline]
pub fn scope_prefix(name: &str) -> Option<(Scopes, Scopes, ArgumentValue)> {
SCOPE_PREFIX_MAP.get(name).copied()
}
static SCOPE_PREFIX_MAP: LazyLock<TigerHashMap<&'static str, (Scopes, Scopes, ArgumentValue)>> =
LazyLock::new(|| {
let mut hash = TigerHashMap::default();
for (from, s, to, argument) in SCOPE_PREFIX.iter().copied() {
hash.insert(s, (expand_scopes_hoi4(from), to, argument));
}
hash
});
const SCOPE_PREFIX: &[(Scopes, &str, Scopes, ArgumentValue)] = {
use crate::item::Item;
use ArgumentValue::*;
&[
(Scopes::None, "constant", Scopes::Value, Item(Item::ScriptedConstant)),
(Scopes::all(), "event_target", Scopes::all(), UncheckedValue),
(Scopes::Country, "mio", Scopes::IndustrialOrg, Item(Item::IndustrialOrg)),
(Scopes::Country, "sp", Scopes::SpecialProject, Item(Item::SpecialProject)),
(Scopes::None, "token", Scopes::all(), UncheckedValue),
(Scopes::all(), "var", Scopes::all(), UncheckedValue),
]
};
pub fn scope_to_scope_removed(name: &str) -> Option<(&'static str, &'static str)> {
for (removed_name, version, explanation) in SCOPE_TO_SCOPE_REMOVED.iter().copied() {
if name == removed_name {
return Some((version, explanation));
}
}
None
}
const SCOPE_TO_SCOPE_REMOVED: &[(&str, &str, &str)] = &[];