Skip to content

Commit

Permalink
Fixed error
Browse files Browse the repository at this point in the history
  • Loading branch information
BobDaGithubAccount committed Dec 14, 2024
1 parent f84b483 commit a98004f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "atomica_lib"
version = "0.1.0"
edition = "2021"
repository="https://github.com/BobDaGithubAccount/Atomica"

[dependencies]
wasm-bindgen = "0.2"
Expand All @@ -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"
Expand Down
16 changes: 12 additions & 4 deletions lib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>),
Expand Down Expand Up @@ -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<String>) {
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));
}
}
}
}

for message in log_messages {
log(message);
}
}
10 changes: 7 additions & 3 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <degrees>");
register_command!("fov", update_camera_fov_command, "Update camera field of view (FOV)", "fov [degrees]");
commands::init();
}

Expand Down Expand Up @@ -226,8 +226,12 @@ pub fn handle_command(command_line: &str) {
let command_name = parts[0];
let args: Vec<String> = 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));
Expand Down

0 comments on commit a98004f

Please sign in to comment.