From a98004f676401d0d697ff04f0efc45ea7664cc78 Mon Sep 17 00:00:00 2001 From: BobDaGithubAccount Date: Sat, 14 Dec 2024 19:24:59 +0000 Subject: [PATCH] Fixed error --- lib/Cargo.toml | 2 +- lib/src/commands.rs | 16 ++++++++++++---- lib/src/lib.rs | 10 +++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 563fb09..0f7de4e 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -2,6 +2,7 @@ name = "atomica_lib" version = "0.1.0" edition = "2021" +repository="https://github.com/BobDaGithubAccount/Atomica" [dependencies] wasm-bindgen = "0.2" @@ -11,7 +12,6 @@ three-d = "0.17.0" log = "0.4" winit = "0.28" lazy_static = "1.4.0" -cgmath = "0.18" console_error_panic_hook = "0.1" console_log = "1" js-sys = "0.3" diff --git a/lib/src/commands.rs b/lib/src/commands.rs index 73e9cc9..ec80ac9 100644 --- a/lib/src/commands.rs +++ b/lib/src/commands.rs @@ -3,6 +3,7 @@ use std::sync::Mutex; use lazy_static::lazy_static; use crate::log; +#[derive(Clone)] pub struct Command { pub name: &'static str, pub func: fn(Vec), @@ -34,19 +35,26 @@ pub fn init() { register_command!("help", help_command, "Prints help information", "help [command]"); } +//TODO FIX LOCKING ISSUES WITH COMMAND REGISTRY fn help_command(args: Vec) { let registry = COMMAND_REGISTRY.lock().unwrap(); + let mut log_messages = Vec::new(); + log(format!("Help:")); if args.is_empty() { for command in registry.values() { - log(format!("{}: {} | {}", command.name, command.help, command.usage)); + log_messages.push(format!("{}: {} | {}", command.name, command.help, command.usage)); } } else { for arg in args { if let Some(command) = registry.get(&arg[..]) { - log(format!("{}: {} | {}", command.name, command.help, command.usage)); + log_messages.push(format!("{}: {} | {}", command.name, command.help, command.usage)); } else { - log(format!("Command not found: {}", arg)); + log_messages.push(format!("Command not found: {}", arg)); } } } -} \ No newline at end of file + + for message in log_messages { + log(message); + } +} diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 48915ba..9e43c8d 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -146,7 +146,7 @@ pub fn log(message: String) { pub fn register_commands() { register_command!("reset_camera", reset_camera_command, "Reset camera to default settings", "reset_camera"); - register_command!("fov", update_camera_fov_command, "Update camera field of view (FOV)", "fov "); + register_command!("fov", update_camera_fov_command, "Update camera field of view (FOV)", "fov [degrees]"); commands::init(); } @@ -226,8 +226,12 @@ pub fn handle_command(command_line: &str) { let command_name = parts[0]; let args: Vec = parts[1..].iter().map(|&s| s.to_string()).collect(); - let registry = commands::COMMAND_REGISTRY.lock().unwrap(); - if let Some(command) = registry.get(command_name) { + let registry_clone = { + let registry = commands::COMMAND_REGISTRY.lock().unwrap(); + registry.clone() + }; + + if let Some(command) = registry_clone.get(command_name) { (command.func)(args); } else { log(format!("Command not found: {}", command_name));