improve and add models

This commit is contained in:
timurgordon
2025-06-12 05:22:17 +03:00
parent c3f6b91aa0
commit 00c4e6a1eb
19 changed files with 1520 additions and 42 deletions

View File

@@ -0,0 +1,38 @@
use heromodels::db::hero::OurDB;
use heromodels::models::register_library_rhai_module;
use rhai::Engine;
use std::sync::Arc;
use std::{fs, path::Path};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize Rhai engine
let mut engine = Engine::new();
// Initialize database with OurDB
let db_path = "temp_library_db";
// Clean up previous database file if it exists
if Path::new(db_path).exists() {
fs::remove_dir_all(db_path)?;
}
let db = Arc::new(OurDB::new(db_path, true).expect("Failed to create database"));
// Register the library module with Rhai
register_library_rhai_module(&mut engine, db.clone());
// Load and evaluate the Rhai script
let script_path = Path::new(file!()).parent().unwrap().join("library.rhai");
let script = fs::read_to_string(&script_path)?;
println!("--- Running Library Rhai Script ---");
match engine.eval::<()>(&script) {
Ok(_) => println!("\n--- Script executed successfully! ---"),
Err(e) => eprintln!("\n--- Script execution failed: {} ---", e),
}
// Clean up the database file
fs::remove_dir_all(db_path)?;
println!("--- Cleaned up temporary database. ---");
Ok(())
}