RichoDemus/bevy-console

Some way to avoid having to wrap things in an `if`

Opened this issue · 1 comments

It's slightly annoying that, even for commands that have no body, I still have to wrap the entire body in an if statement. For the common case where you only want to handle fully-formed valid commands, maybe an API like

#[derive(Parser, ConsoleCommand)]
struct DoSomething {
  arg: u32
}

fn do_something_system(
  In(command): In<DoSomething>,
  resource: Res<SomeResource>
) {
  todo!()
}

would work. The in-parameter can then be inferred so you wouldn't need to pass it again in add_console_command. Could also allow In(command): In<Result<DoSomething>> if you want to handle parse errors in your system.

Hi, it's not really possible to avoid the condition within the system, since the SystemParam needs to always return something, in the case that the system run but no command was available, or in the case of the parse error, we need to be able to provide some variant of the type.

We could provide another type of SystemParam, let's also call it In, which would operate over a different type of event, let's call it ParsedConsoleCommand which would always be a valid command, but then it is always possible the system runs in a state where no such events are available, meaning it would need to panic. And if it were not to panic, we'd need an Option involved, turning the signature into In<Option<T>> which does not really help the problem.

We could (maybe idk if it's sound) avoid panics by separating the command systems into "parsed" and "unparsed" command systems with the appropriate guarantess via run conditions, but that adds a whole lot of complexity and I am not convinved the benefits outweigh the cons in this case.