예제 #1
0
        /// <summary>
        /// Renders a list of daily routine functions
        /// </summary>
        /// <param name="dailyRoutineEvents">Daily routine events</param>
        /// <param name="flexFieldObject">Npc to which the events belong</param>
        /// <returns>List of daily routine functions</returns>
        public async Task <List <DailyRoutineFunction> > RenderDailyRoutineFunctions(List <KortistoNpcDailyRoutineEvent> dailyRoutineEvents, FlexFieldObject flexFieldObject)
        {
            if (dailyRoutineEvents == null || !dailyRoutineEvents.Any())
            {
                return(new List <DailyRoutineFunction>());
            }

            _nodeGraphParser.SetErrorCollection(_errorCollection);

            _curProject = await _cachedDbAccess.GetUserProject();

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

            SetupStepRenderes();

            List <DailyRoutineFunction> functions = new List <DailyRoutineFunction>();

            foreach (KortistoNpcDailyRoutineEvent curEvent in dailyRoutineEvents)
            {
                if (curEvent.ScriptType == ExportConstants.ScriptType_None)
                {
                    continue;
                }

                DailyRoutineFunction function = new DailyRoutineFunction();
                functions.Add(function);

                function.FunctionName = await _dailyRoutineFunctionNameGenerator.GetNewDailyRoutineStepFunction(_curProject.Id, flexFieldObject.Id, curEvent.EventId);

                function.ParentPreviewText = "";
                if (curEvent.ScriptType == ExportConstants.ScriptType_Code)
                {
                    function.Code = curEvent.ScriptCode;
                }
                else
                {
                    await RenderDailyRoutineEventNodeGraph(functions, curEvent.ScriptNodeGraph, flexFieldObject, function);
                }
            }

            return(functions);
        }
        /// <summary>
        /// Renders a list of state functions
        /// </summary>
        /// <param name="state">State to render</param>
        /// <param name="flexFieldObject">Npc to which the events belong</param>
        /// <returns>List of state functions</returns>
        public async Task <List <StateFunction> > RenderStateFunctions(StateMachineState state, FlexFieldObject flexFieldObject)
        {
            if (state == null)
            {
                return(new List <StateFunction>());
            }

            _nodeGraphParser.SetErrorCollection(_errorCollection);

            _curProject = await _cachedDbAccess.GetUserProject();

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

            SetupStepRenderes();

            List <StateFunction> functions = new List <StateFunction>();

            if (state.ScriptType == ExportConstants.ScriptType_None)
            {
                return(functions);
            }

            StateFunction function = new StateFunction();

            functions.Add(function);

            function.FunctionName = await _stateMachineFunctionNameGenerator.GetNewStateMachineStepFunction(_curProject.Id, flexFieldObject.Id, state.Id);

            function.ParentPreviewText = "";
            if (state.ScriptType == ExportConstants.ScriptType_Code)
            {
                function.Code = state.ScriptCode;
            }
            else
            {
                await RenderStateMachineEventNodeGraph(functions, state.ScriptNodeGraph, flexFieldObject, function);
            }

            return(functions);
        }
        /// <summary>
        /// Renders a daily routine event node graph
        /// </summary>
        /// <param name="snippetName">Snippet name</param>
        /// <param name="scriptNodeGraph">Node graph to render</param>
        /// <param name="flexFieldObject">Npc to which the events belong</param>
        /// <returns>Task</returns>
        private async Task <List <ExportSnippetFunction> > RenderExportSnippetNodeGraph(string snippetName, NodeGraphSnippet scriptNodeGraph, FlexFieldObject flexFieldObject)
        {
            _nodeGraphParser.SetErrorCollection(_errorCollection);

            _curProject = await _cachedDbAccess.GetUserProject();

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

            SetupStepRenderes();

            ExportDialogData exportData = _nodeGraphParser.ParseNodeGraph(scriptNodeGraph);

            if (exportData == null)
            {
                return(new List <ExportSnippetFunction>());
            }

            exportData = await _nodeGraphFunctionGenerator.GenerateFunctions(flexFieldObject.ProjectId, flexFieldObject.Id, exportData, _errorCollection);

            ExportDialogFunction rootFunction = new ExportDialogFunction(exportData);

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

            List <ExportSnippetFunction> snippetFunctions    = new List <ExportSnippetFunction>();
            ExportSnippetFunction        snippetRootFunction = new ExportSnippetFunction();

            snippetRootFunction.FunctionName = snippetName;
            snippetRootFunction.Code         = await RenderDialogStepList(rootFunction.FunctionSteps, flexFieldObject);

            snippetRootFunction.ParentPreviewText = "";
            snippetFunctions.Add(snippetRootFunction);

            foreach (ExportDialogFunction curAdditionalFunction in additionalFunctions)
            {
                ExportSnippetFunction additionalFunction = new ExportSnippetFunction();
                additionalFunction.FunctionName      = curAdditionalFunction.RootNode.DialogStepFunctionName;
                additionalFunction.ParentPreviewText = await BuildFunctionParentPreview(curAdditionalFunction, flexFieldObject);

                string functionContent = await RenderDialogStepList(curAdditionalFunction.FunctionSteps, flexFieldObject);

                additionalFunction.Code = functionContent;

                snippetFunctions.Add(additionalFunction);
            }

            return(snippetFunctions);
        }
예제 #4
0
        /// <summary>
        /// Renders a node graph
        /// </summary>
        /// <param name="exportNodeGraph">Node graph snippet to render</param>
        /// <param name="npc">Npc to which the snippet belongs</param>
        /// <returns>Result of rendering the node graph</returns>
        public async Task <ExportNodeGraphRenderResult> RenderNodeGraph(NodeGraphSnippet exportNodeGraph, KortistoNpc npc)
        {
            _nodeGraphParser.SetErrorCollection(_errorCollection);
            ExportDialogData exportData = _nodeGraphParser.ParseNodeGraph(exportNodeGraph);

            ExportNodeGraphRenderResult renderResult;

            if (exportData != null)
            {
                exportData = await _nodeGraphFunctionGenerator.GenerateFunctions(npc.ProjectId, npc.Id, exportData, _errorCollection);

                _nodeGraphRenderer.SetErrorCollection(_errorCollection);
                renderResult = await _nodeGraphRenderer.RenderNodeGraph(exportData, npc);
            }
            else
            {
                renderResult = new ExportNodeGraphRenderResult();
                renderResult.StartStepCode           = string.Empty;
                renderResult.AdditionalFunctionsCode = string.Empty;
            }

            return(renderResult);
        }