/// <summary> /// Renders a dialog step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="npc">Npc object to which the dialog belongs</param> /// <param name="textNode">Text node to render</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, KortistoNpc npc, TextNode textNode) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); Template parsedTemplate = ScribanParsingUtil.ParseTemplate(template.Code, _errorCollection); if (parsedTemplate == null) { return(renderResult); } _languageKeyGenerator.SetErrorCollection(_errorCollection); ScribanTextLine textLineData = BuildDialogRenderObject <ScribanTextLine>(data, data.Children.FirstOrDefault() != null ? data.Children.FirstOrDefault().Child : null, npc); textLineData.TextLine = ExportUtil.EscapeCharacters(textNode.Text, _exportSettings.EscapeCharacter, _exportSettings.CharactersNeedingEscaping, _exportSettings.NewlineCharacter); textLineData.UnescapedTextLine = textNode.Text; textLineData.TextLinePreview = ExportUtil.BuildTextPreview(textNode.Text); textLineData.IsPlayerLine = _isPlayerLine; TemplateContext context = BuildTemplateContext(textLineData); renderResult.StepCode = await parsedTemplate.RenderAsync(context); return(renderResult); }
/// <summary> /// Renders a condition step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="conditionNode">Condition node to render</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, FlexFieldObject flexFieldObject, ConditionNode conditionNode) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); Template parsedTemplate = ScribanParsingUtil.ParseTemplate(template.Code, _errorCollection); if (parsedTemplate == null) { return(renderResult); } ScribanCondition conditionData = new ScribanCondition(); SetRenderObjectBaseDataFromFlexFieldObject(conditionData, data, flexFieldObject); conditionData.AllConditions = await BuildAllConditions(data, flexFieldObject, conditionNode); conditionData.Conditions = conditionData.AllConditions.Where(c => c.ChildNode != null).ToList(); conditionData.Else = BuildElsePart(data, flexFieldObject); TemplateContext context = BuildTemplateContext(conditionData); renderResult.StepCode = await parsedTemplate.RenderAsync(context); return(renderResult); }
/// <summary> /// Renders an action step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="nextStep">Next step in the dialog</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="actionContent">Content of the action</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, ExportDialogDataChild nextStep, FlexFieldObject flexFieldObject, string actionContent) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); Template parsedTemplate = ScribanParsingUtil.ParseTemplate(template.Code, _errorCollection); if (parsedTemplate == null) { return(renderResult); } ScribanAction actionData = BuildDialogRenderObject <ScribanAction>(data, nextStep != null ? nextStep.Child : null, flexFieldObject); actionData.Content = actionContent; if (_nextStepNodeData != null) { actionData.NodeStepFunctionWasUsed = _nextStepNodeData.NodeStepFunctionWasUsed; if (actionData.ChildNode != null && _nextStepNodeData.ChildNode != null) { actionData.ChildNode.NodeStepFunctionWasUsed = _nextStepNodeData.ChildNode.NodeStepFunctionWasUsed; } } TemplateContext context = BuildTemplateContext(actionData); renderResult.StepCode = await parsedTemplate.RenderAsync(context); return(renderResult); }
/// <summary> /// Renders an action step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="nextStep">Next step in the dialog</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="actionContent">Content of the action</param> /// <returns>Dialog Step Render Result</returns> public Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, ExportDialogDataChild nextStep, FlexFieldObject flexFieldObject, string actionContent) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); renderResult.StepCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ActionContent).Replace(template.Code, actionContent); renderResult.StepCode = ReplaceBaseStepPlaceholders(renderResult.StepCode, data, nextStep != null ? nextStep.Child : null); return(Task.FromResult(renderResult)); }
/// <summary> /// Renders a list of dialog steps /// </summary> /// <param name="functionSteps">Steps to render</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <returns>Renderd code for list of dialog steps</returns> protected async Task <string> RenderDialogStepList(List <ExportDialogData> functionSteps, FlexFieldObject flexFieldObject) { string stepListCode = string.Empty; foreach (ExportDialogData curData in functionSteps) { ExportDialogStepRenderResult renderResult = await RenderDialogStep(curData, flexFieldObject); stepListCode += renderResult.StepCode; } return(stepListCode); }
/// <summary> /// Renders a choice step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="npc">Npc object to which the dialog belongs</param> /// <param name="choiceNode">Choice node to render</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, KortistoNpc npc, TaleChoiceNode choiceNode) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); renderResult.StepCode = ReplaceNodeId(template.Code, data); renderResult.StepCode = await ExportUtil.BuildRangePlaceholderRegex(Placeholder_ChoicesStart, Placeholder_ChoicesEnd).ReplaceAsync(renderResult.StepCode, async m => { string choices = await BuildChoices(m.Groups[1].Value, data, choiceNode, npc); return(ExportUtil.TrimEmptyLines(ExportUtil.IndentListTemplate(choices, m.Groups[2].Value))); }); return(renderResult); }
/// <summary> /// Renders a dialog step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="npc">Npc object to which the dialog belongs</param> /// <param name="textNode">Text node to render</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, KortistoNpc npc, TextNode textNode) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); renderResult.StepCode = ReplaceBaseStepPlaceholders(template.Code, data, data.Children.FirstOrDefault() != null ? data.Children.FirstOrDefault().Child : null); renderResult.StepCode = ExportUtil.BuildPlaceholderRegex(Placeholder_TextLine).Replace(renderResult.StepCode, ExportUtil.EscapeCharacters(textNode.Text, _exportSettings.EscapeCharacter, _exportSettings.CharactersNeedingEscaping, _exportSettings.NewlineCharacter)); renderResult.StepCode = ExportUtil.BuildPlaceholderRegex(Placeholder_TextLine_Preview).Replace(renderResult.StepCode, ExportUtil.BuildTextPreview(textNode.Text)); renderResult.StepCode = await ExportUtil.BuildPlaceholderRegex(Placeholder_TextLine_LangKey).ReplaceAsync(renderResult.StepCode, async m => { return(await _languageKeyGenerator.GetDialogTextLineKey(npc.Id, npc.Name, _isPlayerLine ? ExportConstants.LanguageKeyTypePlayer : ExportConstants.LanguageKeyTypeNpc, textNode.Id, textNode.Text)); }); return(renderResult); }
/// <summary> /// Renders a dialog step /// </summary> /// <param name="exportDialog">Cur Data to render</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <returns>Result of the rendering of the step</returns> protected async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportDialogData exportDialog, FlexFieldObject flexFieldObject) { foreach (IExportDialogStepRenderer curRenderer in _stepRenderers) { ExportDialogStepRenderResult result = await curRenderer.RenderDialogStep(exportDialog, flexFieldObject); if (result != null) { return(result); } } _errorCollection.AddUnknownDialogStepError(); return(null); }
/// <summary> /// Renders a dialog step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="project">Project for which the epxort is running</param> /// <param name="referenceNodeData">Reference node data</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, GoNorthProject project, ReferenceNodeData referenceNodeData, FlexFieldObject flexFieldObject) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); Template parsedTemplate = ScribanParsingUtil.ParseTemplate(template.Code, _errorCollection); if (parsedTemplate == null) { return(renderResult); } MiscProjectConfig projectConfig = await _exportCachedDbAccess.GetMiscProjectConfig(); _languageKeyGenerator.SetErrorCollection(_errorCollection); ScribanReferenceData referenceData = BuildDialogRenderObject <ScribanReferenceData>(data, data.Children.FirstOrDefault() != null ? data.Children.FirstOrDefault().Child : null, flexFieldObject); referenceData.ReferenceText = referenceNodeData.ReferenceText != null ? referenceNodeData.ReferenceText : string.Empty; referenceData.ObjectType = referenceNodeData.ObjectType; if (referenceNodeData.Npc != null) { referenceData.Npc = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportNpc>(null, null, referenceNodeData.Npc, _exportSettings, _errorCollection); referenceData.Npc.IsPlayer = referenceNodeData.Npc.IsPlayerNpc; } else { referenceData.Npc = null; } referenceData.Item = referenceNodeData.Item != null?FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportItem>(null, null, referenceNodeData.Item, _exportSettings, _errorCollection) : null; referenceData.Skill = referenceNodeData.Skill != null?FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportSkill>(null, null, referenceNodeData.Skill, _exportSettings, _errorCollection) : null; referenceData.Quest = referenceNodeData.Quest != null?FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportQuest>(null, null, referenceNodeData.Quest, _exportSettings, _errorCollection) : null; referenceData.WikiPage = referenceNodeData.WikiPage != null ? new ScribanExportWikiPage(referenceNodeData.WikiPage) : null; referenceData.DailyRoutineEvent = referenceNodeData.DailyRoutineEvent != null ? await ScribanDailyRoutineEventUtil.ConvertDailyRoutineEvent(_dailyRoutineFunctionNameGenerator, referenceNodeData.Npc, referenceNodeData.DailyRoutineEvent, project, projectConfig, _exportSettings) : null; referenceData.Marker = referenceNodeData.Marker != null ? new ScribanExportMapMarker(referenceNodeData.Marker) : null; TemplateContext context = BuildTemplateContext(referenceData); renderResult.StepCode = await parsedTemplate.RenderAsync(context); return(renderResult); }
/// <summary> /// Renders a condition step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="conditionNode">Condition node to render</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, FlexFieldObject flexFieldObject, ConditionNode conditionNode) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); renderResult.StepCode = ReplaceNodeId(template.Code, data); renderResult.StepCode = await ExportUtil.BuildRangePlaceholderRegex(Placeholder_ConditionsStart, Placeholder_ConditionsEnd).ReplaceAsync(renderResult.StepCode, async m => { string conditionData = await BuildConditions(m.Groups[1].Value, data, conditionNode, flexFieldObject, false); return(ExportUtil.TrimEmptyLines(ExportUtil.IndentListTemplate(conditionData, m.Groups[2].Value))); }); renderResult.StepCode = await ExportUtil.BuildRangePlaceholderRegex(Placeholder_AllConditionsStart, Placeholder_AllConditionsEnd).ReplaceAsync(renderResult.StepCode, async m => { string conditionData = await BuildConditions(m.Groups[1].Value, data, conditionNode, flexFieldObject, true); return(ExportUtil.TrimEmptyLines(ExportUtil.IndentListTemplate(conditionData, m.Groups[2].Value))); }); renderResult.StepCode = ExportUtil.BuildRangePlaceholderRegex(Placeholder_ElseStart, Placeholder_ElseEnd).Replace(renderResult.StepCode, m => { return(ExportUtil.IndentListTemplate(BuildElsePart(m.Groups[1].Value, data), m.Groups[2].Value)); }); return(renderResult); }
/// <summary> /// Renders a choice step /// </summary> /// <param name="template">Export template</param> /// <param name="data">Dialog Step Data</param> /// <param name="npc">Npc object to which the dialog belongs</param> /// <param name="choiceNode">Choice node to render</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportTemplate template, ExportDialogData data, KortistoNpc npc, TaleChoiceNode choiceNode) { ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); Template parsedTemplate = ScribanParsingUtil.ParseTemplate(template.Code, _errorCollection); if (parsedTemplate == null) { return(renderResult); } _languageKeyGenerator.SetErrorCollection(_errorCollection); ScribanChoice choiceData = new ScribanChoice(); SetRenderObjectBaseDataFromFlexFieldObject(choiceData, data, npc); choiceData.Choices = await BuildChoiceOptions(data, choiceNode, npc, choiceData); TemplateContext context = BuildTemplateContext(choiceData); renderResult.StepCode = await parsedTemplate.RenderAsync(context); return(renderResult); }