From 1983be6a121d6d5c2d06f2648a40d435d38b7fdd Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Fri, 25 Jun 2021 11:06:52 -0400 Subject: [PATCH] Transform cone prettier --- code/datums/components/overlay_lighting.dm | 23 +++++++++++++++++----- code/game/objects/effects/misc.dm | 6 +----- code/game/objects/effects/overlays.dm | 14 +++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/code/datums/components/overlay_lighting.dm b/code/datums/components/overlay_lighting.dm index 4e778d529ba..b6a812ce9ab 100644 --- a/code/datums/components/overlay_lighting.dm +++ b/code/datums/components/overlay_lighting.dm @@ -94,7 +94,6 @@ cone = new() cone_hint_x = movable_parent.light_cone_x_offset cone_hint_y = movable_parent.light_cone_y_offset - cone.transform = cone.transform.Translate(-32, -32) set_direction(movable_parent.dir) if(!isnull(_range)) movable_parent.set_light_range(_range) @@ -454,7 +453,7 @@ .++ directional_atom.forceMove(scanning) - directional_atom.face_light(GET_PARENT, .) + directional_atom.face_light(GET_PARENT, dir2angle(current_direction), .) ///Tries to place the directional light in a specific turf /datum/component/overlay_lighting/proc/place_directional_light(turf/target) @@ -475,8 +474,13 @@ .++ directional_atom.forceMove(scanning) - directional_atom.face_light(GET_PARENT, .) - set_direction(get_dir(GET_PARENT, scanning), TRUE) + var/turf/Ts = get_turf(GET_PARENT) + var/turf/To = get_turf(GET_LIGHT_SOURCE) + + var/angle = Get_Angle(Ts, To) + + directional_atom.face_light(GET_PARENT, angle, .) + set_cone_direction(NORTH, angle) ///Called when current_holder changes loc. /datum/component/overlay_lighting/proc/on_holder_dir_change(atom/movable/source, olddir, newdir) @@ -488,6 +492,15 @@ SIGNAL_HANDLER set_direction(newdir) +///Sets the cone's direction for directional lighting +/datum/component/overlay_lighting/proc/set_cone_direction(dir, angle) + cone.reset_transform() + if(dir) + cone.set_dir(dir) + if(angle) + cone.transform = turn(cone.transform, angle) + cone.apply_standard_transform() + ///Sets a new direction for the directional cast, then updates luminosity /datum/component/overlay_lighting/proc/set_direction(newdir, skip_update) if(!newdir) @@ -495,7 +508,7 @@ if(current_direction == newdir) return current_direction = newdir - cone.set_dir(newdir) + set_cone_direction(newdir) if(newdir & NORTH) cone.pixel_y = 16 diff --git a/code/game/objects/effects/misc.dm b/code/game/objects/effects/misc.dm index b48ca15f5a4..140f4e502df 100644 --- a/code/game/objects/effects/misc.dm +++ b/code/game/objects/effects/misc.dm @@ -116,14 +116,10 @@ . = ..() vis_contents += light_spot -/obj/effect/abstract/directional_lighting/proc/face_light(atom/movable/source, distance) +/obj/effect/abstract/directional_lighting/proc/face_light(atom/movable/source, angle, distance) if(!loc) // We're in nullspace return - var/turf/Ts = get_turf(source) - var/turf/To = get_turf(src) - var/angle = Get_Angle(Ts, To) - // Save ourselves some matrix math if(angle != trans_angle) trans_angle = angle diff --git a/code/game/objects/effects/overlays.dm b/code/game/objects/effects/overlays.dm index 5a5f043ebd2..3a62216be6f 100644 --- a/code/game/objects/effects/overlays.dm +++ b/code/game/objects/effects/overlays.dm @@ -161,6 +161,20 @@ alpha = 110 blocks_emissive = FALSE + var/static/matrix/normal_transform + +/obj/effect/overlay/light_cone/Initialize() + . = ..() + apply_standard_transform() + +/obj/effect/overlay/light_cone/proc/reset_transform(apply_standard) + transform = initial(transform) + if(apply_standard) + apply_standard_transform() + +/obj/effect/overlay/light_cone/proc/apply_standard_transform() + transform = transform.Translate(-32, -32) + /obj/effect/overlay/light_cone/Destroy(force) if(!force) stack_trace("Directional light cone deleted, but not by our component")