Пример #1
0
        /// <summary>
        /// Fills the dialog placeholders
        /// </summary>
        /// <param name="code">Code</param>
        /// <param name="npc">Npc</param>
        /// <returns>Filled code</returns>
        private async Task <string> FillDialogPlaceholders(string code, KortistoNpc npc)
        {
            GoNorthProject project = await _cachedDbAccess.GetDefaultProject();

            TaleDialog dialog = await _taleDbAccess.GetDialogByRelatedObjectId(npc.Id);

            try
            {
                _errorCollection.CurrentErrorContext = _localizer["DialogErrorContext"].Value;
                _dialogParser.SetErrorCollection(_errorCollection);
                _dialogRenderer.SetErrorCollection(_errorCollection);
                ExportDialogData exportDialog   = null;
                bool             hasValidDialog = HasValidDialog(dialog);
                if (hasValidDialog)
                {
                    exportDialog = _dialogParser.ParseDialog(dialog);
                    if (exportDialog == null)
                    {
                        return(string.Empty);
                    }
                    exportDialog = await _dialogFunctionGenerator.GenerateFunctions(project.Id, npc.Id, exportDialog, _errorCollection);
                }

                code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasDialog_Start, Placeholder_HasDialog_End, hasValidDialog);

                code = await RenderDialog(project, code, exportDialog, dialog, npc);
            }
            finally
            {
                _errorCollection.CurrentErrorContext = "";
            }

            return(code);
        }
Пример #2
0
        /// <summary>
        /// Parses a dialog
        /// </summary>
        /// <param name="inputNpc">Input npc</param>
        /// <param name="project">Project</param>
        /// <param name="dialog">Dialog</param>
        /// <returns>Export dialog data</returns>
        private async Task <ExportDialogData> ParseDialog(KortistoNpc inputNpc, GoNorthProject project, TaleDialog dialog)
        {
            ExportDialogData parsedDialog = null;
            IStringLocalizer localizer    = _localizerFactory.Create(typeof(DialogValueCollector));

            try
            {
                _errorCollection.CurrentErrorContext = localizer["DialogErrorContext"].Value;
                _dialogParser.SetErrorCollection(_errorCollection);
                _dialogRenderer.SetErrorCollection(_errorCollection);
                bool hasValidDialog = SharedDialogExportUtil.HasValidDialog(dialog);
                if (hasValidDialog)
                {
                    parsedDialog = _dialogParser.ParseDialog(dialog);
                    if (parsedDialog != null)
                    {
                        parsedDialog = await _dialogFunctionGenerator.GenerateFunctions(project.Id, inputNpc.Id, parsedDialog, _errorCollection);
                    }
                }
            }
            finally
            {
                _errorCollection.CurrentErrorContext = "";
            }

            return(parsedDialog);
        }