Ejemplo n.º 1
0
        /// <summary>
        /// Merges an error list into this error list
        /// </summary>
        /// <param name="errors">Error list</param>
        public void Merge(ExportPlaceholderErrorCollection errors)
        {
            if (errors == null)
            {
                return;
            }

            foreach (ExportPlaceholderError curError in errors._errorMessages)
            {
                AddErrorMessage(curError.ErrorType, curError.Message);
            }
        }
        /// <summary>
        /// Fills the placeholders of a code
        /// </summary>
        /// <param name="templateType">Template Type</param>
        /// <param name="code">Code to fill</param>
        /// <param name="data">Export Data</param>
        /// <returns>Filled Code</returns>
        public async Task <ExportPlaceholderFillResult> FillPlaceholders(TemplateType templateType, string code, ExportObjectData data)
        {
            ExportPlaceholderErrorCollection errorCollection = new ExportPlaceholderErrorCollection(_localizerFactory);

            foreach (IExportTemplateTopicPlaceholderResolver curResolver in _exportTemplatePlaceholderResolvers)
            {
                if (curResolver.IsValidForTemplateType(templateType))
                {
                    curResolver.SetErrorMessageCollection(errorCollection);
                    code = await curResolver.FillPlaceholders(code, data);
                }
            }

            ExportPlaceholderFillResult result = new ExportPlaceholderFillResult();

            result.Code   = code;
            result.Errors = errorCollection;
            return(result);
        }
 /// <summary>
 /// Sets the error message collection
 /// </summary>
 /// <param name="errorCollection">Error Collection</param>
 public void SetErrorMessageCollection(ExportPlaceholderErrorCollection errorCollection)
 {
     _errorCollection = errorCollection;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="localizer">Localizer</param>
 public BaseExportPlaceholderResolver(IStringLocalizer localizer)
 {
     _localizer       = localizer;
     _errorCollection = null;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Renders a node graph system
        /// </summary>
        /// <param name="dailyRoutineEvent">Daily routine event</param>
        /// <param name="npc">Npc</param>
        /// <param name="errorCollection">Error collection</param>
        /// <returns>Node graph render result</returns>
        private ExportNodeGraphRenderResult RenderNodeGraph(KortistoNpcDailyRoutineEvent dailyRoutineEvent, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection)
        {
            if (dailyRoutineEvent == null || dailyRoutineEvent.ScriptNodeGraph == null)
            {
                return(new ExportNodeGraphRenderResult());
            }

            if (_renderedEvents.ContainsKey(dailyRoutineEvent.EventId))
            {
                return(_renderedEvents[dailyRoutineEvent.EventId]);
            }

            _nodeGraphExporter.SetErrorCollection(errorCollection);
            _nodeGraphExporter.SetNodeGraphFunctionGenerator(_dailyRoutineNodeGraphFunctionGenerator);
            _nodeGraphExporter.SetNodeGraphRenderer(_dailyRoutineNodeGraphRenderer);
            ExportNodeGraphRenderResult renderResult = _nodeGraphExporter.RenderNodeGraph(dailyRoutineEvent.ScriptNodeGraph, npc).Result;

            _renderedEvents.Add(dailyRoutineEvent.EventId, renderResult);
            return(renderResult);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Resolved the placeholders for a single daily routine event
        /// </summary>
        /// <param name="code">Code to resolve the placeholders in</param>
        /// <param name="npc">Npc to which the event belongs</param>
        /// <param name="dailyRoutineEvent">Daily routine to use for resolving the placeholders</param>
        /// <param name="errorCollection">Error collection</param>
        /// <returns>Code with resolved placeholders</returns>
        public string ResolveDailyRoutineEventContentPlaceholders(string code, KortistoNpc npc, KortistoNpcDailyRoutineEvent dailyRoutineEvent, ExportPlaceholderErrorCollection errorCollection)
        {
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, Placeholder_HasAdditionalScriptFunctions_Start, Placeholder_HasAdditionalScriptFunctions_End, m => {
                if (dailyRoutineEvent.ScriptType == ScriptType_NodeGraph)
                {
                    return(!string.IsNullOrEmpty(this.RenderNodeGraph(dailyRoutineEvent, npc, errorCollection).AdditionalFunctionsCode));
                }

                return(false);
            });

            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, Placeholder_HasNoAdditionalScriptFunctions_Start, Placeholder_HasNoAdditionalScriptFunctions_End, m => {
                if (dailyRoutineEvent.ScriptType == ScriptType_NodeGraph)
                {
                    return(string.IsNullOrEmpty(this.RenderNodeGraph(dailyRoutineEvent, npc, errorCollection).AdditionalFunctionsCode));
                }

                return(true);
            });

            code = ExportUtil.BuildPlaceholderRegex(Placeholder_ScriptContent, ExportConstants.ListIndentPrefix).Replace(code, m => {
                if (dailyRoutineEvent.ScriptType == ScriptType_NodeGraph)
                {
                    return(ExportUtil.IndentListTemplate(this.RenderNodeGraph(dailyRoutineEvent, npc, errorCollection).StartStepCode, m.Groups[1].Value));
                }
                else if (dailyRoutineEvent.ScriptType == ScriptType_Code)
                {
                    return(ExportUtil.IndentListTemplate(dailyRoutineEvent.ScriptCode != null ? dailyRoutineEvent.ScriptCode : string.Empty, m.Groups[1].Value));
                }

                return(string.Empty);
            });

            code = ExportUtil.BuildPlaceholderRegex(Placeholder_AdditionalScriptFunctions, ExportConstants.ListIndentPrefix).Replace(code, m => {
                if (dailyRoutineEvent.ScriptType == ScriptType_NodeGraph)
                {
                    return(ExportUtil.IndentListTemplate(this.RenderNodeGraph(dailyRoutineEvent, npc, errorCollection).AdditionalFunctionsCode, m.Groups[1].Value));
                }

                return(string.Empty);
            });

            code = ExportUtil.BuildPlaceholderRegex(Placeholder_Function_ParentPreview).Replace(code, "None");

            return(code);
        }