Ejemplo n.º 1
0
        /// <summary>
        /// Renders the dialog steps
        /// </summary>
        /// <param name="exportDialog">Dialog to render</param>
        /// <param name="npc">Npc</param>
        /// <returns>Function code</returns>
        public async Task <List <ExportDialogFunctionCode> > RenderDialogSteps(ExportDialogData exportDialog, KortistoNpc npc)
        {
            _curProject = await _cachedDbAccess.GetUserProject();

            _exportSettings = await _cachedDbAccess.GetExportSettings(_curProject.Id);

            SetupStepRenderes();

            // Group to Functions
            ExportDialogFunction rootFunction = new ExportDialogFunction(exportDialog);

            AddNodesToFunction(rootFunction, exportDialog);
            List <ExportDialogFunction> additionalFunctions = ExtractAdditionalFunctions(exportDialog);

            // Render functions
            List <ExportDialogFunctionCode> functionCodes = new List <ExportDialogFunctionCode>();
            string startStepCode = await RenderDialogStepList(rootFunction.FunctionSteps, npc);

            functionCodes.Add(new ExportDialogFunctionCode(InitialFunctionName, startStepCode, string.Empty));

            foreach (ExportDialogFunction curAdditionalFunction in additionalFunctions)
            {
                string functionCode = await RenderDialogStepList(curAdditionalFunction.FunctionSteps, npc);

                functionCodes.Add(new ExportDialogFunctionCode(curAdditionalFunction.RootNode.DialogStepFunctionName, functionCode, await BuildFunctionParentPreview(curAdditionalFunction, npc)));
            }

            return(functionCodes);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Extracts all additional dialog functions
        /// </summary>
        /// <param name="exportDialog">Dialog data</param>
        /// <returns>Additional dialog functions</returns>
        private List <ExportDialogFunction> ExtractAdditionalFunctions(ExportDialogData exportDialog)
        {
            List <ExportDialogFunction> additionalDialogFunctions = new List <ExportDialogFunction>();
            HashSet <ExportDialogData>  usedNodesForFunctions     = new HashSet <ExportDialogData>();
            Queue <ExportDialogData>    dataForFunctions          = new Queue <ExportDialogData>();

            foreach (ExportDialogDataChild curChild in exportDialog.Children)
            {
                dataForFunctions.Enqueue(curChild.Child);
                usedNodesForFunctions.Add(curChild.Child);
            }

            while (dataForFunctions.Any())
            {
                ExportDialogData curDialogData = dataForFunctions.Dequeue();
                if (!string.IsNullOrEmpty(curDialogData.DialogStepFunctionName))
                {
                    ExportDialogFunction curAdditionalDialogFunction = new ExportDialogFunction(curDialogData);
                    AddNodesToFunction(curAdditionalDialogFunction, curDialogData);
                    additionalDialogFunctions.Add(curAdditionalDialogFunction);
                }

                foreach (ExportDialogDataChild curChild in curDialogData.Children)
                {
                    if (!usedNodesForFunctions.Contains(curChild.Child))
                    {
                        dataForFunctions.Enqueue(curChild.Child);
                        usedNodesForFunctions.Add(curChild.Child);
                    }
                }
            }

            return(additionalDialogFunctions);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds the dialog function code
        /// </summary>
        /// <param name="additionalFunction">Function</param>
        /// <param name="additionalFunctionsCode">Additional Function Code to wrap</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <returns>Function Code</returns>
        protected override async Task <string> BuildDialogFunctionCode(ExportDialogFunction additionalFunction, string additionalFunctionsCode, KortistoNpc npc)
        {
            string functionCode        = (await _defaultTemplateProvider.GetDefaultTemplateByType(_curProject.Id, TemplateType.TaleDialogFunction)).Code;
            string functionContentCode = (await _defaultTemplateProvider.GetDefaultTemplateByType(_curProject.Id, TemplateType.TaleDialogStep)).Code;

            functionContentCode = ExportUtil.BuildPlaceholderRegex(Placeholder_StepContent).Replace(functionContentCode, additionalFunctionsCode);

            functionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_FunctionName).Replace(functionCode, additionalFunction.RootNode.DialogStepFunctionName);
            functionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Function_ParentPreview).Replace(functionCode, await BuildFunctionParentPreview(additionalFunction, npc));
            functionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_FunctionContent, ExportConstants.ListIndentPrefix).Replace(functionCode, m => {
                return(ExportUtil.TrimEmptyLines(ExportUtil.IndentListTemplate(functionContentCode, m.Groups[1].Value)));
            });

            return(functionCode);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds all nodes that do not start a new function to a dialog function
        /// </summary>
        /// <param name="targetFunction">Target Function</param>
        /// <param name="exportDialog">Dialog step to check</param>
        private void AddNodesToFunction(ExportDialogFunction targetFunction, ExportDialogData exportDialog)
        {
            if (targetFunction.FunctionSteps.Contains(exportDialog))
            {
                return;
            }

            targetFunction.FunctionSteps.Add(exportDialog);
            foreach (ExportDialogDataChild curChild in exportDialog.Children)
            {
                if (string.IsNullOrEmpty(curChild.Child.DialogStepFunctionName))
                {
                    AddNodesToFunction(targetFunction, curChild.Child);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Renders a dialog
        /// </summary>
        /// <param name="exportDialog">Export Dialog</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <returns>Result of rendering the dialog</returns>
        public async Task <ExportDialogRenderResult> RenderDialog(ExportDialogData exportDialog, KortistoNpc npc)
        {
            _curProject = await _cachedDbAccess.GetDefaultProject();

            _exportSettings = await _cachedDbAccess.GetExportSettings(_curProject.Id);

            SetupStepRenderes();

            ExportDialogRenderResult renderResult = new ExportDialogRenderResult();

            renderResult.StartStepCode           = string.Empty;
            renderResult.AdditionalFunctionsCode = string.Empty;

            // Group to Functions
            ExportDialogFunction rootFunction = new ExportDialogFunction(exportDialog);

            AddNodesToFunction(rootFunction, exportDialog);
            List <ExportDialogFunction> additionalFunctions = ExtractAdditionalFunctions(exportDialog);

            // Render functions
            string startStepCode = await RenderDialogStepList(rootFunction.FunctionSteps, npc);

            string additionalFunctionsCode = string.Empty;

            foreach (ExportDialogFunction curAdditionalFunction in additionalFunctions)
            {
                additionalFunctionsCode += await RenderDialogFunction(curAdditionalFunction, npc);
            }

            ExportTemplate dialogStepTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(_curProject.Id, TemplateType.TaleDialogStep);

            renderResult.StartStepCode           = ExportUtil.BuildPlaceholderRegex(Placeholder_StepContent).Replace(dialogStepTemplate.Code, startStepCode);
            renderResult.AdditionalFunctionsCode = additionalFunctionsCode;

            return(renderResult);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Builds a preview for the parents of a function
        /// </summary>
        /// <param name="additionalFunction">Function</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <returns>Preview of the parents of the function</returns>
        private async Task <string> BuildFunctionParentPreview(ExportDialogFunction additionalFunction, KortistoNpc npc)
        {
            if (additionalFunction.RootNode.Parents == null)
            {
                return(string.Empty);
            }

            List <string> previewLines = new List <string>();

            foreach (ExportDialogData curParent in additionalFunction.RootNode.Parents)
            {
                foreach (IExportDialogStepRenderer curRenderer in _stepRenderers)
                {
                    string stepPreview = await curRenderer.BuildParentTextPreview(additionalFunction.RootNode, curParent, npc, _errorCollection);

                    if (stepPreview != null)
                    {
                        previewLines.Add(stepPreview);
                        continue;
                    }
                }
            }
            return(string.Join(", ", previewLines));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Renders a dialog function
        /// </summary>
        /// <param name="additionalFunction">additionalFunction</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <returns>Dialog function code</returns>
        private async Task <string> RenderDialogFunction(ExportDialogFunction additionalFunction, KortistoNpc npc)
        {
            string functionCode = await RenderDialogStepList(additionalFunction.FunctionSteps, npc);

            return(await BuildDialogFunctionCode(additionalFunction, functionCode, npc));
        }