Open azriel91 opened 6 years ago
Previous comments #995:
The amethyst_terminal crate which I will be adding will need to reference the Trans struct. This cannot be done while this struct is in the base crate, as the base crate depends on all other sub crates (cyclic dependency). Then I need to move everything else for the same reason. StateMachine -> (Trans -> State) -> StateEvent and its not possible to go back up the crate hierarchy
– @jojolepro
Why exactly does terminal need to depend on Trans? Can't you make a command system that is generic enough for that ?
– @Rhuagh
we would like to keep the state machine an optional component.
– @torkleyy
re: amethyst_terminal Trans dependency The amethyst_terminal crate is the parser that converts the command string into the concrete types that need to be sent into the EventChannels. For example, the command
$ statechange "MainState"
will try to parse the string as ron data, and if it succeeds, it will push a Trans instance through the global EventChannel.
I'm not sure how I could make that generic enough, considering all commands have a different way of being parsed, some have side effects, etc.
Most commands will be in the amethyst_command crate, because that crate will be access by most other crates like core::TransformSystem to check for "Teleportation" events for example. For the Trans command however, it cannot be inside of amethyst_commands, because that will create a cyclic dependency (almost everything will depend on amethyst_commands, so it cannot depend on anything in return).
The StateMachine will be behind a feature gate. I forgot to include it in the list I made yesterday on discord.
– @jojolepro
StateEvent carries the information of what to do (e.g. Pop or Switch). – @azriel91
That proves why this PR is necessary.
The design you have is effectively what I have on paper. Following rhuagh comments on discord however, the enum containing the different commands will be replaced by something more dynamic. See the opened PR talking about state handle_event made by rhuagh
– @jojolepro
In short, the command crate should be generic enough so different frameworks (e.g. state machine) can register themselves. I like the current structure because it forces us to properly design things and to not couple stuff too much.
– @torkleyy
Thanks for opening the issue!
Ideally, the editor and the command crate would operate over the same interface. We should try to get one interface that's useful for the editor, the command crate, scripting, modding, etc. because otherwise this will get very chaotic.
I was planning on having three frontends (or more) for the command stuff:
@jojolepro "in-game ui"? You mean the one for editing, right?
Independent of that, it should be generic enough so crates can register themselves instead of depending on all of them.
amethyst_ui? :P
By making a generic framework where anything can register their commands we also upon up for the user to have terminal commands added from the game logic.
Transferring this to the RFC repo.
Issue 999, this is gonna be epic!
Summary
Ability to control an Amethyst application using commands issued through stdin, with human-friendly terminal interaction.
Motivation
Inspecting and manipulating the state1 of an application at run time is a crucial part of development, with at least the following use cases:
A command terminal will greatly reduce the effort to carry out the aforementioned tasks.
1 state here means the runtime values, not
amethyst::State
Prior Art
Expand -- copied from #995 (warning: code heavy)
okay, so this post is code heavy, but it's how I've done commands in my game ([youtube](https://youtu.be/jpk2MTeWz3w)). It shouldn't force people to use the state machine, since event types are "plug in if you need it". ## Crate: `stdio_view` (probably analogous to `amethyst_commands`) * Reads `stdin` strings, uses `shell_words` to parse into separate tokens. * Parses the first token into an `AppEventVariant` to determine which `AppEvent` the tokens correspond to. On success, it sends a tuple: `(AppEventVariant, VecDetailed Design
TODO: discuss
Alternatives
The
amethyst-editor
will let you do some of the above tasks (inspecting, manipulating entities and components). It doesn't cater for: