/// <summary> /// Maps a single choice /// </summary> /// <param name="data">Dialog Step Data</param> /// <param name="choice">Choice to map</param> /// <param name="npc">Npc object to which the dialog belongs</param> /// <param name="parentChoiceData">Choice data to which the choices belong</param> /// <returns>Mapped choice</returns> private async ValueTask <ScribanChoiceOption> MapSingleChoice(ExportDialogData data, TaleChoice choice, KortistoNpc npc, ScribanChoice parentChoiceData) { ExportDialogDataChild choiceData = data.Children.FirstOrDefault(c => c.NodeChildId == choice.Id); ScribanDialogStepBaseData childRenderData = null; if (choiceData != null && choiceData.Child != null) { childRenderData = new ScribanDialogStepBaseData(); SetRenderObjectBaseDataFromFlexFieldObject(childRenderData, choiceData.Child, npc); } ScribanChoiceOption choiceOption = new ScribanChoiceOption(); choiceOption.ChildNode = childRenderData; choiceOption.Id = choice.Id; choiceOption.Text = ExportUtil.EscapeCharacters(choice.Text, _exportSettings.EscapeCharacter, _exportSettings.CharactersNeedingEscaping, _exportSettings.NewlineCharacter); choiceOption.UnescapedText = choice.Text; choiceOption.TextPreview = ExportUtil.BuildTextPreview(choice.Text); choiceOption.IsRepeatable = choice.IsRepeatable; choiceOption.Condition = null; if (choice.Condition != null && !string.IsNullOrEmpty(choice.Condition.ConditionElements)) { choiceOption.Condition = await _conditionRenderer.RenderCondition(_project, choice.Condition, _errorCollection, npc, _exportSettings); } choiceOption.ParentChoice = parentChoiceData; return(choiceOption); }
/// <summary> /// Builds a choice /// </summary> /// <param name="choiceTemplate">Choice Template</param> /// <param name="data">Export dialog data</param> /// <param name="choiceObj">Choice element</param> /// <param name="choiceNode">Choice node</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="choiceIndex">Index of the choice</param> /// <returns>Choices as string</returns> private string BuildSingleChoice(string choiceTemplate, ExportDialogData data, TaleChoice choiceObj, TaleChoiceNode choiceNode, KortistoNpc npc, int choiceIndex) { ExportDialogDataChild choice = data.Children.FirstOrDefault(c => c.NodeChildId == choiceObj.Id); string choiceContent = ReplaceBaseStepPlaceholders(choiceTemplate, data, choice != null ? choice.Child : null); choiceContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Choice_Id).Replace(choiceContent, choiceObj.Id.ToString()); choiceContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Choice_Index).Replace(choiceContent, choiceIndex.ToString()); choiceContent = ExportUtil.RenderPlaceholderIfTrue(choiceContent, Placeholder_HasConditionStart, Placeholder_HasConditionEnd, choiceObj.Condition != null && !string.IsNullOrEmpty(choiceObj.Condition.ConditionElements)); choiceContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Condition).Replace(choiceContent, m => { return(BuildCondition(choiceObj.Condition, npc)); }); choiceContent = ExportUtil.RenderPlaceholderIfTrue(choiceContent, Placeholder_Choice_IsRepeatable_Start, Placeholder_Choice_IsRepeatable_End, choiceObj.IsRepeatable); choiceContent = ExportUtil.RenderPlaceholderIfTrue(choiceContent, Placeholder_Choice_IsNotRepeatable_Start, Placeholder_Choice_IsNotRepeatable_End, !choiceObj.IsRepeatable); choiceContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Choice_Text).Replace(choiceContent, ExportUtil.EscapeCharacters(choiceObj.Text, _exportSettings.EscapeCharacter, _exportSettings.CharactersNeedingEscaping, _exportSettings.NewlineCharacter)); choiceContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Choice_Text_Preview).Replace(choiceContent, ExportUtil.BuildTextPreview(choiceObj.Text)); choiceContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Choice_Text_LangKey).Replace(choiceContent, m => { return(_languageKeyGenerator.GetDialogTextLineKey(npc.Id, npc.Name, "choice", choiceNode.Id + "_" + choiceObj.Id, choiceObj.Text).Result); }); return(choiceContent); }