示例#1
0
        public void Update(GameTime gameTime)
        {
            _currentTimePassed += (float)gameTime.ElapsedGameTime.Milliseconds;

            while (_currentTimePassed >= TimePerMinute)
            {
                _currentTimePassed -= TimePerMinute;

                CurrentMinutes++;

                OnMinuteChange?.Invoke(this);

                while (CurrentMinutes >= MinutesPerHour)
                {
                    CurrentMinutes -= MinutesPerHour;

                    CurrentHours++;

                    OnHourChange?.Invoke(this);

                    while (CurrentHours > HoursPerDay)
                    {
                        CurrentHours -= HoursPerDay;

                        CurrentDay++;

                        CurrentDayIndex++;

                        OnDayChange?.Invoke(this);

                        if (CurrentDayIndex >= Days.Count)
                        {
                            CurrentDayIndex = 0;

                            OnWeekChange?.Invoke(this);
                        }

                        if (CurrentDay > (float)Months.ElementAt(CurrentMonthIndex).Value)
                        {
                            CurrentMonthIndex++;

                            OnMonthChange?.Invoke(this);
                        }

                        if (CurrentMonthIndex >= Months.Count)
                        {
                            CurrentMonthIndex = 0;

                            CurrentYear++;

                            OnYearChange?.Invoke(this);
                        }
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Force execute all events at a given time
 /// </summary>
 /// <param name="timeToExecuteOn">Time to execute on</param>
 public void ForceExecuteAllEvents(SavedTime timeToExecuteOn)
 {
     OnSecondChange?.Invoke(timeToExecuteOn);
     OnMinuteChange?.Invoke(timeToExecuteOn);
     OnDayPhaseChange?.Invoke(timeToExecuteOn);
     OnHourChange?.Invoke(timeToExecuteOn);
     OnDayChange?.Invoke(timeToExecuteOn);
     OnMonthChange?.Invoke(timeToExecuteOn);
     OnYearChange?.Invoke(timeToExecuteOn);
 }
示例#3
0
        private void DoTimeEventsUpdate()
        {
            SavedTime thisUpdateTime = MainClock.NowTime;

            if (thisUpdateTime.Seconds != lastUpdateTime.Seconds)
            {
                OnSecondChange?.Invoke(thisUpdateTime);

                if (thisUpdateTime.Minutes != lastUpdateTime.Minutes)
                {
                    OnMinuteChange?.Invoke(thisUpdateTime);

                    if (thisUpdateTime.Hours24 != lastUpdateTime.Hours24)
                    {
                        if (thisUpdateTime.DayPhase != lastUpdateTime.DayPhase)
                        {
                            OnDayPhaseChange?.Invoke(thisUpdateTime);
                        }

                        OnHourChange?.Invoke(thisUpdateTime);

                        if (thisUpdateTime.Day != lastUpdateTime.Day)
                        {
                            OnDayChange?.Invoke(thisUpdateTime);

                            if (thisUpdateTime.Month != lastUpdateTime.Month)
                            {
                                OnMonthChange?.Invoke(thisUpdateTime);

                                if (thisUpdateTime.Year != lastUpdateTime.Year)
                                {
                                    OnYearChange?.Invoke(thisUpdateTime);
                                }
                            }
                        }
                    }
                }
            }

            lastUpdateTime = thisUpdateTime;
        }