Package com.deco2800.game.services
Class DayNightCycleService
java.lang.Object
com.deco2800.game.services.DayNightCycleService
Service for managing the Day and Night cycle of the game.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEmpty method here for save game functionality DO NOT USEDayNightCycleService
(GameTime timer, DayNightCycleConfig config) -
Method Summary
Modifier and TypeMethodDescriptionReturns the current status of the day night cycle.long
Returns the current number of milliseconds since the current day night cycle started.int
Returns the current day number.To enable events to be subscribed toUsed to get the last part of day before the current onelong
Returns the last time game time that the timer was paused.getTimer()
Returns the game timerlong
Returns total amount of time that the timer has been paused for.boolean
hasEnded()
Returns whether the current day night cycle has ended.boolean
Returns whether the day night cycle service has been startedvoid
loadFromSave
(int dayNum, long dayMs, DayNightCycleStatus currentStatus, DayNightCycleStatus prevStatus, int partOfDayHalveIteration) loads the DayNightCycleService from save, setting attributes as necessary Sets LoadedTimeOffsetvoid
pause()
Pauses the timer for the day night cycle.boolean
paused()
Returns whether the day night cycle is paused.void
resume()
void
run()
Main loop for the service that updates the game status.void
setPartOfDayTo
(DayNightCycleStatus nextPartOfDay) Helps make testing easy in mocking.start()
Starts the day night cycle for the game.void
stop()
Stops the day night cycle timer for the game.
-
Field Details
-
EVENT_DAY_PASSED
- See Also:
-
EVENT_PART_OF_DAY_PASSED
- See Also:
-
EVENT_INTERMITTENT_PART_OF_DAY_CLOCK
- See Also:
-
currentCycleStatus
-
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
-
timer
-
timeSinceLastPartOfDay
public long timeSinceLastPartOfDay -
timePerHalveOfPartOfDay
public long timePerHalveOfPartOfDay -
partOfDayHalveIteration
public int partOfDayHalveIteration -
lastPartOfDayHalveIteration
public int lastPartOfDayHalveIteration -
loadedTimeOffset
public long loadedTimeOffset -
events
-
-
Constructor Details
-
DayNightCycleService
public DayNightCycleService()Empty method here for save game functionality DO NOT USE -
DayNightCycleService
-
-
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 saveddayMs
- the ms through that day when savedcurrentStatus
- the status when savedprevStatus
- the previous status when savedpartOfDayHalveIteration
- 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
Returns the current status of the day night cycle.- Returns:
- DayNightCycleStatus
-
getLastCycleStatus
Used to get the last part of day before the current oneNOTE: 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
Returns the game timer- Returns:
- GameTime
-
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
Main loop for the service that updates the game status.- Throws:
InterruptedException
-
setPartOfDayTo
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
To enable events to be subscribed to- Returns:
- the event handler for the service
-