Skip to content

Commit

Permalink
Merge pull request #19 from Paxilmaniac/day-night-cycle
Browse files Browse the repository at this point in the history
fixes day night for real this time
  • Loading branch information
Paxilmaniac authored Jun 29, 2024
2 parents 2125612 + bf4fffa commit d27155a
Showing 1 changed file with 62 additions and 34 deletions.
96 changes: 62 additions & 34 deletions code/controllers/subsystem/like_night_and_day.dm
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
SUBSYSTEM_DEF(daynight)
name = "Daynight"
wait = 10 SECONDS
flags = SS_NO_FIRE
init_order = INIT_ORDER_NIGHT_AND_DAY
runlevels = RUNLEVELS_DEFAULT
/// This is insanely stupid but it might work? The obj we keep in nullspace that we animate the colors and alpha on to modify our lighting from
var/obj/color_alpha_tracker
/// List of all areas we check for in the day/night cycle
var/list/areas_influenced = list(
/area/vintage/surface_generator,
Expand Down Expand Up @@ -36,54 +34,84 @@ SUBSYSTEM_DEF(daynight)
var/night_duration = 10 MINUTES

/datum/controller/subsystem/daynight/Initialize()
color_alpha_tracker = new
addtimer(CALLBACK(src, PROC_REF(start_afternoon_transition)), daytime_duration)
addtimer(CALLBACK(src, PROC_REF(start_afternoon_transition)), 10 MINUTES)
return SS_INIT_SUCCESS

/datum/controller/subsystem/daynight/fire(resumed)
var/list/areas_to_transition = get_areas_to_edit()
for(var/area/transition_area in areas_to_transition)
if(!transition_area.base_lighting_alpha == color_alpha_tracker.alpha)
transition_area.base_lighting_alpha = color_alpha_tracker.alpha
if(!transition_area.base_lighting_color == color_alpha_tracker.color)
transition_area.base_lighting_color = color_alpha_tracker.color

/// Gets the areas the controller will need to edit
/datum/controller/subsystem/daynight/proc/get_areas_to_edit()
var/list/areas_to_edit = list()
for(var/area_to_check in areas_influenced)
areas_to_edit += GLOB.areas_by_type[area_to_check]
return areas_to_edit

/datum/controller/subsystem/daynight/proc/start_animation(color_to_trans, alpha_to_trans, time_to_trans)
animate(color_alpha_tracker, color = color_to_trans, alpha = alpha_to_trans, time = time_to_trans)

/// Starts the transition to afternoon
/datum/controller/subsystem/daynight/proc/start_afternoon_transition()
start_animation(day_transition_color,day_transition_alpha, day_transition_duration)
addtimer(CALLBACK(src, PROC_REF(start_afternoon_golden_hour)), day_transition_duration + 10 SECONDS)
/datum/controller/subsystem/daynight/proc/start_afternoon_transition(iteration = 1)
var/list/areas_edited_now = get_areas_to_edit()
for(var/area/surface_area in areas_edited_now)
surface_area.base_lighting_alpha = LERP(daytime_alpha, day_transition_alpha, iteration / 5)
surface_area.base_lighting_color = hsl_gradient(iteration / 5, 0, daytime_color, 1, day_transition_color)
surface_area.update_base_lighting()
if(iteration < 5)
addtimer(CALLBACK(src, PROC_REF(start_afternoon_transition), iteration + 1), day_transition_duration / 5)
return
addtimer(CALLBACK(src, PROC_REF(start_afternoon_golden_hour)), day_transition_duration / 5)

/// Starts the transition to afternoon golden hour
/datum/controller/subsystem/daynight/proc/start_afternoon_golden_hour()
start_animation(golden_hour_color, golden_hour_alpha, golden_hour_duration)
addtimer(CALLBACK(src, PROC_REF(start_end_of_day)), golden_hour_duration + 10 SECONDS)
/datum/controller/subsystem/daynight/proc/start_afternoon_golden_hour(iteration = 1)
var/list/areas_edited_now = get_areas_to_edit()
for(var/area/surface_area in areas_edited_now)
surface_area.base_lighting_alpha = LERP(day_transition_alpha, golden_hour_alpha, iteration / 5)
surface_area.base_lighting_color = hsl_gradient(iteration / 5, 0, day_transition_color, 1, golden_hour_color)
surface_area.update_base_lighting()
if(iteration < 5)
addtimer(CALLBACK(src, PROC_REF(start_afternoon_golden_hour), iteration + 1), day_transition_duration / 5)
return
addtimer(CALLBACK(src, PROC_REF(start_end_of_day)), golden_hour_duration / 5)

/// Starts the transition to the end of the day
/datum/controller/subsystem/daynight/proc/start_end_of_day()
start_animation(night_color, night_alpha, night_duration)
addtimer(CALLBACK(src, PROC_REF(start_morning_golden_hour)), night_duration + 10 SECONDS)
/datum/controller/subsystem/daynight/proc/start_end_of_day(iteration = 1)
var/list/areas_edited_now = get_areas_to_edit()
for(var/area/surface_area in areas_edited_now)
surface_area.base_lighting_alpha = LERP(golden_hour_alpha, night_alpha, iteration / 5)
surface_area.base_lighting_color = hsl_gradient(iteration / 5, 0, golden_hour_color, 1, night_color)
surface_area.update_base_lighting()
if(iteration < 5)
addtimer(CALLBACK(src, PROC_REF(start_end_of_day), iteration + 1), day_transition_duration / 10)
return
addtimer(CALLBACK(src, PROC_REF(start_morning_golden_hour)), night_duration / 2)

/// Starts the transition to early morning
/datum/controller/subsystem/daynight/proc/start_morning_golden_hour()
start_animation(golden_hour_color, golden_hour_alpha, golden_hour_duration)
addtimer(CALLBACK(src, PROC_REF(start_morning_transition)), golden_hour_duration + 10 SECONDS)
/datum/controller/subsystem/daynight/proc/start_morning_golden_hour(iteration = 1)
var/list/areas_edited_now = get_areas_to_edit()
for(var/area/surface_area in areas_edited_now)
surface_area.base_lighting_alpha = LERP(night_alpha, golden_hour_alpha, iteration / 5)
surface_area.base_lighting_color = hsl_gradient(iteration / 5, 0, night_color, 1, golden_hour_color)
surface_area.update_base_lighting()
if(iteration < 5)
addtimer(CALLBACK(src, PROC_REF(start_morning_golden_hour), iteration + 1), day_transition_duration / 5)
return
addtimer(CALLBACK(src, PROC_REF(start_morning_transition)), golden_hour_duration / 5)

/// Starts the transition to morning
/datum/controller/subsystem/daynight/proc/start_morning_transition()
start_animation(day_transition_color, day_transition_alpha, day_transition_duration)
addtimer(CALLBACK(src, PROC_REF(start_mid_day)), day_transition_duration + 10 SECONDS)
/datum/controller/subsystem/daynight/proc/start_morning_transition(iteration = 1)
var/list/areas_edited_now = get_areas_to_edit()
for(var/area/surface_area in areas_edited_now)
surface_area.base_lighting_alpha = LERP(golden_hour_alpha, day_transition_alpha, iteration / 5)
surface_area.base_lighting_color = hsl_gradient(iteration / 5, 0, golden_hour_color, 1, day_transition_color)
surface_area.update_base_lighting()
if(iteration < 5)
addtimer(CALLBACK(src, PROC_REF(start_morning_transition), iteration + 1), day_transition_duration / 5)
return
addtimer(CALLBACK(src, PROC_REF(start_mid_day)), day_transition_duration / 5)

/// Starts mid-day
/datum/controller/subsystem/daynight/proc/start_mid_day()
start_animation(daytime_color, daytime_alpha, daytime_duration / 3)
addtimer(CALLBACK(src, PROC_REF(start_afternoon_transition)), daytime_duration)
/datum/controller/subsystem/daynight/proc/start_mid_day(iteration = 1)
var/list/areas_edited_now = get_areas_to_edit()
for(var/area/surface_area in areas_edited_now)
surface_area.base_lighting_alpha = LERP(day_transition_alpha, daytime_alpha, iteration / 5)
surface_area.base_lighting_color = hsl_gradient(iteration / 5, 0, day_transition_color, 1, daytime_color)
surface_area.update_base_lighting()
if(iteration < 5)
addtimer(CALLBACK(src, PROC_REF(start_mid_day), iteration + 1), day_transition_duration / 15)
return
addtimer(CALLBACK(src, PROC_REF(start_afternoon_transition)), daytime_duration / 3)

0 comments on commit d27155a

Please sign in to comment.