Ejemplo n.º 1
0
        /// <summary>
        /// Builds the template context for exporting
        /// </summary>
        /// <param name="referenceNodeData">Reference node data</param>
        /// <returns>Template context</returns>
        private TemplateContext BuildTemplateContext(ScribanReferenceData referenceNodeData)
        {
            ScriptObject exportObject = new ScriptObject();

            exportObject.Add(ReferenceKey, referenceNodeData);
            exportObject.Add(ExportConstants.ScribanLanguageKeyName, _languageKeyGenerator);
            TemplateContext context = new TemplateContext();

            context.TemplateLoader = new ScribanIncludeTemplateLoader(_exportCachedDbAccess, _errorCollection);
            context.PushGlobal(exportObject);
            return(context);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders a dialog step
        /// </summary>
        /// <param name="template">Export template</param>
        /// <param name="data">Dialog Step Data</param>
        /// <param name="project">Project for which the epxort is running</param>
        /// <param name="referenceNodeData">Reference node 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(ExportTemplate template, ExportDialogData data, GoNorthProject project, ReferenceNodeData referenceNodeData, FlexFieldObject flexFieldObject)
        {
            ExportDialogStepRenderResult renderResult = new ExportDialogStepRenderResult();

            Template parsedTemplate = ScribanParsingUtil.ParseTemplate(template.Code, _errorCollection);

            if (parsedTemplate == null)
            {
                return(renderResult);
            }

            MiscProjectConfig projectConfig = await _exportCachedDbAccess.GetMiscProjectConfig();

            _languageKeyGenerator.SetErrorCollection(_errorCollection);

            ScribanReferenceData referenceData = BuildDialogRenderObject <ScribanReferenceData>(data, data.Children.FirstOrDefault() != null ? data.Children.FirstOrDefault().Child : null, flexFieldObject);

            referenceData.ReferenceText = referenceNodeData.ReferenceText != null ? referenceNodeData.ReferenceText : string.Empty;
            referenceData.ObjectType    = referenceNodeData.ObjectType;
            if (referenceNodeData.Npc != null)
            {
                referenceData.Npc          = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportNpc>(null, null, referenceNodeData.Npc, _exportSettings, _errorCollection);
                referenceData.Npc.IsPlayer = referenceNodeData.Npc.IsPlayerNpc;
            }
            else
            {
                referenceData.Npc = null;
            }
            referenceData.Item = referenceNodeData.Item != null?FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportItem>(null, null, referenceNodeData.Item, _exportSettings, _errorCollection) : null;

            referenceData.Skill = referenceNodeData.Skill != null?FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportSkill>(null, null, referenceNodeData.Skill, _exportSettings, _errorCollection) : null;

            referenceData.Quest = referenceNodeData.Quest != null?FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportQuest>(null, null, referenceNodeData.Quest, _exportSettings, _errorCollection) : null;

            referenceData.WikiPage          = referenceNodeData.WikiPage != null ? new ScribanExportWikiPage(referenceNodeData.WikiPage) : null;
            referenceData.DailyRoutineEvent = referenceNodeData.DailyRoutineEvent != null ? await ScribanDailyRoutineEventUtil.ConvertDailyRoutineEvent(_dailyRoutineFunctionNameGenerator, referenceNodeData.Npc, referenceNodeData.DailyRoutineEvent, project, projectConfig, _exportSettings) : null;

            referenceData.Marker = referenceNodeData.Marker != null ? new ScribanExportMapMarker(referenceNodeData.Marker) : null;

            TemplateContext context = BuildTemplateContext(referenceData);

            renderResult.StepCode = await parsedTemplate.RenderAsync(context);

            return(renderResult);
        }