Load and parse the JSON spec. Relative paths in the spec (`scene`, `env.path`) are resolved against the spec file's own directory so the spec can live alongside its assets and be moved as a unit.
(path: &Path)
| 75 | /// directory so the spec can live alongside its assets and be moved |
| 76 | /// as a unit. |
| 77 | fn load_spec(path: &Path) -> Result<(ViewSpec, PathBuf), String> { |
| 78 | let text = std::fs::read_to_string(path).map_err(|e| format!("read {:?}: {e}", path))?; |
| 79 | let spec: ViewSpec = serde_json::from_str(&text).map_err(|e| format!("parse {:?}: {e}", path))?; |
| 80 | let base_dir = path |
| 81 | .parent() |
| 82 | .map(|p| p.to_path_buf()) |
| 83 | .unwrap_or_else(|| PathBuf::from(".")); |
| 84 | Ok((spec, base_dir)) |
| 85 | } |
| 86 | |
| 87 | // ============================================================ |
| 88 | // Scene representation |