protected override async Task Begin(SceneInstructionContainer instructions, TextGeneratorContext context)
        {
            await context.WriteIndent();

            switch (instructions)
            {
            case If ifInstruction:
                await context.WriteString("if ");
                await RenderCondition(ifInstruction.Condition, context);

                break;

            case Hear hear:
                await context.WriteString("hear ");

                var existingPhrase = false;
                foreach (var phrase in hear.Phrases)
                {
                    if (existingPhrase)
                    {
                        await context.WriteString(", ");
                    }
                    await context.WriteString(phrase);

                    existingPhrase = true;
                }
                break;
            }
            await context.WriteString(" {", true);

            context.CurrentLevel++;
        }
        protected async Task Generate(SceneInstructionContainer instructions, TContext context)
        {
            if (instructions == null)
            {
                return;
            }
            await Begin(instructions, context);

            var instructionIndex = 0;

            foreach (var instruction in instructions.Instructions)
            {
                context.SetLoop(instructionIndex, instructions.Instructions.Count - 1);
                if (instruction is SceneInstructionContainer container)
                {
                    await GenerateComment(instruction, context);
                    await Generate(container, context);

                    context.ClearLoop();
                    continue;
                }
                await GenerateComment(instruction, context);
                await Render(instruction, context);

                context.ClearLoop();
            }
            await End(instructions, context);
        }
        protected override Task End(SceneInstructionContainer instructions, CodeGeneratorContext context)
        {
            if (context.CodeScope.Peek() is CodeConditionStatement || context.CodeScope.Peek() is CodeMemberMethod)
            {
                context.CodeScope.Pop();
            }

            if (context.CodeScope.Peek() is CodeTypeDeclaration typeDeclaration)
            {
                context.CodeScope.Push(typeDeclaration.GetMainMethod());
            }

            return(base.End(instructions, context));
        }
        protected override Task Begin(SceneInstructionContainer instructions, CodeGeneratorContext context)
        {
            CodeStatementCollection statements = context.CodeScope.Statements();

            switch (instructions)
            {
            case If ifStmt:
            {
                var codeIf = new CodeConditionStatement(CodeGeneration_Condition.Generate(ifStmt.Condition));
                statements.Add(codeIf);
                context.CodeScope.Push(codeIf);
                break;
            }

            case Hear hear when !context.CodeScope.OfType <Hear>().Any():
                CodeGeneration_Interaction.AddHearMarker(context, statements);
                CodeGeneration_Interaction.AddIntent(context, hear.Phrases, statements);
                break;
            }


            return(base.Begin(instructions, context));
        }
 protected override async Task End(SceneInstructionContainer instructions, TextGeneratorContext context)
 {
     context.CurrentLevel--;
     await context.WriteLine("}");
 }
 protected virtual Task End(SceneInstructionContainer instructions, TContext context)
 {
     return(Noop(context));
 }