Ejemplo n.º 1
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.º 2
0
        /// <summary>
        /// Checks if a dialog node can reach the end of a dialog or is part of an infinity loop
        /// </summary>
        /// <param name="curData">Cur Data to check</param>
        /// <param name="checkedNodes">Checked nodes for this run</param>
        /// <returns>true if the dialog can reach the end of the dialog, else false</returns>
        private bool CheckIfDialogDataCanReachEndOfDialog(ExportDialogData curData, HashSet <ExportDialogData> checkedNodes)
        {
            checkedNodes.Add(curData);
            if (curData.NotPartOfInfinityLoop || curData.Children == null || curData.Children.Count == 0 || ChoiceNodeHasChoiceWithNoChild(curData) || ConditionNodeHasConditionWithNoChild(curData))
            {
                curData.NotPartOfInfinityLoop = true;
                return(true);
            }

            foreach (ExportDialogDataChild curChild in curData.Children)
            {
                if (checkedNodes.Contains(curChild.Child))
                {
                    continue;
                }

                if (CheckIfDialogDataCanReachEndOfDialog(curChild.Child, checkedNodes))
                {
                    // Save node is not part of an infinity loop to save performance by not having to travel the whole tree for every node again
                    curData.NotPartOfInfinityLoop = true;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses a dialog for exporting
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <param name="objectId">Object Id</param>
        /// <param name="dialog">Dialog to parse</param>
        /// <param name="errorCollection">Error Collection to send errors to</param>
        /// <returns>Parsed dialog</returns>
        public async Task <ExportDialogData> GenerateFunctions(string projectId, string objectId, ExportDialogData dialog, ExportPlaceholderErrorCollection errorCollection)
        {
            DialogFunctionGenerationConditionCollection dialogFunctionGenerationConditions = await _dialogFunctionGenerationConditionProvider.GetDialogFunctionGenerationConditions(projectId);

            HashSet <string>         usedDialogSteps   = new HashSet <string>();
            Queue <ExportDialogData> dialogDataToQueue = new Queue <ExportDialogData>();

            dialogDataToQueue.Enqueue(dialog);

            while (dialogDataToQueue.Any())
            {
                ExportDialogData curData = dialogDataToQueue.Dequeue();

                await CheckAndBuildFunctionForDialogStep(curData, dialogFunctionGenerationConditions, projectId, objectId, errorCollection);

                foreach (ExportDialogDataChild curChild in curData.Children)
                {
                    if (!usedDialogSteps.Contains(curChild.Child.Id))
                    {
                        dialogDataToQueue.Enqueue(curChild.Child);
                        usedDialogSteps.Add(curChild.Child.Id);
                    }
                }
            }

            return(dialog);
        }
Ejemplo n.º 5
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.º 6
0
        /// <summary>
        /// Renders a dialog step
        /// </summary>
        /// <param name="code">Code to update</param>
        /// <param name="curStep">Current Step</param>
        /// <param name="nextStep">Next step</param>
        /// <returns>Updated code</returns>
        public string ReplaceBaseStepPlaceholders(string code, ExportDialogData curStep, ExportDialogData nextStep)
        {
            code = ReplaceNodeId(code, curStep);
            code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasChild_Start, Placeholder_HasChild_End, nextStep != null);
            code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasNoChild_Start, Placeholder_HasNoChild_End, nextStep == null);
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, Placeholder_IsChildNodeOfType_Start, Placeholder_IsChildNodeOfType_End, m => {
                return(m.Groups[1].Value.ToLowerInvariant() == GetStepType(nextStep));
            });
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, Placeholder_IsChildNodeNotOfType_Start, Placeholder_IsChildNodeNotOfType_End, m => {
                return(m.Groups[1].Value.ToLowerInvariant() != GetStepType(nextStep));
            });
            code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_ChildNode_HasFunction_Start, Placeholder_ChildNode_HasFunction_End, nextStep != null && !string.IsNullOrEmpty(nextStep.DialogStepFunctionName));
            code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_ChildNode_HasNoFunction_Start, Placeholder_ChildNode_HasNoFunction_End, nextStep == null || string.IsNullOrEmpty(nextStep.DialogStepFunctionName));
            code = ExportUtil.BuildPlaceholderRegex(Placeholder_ChildNodeFunction).Replace(code, m => {
                if (nextStep == null)
                {
                    _errorCollection.AddNodeHasNoChildForFunction();
                    return(string.Empty);
                }

                return(nextStep.DialogStepFunctionName);
            });

            return(code);
        }
        /// <summary>
        /// Builds a parent text preview for the a dialog step
        /// </summary>
        /// <param name="child">Child node</param>
        /// <param name="parent">Parent</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <returns>Parent text preview for the dialog step</returns>
        public async Task <string> BuildParentTextPreview(ExportDialogData child, ExportDialogData parent, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection)
        {
            ConditionNode conditionNode = parent.Condition;

            if (conditionNode == null)
            {
                return(null);
            }

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

            foreach (Condition curCondition in conditionNode.Conditions)
            {
                ExportDialogDataChild childObj = parent.Children.FirstOrDefault(c => c.NodeChildId == curCondition.Id);
                if (childObj == null || childObj.Child != child)
                {
                    continue;
                }

                string conditionText = await _conditionRenderer.RenderCondition(_project, curCondition, _errorCollection, npc, _exportSettings);

                previewForConditions.Add(ExportUtil.BuildTextPreview(conditionText));
            }

            if (parent.Children.Any(c => c.Child == child && c.NodeChildId == ExportConstants.ConditionElseNodeChildId))
            {
                previewForConditions.Add("else");
            }

            return(string.Join(", ", previewForConditions));
        }
        /// <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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Ensures that no infinity loop exists
        /// </summary>
        /// <param name="exportDialog">Export Dialog data</param>
        private void EnsureNoInfinityLoopExists(ExportDialogData exportDialog)
        {
            HashSet <ExportDialogData> usedDialogData = new HashSet <ExportDialogData>();
            Queue <ExportDialogData>   dataToCheck    = new Queue <ExportDialogData>();

            dataToCheck.Enqueue(exportDialog);
            usedDialogData.Add(exportDialog);

            while (dataToCheck.Any())
            {
                ExportDialogData curData = dataToCheck.Dequeue();
                if (!curData.NotPartOfInfinityLoop)
                {
                    HashSet <ExportDialogData> checkedNodes = new HashSet <ExportDialogData>();
                    if (!CheckIfDialogDataCanReachEndOfDialog(curData, checkedNodes))
                    {
                        _errorCollection.AddDialogInfinityLoopError();
                        break;
                    }
                }

                foreach (ExportDialogDataChild curChild in curData.Children)
                {
                    if (!usedDialogData.Contains(curChild.Child))
                    {
                        dataToCheck.Enqueue(curChild.Child);
                        usedDialogData.Add(curChild.Child);
                    }
                }
            }
        }
        /// <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);
            }

            TextNode textNode = GetValidTextNode(data);

            if (textNode == null)
            {
                return(null);
            }

            ExportTemplate template = await _defaultTemplateProvider.GetDefaultTemplateByType(_project.Id, _isPlayerLine?TemplateType.TalePlayerTextLine : TemplateType.TaleNpcTextLine);

            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 = ExportUtil.BuildPlaceholderRegex(Placeholder_TextLine_LangKey).Replace(renderResult.StepCode, m => {
                return(_languageKeyGenerator.GetDialogTextLineKey(npc.Id, npc.Name, _isPlayerLine ? ExportConstants.LanguageKeyTypePlayer : ExportConstants.LanguageKeyTypeNpc, textNode.Id, textNode.Text).Result);
            });

            return(renderResult);
        }
        /// <summary>
        /// Returns the stept type
        /// </summary>
        /// <param name="nextStep">Next Step</param>
        /// <returns>Step Type</returns>
        private string GetStepType(ExportDialogData nextStep)
        {
            if (nextStep == null)
            {
                return(string.Empty);
            }

            return(nextStep.GetNodeType().ToLowerInvariant());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns true if a node is of a certain type
        /// </summary>
        /// <param name="dialogData">Dialog Data</param>
        /// <param name="nodeType">Node Type</param>
        /// <param name="errorCollection">Error Collection to send errors to</param>
        /// <returns>true if node is of searched type</returns>
        private bool IsNodeOfType(ExportDialogData dialogData, string nodeType, ExportPlaceholderErrorCollection errorCollection)
        {
            if (string.IsNullOrEmpty(nodeType))
            {
                return(false);
            }

            return(nodeType.ToLowerInvariant() == GetNodeType(dialogData, errorCollection).ToLowerInvariant());
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns true if an action node is of a certain action type
        /// </summary>
        /// <param name="dialogData">Dialog Data</param>
        /// <param name="actionType">Action Type</param>
        /// <param name="errorCollection">Error Collection to send errors to</param>
        /// <returns>true if node is of searched type</returns>
        private bool IsNodeOfActionType(ExportDialogData dialogData, ActionType actionType, ExportPlaceholderErrorCollection errorCollection)
        {
            int parsedActionType = 0;

            if (dialogData.Action == null || !int.TryParse(dialogData.Action.ActionType, out parsedActionType))
            {
                return(false);
            }

            return((int)actionType == parsedActionType);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Builds the action content
        /// </summary>
        /// <param name="actionNode">Action Node</param>
        /// <param name="data">Dialog data</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <returns>Action content</returns>
        private async Task <string> BuildActionContent(ActionNode actionNode, ExportDialogData data, KortistoNpc npc)
        {
            IActionRenderer actionRenderer = GetActionRenderForNode(actionNode);

            if (actionRenderer == null)
            {
                return(string.Empty);
            }

            return(await actionRenderer.BuildActionElement(actionNode, data, _project, _errorCollection, npc, _exportSettings));
        }
        /// <summary>
        /// Builds the else part
        /// </summary>
        /// <param name="elseTemplate">Else template</param>
        /// <param name="data">Dialog data</param>
        /// <returns>Else part</returns>
        private string BuildElsePart(string elseTemplate, ExportDialogData data)
        {
            ExportDialogDataChild elseChild = data.Children.FirstOrDefault(c => c.NodeChildId == ExportConstants.ConditionElseNodeChildId);

            if (elseChild == null)
            {
                return(string.Empty);
            }

            return(ReplaceBaseStepPlaceholders(elseTemplate, data, elseChild.Child));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Builds a parent text preview for the a dialog step
        /// </summary>
        /// <param name="child">Child node</param>
        /// <param name="parent">Parent</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <returns>Parent text preview for the dialog step</returns>
        public Task <string> BuildParentTextPreview(ExportDialogData child, ExportDialogData parent, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection)
        {
            TextNode textNode = GetValidTextNode(parent);

            if (textNode == null)
            {
                return(Task.FromResult <string>(null));
            }

            return(Task.FromResult(ExportUtil.BuildTextPreview(textNode.Text)));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Returns the valid text node
        /// </summary>
        /// <param name="data">Dialog step data</param>
        /// <returns>Valid text node</returns>
        private TextNode GetValidTextNode(ExportDialogData data)
        {
            TextNode textNode = data.PlayerText;

            if (!_isPlayerLine)
            {
                textNode = data.NpcText;
            }

            return(textNode);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Evaluates a list of conditions
        /// </summary>
        /// <param name="dialogData">Dialog data for the step</param>
        /// <param name="functionGenerationConditions">Function generation conditions</param>
        /// <param name="errorCollection">Error Collection to send errors to</param>
        /// <returns>true if one of the conditions are true, else false</returns>
        private bool EvaluateConditions(ExportDialogData dialogData, List <DialogFunctionGenerationCondition> functionGenerationConditions, ExportPlaceholderErrorCollection errorCollection)
        {
            foreach (DialogFunctionGenerationCondition curCondition in functionGenerationConditions)
            {
                if (EvaluateConditionList(dialogData, DialogFunctionGenerationConditionGroupOperator.And, curCondition.ConditionElements, errorCollection))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Returns the node type of dailog step
        /// </summary>
        /// <param name="dialogData">Dialog data to check</param>
        /// <param name="errorCollection">Error Collection to send errors to</param>
        /// <returns>Node type</returns>
        private string GetNodeType(ExportDialogData dialogData, ExportPlaceholderErrorCollection errorCollection)
        {
            string nodeType = dialogData.GetNodeType();

            if (!string.IsNullOrEmpty(nodeType))
            {
                return(nodeType);
            }

            errorCollection.AddUnknownDialogStepError();
            return("unknown");
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Checks and builds the function for a dialog step
        /// </summary>
        /// <param name="dialogData">Dialog data for the step</param>
        /// <param name="dialogFunctionGenerationConditions">Dialog Function Generation Conditions</param>
        /// <param name="projectId">Project Id</param>
        /// <param name="objectId">Object Id</param>
        /// <param name="errorCollection">Error Collection to send errors to</param>
        private async Task CheckAndBuildFunctionForDialogStep(ExportDialogData dialogData, DialogFunctionGenerationConditionCollection dialogFunctionGenerationConditions, string projectId, string objectId, ExportPlaceholderErrorCollection errorCollection)
        {
            if (EvaluateConditions(dialogData, dialogFunctionGenerationConditions.PreventGenerationRules, errorCollection))
            {
                return;
            }

            if (EvaluateConditions(dialogData, dialogFunctionGenerationConditions.GenerateRules, errorCollection))
            {
                dialogData.DialogStepFunctionName = await _functionNameGenerator.GetNewDialogStepFunction(GetNodeType(dialogData, errorCollection), projectId, objectId, dialogData.Id);
            }
        }
        /// <summary>
        /// Builds a condition
        /// </summary>
        /// <param name="conditionTemplate">Condition Template</param>
        /// <param name="data">Export dialog data</param>
        /// <param name="conditionObj">Condition object</param>
        /// <param name="conditionNode">Condition node</param>
        /// <param name="condition">Export dialog data for the condition</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <param name="conditionIndex">Index of the condition</param>
        /// <returns>Conditions as string</returns>
        private string BuildSingleCondition(string conditionTemplate, ExportDialogData data, Condition conditionObj, ConditionNode conditionNode, ExportDialogDataChild condition, KortistoNpc npc, int conditionIndex)
        {
            string conditionContent = ReplaceBaseStepPlaceholders(conditionTemplate, data, condition != null ? condition.Child : null);

            conditionContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Condition_Id).Replace(conditionContent, conditionObj.Id.ToString());
            conditionContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Condition_Index).Replace(conditionContent, conditionIndex.ToString());
            conditionContent = ExportUtil.RenderPlaceholderIfTrue(conditionContent, Placeholder_Condition_IsFirst_Start, Placeholder_Condition_IsFirst_End, conditionIndex == 0);
            conditionContent = ExportUtil.RenderPlaceholderIfTrue(conditionContent, Placeholder_Condition_IsNotFirst_Start, Placeholder_Condition_IsNotFirst_End, conditionIndex != 0);
            conditionContent = ExportUtil.BuildPlaceholderRegex(Placeholder_Condition).Replace(conditionContent, m => {
                return(BuildCondition(conditionObj, npc));
            });

            return(conditionContent);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Renders a dialog step
        /// </summary>
        /// <param name="exportDialog">Cur Data to render</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <returns>Result of the rendering of the step</returns>
        private async Task <ExportDialogStepRenderResult> RenderDialogStep(ExportDialogData exportDialog, KortistoNpc npc)
        {
            foreach (IExportDialogStepRenderer curRenderer in _stepRenderers)
            {
                ExportDialogStepRenderResult result = await curRenderer.RenderDialogStep(exportDialog, npc);

                if (result != null)
                {
                    return(result);
                }
            }

            _errorCollection.AddUnknownDialogStepError();
            return(null);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Checks if a choice node has a choice with no child
        /// </summary>
        /// <param name="curData">Cur Data to for choice node</param>
        /// <returns>true if the choice node has a choice with no child</returns>
        private bool ChoiceNodeHasChoiceWithNoChild(ExportDialogData curData)
        {
            if (curData.Choice == null || curData.Choice.Choices == null)
            {
                return(false);
            }

            foreach (TaleChoice curChoice in curData.Choice.Choices)
            {
                if (!curData.Children.Any(f => f.NodeChildId == curChoice.Id))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Extracts the root nodes from a list
        /// </summary>
        /// <param name="nodeList">Node List</param>
        /// <param name="links">Links</param>
        /// <param name="assignExportProperty">Action to assign the nodes to the export dialog property</param>
        /// <typeparam name="T">Type of the node</typeparam>
        /// <returns>List of root nodes</returns>
        private List <ExportDialogData> GetRootNodesFromList <T>(List <T> nodeList, List <NodeLink> links, Action <ExportDialogData, T> assignExportProperty) where T : BaseNode
        {
            if (nodeList == null || links == null)
            {
                return(new List <ExportDialogData>());
            }

            List <T> rootNodes = nodeList.Where(n => !links.Any(l => l.TargetNodeId == n.Id)).ToList();

            return(rootNodes.Select(n => {
                ExportDialogData dialogData = GetNewDialogData();
                dialogData.Id = n.Id;
                assignExportProperty(dialogData, n);
                return dialogData;
            }).ToList());
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Parses a dialog for exporting
        /// </summary>
        /// <param name="dialog">Dialog to parse</param>
        /// <returns>Parsed dialog</returns>
        public ExportDialogData ParseDialog(TaleDialog dialog)
        {
            _currentNodeIndex = 0;
            ExportDialogData exportDialog = SearchDialogRootNode(dialog);

            if (exportDialog == null)
            {
                return(null);
            }

            IterateDialogTree(exportDialog, dialog);

            EnsureNoInfinityLoopExists(exportDialog);

            return(exportDialog);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Checks if a condition node has a condition with no child
        /// </summary>
        /// <param name="curData">Cur Data to for condition node</param>
        /// <returns>true if the condition node has a condition with no child</returns>
        private bool ConditionNodeHasConditionWithNoChild(ExportDialogData curData)
        {
            if (curData.Condition == null || curData.Condition.Conditions == null)
            {
                return(false);
            }

            foreach (Condition curCondition in curData.Condition.Conditions)
            {
                if (!curData.Children.Any(f => f.NodeChildId == curCondition.Id))
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Builds the list of choices
        /// </summary>
        /// <param name="choiceTemplate">Choice Template</param>
        /// <param name="data">Export dialog data</param>
        /// <param name="choiceNode">Choice node</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <returns>Choices as string</returns>
        private string BuildChoices(string choiceTemplate, ExportDialogData data, TaleChoiceNode choiceNode, KortistoNpc npc)
        {
            if (choiceNode.Choices == null)
            {
                return(string.Empty);
            }

            string choicesResult = string.Empty;

            for (int curChoice = 0; curChoice < choiceNode.Choices.Count; ++curChoice)
            {
                choicesResult += BuildSingleChoice(choiceTemplate, data, choiceNode.Choices[curChoice], choiceNode, npc, curChoice);
            }

            return(choicesResult);
        }
Ejemplo n.º 28
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.º 29
0
        /// <summary>
        /// Evaluates a list of condition elements
        /// </summary>
        /// <param name="dialogData">Dialog data for the step</param>
        /// <param name="groupOperator">Group operator</param>
        /// <param name="conditionElements">Condition Elements</param>
        /// <param name="errorCollection">Error Collection to send errors to</param>
        /// <returns>true if the condition list evaluates to true, else false</returns>
        private bool EvaluateConditionList(ExportDialogData dialogData, DialogFunctionGenerationConditionGroupOperator groupOperator, List <DialogFunctionGenerationConditionElement> conditionElements, ExportPlaceholderErrorCollection errorCollection)
        {
            foreach (DialogFunctionGenerationConditionElement curElement in conditionElements)
            {
                bool isElementTrue = EvaluateConditionElement(dialogData, curElement, errorCollection);
                if (!isElementTrue && groupOperator == DialogFunctionGenerationConditionGroupOperator.And)
                {
                    return(false);
                }
                else if (isElementTrue && groupOperator == DialogFunctionGenerationConditionGroupOperator.Or)
                {
                    return(true);
                }
            }

            return(groupOperator == DialogFunctionGenerationConditionGroupOperator.And);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Builds a parent text preview for the a dialog step
        /// </summary>
        /// <param name="child">Child node</param>
        /// <param name="parent">Parent</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <returns>Parent text preview for the dialog step</returns>
        public async Task <string> BuildParentTextPreview(ExportDialogData child, ExportDialogData parent, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection)
        {
            ActionNode actionNode = parent.Action;

            if (actionNode == null)
            {
                return(null);
            }

            IActionRenderer actionRenderer = GetActionRenderForNode(actionNode);

            if (actionRenderer == null)
            {
                return(string.Empty);
            }

            return(await actionRenderer.BuildPreviewText(actionNode, npc, errorCollection));
        }