- edited description
Interactive Command System
This would be quite a large system which would allow commands to yield in order to perform external actions (user input, delay etc.) before resuming execution
This would allow you to write commands such as the following
public static IEnumerable<ICommandAction> PrintInput()
{
Debug.Log("Write something");
yield return new CommandInput(out string text);
Debug.Log($"Input: {text}");
}
This would require quite specialized support outside of the processor (i.e in QuantumConsole.cs) just like async commands; so should not be added unless it can be done properly. Perhaps a new system could be added to allow both async and interactive commands to be supported without being coupled to the console?
The fundamental unit of of control for an interactive command would be ICommandAction
, which can be yielded to invoke the custom behavior. A command would become interactive if its return is IEnumerable<ICommandAction>
, just like commands become async by having a Task
or Task<T>
return
Mockup
public interface ICommandAction
{
void StartAction(Context ctx);
bool IsActionFinished { get; }
}
Context
is still undecided but it would likely contain the info on the console needed to provide custom behaviour
Mockup
public class CommandInput : ICommandAction
{
public void StartAction(Context ctx);
private readonly ref string _output;
public CommandInput(ref string output)
{
_output = output;
}
public void StartAction(Context ctx)
{
// start listening to user input using ctx
// set _output to the input then IsActionFinished to true to terminate
}
}
The processing side when then look something like this
res = Invoke(cmd);
if (res is IEnumerable<ICommandAction>)
// add res to list of inflight interactive commands
...
foreach (cmd in interactive commands)
if (cmd.current is done)
cmd.move next, StartAction(ctx)
if(cmd.done)
remove cmd
Crude psuedocode to demonstrate the concept
This is all extremely still up for discussion and whilst something like this has great potential, I want to make sure it’s implemented correctly
Comments (4)
-
reporter -
reporter - edited description
-
reporter - changed status to open
-
reporter - changed status to resolved
Action system finished and debuting in V2.4.0
- Log in to comment