I'm developing a dev console for my game. Currently I have a simple parser which is basically a regex which accepts words with dashes and dots (ie. list
, 1.0
, list -i
) or simplistic arrays and maps (ie. [1,2,3]
, [x:1.0, y:2.0]
). I plan on making an AST parser later on but for now this works well enough.
When these tokens get parsed first token in parsed line is the command token which is used to invoke a registered command. Commands are classes which implement a ConsoleCommand
interface which looks like this (basic command pattern):
interface ConsoleCommand {
val description: String
val instructions: String
fun execute(args: Array<Any>): String
}
This works, but I'm not quite satisfied since to actually register any console commands I must do so where I can access the entity. For example if I want to register the player as an interactable console command I must do so either in a custom system only created for the specific console command, or add console specific code into existing systems, basically polluting my codebase with console specific code.
My question here is what are alternative dev console implementations? Is there a way to implement a console which wouldn't affect the rest of the codebase?
I have an inkling of an idea where the console could be some sort of an observer and it itself would register onto entities and stuff, but I don't see a way of implementing that without having the entities implement some sort of special observable interface so that they can actually be observed, as well as the fact that observers
usually don't manipulate the entities themselves....