/// <summary> /// Renders a dialog step /// </summary> /// <param name="data">Dialog Step Data</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <returns>Dialog Step Render Result</returns> public async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportDialogData data, KortistoNpc npc) { ConditionNode conditionNode = data.Condition; if (conditionNode == null) { return(null); } ExportTemplate template = await _defaultTemplateProvider.GetDefaultTemplateByType(_project.Id, TemplateType.TaleCondition); ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); renderResult.StepCode = ReplaceNodeId(template.Code, data); renderResult.StepCode = ExportUtil.BuildRangePlaceholderRegex(Placeholder_ConditionsStart, Placeholder_ConditionsEnd).Replace(renderResult.StepCode, m => { return(ExportUtil.TrimEmptyLines(ExportUtil.IndentListTemplate(BuildConditions(m.Groups[1].Value, data, conditionNode, npc, false), m.Groups[2].Value))); }); renderResult.StepCode = ExportUtil.BuildRangePlaceholderRegex(Placeholder_AllConditionsStart, Placeholder_AllConditionsEnd).Replace(renderResult.StepCode, m => { return(ExportUtil.TrimEmptyLines(ExportUtil.IndentListTemplate(BuildConditions(m.Groups[1].Value, data, conditionNode, npc, true), 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> /// Fills the daily routine placeholders /// </summary> /// <param name="code">Code</param> /// <param name="npc">Npc</param> /// <returns>Filled code</returns> private async Task <string> FillDailyRoutinePlaceholders(string code, KortistoNpc npc) { GoNorthProject project = await _cachedDbAccess.GetDefaultProject(); ExportTemplate dailyRoutineEventTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.ObjectDailyRoutineEventList); ExportTemplate dailyRoutineFunctionListTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.ObjectDailyRoutineFunctionList); ExportTemplate dailyRoutineFunctionTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.ObjectDailyRoutineFunction); code = ExportUtil.BuildPlaceholderRegex(Placeholder_DailyRoutine_Events, ExportConstants.ListIndentPrefix).Replace(code, m => { return(ExportUtil.IndentListTemplate(dailyRoutineEventTemplate.Code, m.Groups[1].Value)); }); code = ExportUtil.BuildPlaceholderRegex(Placeholder_DailyRoutine_Functions, ExportConstants.ListIndentPrefix).Replace(code, m => { return(ExportUtil.IndentListTemplate(dailyRoutineFunctionListTemplate.Code, m.Groups[1].Value)); }); code = ExportUtil.BuildPlaceholderRegex(Placeholder_DailyRoutine_Function, ExportConstants.ListIndentPrefix).Replace(code, m => { return(ExportUtil.IndentListTemplate(dailyRoutineFunctionTemplate.Code, m.Groups[1].Value)); }); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasDailyRoutine_Start, Placeholder_HasDailyRoutine_End, npc.DailyRoutine != null && npc.DailyRoutine.Count > 0); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_DailyRoutine_Events_Start, Placeholder_DailyRoutine_Events_End).Replace(code, m => { return(ExportUtil.TrimEmptyLines(BuildEventList(m.Groups[1].Value, project, npc))); }); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_DailyRoutine_Functions_Start, Placeholder_DailyRoutine_Functions_End).Replace(code, m => { return(ExportUtil.TrimEmptyLines(BuildFunctionList(m.Groups[1].Value, project, npc))); }); return(code); }
/// <summary> /// Renders a dialog step /// </summary> /// <param name="data">Dialog Step 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(ExportDialogData data, FlexFieldObject flexFieldObject) { KortistoNpc npc = flexFieldObject as KortistoNpc; if (npc == null) { return(null); } TaleChoiceNode choiceNode = data.Choice; if (choiceNode == null) { return(null); } ExportTemplate template = await _defaultTemplateProvider.GetDefaultTemplateByType(_project.Id, TemplateType.TaleChoice); ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult(); renderResult.StepCode = ReplaceNodeId(template.Code, data); renderResult.StepCode = ExportUtil.BuildRangePlaceholderRegex(Placeholder_ChoicesStart, Placeholder_ChoicesEnd).Replace(renderResult.StepCode, m => { return(ExportUtil.TrimEmptyLines(ExportUtil.IndentListTemplate(BuildChoices(m.Groups[1].Value, data, choiceNode, npc), 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(); 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> /// Fills the inventory placeholders /// </summary> /// <param name="code">Code</param> /// <param name="npc">Npc</param> /// <param name="data">Export Data</param> /// <returns>Filled code</returns> private async Task <string> FillInventoryPlaceholders(string code, KortistoNpc npc, ExportObjectData data) { code = await ExportUtil.BuildPlaceholderRegex(Placeholder_Inventory, ExportConstants.ListIndentPrefix).ReplaceAsync(code, async m => { return(await RenderInventory(data, m.Groups[1].Value)); }); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasItems_Start, Placeholder_HasItems_End, npc.Inventory != null && npc.Inventory.Count > 0); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_Inventory_Start, Placeholder_Inventory_End).Replace(code, m => { return(ExportUtil.TrimEmptyLines(BuildInventory(m.Groups[1].Value, npc))); }); return(code); }
/// <summary> /// Fills the language key Placeholders /// </summary> /// <param name="code">Code to fill</param> /// <param name="flexFieldObject">Flex Field Object</param> /// <returns>Filled Code</returns> private async Task <string> FillLanguageKeyPlaceholders(string code, IFlexFieldExportable flexFieldObject) { GoNorthProject project = await _cachedDbAccess.GetDefaultProject(); List <LanguageKey> languageKeys = await _languageKeyDbAccess.GetLanguageKeysByGroupId(project.Id, flexFieldObject.Id); ExportSettings exportSettings = await _cachedDbAccess.GetExportSettings(project.Id); code = ExportUtil.BuildPlaceholderRegex(Placeholder_ObjectName).Replace(code, flexFieldObject.Name); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_LanguageKeys_Start, Placeholder_LanguageKeys_End).Replace(code, m => { return(BuildLanguageKeyList(m.Groups[1].Value, languageKeys, exportSettings)); }); return(code); }
/// <summary> /// Fills the inventory placeholders /// </summary> /// <param name="code">Code</param> /// <param name="npc">Npc</param> /// <returns>Filled code</returns> private async Task <string> FillInventoryPlaceholders(string code, KortistoNpc npc) { GoNorthProject project = await _cachedDbAccess.GetDefaultProject(); ExportTemplate inventoryTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.ObjectInventory); code = ExportUtil.BuildPlaceholderRegex(Placeholder_Inventory, ExportConstants.ListIndentPrefix).Replace(code, m => { return(ExportUtil.IndentListTemplate(inventoryTemplate.Code, m.Groups[1].Value)); }); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_Inventory_Start, Placeholder_Inventory_End).Replace(code, m => { return(ExportUtil.TrimEmptyLines(BuildInventory(m.Groups[1].Value, npc))); }); return(code); }
/// <summary> /// Fills the skill placeholders /// </summary> /// <param name="code">Code</param> /// <param name="npc">Npc</param> /// <returns>Filled code</returns> private async Task <string> FillSkillPlaceholders(string code, KortistoNpc npc) { GoNorthProject project = await _cachedDbAccess.GetDefaultProject(); ExportTemplate skillTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.ObjectSkillList); code = ExportUtil.BuildPlaceholderRegex(Placeholder_Skills, ExportConstants.ListIndentPrefix).Replace(code, m => { return(ExportUtil.IndentListTemplate(skillTemplate.Code, m.Groups[1].Value)); }); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasSkills_Start, Placeholder_HasSkills_End, npc.Skills != null && npc.Skills.Count > 0); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_Skill_Start, Placeholder_Skill_End).Replace(code, m => { return(ExportUtil.TrimEmptyLines(BuildSkills(m.Groups[1].Value, npc))); }); return(code); }
/// <summary> /// Fills the language key Placeholders /// </summary> /// <param name="code">Code to fill</param> /// <param name="flexFieldObject">Flex Field Object</param> /// <param name="referencedLanguageKeys">Referenced language keys</param> /// <returns>Filled Code</returns> private async Task <string> FillLanguageKeyPlaceholders(string code, IFlexFieldExportable flexFieldObject, List <LanguageKey> referencedLanguageKeys) { GoNorthProject project = await _cachedDbAccess.GetUserProject(); List <LanguageKey> languageKeys = await _languageKeyDbAccess.GetLanguageKeysByGroupId(project.Id, flexFieldObject.Id); ExportSettings exportSettings = await _cachedDbAccess.GetExportSettings(project.Id); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_Has_Referenced_LanguageKeys_Start, Placeholder_Has_Referenced_LanguageKeys_End, referencedLanguageKeys != null && referencedLanguageKeys.Any()); code = ExportUtil.BuildPlaceholderRegex(Placeholder_ObjectName).Replace(code, flexFieldObject.Name); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_LanguageKeys_Start, Placeholder_LanguageKeys_End).Replace(code, m => { return(BuildLanguageKeyList(m.Groups[1].Value, languageKeys, exportSettings)); }); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_Referenced_LanguageKeys_Start, Placeholder_Referenced_LanguageKeys_End).Replace(code, m => { return(BuildLanguageKeyList(m.Groups[1].Value, referencedLanguageKeys, exportSettings)); }); return(code); }
/// <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 list of daily routine functions /// </summary> /// <param name="code">Code to use</param> /// <param name="functions">Function list to render</param> /// <returns>Filled code</returns> private async Task <string> FillDailyRoutineFunctionListPlaceholders(string code, List <DailyRoutineFunction> functions) { GoNorthProject project = await _cachedDbAccess.GetUserProject(); ExportTemplate dailyRoutineFunctionTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.ObjectDailyRoutineFunction); code = ExportUtil.BuildPlaceholderRegex(Placeholder_DailyRoutine_Function, ExportConstants.ListIndentPrefix).Replace(code, m => { return(ExportUtil.IndentListTemplate(dailyRoutineFunctionTemplate.Code, m.Groups[1].Value)); }); code = await ExportUtil.BuildRangePlaceholderRegex(Placeholder_DailyRoutine_Functions_Start, Placeholder_DailyRoutine_Functions_End).ReplaceAsync(code, async m => { string functionCode = m.Groups[1].Value; string filledCode = string.Empty; foreach (DailyRoutineFunction curFunction in functions) { string curFunctionCode = _eventPlaceholderResolver.ResolveDailyRoutineEventHasScript(functionCode, true); curFunctionCode = _eventContentPlaceholderResolver.FillFunctionCode(curFunctionCode, curFunction); filledCode += await _eventContentPlaceholderResolver.ReplaceEventFunction(curFunctionCode, curFunction, _errorCollection); } return(filledCode); }); return(code); }
/// <summary> /// Fills the Flex Field Placeholders /// </summary> /// <param name="code">Code to fill</param> /// <param name="flexFieldObject">Flex Field Object</param> /// <param name="objectType">Object Type</param> /// <param name="data">Export Data</param> /// <returns>Filled Code</returns> private async Task <string> FillFlexFieldPlaceholders(string code, IFlexFieldExportable flexFieldObject, string objectType, ExportObjectData data) { GoNorthProject project = await _exportCachedDbAccess.GetUserProject(); ExportSettings exportSettings = await _exportCachedDbAccess.GetExportSettings(project.Id); HashSet <string> usedFields = new HashSet <string>(); code = ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_Name)).Replace(code, flexFieldObject.Name); code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_Field_Value_Equals_Start), BuildFinalPlaceholder(Placeholder_Field_Value_Equals_End), m => { string fieldName = m.Groups[1].Value; FlexField field = FindFlexField(flexFieldObject, fieldName); if (field == null) { return(false); } return(m.Groups[2].Value == field.Value); }); code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_Field_Value_NotEquals_Start), BuildFinalPlaceholder(Placeholder_Field_Value_NotEquals_End), m => { string fieldName = m.Groups[1].Value; FlexField field = FindFlexField(flexFieldObject, fieldName); if (field == null) { return(true); } return(m.Groups[2].Value != field.Value); }); code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_FlexField_HasField_Start), BuildFinalPlaceholder(Placeholder_FlexField_HasField_End), m => { string fieldName = m.Groups[1].Value; FlexField field = FindFlexField(flexFieldObject, fieldName); return(field != null); }); code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_FlexField_NotHasField_Start), BuildFinalPlaceholder(Placeholder_FlexField_NotHasField_End), m => { string fieldName = m.Groups[1].Value; FlexField field = FindFlexField(flexFieldObject, fieldName); return(field == null); }); code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_FlexField_FieldIsBlank_Start), BuildFinalPlaceholder(Placeholder_FlexField_FieldIsBlank_End), m => { string fieldName = m.Groups[1].Value; FlexField field = FindFlexField(flexFieldObject, fieldName); if (field == null) { return(true); } return(string.IsNullOrEmpty(field.Value)); }); code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_FlexField_FieldIsNotBlank_Start), BuildFinalPlaceholder(Placeholder_FlexField_FieldIsNotBlank_End), m => { string fieldName = m.Groups[1].Value; FlexField field = FindFlexField(flexFieldObject, fieldName); if (field == null) { return(false); } return(!string.IsNullOrEmpty(field.Value)); }); code = await ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_Name_LangKey)).ReplaceAsync(code, async m => { // Run in function to only create language key if required string key = await _languageKeyGenerator.GetFlexFieldNameKey(flexFieldObject.Id, flexFieldObject.Name, objectType); return(key); }); code = ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_Field_Value)).Replace(code, m => { string fieldName = m.Groups[1].Value; FlexField field = FindFlexField(flexFieldObject, fieldName); if (field != null) { usedFields.Add(field.Id); return(EscapedFieldValue(field, exportSettings)); } _errorCollection.AddErrorFlexField(fieldName, flexFieldObject.Name); return("<<" + flexFieldObject.Name + "[" + fieldName + "] MISSING>>"); }); code = ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_Field_LangKey)).Replace(code, m => { string fieldName = m.Groups[1].Value; FlexField field = FindFlexField(flexFieldObject, fieldName); if (field != null && (field.FieldType == ExportConstants.FlexFieldType_String || field.FieldType == ExportConstants.FlexFieldType_Option)) { usedFields.Add(field.Id); return(BuildFlexFieldLangKey(flexFieldObject, field, objectType)); } _errorCollection.AddErrorFlexField(fieldName, flexFieldObject.Name); return("<<" + flexFieldObject.Name + "[" + fieldName + "] MISSING>>"); }); code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_HasUnusedFields_Start), BuildFinalPlaceholder(Placeholder_HasUnusedFields_End), m => { return(flexFieldObject.Fields.Where(f => !usedFields.Contains(f.Id)).Any()); }); code = ExportUtil.BuildRangePlaceholderRegex(BuildFinalPlaceholder(Placeholder_UnusedFields_Start), BuildFinalPlaceholder(Placeholder_UnusedFields_End)).Replace(code, m => { List <FlexField> fieldsToUse = flexFieldObject.Fields.Where(f => !usedFields.Contains(f.Id)).ToList(); return(BuildFlexFieldList(m.Groups[1].Value, fieldsToUse, flexFieldObject, exportSettings, objectType)); }); code = ExportUtil.BuildRangePlaceholderRegex(BuildFinalPlaceholder(Placeholder_AllFields_Start), BuildFinalPlaceholder(Placeholder_AllFields_End)).Replace(code, m => { return(BuildFlexFieldList(m.Groups[1].Value, flexFieldObject.Fields, flexFieldObject, exportSettings, objectType)); }); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_FlexFieldList_Start, Placeholder_FlexFieldList_End).Replace(code, m => { return(BuildFlexFieldList(m.Groups[1].Value, flexFieldObject.Fields, flexFieldObject, exportSettings, objectType)); }); code = await ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_UnusedFields), ExportConstants.ListIndentPrefix).ReplaceAsync(code, async m => { return(await RenderAttributeList(project, FilterInvalidFlexFields(flexFieldObject.Fields.Where(f => !usedFields.Contains(f.Id)).ToList()), data, m.Groups[1].Value)); }); code = await ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_AllFields), ExportConstants.ListIndentPrefix).ReplaceAsync(code, async m => { return(await RenderAttributeList(project, FilterInvalidFlexFields(flexFieldObject.Fields), data, m.Groups[1].Value)); }); return(code); }