/// <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(SetDailyRoutineEventState.SetDailyRoutineEventStateData parsedData, FlexFieldObject flexFieldObject, ExportPlaceholderErrorCollection errorCollection, ExportDialogData child, ExportDialogData parent) { KortistoNpc eventNpc = await _cachedDbAccess.GetNpcById(parsedData.NpcId); if (eventNpc == null) { return(string.Empty); } KortistoNpcDailyRoutineEvent exportEvent = null; if (eventNpc.DailyRoutine != null) { exportEvent = eventNpc.DailyRoutine.FirstOrDefault(e => e.EventId == parsedData.EventId); } if (exportEvent == null) { errorCollection.AddDialogDailyRoutineEventNotFoundError(eventNpc.Name); return(string.Empty); } string timeDisplay = FormatDailyRoutineEventTime(exportEvent.EarliestTime); if (exportEvent.EarliestTime != null && exportEvent.LatestTime != null && (exportEvent.EarliestTime.Hours != exportEvent.LatestTime.Hours || exportEvent.EarliestTime.Minutes != exportEvent.LatestTime.Minutes)) { if (!string.IsNullOrEmpty(timeDisplay)) { timeDisplay += " - "; } timeDisplay += FormatDailyRoutineEventTime(exportEvent.LatestTime); } return(GetPreviewPrefix() + " (" + eventNpc.Name + ", " + timeDisplay + ")"); }
public async Task <IActionResult> SaveDailyRoutineEvent(string id, [FromBody] KortistoNpcDailyRoutineEvent routineEvent) { KortistoNpc npc = await _objectDbAccess.GetFlexFieldObjectById(id); if (npc == null) { return(NotFound()); } // Update / Create event if (npc.DailyRoutine == null) { npc.DailyRoutine = new List <KortistoNpcDailyRoutineEvent>(); } if (string.IsNullOrEmpty(routineEvent.EventId)) { routineEvent.EventId = Guid.NewGuid().ToString(); npc.DailyRoutine.Add(routineEvent); } else { int targetIndex = npc.DailyRoutine.FindIndex(d => d.EventId == routineEvent.EventId); if (targetIndex == -1) { return(BadRequest()); } npc.DailyRoutine[targetIndex] = routineEvent; } await SaveNpcAfterEventUpdate(npc); return(Ok(routineEvent.EventId)); }
/// <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(SetDailyRoutineEventState.SetDailyRoutineEventStateData parsedData, ExportDialogData data, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings) { ExportTemplate actionTemplate = await GetExportTemplate(project); KortistoNpc eventNpc = await _cachedDbAccess.GetNpcById(parsedData.NpcId); if (eventNpc == null) { return(string.Empty); } KortistoNpcDailyRoutineEvent exportEvent = null; if (eventNpc.DailyRoutine != null) { exportEvent = eventNpc.DailyRoutine.FirstOrDefault(e => e.EventId == parsedData.EventId); } if (exportEvent == null) { errorCollection.AddDialogDailyRoutineEventNotFoundError(eventNpc.Name); return(string.Empty); } string actionCode = await _dailyRoutineEventPlaceholderResolver.ResolveDailyRoutineEventPlaceholders(actionTemplate.Code, eventNpc, exportEvent); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, eventNpc); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeNpc); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); actionCode = _flexFieldPlaceholderResolver.FillPlaceholders(actionCode, flexFieldExportData).Result; return(actionCode); }
/// <summary> /// Returns the value object to use for scriban exporting /// </summary> /// <param name="parsedData">Parsed 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>Value Object</returns> protected override async Task <ScribanDailyRoutineEventStateConditionData> GetExportObject(DailyRoutineEventStateConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings) { KortistoNpc eventNpc = await _cachedDbAccess.GetNpcById(parsedData.NpcId); if (eventNpc == null) { errorCollection.AddDialogNpcNotFoundError(); return(null); } KortistoNpcDailyRoutineEvent exportEvent = null; if (eventNpc.DailyRoutine != null) { exportEvent = eventNpc.DailyRoutine.FirstOrDefault(e => e.EventId == parsedData.EventId); } if (exportEvent == null) { errorCollection.AddDialogDailyRoutineEventNotFoundError(eventNpc.Name); return(null); } MiscProjectConfig projectConfig = await _cachedDbAccess.GetMiscProjectConfig(); ScribanDailyRoutineEventStateConditionData conditionData = new ScribanDailyRoutineEventStateConditionData(); conditionData.Npc = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportNpc>(null, null, eventNpc, exportSettings, errorCollection); conditionData.DailyRoutineEvent = await ScribanDailyRoutineEventUtil.ConvertDailyRoutineEvent(_dailyRoutineFunctionNameGenerator, eventNpc, exportEvent, project, projectConfig, exportSettings); return(conditionData); }
/// <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); }
/// <summary> /// Formats the daily routine event time /// </summary> /// <param name="dailyRoutines">Daily routines</param> /// <param name="deletedEventId">Event Id</param> /// <returns>Formatted Routine Event</returns> private string FormatDailyRoutineEventTime(List <KortistoNpcDailyRoutineEvent> dailyRoutines, string deletedEventId) { KortistoNpcDailyRoutineEvent dailyRoutineEvent = dailyRoutines.FirstOrDefault(d => d.EventId == deletedEventId); if (dailyRoutineEvent == null) { return(string.Empty); } string timeFormat = _localizer["TimeFormat"].Value; if (dailyRoutineEvent.EarliestTime.Hours == dailyRoutineEvent.LatestTime.Hours && dailyRoutineEvent.EarliestTime.Minutes == dailyRoutineEvent.LatestTime.Minutes) { return(dailyRoutineEvent.EarliestTime.ToString(timeFormat)); } string earliestTime = dailyRoutineEvent.EarliestTime.ToString(timeFormat); string latestTime = dailyRoutineEvent.LatestTime.ToString(timeFormat); return(string.Format("{0} - {1}", earliestTime, latestTime)); }
/// <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(DailyRoutineEventStateConditionResolver.DailyRoutineEventStateConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, KortistoNpc npc, ExportSettings exportSettings) { ExportTemplate conditionTemplate = _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, _isDisabled ? TemplateType.TaleConditionDailyRoutineEventDisabled : TemplateType.TaleConditionDailyRoutineEventEnabled).Result; KortistoNpc eventNpc = _cachedDbAccess.GetNpcById(parsedData.NpcId).Result; if (eventNpc == null) { return(string.Empty); } KortistoNpcDailyRoutineEvent exportEvent = null; if (eventNpc.DailyRoutine != null) { exportEvent = eventNpc.DailyRoutine.FirstOrDefault(e => e.EventId == parsedData.EventId); } if (exportEvent == null) { errorCollection.AddDialogDailyRoutineEventNotFoundError(eventNpc.Name); return(string.Empty); } MiscProjectConfig projectConfig = _cachedDbAccess.GetMiscProjectConfig().Result; string conditionCode = _dailyRoutineEventPlaceholderResolver.ResolveDailyRoutineEventPlaceholders(conditionTemplate.Code, eventNpc, exportEvent).Result; ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, eventNpc); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeNpc); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); conditionCode = _flexFieldPlaceholderResolver.FillPlaceholders(conditionCode, flexFieldExportData).Result; return(conditionCode); }
/// <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, SetDailyRoutineEventStateData parsedData, ExportDialogData data, ExportDialogData nextStep, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { KortistoNpc eventNpc = await _cachedDbAccess.GetNpcById(parsedData.NpcId); if (eventNpc == null) { return(string.Empty); } KortistoNpcDailyRoutineEvent exportEvent = null; if (eventNpc.DailyRoutine != null) { exportEvent = eventNpc.DailyRoutine.FirstOrDefault(e => e.EventId == parsedData.EventId); } if (exportEvent == null) { errorCollection.AddDialogDailyRoutineEventNotFoundError(eventNpc.Name); return(string.Empty); } return(await FillPlaceholders(template, errorCollection, parsedData, eventNpc, exportEvent, flexFieldObject, data, nextStep, project, exportSettings, stepRenderer)); }
/// <summary> /// Renders the daily routine functions /// </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 async Task <List <DailyRoutineFunction> > RenderDailyRoutineFunctions(KortistoNpcDailyRoutineEvent dailyRoutineEvent, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection) { if (dailyRoutineEvent == null) { return(new List <DailyRoutineFunction>()); } if (_renderedEvents.ContainsKey(dailyRoutineEvent.EventId)) { return(_renderedEvents[dailyRoutineEvent.EventId]); } List <DailyRoutineFunction> functions = await _dailyRoutineFunctionRenderer.RenderDailyRoutineFunctions(new List <KortistoNpcDailyRoutineEvent> { dailyRoutineEvent }, npc); _renderedEvents.Add(dailyRoutineEvent.EventId, functions); return(functions); }
/// <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 async Task <string> ResolveDailyRoutineEventContentPlaceholders(string code, KortistoNpc npc, KortistoNpcDailyRoutineEvent dailyRoutineEvent, ExportPlaceholderErrorCollection errorCollection) { GoNorthProject project = await _cachedDbAccess.GetUserProject(); ExportTemplate dailyRoutineFunctionTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.ObjectDailyRoutineFunction); List <DailyRoutineFunction> functions = await this.RenderDailyRoutineFunctions(dailyRoutineEvent, npc, errorCollection); string finalCode = string.Empty; foreach (DailyRoutineFunction curFunction in functions) { if (!string.IsNullOrEmpty(finalCode)) { finalCode += Environment.NewLine; } string functionCode = code; if (dailyRoutineFunctionTemplate.RenderingEngine == ExportTemplateRenderingEngine.Scriban) { functionCode = await ReplaceEventFunction(functionCode, curFunction, errorCollection); } functionCode = FillFunctionCode(functionCode, curFunction); finalCode += functionCode; } return(finalCode); }
/// <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> /// <returns>Code with resolved placeholders</returns> public async Task <string> ResolveDailyRoutineEventPlaceholders(string code, KortistoNpc npc, KortistoNpcDailyRoutineEvent dailyRoutineEvent) { GoNorthProject defaultProject = await _cachedDbAccess.GetDefaultProject(); MiscProjectConfig projectConfig = await _cachedDbAccess.GetMiscProjectConfig(); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasMovementTargetStart, Placeholder_HasMovementTargetEnd, dailyRoutineEvent.MovementTarget != null && !string.IsNullOrEmpty(dailyRoutineEvent.MovementTarget.Name)); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasNoMovementTargetStart, Placeholder_HasNoMovementTargetEnd, dailyRoutineEvent.MovementTarget == null || string.IsNullOrEmpty(dailyRoutineEvent.MovementTarget.Name)); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasMovementTargetExportNameStart, Placeholder_HasMovementTargetExportNameEnd, dailyRoutineEvent.MovementTarget != null && !string.IsNullOrEmpty(dailyRoutineEvent.MovementTarget.ExportName)); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasNoMovementTargetExportNameStart, Placeholder_HasNoMovementTargetExportNameEnd, dailyRoutineEvent.MovementTarget == null || string.IsNullOrEmpty(dailyRoutineEvent.MovementTarget.ExportName)); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasNoScriptStart, Placeholder_HasNoScriptEnd, dailyRoutineEvent.ScriptType == ScriptType_None); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasScriptStart, Placeholder_HasScriptEnd, dailyRoutineEvent.ScriptType != ScriptType_None); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasNodeGraphScriptStart, Placeholder_HasNodeGraphScriptEnd, dailyRoutineEvent.ScriptType == ScriptType_NodeGraph); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasCodeScriptStart, Placeholder_HasCodeScriptEnd, dailyRoutineEvent.ScriptType == ScriptType_Code); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasTargetStateStart, Placeholder_HasTargetStateEnd, !string.IsNullOrEmpty(dailyRoutineEvent.TargetState)); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasNoTargetStateStart, Placeholder_HasNoTargetStateEnd, string.IsNullOrEmpty(dailyRoutineEvent.TargetState)); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_IsEnabledByDefaultStart, Placeholder_IsEnabledByDefaultEnd, dailyRoutineEvent.EnabledByDefault); code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_IsDisabledByDefaultStart, Placeholder_IsDisabledByDefaultEnd, !dailyRoutineEvent.EnabledByDefault); code = ExportUtil.BuildPlaceholderRegex(Placeholder_EventId).Replace(code, dailyRoutineEvent.EventId); code = ExportUtil.BuildPlaceholderRegex(Placeholder_EarliestTime_Hours).Replace(code, dailyRoutineEvent.EarliestTime != null ? dailyRoutineEvent.EarliestTime.Hours.ToString() : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_EarliestTime_Minutes).Replace(code, dailyRoutineEvent.EarliestTime != null ? dailyRoutineEvent.EarliestTime.Minutes.ToString() : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_EarliestTime_TotalMinutes).Replace(code, dailyRoutineEvent.EarliestTime != null ? (dailyRoutineEvent.EarliestTime.Hours * projectConfig.MinutesPerHour + dailyRoutineEvent.EarliestTime.Minutes).ToString() : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_LatestTime_Hours).Replace(code, dailyRoutineEvent.LatestTime != null ? dailyRoutineEvent.LatestTime.Hours.ToString() : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_LatestTime_Minutes).Replace(code, dailyRoutineEvent.LatestTime != null ? dailyRoutineEvent.LatestTime.Minutes.ToString() : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_LatestTime_TotalMinutes).Replace(code, dailyRoutineEvent.LatestTime != null ? (dailyRoutineEvent.LatestTime.Hours * projectConfig.MinutesPerHour + dailyRoutineEvent.LatestTime.Minutes).ToString() : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_MovementTargetName).Replace(code, dailyRoutineEvent.MovementTarget != null && dailyRoutineEvent.MovementTarget.Name != null ? dailyRoutineEvent.MovementTarget.Name : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_MovementTargetExportName).Replace(code, dailyRoutineEvent.MovementTarget != null && dailyRoutineEvent.MovementTarget.ExportName != null ? dailyRoutineEvent.MovementTarget.ExportName : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_MovementTargetExportNameOrName).Replace(code, dailyRoutineEvent.MovementTarget != null && !string.IsNullOrEmpty(dailyRoutineEvent.MovementTarget.ExportName) ? dailyRoutineEvent.MovementTarget.ExportName : (dailyRoutineEvent.MovementTarget != null && dailyRoutineEvent.MovementTarget.Name != null ? dailyRoutineEvent.MovementTarget.Name : string.Empty)); code = ExportUtil.BuildPlaceholderRegex(Placeholder_ScriptFunctionName).Replace(code, m => { return(_dailyRoutineFunctionNameGenerator.GetNewDailyRoutineStepFunction(defaultProject.Id, npc.Id, dailyRoutineEvent.EventId).Result); }); code = ExportUtil.BuildPlaceholderRegex(Placeholder_ScriptName).Replace(code, dailyRoutineEvent.ScriptName != null ? dailyRoutineEvent.ScriptName : string.Empty); code = ExportUtil.BuildPlaceholderRegex(Placeholder_TargetState).Replace(code, dailyRoutineEvent.TargetState != null ? dailyRoutineEvent.TargetState : string.Empty); return(code); }
/// <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="eventNpc">Npc to which the event belongs</param> /// <param name="exportEvent">Event 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="project">Project</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, SetDailyRoutineEventStateData parsedData, KortistoNpc eventNpc, KortistoNpcDailyRoutineEvent exportEvent, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, GoNorthProject project, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { MiscProjectConfig projectConfig = await _cachedDbAccess.GetMiscProjectConfig(); ScribanSetDailyRoutineEventStateActionData setDailyRoutineEventStateData = new ScribanSetDailyRoutineEventStateActionData(); setDailyRoutineEventStateData.Npc = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportNpc>(null, null, eventNpc, exportSettings, errorCollection); setDailyRoutineEventStateData.Npc.IsPlayer = eventNpc.IsPlayerNpc; setDailyRoutineEventStateData.DailyRoutineEvent = await ScribanDailyRoutineEventUtil.ConvertDailyRoutineEvent(_dailyRoutineFunctionNameGenerator, eventNpc, exportEvent, project, projectConfig, exportSettings); return(await ScribanActionRenderingUtil.FillPlaceholders(_cachedDbAccess, errorCollection, template.Code, setDailyRoutineEventStateData, flexFieldObject, curStep, nextStep, _scribanLanguageKeyGenerator, stepRenderer)); }
/// <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); }
/// <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="eventNpc">Npc to which the event belongs</param> /// <param name="exportEvent">Event 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="project">Project</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, SetDailyRoutineEventStateData parsedData, KortistoNpc eventNpc, KortistoNpcDailyRoutineEvent exportEvent, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, GoNorthProject project, ExportSettings exportSettings, IActionStepRenderer stepRenderer);
/// <summary> /// Builds a flex field value object /// </summary> /// <param name="dailyRoutineFunctionNameGenerator">Daily routine function name generator</param> /// <param name="npc">Npc to which the event belongs</param> /// <param name="exportEvent">Export event</param> /// <param name="project">Project</param> /// <param name="projectConfig">Project config</param> /// <param name="exportSettings">Export settings</param> /// <returns>Converted value</returns> public static async Task <ScribanExportDailyRoutineEvent> ConvertDailyRoutineEvent(IDailyRoutineFunctionNameGenerator dailyRoutineFunctionNameGenerator, KortistoNpc npc, KortistoNpcDailyRoutineEvent exportEvent, GoNorthProject project, MiscProjectConfig projectConfig, ExportSettings exportSettings) { ScribanExportDailyRoutineEvent convertedEvent = new ScribanExportDailyRoutineEvent(); convertedEvent.OriginalEvent = exportEvent; convertedEvent.EventId = exportEvent.EventId; convertedEvent.EarliestTime = ConvertEventTime(exportEvent.EarliestTime, projectConfig); convertedEvent.LatestTime = ConvertEventTime(exportEvent.LatestTime, projectConfig); convertedEvent.UnescapedMovementTarget = exportEvent.MovementTarget != null && !string.IsNullOrEmpty(exportEvent.MovementTarget.Name) ? exportEvent.MovementTarget.Name : null; convertedEvent.UnescapedMovementTargetExportName = exportEvent.MovementTarget != null && !string.IsNullOrEmpty(exportEvent.MovementTarget.ExportName) ? exportEvent.MovementTarget.ExportName : null; convertedEvent.UnescapedMovementTargetExportNameOrName = GetMovementTargetExportNameOrName(exportEvent.MovementTarget); convertedEvent.MovementTarget = EscapeValueIfExist(convertedEvent.UnescapedMovementTarget, exportSettings); convertedEvent.MovementTargetExportName = EscapeValueIfExist(convertedEvent.UnescapedMovementTargetExportName, exportSettings); convertedEvent.MovementTargetExportNameOrName = EscapeValueIfExist(convertedEvent.UnescapedMovementTargetExportNameOrName, exportSettings); convertedEvent.ScriptType = ScribanScriptUtil.ConvertScriptType(exportEvent.ScriptType); if (exportEvent.ScriptType != ExportConstants.ScriptType_None) { convertedEvent.ScriptName = exportEvent.ScriptName; convertedEvent.ScriptFunctionName = await dailyRoutineFunctionNameGenerator.GetNewDailyRoutineStepFunction(project.Id, npc.Id, exportEvent.EventId); } else { convertedEvent.ScriptName = null; convertedEvent.ScriptFunctionName = null; } convertedEvent.TargetState = !string.IsNullOrEmpty(exportEvent.TargetState) ? exportEvent.TargetState : null; convertedEvent.IsEnabledByDefault = exportEvent.EnabledByDefault; return(convertedEvent); }
/// <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="eventNpc">Npc to which the event belongs</param> /// <param name="exportEvent">Event 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="project">Project</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, SetDailyRoutineEventStateData parsedData, KortistoNpc eventNpc, KortistoNpcDailyRoutineEvent exportEvent, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, GoNorthProject project, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { string actionCode = await _dailyRoutineEventPlaceholderResolver.ResolveDailyRoutineEventPlaceholders(template.Code, eventNpc, exportEvent); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, eventNpc); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeNpc); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); actionCode = _flexFieldPlaceholderResolver.FillPlaceholders(actionCode, flexFieldExportData).Result; return(await stepRenderer.ReplaceBasePlaceholders(errorCollection, actionCode, curStep, nextStep, flexFieldObject)); }