public void ReceiveSceneInstruction(SceneInstruction sentInstruction) { sceneToLoad = sentInstruction.SceneName; currentSceneInstruction = sentInstruction; QueueProecess(); return; }
public override void ProcessArrayList(ArrayList sentArrayList) { for (int i = 0; i < sentArrayList.Count; i++) { if (sentArrayList[i] is SceneInstruction) { SceneInstruction instruction = (SceneInstruction)sentArrayList[i]; ChangeScene(instruction.SceneName); } } }
public async Task TestInstruction(SceneInstruction instruction, string expectedOutput) { var story = new Story(); var scene = new Scene { Name = "test this thing" }; scene.Add(new SceneInstructions()); scene.Instructions.Add(instruction); story.Scenes.Add("test", scene); var output = await OutputStory(story); Assert.Equal($"@test this thing\n\t*then\n\t\t{expectedOutput}\n", output); }
protected override Task Render(SceneInstruction instruction, TextGeneratorContext context) { switch (instruction) { case Clear clear: return(context.WriteLine($"clear {clear.Variable}")); case ClearAll all: return(context.WriteLine("clear *")); case Decrease decrease: return(context.WriteLine($"increase {decrease.Variable} by {decrease.Amount}")); case Flag flag: return(context.WriteLine($"flag {flag.Variable}")); case GoTo goTo: return(context.WriteLine($"-> {goTo.SceneName}")); case GoToAndReturn goToAndReturn: return(context.WriteLine($"<-> {goToAndReturn}")); case Increase increase: return(context.WriteLine($"increase {increase.Variable} by {increase.Amount}")); case Set set: return(context.WriteLine($"increase {set.Variable} to {set.Value}")); case SlotAssignment slot: return(context.WriteLine($"slot {slot.SlotName} to '{slot.SlotType}'")); case Unflag unflag: return(context.WriteLine($"unflag {unflag.Variable}")); case Back back: return(context.WriteLine(">> BACK")); case End end: return(context.WriteLine(">> END")); case Pause pause: return(context.WriteLine(">> PAUSE")); case Repeat repeat: return(context.WriteLine(">> REPEAT")); case Reprompt reprompt: return(context.WriteLine(">> REPROMPT")); case Restart restart: return(context.WriteLine(">> RESTART")); case Resume resume: return(context.WriteLine(">> RESUME")); case Return returnvalue: return(context.WriteLine(">> RETURN")); default: if (Extensions.ContainsKey(instruction.GetType())) { return(Extensions[instruction.GetType()].Generate(instruction, context)); } return(Noop(context)); } }
protected override Task Render(SceneInstruction instruction, CodeGeneratorContext context) { CodeStatementCollection statements; switch (context.CodeScope.Peek()) { case CodeMemberMethod member: statements = member.Statements; break; case CodeTypeDeclaration codeType: statements = codeType.GetMainMethod().Statements; break; case CodeConditionStatement stmt: statements = stmt.TrueStatements; break; default: return(Noop(context)); } CodeGeneration_Instructions.EnsureStateMaintenance(context); switch (instruction) { case Clear clear: statements.Clear(clear.Variable); break; case ClearAll clearAll: statements.ClearAll(); break; case Decrease decrease: statements.Decrease(decrease.Variable, decrease.Amount); break; case Flag flag: statements.SetVariable(flag.Variable, true); break; case GoTo gto: statements.Add(CodeGeneration_Navigation.GoToScene(gto.SceneName)); statements.Add(new CodeMethodReturnStatement()); break; case GoToAndReturn goToAndReturn: statements.Add(CodeGeneration_Navigation.GoToScene(goToAndReturn.SceneName)); break; case Increase increase: statements.Increase(increase.Variable, increase.Amount); break; case Set set: statements.SetVariable(set.Variable, set.Value); break; case SlotAssignment slotAssignment: context.SetSlotType(slotAssignment.SlotName, slotAssignment.SlotType); break; case Unflag unflag: statements.SetVariable(unflag.Variable, false); break; case End end: statements.Reset(); statements.Add(new CodeMethodReturnStatement()); break; case Repeat repeat: statements.Add(new CodeVariableDeclarationStatement(CodeConstants.Var, "lastSpeech", CodeGeneration_Instructions.GetVariable("scene_lastSpeech", typeof(string), false))); statements.Add(new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("Output"), "AddSpeech", CodeConstants.RequestVariableRef, new CodeVariableReferenceExpression("lastSpeech"), new CodePrimitiveExpression(true))); statements.Add(new CodeMethodReturnStatement()); break; case Restart restart: statements.ClearAll("scene_"); statements.ClearAll("_scene"); CodeGeneration_Navigation.GoToScene("start"); statements.Add(new CodeMethodReturnStatement()); break; case Resume resume: statements.Add(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("await Navigation"), "Resume", CodeConstants.RequestVariableRef, new CodePrimitiveExpression(true))); statements.Add(new CodeMethodReturnStatement()); break; case Return returnCmd: statements.Add(new CodeMethodReturnStatement()); break; case Reprompt reprompt: statements.Add(new CodeVariableDeclarationStatement(CodeConstants.Var, "reprompt", CodeGeneration_Instructions.GetVariable("scene_reprompt", typeof(string), false))); statements.Add(new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("Output"), "AddSpeech", CodeConstants.RequestVariableRef, new CodeVariableReferenceExpression("reprompt"), new CodePrimitiveExpression(true))); statements.Add(new CodeMethodReturnStatement()); break; case Back back: statements.Add(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("await Navigation"), "Back", CodeConstants.RequestVariableRef)); statements.Add(new CodeMethodReturnStatement()); break; case Pause pause: statements.Add(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("await Navigation"), "Pause", CodeConstants.RequestVariableRef)); statements.Add(new CodeMethodReturnStatement()); break; } return(base.Render(instruction, context)); }
public override void AddDataToArrayList(ArrayList sentArrayList) { SceneInstruction instruction = new SceneInstruction(SceneManager.GetActiveScene().name); sentArrayList.Add(instruction); }
public SceneInstruction(SceneInstruction sentInstruction) { sceneName = sentInstruction.SceneName; }
protected virtual Task Render(SceneInstruction instruction, TContext context) { return(Noop(context)); }