/// <summary> /// Builds an action from parsed data /// </summary> /// <param name="template">Template to export</param> /// <param name="parsedData">Parsed data</param> /// <param name="data">Dialog data</param> /// <param name="nextStep">Next step in the dialog</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Action string</returns> public override async Task <string> BuildActionFromParsedData(ExportTemplate template, AddQuestTextData parsedData, ExportDialogData data, ExportDialogData nextStep, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { IFlexFieldExportable valueObject = await GetQuest(parsedData, errorCollection); if (valueObject == null) { return(string.Empty); } return(await FillPlaceholders(template, errorCollection, parsedData, valueObject, flexFieldObject, data, nextStep, exportSettings, stepRenderer)); }
/// <summary> /// Builds a preview text from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="errorCollection">Error Collection</param> /// <param name="child">Child node</param> /// <param name="parent">Parent</param> /// <returns>Preview text</returns> public override async Task <string> BuildPreviewTextFromParsedData(UseItemActionRenderer.UseItemActionData parsedData, FlexFieldObject flexFieldObject, ExportPlaceholderErrorCollection errorCollection, ExportDialogData child, ExportDialogData parent) { IFlexFieldExportable valueItem = await GetItem(parsedData, errorCollection); IFlexFieldExportable valueNpc = await GetNpc(flexFieldObject, parsedData, errorCollection); if (valueItem == null || valueNpc == null) { return(string.Empty); } return(valueNpc.Name + " uses " + valueItem.Name); }
/// <summary> /// Returns a sort order for language keys.null This ranks name keys and field keys higher than dialog keys /// </summary> /// <param name="langKey">Language key</param> /// <param name="flexFieldExportable">Flex field exportable</param> /// <returns>Sort order</returns> private int GetLanguageKeySortOrder(LanguageKey langKey, IFlexFieldExportable flexFieldExportable) { if (langKey.LangKeyRef == "Name") { return(0); } if (flexFieldExportable.Fields != null && flexFieldExportable.Fields.Any(f => f.Id == langKey.LangKeyRef)) { return(1); } return(2); }
/// <summary> /// Fills the language key Placeholders /// </summary> /// <param name="code">Code to fill</param> /// <param name="flexFieldObject">Flex Field Object</param> /// <returns>Filled Code</returns> private async Task <string> FillLanguageKeyPlaceholders(string code, IFlexFieldExportable flexFieldObject) { GoNorthProject project = await _cachedDbAccess.GetDefaultProject(); List <LanguageKey> languageKeys = await _languageKeyDbAccess.GetLanguageKeysByGroupId(project.Id, flexFieldObject.Id); ExportSettings exportSettings = await _cachedDbAccess.GetExportSettings(project.Id); code = ExportUtil.BuildPlaceholderRegex(Placeholder_ObjectName).Replace(code, flexFieldObject.Name); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_LanguageKeys_Start, Placeholder_LanguageKeys_End).Replace(code, m => { return(BuildLanguageKeyList(m.Groups[1].Value, languageKeys, exportSettings)); }); return(code); }
/// <summary> /// Builds a preview text from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="errorCollection">Error Collection</param> /// <returns>Preview text</returns> public override async Task <string> BuildPreviewTextFromParsedData(LearnForgetSkillActionRenderer.LearnForgetSkillActionData parsedData, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection) { IFlexFieldExportable valueObject = await GetSkill(parsedData, errorCollection); if (valueObject == null) { return(string.Empty); } string label = _isPlayer ? "Npc" : "Player"; label += _isLearn ? "Learn" : "Forget"; return(label + " (" + valueObject.Name + ")"); }
/// <summary> /// Builds an action from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="data">Dialog data</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <returns>Action string</returns> public override async Task <string> BuildActionFromParsedData(ValueActionRenderBase.ValueFieldActionData parsedData, ExportDialogData data, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, KortistoNpc npc, ExportSettings exportSettings) { ExportTemplate actionTemplate = await GetExportTemplate(project); IFlexFieldExportable valueObject = await GetValueObject(parsedData, npc, errorCollection); if (valueObject == null) { return(string.Empty); } FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string actionCode = actionTemplate.Code; actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueName).Replace(actionCode, m => { return(DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection)); }); actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Operator).Replace(actionCode, GetOperatorFromTemplate(project, parsedData.Operator, errorCollection)); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsSetTo_Start, Placeholder_OperatorIsSetTo_End, parsedData.Operator == "="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotSetTo_Start, Placeholder_OperatorIsNotSetTo_End, parsedData.Operator != "="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_ValueIsString_Start, Placeholder_ValueIsString_End, exportField.FieldType != ExportConstants.FlexFieldType_Number); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_ValueIsNumber_Start, Placeholder_ValueIsNumber_End, exportField.FieldType == ExportConstants.FlexFieldType_Number); actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueChange).Replace(actionCode, m => { if (exportField.FieldType != ExportConstants.FlexFieldType_Number) { return(ExportUtil.EscapeCharacters(parsedData.ValueChange, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter)); } return(parsedData.ValueChange); }); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, GetFlexFieldExportObjectType()); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); actionCode = _flexFieldPlaceholderResolver.FillPlaceholders(actionCode, flexFieldExportData).Result; return(actionCode); }
/// <summary> /// Builds a condition element from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <returns>Condition string</returns> public override string BuildConditionElementFromParsedData(ValueConditionResolverBase.ValueFieldConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, KortistoNpc npc, ExportSettings exportSettings) { ExportTemplate conditionTemplate = GetExportTemplate(project); IFlexFieldExportable valueObject = GetValueObject(parsedData, npc, errorCollection); if (valueObject == null) { return(string.Empty); } FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string conditionCode = conditionTemplate.Code; conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_IsOperatorPrimitiveStart, Placeholder_IsOperatorPrimitiveEnd, IsOperatorPrimitiveOperator(parsedData.Operator)); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_IsOperatorNonPrimitiveStart, Placeholder_IsOperatorNonPrimitiveEnd, !IsOperatorPrimitiveOperator(parsedData.Operator)); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueName).Replace(conditionCode, m => { return(DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection)); }); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Operator).Replace(conditionCode, GetOperatorFromTemplate(project, parsedData.Operator, errorCollection)); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_ValueIsString_Start, Placeholder_ValueIsString_End, exportField.FieldType != ExportConstants.FlexFieldType_Number); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_ValueIsNumber_Start, Placeholder_ValueIsNumber_End, exportField.FieldType == ExportConstants.FlexFieldType_Number); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_CompareValue).Replace(conditionCode, m => { if (exportField.FieldType != ExportConstants.FlexFieldType_Number) { return(ExportUtil.EscapeCharacters(parsedData.CompareValue, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter)); } return(parsedData.CompareValue); }); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, GetFlexFieldExportObjectType()); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); conditionCode = _flexFieldPlaceholderResolver.FillPlaceholders(conditionCode, flexFieldExportData).Result; return(conditionCode); }
/// <summary> /// Fills the placeholders of a code /// </summary> /// <param name="code">Code to fill</param> /// <param name="data">Export Data</param> /// <returns>Filled Code</returns> public Task <string> FillPlaceholders(string code, ExportObjectData data) { // Check Data if (!data.ExportData.ContainsKey(ExportConstants.ExportDataObject)) { return(Task.FromResult(code)); } IFlexFieldExportable flexFieldObject = data.ExportData[ExportConstants.ExportDataObject] as IFlexFieldExportable; if (flexFieldObject == null) { return(Task.FromResult(code)); } // Replace Flex Field Placeholders return(FillFlexFieldPlaceholders(code, flexFieldObject, data.ExportData[ExportConstants.ExportDataObjectType].ToString(), data)); }
/// <summary> /// Builds an action from parsed data /// </summary> /// <param name="template">Template to export</param> /// <param name="parsedData">Parsed data</param> /// <param name="data">Dialog data</param> /// <param name="nextStep">Next step in the dialog</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Action string</returns> public override async Task <string> BuildActionFromParsedData(ExportTemplate template, InventoryChooseNpcActionData parsedData, ExportDialogData data, ExportDialogData nextStep, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { IFlexFieldExportable itemObject = await GetItem(parsedData, errorCollection); if (itemObject == null) { return(string.Empty); } IFlexFieldExportable npcObject = await GetNpc(parsedData, errorCollection); if (npcObject == null) { return(string.Empty); } return(await FillPlaceholders(template, errorCollection, parsedData, itemObject, npcObject, flexFieldObject, data, nextStep, exportSettings, stepRenderer)); }
/// <summary> /// Builds a preview text from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="errorCollection">Error Collection</param> /// <param name="child">Child node</param> /// <param name="parent">Parent</param> /// <returns>Preview text</returns> public override async Task <string> BuildPreviewTextFromParsedData(SpawnObjectAtMarkerRendererBase.SpawnObjectActionData parsedData, FlexFieldObject flexFieldObject, ExportPlaceholderErrorCollection errorCollection, ExportDialogData child, ExportDialogData parent) { IFlexFieldExportable valueObject = await GetValueObject(parsedData, flexFieldObject, errorCollection); if (valueObject == null) { return(string.Empty); } KartaMapNamedMarkerQueryResult markerResult = await GetMarker(parsedData); if (markerResult == null) { return(string.Empty); } return(GetPreviewPrefixText(valueObject.Name, markerResult.MarkerName)); }
/// <summary> /// Collects the values for an export /// </summary> /// <param name="templateType">Template type</param> /// <param name="parsedTemplate">Parsed scriban template</param> /// <param name="scriptObject">Scriban script object to fill</param> /// <param name="data">Export Data</param> /// <returns>Task</returns> public override async Task CollectValues(TemplateType templateType, Template parsedTemplate, ScriptObject scriptObject, ExportObjectData data) { IFlexFieldExportable exportable = data.ExportData[ExportConstants.ExportDataObject] as IFlexFieldExportable; if (exportable == null) { return; } _languageKeyGenerator.SetErrorCollection(_errorCollection); GoNorthProject project = await _cachedDbAccess.GetUserProject(); ExportSettings exportSettings = await _cachedDbAccess.GetExportSettings(project.Id); scriptObject.AddOrUpdate(ObjectKey, FlexFieldValueCollectorUtil.ExtractScribanFields(exportable, exportSettings, _errorCollection)); scriptObject.AddOrUpdate(ExportConstants.ScribanLanguageKeyName, _languageKeyGenerator); }
/// <summary> /// Fills the language key Placeholders /// </summary> /// <param name="code">Code to fill</param> /// <param name="flexFieldObject">Flex Field Object</param> /// <param name="referencedLanguageKeys">Referenced language keys</param> /// <returns>Filled Code</returns> private async Task <string> FillLanguageKeyPlaceholders(string code, IFlexFieldExportable flexFieldObject, List <LanguageKey> referencedLanguageKeys) { GoNorthProject project = await _cachedDbAccess.GetUserProject(); List <LanguageKey> languageKeys = await _languageKeyDbAccess.GetLanguageKeysByGroupId(project.Id, flexFieldObject.Id); ExportSettings exportSettings = await _cachedDbAccess.GetExportSettings(project.Id); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_Has_Referenced_LanguageKeys_Start, Placeholder_Has_Referenced_LanguageKeys_End, referencedLanguageKeys != null && referencedLanguageKeys.Any()); code = ExportUtil.BuildPlaceholderRegex(Placeholder_ObjectName).Replace(code, flexFieldObject.Name); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_LanguageKeys_Start, Placeholder_LanguageKeys_End).Replace(code, m => { return(BuildLanguageKeyList(m.Groups[1].Value, languageKeys, exportSettings)); }); code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_Referenced_LanguageKeys_Start, Placeholder_Referenced_LanguageKeys_End).Replace(code, m => { return(BuildLanguageKeyList(m.Groups[1].Value, referencedLanguageKeys, exportSettings)); }); return(code); }
/// <summary> /// Builds an action from parsed data /// </summary> /// <param name="template">Template to export</param> /// <param name="parsedData">Parsed data</param> /// <param name="data">Dialog data</param> /// <param name="nextStep">Next step in the dialog</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Action string</returns> public override async Task <string> BuildActionFromParsedData(ExportTemplate template, SpawnObjectActionData parsedData, ExportDialogData data, ExportDialogData nextStep, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { IFlexFieldExportable valueObject = await GetValueObject(parsedData, flexFieldObject, errorCollection); if (valueObject == null) { return(string.Empty); } KartaMapNamedMarkerQueryResult markerResult = await GetMarker(parsedData); if (markerResult == null) { errorCollection.AddDialogMarkerNotFoundError(); return(string.Empty); } return(await FillPlaceholders(template, errorCollection, parsedData, valueObject, markerResult, flexFieldObject, data, nextStep, exportSettings, stepRenderer)); }
/// <summary> /// Builds an action from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="data">Dialog data</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <returns>Action string</returns> public override async Task<string> BuildActionFromParsedData(ChangeNpcStateActionRenderer.ChangeNpcStateActionData parsedData, ExportDialogData data, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings) { ExportTemplate actionTemplate = await GetExportTemplate(project); IFlexFieldExportable valueObject = await GetNpc(flexFieldObject, errorCollection); if(valueObject == null) { return string.Empty; } string actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_State).Replace(actionTemplate.Code, ExportUtil.EscapeCharacters(parsedData.ObjectState, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter)); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeNpc); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); actionCode = _flexFieldPlaceholderResolver.FillPlaceholders(actionCode, flexFieldExportData).Result; return actionCode; }
/// <summary> /// Exports an object /// </summary> /// <param name="template">Template to use</param> /// <param name="objectData">Object data</param> /// <returns>Export Result</returns> public async Task <ExportObjectResult> ExportObject(ExportTemplate template, ExportObjectData objectData) { // Run script export to refresh language keys IFlexFieldExportable flexFieldObject = null; if (objectData.ExportData.ContainsKey(ExportConstants.ExportDataObject)) { flexFieldObject = objectData.ExportData[ExportConstants.ExportDataObject] as IFlexFieldExportable; } if (flexFieldObject != null) { _languageKeyReferenceCollector.PrepareCollectionForGroup(flexFieldObject.Id); } else { _languageKeyReferenceCollector.PrepareCollectionForGroup(null); } await _scriptExporter.ExportObject(template, objectData); objectData.ExportData[ExportConstants.ExportDataReferencedLanguageIds] = _languageKeyReferenceCollector.GetReferencedLanguageKeys(); // Export language keys GoNorthProject project = await _userProjectAccess.GetUserProject(); ExportSettings exportSettings = await _exportSettingsDbAccess.GetExportSettings(project.Id); ExportTemplate exportTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.LanguageFile); ExportObjectResult result = new ExportObjectResult(); result.FileExtension = exportSettings.LanguageFileExtension; ExportPlaceholderFillResult filledResult = await _placeholderResolver.FillPlaceholders(TemplateType.LanguageFile, exportTemplate.Code, objectData, exportTemplate.RenderingEngine); result.Code = filledResult.Code; result.Errors = filledResult.Errors.ToErrorList(); return(result); }
/// <summary> /// Builds an action from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="data">Dialog data</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <returns>Action string</returns> public override async Task <string> BuildActionFromParsedData(LearnForgetSkillActionRenderer.LearnForgetSkillActionData parsedData, ExportDialogData data, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, KortistoNpc npc, ExportSettings exportSettings) { ExportTemplate actionTemplate = await GetExportTemplate(project); IFlexFieldExportable valueObject = await GetSkill(parsedData, errorCollection); if (valueObject == null) { return(string.Empty); } ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeSkill); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); string actionCode = _flexFieldPlaceholderResolver.FillPlaceholders(actionTemplate.Code, flexFieldExportData).Result; return(actionCode); }
/// <summary> /// Builds a preview text from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="errorCollection">Error Collection</param> /// <returns>Preview text</returns> public override async Task <string> BuildPreviewTextFromParsedData(ValueActionRenderBase.ValueFieldActionData parsedData, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection) { IFlexFieldExportable valueObject = await GetValueObject(parsedData, npc, errorCollection); if (valueObject == null) { return(string.Empty); } FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string fieldName = DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection); return(GetPreviewPrefix() + " (" + fieldName + ")"); }
/// <summary> /// Builds a preview text from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="errorCollection">Error Collection</param> /// <param name="child">Child node</param> /// <param name="parent">Parent</param> /// <returns>Preview text</returns> public override async Task <string> BuildPreviewTextFromParsedData(InventoryActionData parsedData, FlexFieldObject flexFieldObject, ExportPlaceholderErrorCollection errorCollection, ExportDialogData child, ExportDialogData parent) { IFlexFieldExportable valueObject = await GetItem(parsedData, errorCollection); if (valueObject == null) { return(string.Empty); } string prefix = ""; if (_isPlayer) { prefix = _isRemoval ? "RemoveItemFromPlayerInventory" : (_isTransfer ? "TransferItemToPlayer" : "SpawnItemInPlayerInventory"); } else { prefix = _isRemoval ? "RemoveItemFromNpcInventory" : (_isTransfer ? "TransferItemToNpc" : "SpawnItemInNpcInventory"); } return(prefix + " (" + valueObject.Name + ")"); }
/// <summary> /// Builds a preview text from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="errorCollection">Error Collection</param> /// <returns>Preview text</returns> public override async Task <string> BuildPreviewTextFromParsedData(InventoryActionRenderer.InventoryActionData parsedData, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection) { IFlexFieldExportable valueObject = await GetItem(parsedData, errorCollection); if (valueObject == null) { return(string.Empty); } string prefix = ""; if (_isPlayer) { prefix = _isTransfer ? "TransferItemToPlayer" : "SpawnItemInPlayerInventory"; } else { prefix = _isTransfer ? "TransferItemToNpc" : "SpawnItemInNpcInventory"; } return(prefix + " (" + valueObject.Name + ")"); }
/// <summary> /// Collects the values for an export /// </summary> /// <param name="templateType">Template type</param> /// <param name="parsedTemplate">Parsed scriban template</param> /// <param name="scriptObject">Scriban script object to fill</param> /// <param name="data">Export Data</param> /// <returns>Task</returns> public override async Task CollectValues(TemplateType templateType, Template parsedTemplate, ScriptObject scriptObject, ExportObjectData data) { IFlexFieldExportable flexFieldObject = data.ExportData[ExportConstants.ExportDataObject] as IFlexFieldExportable; if (flexFieldObject == null) { return; } List <LanguageKey> referencedLanguageKeys = null; if (data.ExportData.ContainsKey(ExportConstants.ExportDataReferencedLanguageIds)) { referencedLanguageKeys = data.ExportData[ExportConstants.ExportDataReferencedLanguageIds] as List <LanguageKey>; } if (referencedLanguageKeys == null) { referencedLanguageKeys = new List <LanguageKey>(); } GoNorthProject project = await _exportCachedDbAccess.GetUserProject(); List <LanguageKey> languageKeys = await _languageKeyDbAccess.GetLanguageKeysByGroupId(project.Id, flexFieldObject.Id); ExportSettings exportSettings = await _exportCachedDbAccess.GetExportSettings(project.Id); languageKeys = languageKeys.OrderBy(l => GetLanguageKeySortOrder(l, flexFieldObject)).ToList(); ScribanExportLanguageFile languageFileData = new ScribanExportLanguageFile(); languageFileData.Object = FlexFieldValueCollectorUtil.ConvertScribanFlexFieldObject(flexFieldObject, exportSettings, _errorCollection); languageFileData.LanguageKeys = ConvertLanguageKeysToScriban(languageKeys, exportSettings); languageFileData.ReferencedLanguageKeys = ConvertLanguageKeysToScriban(referencedLanguageKeys, exportSettings); scriptObject.AddOrUpdate(LanguageObjectKey, languageFileData); }
/// <summary> /// Builds an action from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="data">Dialog data</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <returns>Action string</returns> public override async Task <string> BuildActionFromParsedData(InventoryActionChooseNpcRenderer.InventoryChooseNpcActionData parsedData, ExportDialogData data, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings) { ExportTemplate actionTemplate = await GetExportTemplate(project); IFlexFieldExportable itemObject = await GetItem(parsedData, errorCollection); if (itemObject == null) { return(string.Empty); } IFlexFieldExportable npcObject = await GetNpc(parsedData, errorCollection); if (npcObject == null) { return(string.Empty); } string actionCode = actionTemplate.Code; actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Quantity).Replace(actionCode, parsedData.Quantity.HasValue ? parsedData.Quantity.Value.ToString() : "1"); ExportObjectData itemExportData = new ExportObjectData(); itemExportData.ExportData.Add(ExportConstants.ExportDataObject, itemObject); itemExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeItem); _flexFieldPlaceholderResolverItem.SetErrorMessageCollection(errorCollection); actionCode = _flexFieldPlaceholderResolverItem.FillPlaceholders(actionCode, itemExportData).Result; ExportObjectData npcExportData = new ExportObjectData(); npcExportData.ExportData.Add(ExportConstants.ExportDataObject, npcObject); npcExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeNpc); _flexFieldPlaceholderResolverNpc.SetErrorMessageCollection(errorCollection); actionCode = _flexFieldPlaceholderResolverNpc.FillPlaceholders(actionCode, npcExportData).Result; return(actionCode); }
/// <summary> /// Fills the placeholders /// </summary> /// <param name="template">Template to use</param> /// <param name="errorCollection">Error Collection</param> /// <param name="parsedData">Parsed config data</param> /// <param name="valueObject">Value object</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="curStep">Current step that is rendered</param> /// <param name="nextStep">Next step that is being rendered</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Filled placeholders</returns> protected abstract Task <string> FillPlaceholders(ExportTemplate template, ExportPlaceholderErrorCollection errorCollection, SetQuestStateActionData parsedData, IFlexFieldExportable valueObject, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, ExportSettings exportSettings, IActionStepRenderer stepRenderer);
/// <summary> /// Fills the placeholders /// </summary> /// <param name="template">Template to use</param> /// <param name="errorCollection">Error Collection</param> /// <param name="parsedData">Parsed config data</param> /// <param name="valueObject">Value object to export</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="curStep">Current step that is rendered</param> /// <param name="nextStep">Next step that is being rendered</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Filled placeholders</returns> protected override async Task <string> FillPlaceholders(ExportTemplate template, ExportPlaceholderErrorCollection errorCollection, ChangeNpcStateActionData parsedData, IFlexFieldExportable valueObject, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { KortistoNpc npc = valueObject as KortistoNpc; if (npc == null) { errorCollection.AddDialogNpcNotFoundError(); return(string.Empty); } ScribanChangeNpcStateActionData changeNpcStateData = new ScribanChangeNpcStateActionData(); changeNpcStateData.Npc = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportNpc>(null, null, npc, exportSettings, errorCollection); changeNpcStateData.Npc.IsPlayer = npc.IsPlayerNpc; changeNpcStateData.TargetState = ExportUtil.EscapeCharacters(parsedData.ObjectState, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter); changeNpcStateData.UnescapedTargetState = parsedData.ObjectState; return(await ScribanActionRenderingUtil.FillPlaceholders(_cachedDbAccess, errorCollection, template.Code, changeNpcStateData, flexFieldObject, curStep, nextStep, _scribanLanguageKeyGenerator, stepRenderer)); }
/// <summary> /// Fills the placeholders /// </summary> /// <param name="template">Template to use</param> /// <param name="errorCollection">Error Collection</param> /// <param name="parsedData">Parsed config data</param> /// <param name="valueItem">Item to export</param> /// <param name="valueNpc">Npc to export</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="curStep">Current step that is rendered</param> /// <param name="nextStep">Next step that is being rendered</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Filled placeholders</returns> protected override async Task <string> FillPlaceholders(ExportTemplate template, ExportPlaceholderErrorCollection errorCollection, UseItemActionData parsedData, IFlexFieldExportable valueItem, IFlexFieldExportable valueNpc, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { string actionCode = template.Code; ExportObjectData flexFieldExportDataItem = new ExportObjectData(); flexFieldExportDataItem.ExportData.Add(ExportConstants.ExportDataObject, valueItem); flexFieldExportDataItem.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeItem); _flexFieldPlaceholderResolverItem.SetErrorMessageCollection(errorCollection); actionCode = await _flexFieldPlaceholderResolverItem.FillPlaceholders(actionCode, flexFieldExportDataItem); ExportObjectData flexFieldExportDataNpc = new ExportObjectData(); flexFieldExportDataNpc.ExportData.Add(ExportConstants.ExportDataObject, valueNpc); flexFieldExportDataNpc.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeNpc); _flexFieldPlaceholderResolverNpc.SetErrorMessageCollection(errorCollection); actionCode = await _flexFieldPlaceholderResolverNpc.FillPlaceholders(actionCode, flexFieldExportDataNpc); return(await stepRenderer.ReplaceBasePlaceholders(errorCollection, actionCode, curStep, nextStep, flexFieldObject)); }
/// <summary> /// Builds a flex field value object /// </summary> /// <param name="objectPrefix">Prefix of the object during export</param> /// <param name="parsedTemplate">Parsed scriban template</param> /// <param name="valueObject">Value object to read from</param> /// <param name="exportSettings">Export settings</param> /// <param name="errorCollection">Error collection</param> /// <typeparam name="T">Type of the returned object</typeparam> /// <returns>Converted value</returns> public static T BuildFlexFieldValueObject <T>(string objectPrefix, Template parsedTemplate, IFlexFieldExportable valueObject, ExportSettings exportSettings, ExportPlaceholderErrorCollection errorCollection) where T : ScribanFlexFieldObject, new() { T resultObject = new T(); resultObject.Id = valueObject.Id; resultObject.Name = valueObject.Name; resultObject.Fields = new ScribanFlexFieldDictionary(resultObject, errorCollection); resultObject.UsedFieldIds = new HashSet <string>(); if (valueObject.Fields != null) { resultObject.Fields = new ScribanFlexFieldDictionary(resultObject, errorCollection, valueObject.Fields.Where(f => IsFlexFieldValidForExport(f, true)).SelectMany(f => ConvertFieldToExportField(resultObject, f, exportSettings)).DistinctBy(f => f.Name).ToDictionary(f => f.Name)); if (!string.IsNullOrEmpty(objectPrefix) && parsedTemplate != null) { resultObject.UsedFieldIds = CollectUsedFieldIds(objectPrefix, parsedTemplate, resultObject.Fields).ToHashSet(); } } return(resultObject); }
/// <summary> /// Fills the placeholders /// </summary> /// <param name="template">Template to use</param> /// <param name="errorCollection">Error Collection</param> /// <param name="parsedData">Parsed config data</param> /// <param name="valueObject">Value object to export</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="curStep">Current step that is rendered</param> /// <param name="nextStep">Next step that is being rendered</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Filled placeholders</returns> protected override async Task <string> FillPlaceholders(ExportTemplate template, ExportPlaceholderErrorCollection errorCollection, InventoryActionData parsedData, IFlexFieldExportable valueObject, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { ScribanInventoryActionData codeActionData = new ScribanInventoryActionData(); codeActionData.SelectedItem = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportItem>(null, null, valueObject, exportSettings, errorCollection); codeActionData.Quantity = parsedData.Quantity.HasValue ? parsedData.Quantity.Value : 1; return(await ScribanActionRenderingUtil.FillPlaceholders(_cachedDbAccess, errorCollection, template.Code, codeActionData, flexFieldObject, curStep, nextStep, _scribanLanguageKeyGenerator, stepRenderer)); }
/// <summary> /// Returns the flex field by id /// </summary> /// <param name="valueObject">Value object to export</param> /// <param name="fieldId">Field Id</param> /// <returns>Flex Field</returns> public static FlexField GetFlexField(IFlexFieldExportable valueObject, string fieldId) { FlexField field = valueObject.Fields.FirstOrDefault(f => f.Id == fieldId); return(field); }
/// <summary> /// Fills the placeholders /// </summary> /// <param name="template">Template to use</param> /// <param name="errorCollection">Error Collection</param> /// <param name="parsedData">Parsed config data</param> /// <param name="valueObject">Value object to export</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="curStep">Current step that is rendered</param> /// <param name="nextStep">Next step that is being rendered</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Filled placeholders</returns> protected override async Task <string> FillPlaceholders(ExportTemplate template, ExportPlaceholderErrorCollection errorCollection, LearnForgetSkillActionData parsedData, IFlexFieldExportable valueObject, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { ScribanLearnForgetSkillActionData actionData = new ScribanLearnForgetSkillActionData(); actionData.Skill = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportSkill>(null, null, valueObject, exportSettings, errorCollection); return(await ScribanActionRenderingUtil.FillPlaceholders(_cachedDbAccess, errorCollection, template.Code, actionData, flexFieldObject, curStep, nextStep, _scribanLanguageKeyGenerator, stepRenderer)); }
/// <summary> /// Fills the placeholders /// </summary> /// <param name="template">Template to use</param> /// <param name="errorCollection">Error Collection</param> /// <param name="parsedData">Parsed config data</param> /// <param name="valueObject">Value object to use</param> /// <param name="actionOperator">Action operator to use</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="curStep">Current step that is rendered</param> /// <param name="nextStep">Next step that is being rendered</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Filled placeholders</returns> protected override async Task <string> FillPlaceholders(ExportTemplate template, ExportPlaceholderErrorCollection errorCollection, ValueFieldActionData parsedData, IFlexFieldExportable valueObject, string actionOperator, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string actionCode = template.Code; actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueName).Replace(actionCode, m => { return(DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection)); }); actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Operator).Replace(actionCode, actionOperator); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsSetTo_Start, Placeholder_OperatorIsSetTo_End, parsedData.Operator == "="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotSetTo_Start, Placeholder_OperatorIsNotSetTo_End, parsedData.Operator != "="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsAdd_Start, Placeholder_OperatorIsAdd_End, parsedData.Operator == "+="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotAdd_Start, Placeholder_OperatorIsNotAdd_End, parsedData.Operator != "+="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsSubstract_Start, Placeholder_OperatorIsSubstract_End, parsedData.Operator == "-="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotSubstract_Start, Placeholder_OperatorIsNotSubstract_End, parsedData.Operator != "-="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsMultiply_Start, Placeholder_OperatorIsMultiply_End, parsedData.Operator == "*="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotMultiply_Start, Placeholder_OperatorIsNotMultiply_End, parsedData.Operator != "*="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsDivide_Start, Placeholder_OperatorIsDivide_End, parsedData.Operator == "/="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotDivide_Start, Placeholder_OperatorIsNotDivide_End, parsedData.Operator != "/="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_ValueIsString_Start, Placeholder_ValueIsString_End, exportField.FieldType != ExportConstants.FlexFieldType_Number); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_ValueIsNumber_Start, Placeholder_ValueIsNumber_End, exportField.FieldType == ExportConstants.FlexFieldType_Number); actionCode = ExportUtil.RenderPlaceholderIfFuncTrue(actionCode, Placeholder_ValueNameEquals_Start, Placeholder_ValueNameEquals_End, m => { string searchedFieldName = m.Groups[1].Value; searchedFieldName = searchedFieldName.ToLowerInvariant(); string fieldName = string.Empty; if (!string.IsNullOrEmpty(exportField.Name)) { fieldName = exportField.Name.ToLowerInvariant(); } return(fieldName == searchedFieldName); }); actionCode = ExportUtil.RenderPlaceholderIfFuncTrue(actionCode, Placeholder_ValueNameNotEquals_Start, Placeholder_ValueNameNotEquals_End, m => { string searchedFieldName = m.Groups[1].Value; searchedFieldName = searchedFieldName.ToLowerInvariant(); string fieldName = string.Empty; if (!string.IsNullOrEmpty(exportField.Name)) { fieldName = exportField.Name.ToLowerInvariant(); } return(fieldName != searchedFieldName); }); actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueChange).Replace(actionCode, m => { if (exportField.FieldType != ExportConstants.FlexFieldType_Number) { return(ExportUtil.EscapeCharacters(parsedData.ValueChange, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter)); } return(parsedData.ValueChange); }); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, GetFlexFieldExportObjectType()); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); actionCode = await _flexFieldPlaceholderResolver.FillPlaceholders(actionCode, flexFieldExportData); return(await stepRenderer.ReplaceBasePlaceholders(errorCollection, actionCode, curStep, nextStep, flexFieldObject)); }
/// <summary> /// Fills the placeholders /// </summary> /// <param name="template">Template to use</param> /// <param name="errorCollection">Error Collection</param> /// <param name="parsedData">Parsed config data</param> /// <param name="valueObject">Value object to use</param> /// <param name="actionOperator">Action operator to use</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="curStep">Current step that is rendered</param> /// <param name="nextStep">Next step that is being rendered</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Filled placeholders</returns> protected override async Task <string> FillPlaceholders(ExportTemplate template, ExportPlaceholderErrorCollection errorCollection, ValueFieldActionData parsedData, IFlexFieldExportable valueObject, string actionOperator, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { ScribanValueActionData valueData = new ScribanValueActionData(); valueData.ValueObject = FlexFieldValueCollectorUtil.ConvertScribanFlexFieldObject(valueObject, exportSettings, errorCollection); valueData.TargetField = FlexFieldValueCollectorUtil.GetFlexField(valueData.ValueObject.Fields.Values, parsedData.FieldId, parsedData.FieldName); if (valueData.TargetField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } valueData.Operator = actionOperator; valueData.OriginalOperator = parsedData.Operator; valueData.ValueChange = FlexFieldValueCollectorUtil.MapValueToFieldValue(valueData.TargetField, parsedData.ValueChange, exportSettings); return(await ScribanActionRenderingUtil.FillPlaceholders(_cachedDbAccess, errorCollection, template.Code, valueData, flexFieldObject, curStep, nextStep, _scribanLanguageKeyGenerator, stepRenderer)); }