/// <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>
        /// 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);
        }
Exemple #3
0
 /// <summary>
 /// Returns a new step function
 /// </summary>
 /// <param name="stepType">Stype type (Text, Choice)</param>
 /// <param name="projectId">Project id</param>
 /// <param name="objectId">Object Id</param>
 /// <param name="functionObjectId">Function object id</param>
 /// <returns>New step Function</returns>
 public override async Task <string> GenerateFunctionName(string stepType, string projectId, string objectId, string functionObjectId)
 {
     return(await _functionNameGenerator.GetNewDailyRoutineStepFunction(projectId, objectId, functionObjectId));
 }