#[derive(Debug, Clone)]
pub(crate) struct CompanionSpec {
pub name: &'static str,
pub asset_type: &'static str,
pub args: serde_json::Value,
}
fn graphics_config_marker() -> Vec<CompanionSpec> {
vec![CompanionSpec {
name: "GraphicsConfig",
asset_type: "GraphicsConfig",
args: serde_json::json!({}),
}]
}
fn graphics_config_companions() -> Vec<CompanionSpec> {
vec![CompanionSpec {
name: "Window",
asset_type: "Window",
args: serde_json::json!({}),
}]
}
pub(crate) fn companions_for(type_norm: &str) -> Vec<CompanionSpec> {
if type_norm == "graphicsconfig" {
graphics_config_companions()
} else if crate::registry::type_renders(type_norm) {
graphics_config_marker()
} else {
Vec::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn renderable_assets_imply_graphics_config() {
for ty in [
"prop",
"sprite",
"textlabel",
"voxelworld",
"watersurface",
"instancedprop",
"skinnedmesh",
] {
let specs = companions_for(ty);
assert!(
specs.iter().any(|c| c.asset_type == "GraphicsConfig"),
"{ty} should imply a GraphicsConfig companion"
);
}
}
#[test]
fn unknown_type_implies_no_companions() {
assert!(companions_for("window").is_empty());
assert!(companions_for("mesh").is_empty());
}
#[test]
fn graphics_config_injects_a_window() {
let specs = companions_for("graphicsconfig");
assert!(specs.iter().any(|c| c.asset_type == "Window"));
assert!(!specs.iter().any(|c| c.asset_type == "Shader"));
}
}