de-duplicate logger

This commit is contained in:
2026-01-05 02:40:34 +00:00
parent b3f09bb742
commit 16e83aca67
16 changed files with 202 additions and 824 deletions

View File

@@ -8,3 +8,4 @@ unity-parser = { path = "../unity-parser" }
serde_yaml = "0.9"
inventory = "0.3"
sparsey = "0.13"
log = { version = "0.4", features = ["std"] }

View File

@@ -13,29 +13,34 @@ use unity_parser::UnityFile;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use unity_parser::log::DedupLogger;
use log::{info, warn, error, LevelFilter};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🎮 Cursebreaker - Resource Parser");
println!("{}", "=".repeat(70));
println!();
let logger = DedupLogger::new();
log::set_boxed_logger(Box::new(logger))
.map(|()| log::set_max_level(LevelFilter::Trace))
.unwrap();
log::set_max_level(LevelFilter::Warn);
info!("🎮 Cursebreaker - Resource Parser");
let scene_path = Path::new("/home/connor/repos/CBAssets/_GameAssets/Scenes/Tiles/10_3.unity");
// Check if scene exists
if !scene_path.exists() {
eprintln!("❌ Error: Scene not found at {}", scene_path.display());
error!("Scene not found at {}", scene_path.display());
return Err("Scene file not found".into());
}
println!("📁 Parsing scene: {}", scene_path.display());
println!();
info!("📁 Parsing scene: {}", scene_path.display());
// Parse the scene
match UnityFile::from_path(&scene_path) {
Ok(UnityFile::Scene(scene)) => {
println!("✅ Scene parsed successfully!");
println!(" Total entities: {}", scene.entity_map.len());
println!();
info!("✅ Scene parsed successfully!");
info!(" Total entities: {}", scene.entity_map.len());
// Get views for component types we need
let resource_view = scene.world.borrow::<InteractableResource>();
@@ -62,21 +67,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
println!("🔍 Found {} Interactable_Resource component(s)", found_resources.len());
println!();
info!("🔍 Found {} Interactable_Resource component(s)", found_resources.len());
if !found_resources.is_empty() {
// Display resources in console
for (name, resource, position) in &found_resources {
println!(" 📦 Resource: \"{}\"", name);
println!(" • typeId: {}", resource.type_id);
println!(" • maxHealth: {}", resource.max_health);
info!(" 📦 Resource: \"{}\"", name);
info!(" • typeId: {}", resource.type_id);
info!(" • maxHealth: {}", resource.max_health);
if let Some((x, y, z)) = position {
println!(" • Position: ({:.2}, {:.2}, {:.2})", x, y, z);
info!(" • Position: ({:.2}, {:.2}, {:.2})", x, y, z);
} else {
println!(" • Position: (no transform)");
info!(" • Position: (no transform)");
}
println!();
}
// Write to output file
@@ -106,23 +109,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(output_file, "{}", "=".repeat(70))?;
writeln!(output_file, "End of resource data")?;
println!("📝 Resource data written to: {}", output_path);
println!();
info!("📝 Resource data written to: {}", output_path);
}
println!("{}", "=".repeat(70));
println!("✅ Parsing complete!");
println!("{}", "=".repeat(70));
info!("✅ Parsing complete!");
}
Ok(_) => {
eprintln!("❌ Error: File is not a scene");
error!("File is not a scene");
return Err("Not a Unity scene file".into());
}
Err(e) => {
eprintln!("Parse error: {}", e);
error!("Parse error: {}", e);
return Err(Box::new(e));
}
}
log::logger().flush();
Ok(())
}