예제 #1
0
파일: Activities.cs 프로젝트: Reve/ORTS-MG
 protected Activity(string name, string filePath, ActivityFile activityFile, Consist consist, Path path)
 {
     if (filePath == null && this is DefaultExploreActivity)
     {
         Name = catalog.GetString("- Explore Route -");
     }
     else if (filePath == null && this is ExploreThroughActivity)
     {
         Name = catalog.GetString("+ Explore in Activity Mode +");
     }
     else if (null != activityFile)
     {
         // ITR activities are excluded.
         Name = activityFile.Activity.Header.Name;
         if (activityFile.Activity.Header.Mode == ActivityMode.Introductory)
         {
             Name = "Introductory Train Ride";
         }
         Description = activityFile.Activity.Header.Description;
         Briefing    = activityFile.Activity.Header.Briefing;
         StartTime   = activityFile.Activity.Header.StartTime;
         Season      = activityFile.Activity.Header.Season;
         Weather     = activityFile.Activity.Header.Weather;
         Difficulty  = activityFile.Activity.Header.Difficulty;
         Duration    = activityFile.Activity.Header.Duration;
         Consist     = consist;
         Path        = path;
     }
     else
     {
         Name = name;
     }
     if (string.IsNullOrEmpty(Name))
     {
         Name = $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>";
     }
     if (string.IsNullOrEmpty(Description))
     {
         Description = null;
     }
     if (string.IsNullOrEmpty(Briefing))
     {
         Briefing = null;
     }
     FilePath = filePath;
 }
예제 #2
0
파일: Consists.cs 프로젝트: Reve/ORTS-MG
        internal static async Task <Consist> FromFileAsync(string fileName, Folder folder, bool reverseConsist, CancellationToken token)
        {
            return(await Task.Run(() =>
            {
                Consist result = null;

                try
                {
                    ConsistFile conFile = new ConsistFile(fileName);
                    Locomotive locomotive = reverseConsist ? GetLocomotiveReverse(conFile, folder) : GetLocomotive(conFile, folder);
                    if (locomotive != null)
                    {
                        result = new Consist(conFile, locomotive, fileName);
                    }
                }
                catch
                {
                    result = new Consist($"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>", fileName);
                }
                return result;
            }, token).ConfigureAwait(false));
        }
예제 #3
0
파일: Activities.cs 프로젝트: Reve/ORTS-MG
        public void UpdateActivity(string startTime, SeasonType season, WeatherType weather, Consist consist, Path path)
        {
            var time = startTime.Split(':');

            if (!int.TryParse(time[0], out int hour))
            {
                hour = 12;
            }
            if (time.Length < 2 || !int.TryParse(time[1], out int minute))
            {
                minute = 0;
            }
            if (time.Length < 3 || !int.TryParse(time[2], out int second))
            {
                second = 0;
            }
            StartTime = new StartTime(hour, minute, second);
            Season    = season;
            Weather   = weather;
            Consist   = consist;
            Path      = path;
        }
예제 #4
0
파일: Activities.cs 프로젝트: Reve/ORTS-MG
        internal static async Task <Activity> FromPathAsync(string filePath, Folder folder, Route route, CancellationToken token)
        {
            return(await Task.Run(async() =>
            {
                Activity result;

                try
                {
                    ActivityFile activityFile = new ActivityFile(filePath);
                    ServiceFile srvFile = new ServiceFile(route.RouteFolder.ServiceFile(activityFile.Activity.PlayerServices.Name));
                    var constistTask = Consist.GetConsist(folder, srvFile.TrainConfig, false, token);
                    var pathTask = Path.FromFileAsync(route.RouteFolder.PathFile(srvFile.PathId), token);
                    await Task.WhenAll(constistTask, pathTask).ConfigureAwait(false);
                    Consist consist = await constistTask;
                    Path path = await pathTask;
                    if (!path.IsPlayerPath)
                    {
                        return null;

                        // Not nice to throw an error now. Error was originally thrown by new Path(...);
                        throw new InvalidDataException("Not a player path");
                    }
                    else if (!activityFile.Activity.Header.RouteID.Equals(route.RouteID, StringComparison.OrdinalIgnoreCase))
                    {
                        //Activity and route have different RouteID.
                        result = new Activity($"<{catalog.GetString("Not same route:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>", filePath, null, null, null);
                    }
                    else
                    {
                        result = new Activity(string.Empty, filePath, activityFile, consist, path);
                    }
                }
                catch
                {
                    result = new Activity($"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>", filePath, null, null, null);
                }
                return result;
            }, token).ConfigureAwait(false));
        }