bool HandleBoolEvent(EventContext context, IAsyncEvent <bool> boolEvent, IBranchNode branch) // Return value = whether to return. { context.Status = EventContextStatus.Waiting; int waiting = RaiseAsync(boolEvent, result => { #if DEBUG Raise(new LogEvent(LogEvent.Level.Info, $"if ({context.Node.Event}) => {result}")); #endif context.Node = result ? branch.Next : branch.NextIfFalse; // If a non-query event needs to set this it will have to do it itself. This is to allow // things like chest / door events where different combinations of their IAsyncEvent<bool> result // and the LastEventResult can mean successful opening, exiting the screen without success or a // trap has been triggered. if (boolEvent is IQueryEvent) { LastEventResult = result; } context.Status = EventContextStatus.Ready; }); if (waiting == 0) { ApiUtil.Assert($"Async event {boolEvent} not acknowledged. Continuing immediately."); context.Node = context.Node.Next; context.Status = EventContextStatus.Ready; } else if (context.Status == EventContextStatus.Waiting) { // If the continuation hasn't been called then stop iterating for now and wait for completion. _threadContexts.Value.Pop(); return(true); } // If the continuation was called already then continue iterating. return(false); }
public static List <Instruction> CompileBranch(IBranchNode node) { var instructions = new List <Instruction>(); var branchAddress = new PrecompiledAdress(); var innerInstructions = new List <Instruction>(); CompileGeneral(node.Block, ref innerInstructions); innerInstructions.Add(new Instruction { OpCode = OperationCode.move, Value = new PrecompiledAdress() }); branchAddress.Delta = innerInstructions.Count; CompileGeneral(node.Condition, ref instructions); instructions.Add(new Instruction { OpCode = OperationCode.brfalse, Value = branchAddress }); instructions = instructions.Concat(innerInstructions).ToList(); return(instructions); }
public static IContainerNode <T> When <T, TReturn>(this IBranchNode <T, TReturn> branchNode, TReturn value) { return(branchNode.When(r => r.Equals(value))); }