Class DayNightCycleService

java.lang.Object
com.deco2800.game.services.DayNightCycleService

public class DayNightCycleService extends Object
Service for managing the Day and Night cycle of the game.
  • Field Details

    • EVENT_DAY_PASSED

      public static final String EVENT_DAY_PASSED
      See Also:
    • EVENT_PART_OF_DAY_PASSED

      public static final String EVENT_PART_OF_DAY_PASSED
      See Also:
    • EVENT_INTERMITTENT_PART_OF_DAY_CLOCK

      public static final String EVENT_INTERMITTENT_PART_OF_DAY_CLOCK
      See Also:
    • currentCycleStatus

      public DayNightCycleStatus currentCycleStatus
    • lastCycleStatus

      public DayNightCycleStatus lastCycleStatus
    • currentDayNumber

      public int currentDayNumber
    • currentDayMillis

      public long currentDayMillis
    • timePaused

      public long timePaused
    • totalDurationPaused

      public long totalDurationPaused
    • isPaused

      public boolean isPaused
    • isStarted

      public boolean isStarted
    • config

      public DayNightCycleConfig config
    • timer

      public GameTime timer
    • timeSinceLastPartOfDay

      public long timeSinceLastPartOfDay
    • timePerHalveOfPartOfDay

      public long timePerHalveOfPartOfDay
    • partOfDayHalveIteration

      public int partOfDayHalveIteration
    • lastPartOfDayHalveIteration

      public int lastPartOfDayHalveIteration
    • loadedTimeOffset

      public long loadedTimeOffset
    • events

      public transient EventHandler events
  • Constructor Details

    • DayNightCycleService

      public DayNightCycleService()
      Empty method here for save game functionality DO NOT USE
    • DayNightCycleService

      public DayNightCycleService(GameTime timer, DayNightCycleConfig config)
  • Method Details

    • loadFromSave

      public void loadFromSave(int dayNum, long dayMs, DayNightCycleStatus currentStatus, DayNightCycleStatus prevStatus, int partOfDayHalveIteration)
      loads the DayNightCycleService from save, setting attributes as necessary Sets LoadedTimeOffset
      Parameters:
      dayNum - the day number when saved
      dayMs - the ms through that day when saved
      currentStatus - the status when saved
      prevStatus - the previous status when saved
      partOfDayHalveIteration - the iteration through the day/night the timer was when saved
    • hasEnded

      public boolean hasEnded()
      Returns whether the current day night cycle has ended.
      Returns:
      boolean
    • hasStarted

      public boolean hasStarted()
      Returns whether the day night cycle service has been started
      Returns:
      boolean
    • paused

      public boolean paused()
      Returns whether the day night cycle is paused.
      Returns:
      boolean
    • getCurrentCycleStatus

      public DayNightCycleStatus getCurrentCycleStatus()
      Returns the current status of the day night cycle.
      Returns:
      DayNightCycleStatus
    • getLastCycleStatus

      public DayNightCycleStatus getLastCycleStatus()
      Used to get the last part of day before the current one

      NOTE: helps with testing behaviour

      Returns:
      last part of day
    • getTimePaused

      public long getTimePaused()
      Returns the last time game time that the timer was paused.
      Returns:
      long
    • getTotalDurationPaused

      public long getTotalDurationPaused()
      Returns total amount of time that the timer has been paused for.
      Returns:
      long
    • getCurrentDayNumber

      public int getCurrentDayNumber()
      Returns the current day number.
      Returns:
      int
    • getCurrentDayMillis

      public long getCurrentDayMillis()
      Returns the current number of milliseconds since the current day night cycle started.
      Returns:
      long
    • getTimer

      public GameTime getTimer()
      Returns the game timer
      Returns:
      GameTime
    • start

      public CompletableFuture<Object> start()
      Starts the day night cycle for the game.
      Returns:
      a future that can be used to join.
    • stop

      public void stop()
      Stops the day night cycle timer for the game.
    • resume

      public void resume()
    • pause

      public void pause()
      Pauses the timer for the day night cycle.
    • run

      public void run() throws InterruptedException
      Main loop for the service that updates the game status.
      Throws:
      InterruptedException
    • setPartOfDayTo

      public void setPartOfDayTo(DayNightCycleStatus nextPartOfDay)
      Helps make testing easy in mocking. It's used change to the next part of the day.
      Parameters:
      nextPartOfDay - next part of the day to change to as a DayNightCycleStatus
    • getEvents

      public EventHandler getEvents()
      To enable events to be subscribed to
      Returns:
      the event handler for the service