Esempio n. 1
0
            public GameClockTimer(UtopiaTimeSpan interval, Clock worldClock, TimerRaised callBack)
            {
                OnTimerRaised += callBack;
                _worldClock    = worldClock;
                _triggerSpan   = interval;

                WorldTimeChanged(worldClock.Now);
            }
Esempio n. 2
0
        public static UtopiaTimeSpan Parse(string s)
        {
            if (!s.Contains(":") || s.Contains(" "))
            {
                var spl = s.ToLower().Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                var span = new UtopiaTimeSpan();

                foreach (var s1 in spl)
                {
                    var value = s1.Remove(s1.Length - 1);
                    if (s1.EndsWith("y"))
                    {
                        int years;
                        if (int.TryParse(value, out years))
                        {
                            span += FromYears(years);
                        }
                    }
                    if (s1.EndsWith("s"))
                    {
                        int seasons;
                        if (int.TryParse(value, out seasons))
                        {
                            span += FromSeasons(seasons);
                        }
                    }
                    if (s1.EndsWith("d"))
                    {
                        int days;
                        if (int.TryParse(value, out days))
                        {
                            span += FromDays(days);
                        }
                    }
                    if (s1.EndsWith("h"))
                    {
                        int hours;
                        if (int.TryParse(value, out hours))
                        {
                            span += FromHours(hours);
                        }
                    }
                    if (s1.Contains(":"))
                    {
                        var ts = TimeSpan.Parse(s1);
                        span += FromSeconds(ts.TotalSeconds);
                    }
                }

                return(span);
            }
            else
            {
                var ts = TimeSpan.Parse(s);
                return(FromSeconds(ts.TotalSeconds));
            }
        }
Esempio n. 3
0
 public void SetCurrentTimeOfDay(UtopiaTimeSpan time)
 {
     SetCurrentTime(Now.Date + time);
 }
Esempio n. 4
0
 public TimeSpan GameToReal(UtopiaTimeSpan gameSpan)
 {
     return(TimeSpan.FromSeconds(gameSpan.TotalSeconds / _timeFactor));
 }
Esempio n. 5
0
 /// <summary>
 /// Converts real time span to game time span
 /// </summary>
 /// <param name="realTimeSpan"></param>
 /// <returns></returns>
 public UtopiaTimeSpan RealToGameSpan(TimeSpan realTimeSpan)
 {
     return(UtopiaTimeSpan.FromSeconds(realTimeSpan.TotalSeconds * _timeFactor));
 }
Esempio n. 6
0
 public static UtopiaTimeSpan operator -(UtopiaTime t1, UtopiaTime t2)
 {
     return UtopiaTimeSpan.FromSeconds(t1.TotalSeconds - t2.TotalSeconds);
 }
Esempio n. 7
0
 public bool Equals(UtopiaTimeSpan other)
 {
     return(TotalSeconds == other.TotalSeconds);
 }