From 1ff2b9153afe577c7ad778157c2c3b6e410eb4cd Mon Sep 17 00:00:00 2001 From: "Wowzewow (Wezzy)" <42310821+alsoandanswer@users.noreply.github.com> Date: Sun, 23 Mar 2025 06:30:03 +0800 Subject: [PATCH] Fixes double door cabinet animations (#20602) Title. --- .../structures/crates_lockers/closets.dm | 62 +++++++++++-------- .../crates_lockers/closets/gimmick.dm | 2 +- .../crates_lockers/closets/secure/bar.dm | 2 +- .../crates_lockers/closets/secure/personal.dm | 2 +- html/changelogs/wezzy_cabinetfix.yml | 58 +++++++++++++++++ 5 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 html/changelogs/wezzy_cabinetfix.yml diff --git a/code/game/objects/structures/crates_lockers/closets.dm b/code/game/objects/structures/crates_lockers/closets.dm index 129c3f04c1d..4a20f327187 100644 --- a/code/game/objects/structures/crates_lockers/closets.dm +++ b/code/game/objects/structures/crates_lockers/closets.dm @@ -66,13 +66,13 @@ /// Used if you want to have an overlay below the door. used for guncabinets. var/door_underlay = FALSE /// Multiplier on proc/get_door_transform. basically, how far you want this to swing out. value of 1 means the length of the door is unchanged (and will swing out of the tile), 0 means it will just slide back and forth. - var/door_anim_squish = 0.12 + var/door_anim_squish = 0.12 // DON'T TOUCH!!! /// The maximum angle the door will be drawn at - var/door_anim_angle = 140 + var/door_anim_angle = 136 // DON'T TOUCH!!! /// X position of the closet door hinge, relative to the center of the sprite var/door_hinge_x = -6.5 /// For closets with two doors. why a seperate var? because some closets may be weirdly shaped or something. - var/door_hinge_alt = 6.5 + var/door_hinge_x_alt = 6.5 /// Set to 0 to make the door not animate at all var/door_anim_time = 2.5 @@ -623,26 +623,23 @@ if(!door_obj) door_obj = new var/default_door_icon = "[icon_door || icon_state]_door" - vis_contents += door_obj + vis_contents |= door_obj door_obj.icon = icon door_obj.icon_state = default_door_icon is_animating_door = TRUE var/num_steps = door_anim_time / world.tick_lag - for(var/step in 0 to num_steps) var/angle = door_anim_angle * (closing ? 1 - (step/num_steps) : (step/num_steps)) - var/matrix/door_transform = get_door_transform(angle) var/door_state var/door_layer if (angle >= 90) - door_state = "[icon_state]_back" + door_state = "[icon_door_override ? icon_door : icon_state]_back" door_layer = FLOAT_LAYER else door_state = default_door_icon door_layer = ABOVE_HUMAN_LAYER - if(step == 0) door_obj.transform = door_transform door_obj.icon_state = door_state @@ -654,34 +651,44 @@ addtimer(CALLBACK(src, PROC_REF(end_door_animation)), door_anim_time, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_CLIENT_TIME) /obj/structure/closet/proc/end_door_animation() - is_animating_door = FALSE - vis_contents -= door_obj + is_animating_door = FALSE // comment this out and the line below to manually tweak the animation end state by fiddling with the door_anim vars to match the open door icon + remove_vis_contents(door_obj) update_icon() + UpdateOverlays(src) /obj/structure/closet/proc/animate_door_alt(var/closing = FALSE) if(!door_anim_time) return - if(!door_obj_alt) door_obj_alt = new + if(!door_obj_alt) + door_obj_alt = new + var/default_door_icon = "[icon_door || icon_state]_door_alt" vis_contents |= door_obj_alt door_obj_alt.icon = icon - door_obj_alt.icon_state = "[icon_door || icon_state]_door_alt" + door_obj_alt.icon_state = default_door_icon is_animating_door = TRUE var/num_steps = door_anim_time / world.tick_lag - for(var/I in 0 to num_steps) - var/angle = door_anim_angle * (closing ? 1 - (I/num_steps) : (I/num_steps)) - var/matrix/M = get_door_transform(angle, TRUE) - var/door_state = angle >= 90 ? "[icon_door_override ? icon_door : icon_state]_back_alt" : "[icon_door || icon_state]_door_alt" - var/door_layer = angle >= 90 ? FLOAT_LAYER : ABOVE_HUMAN_LAYER + for(var/step in 0 to num_steps) + var/angle = door_anim_angle * (closing ? 1 - (step/num_steps) : (step/num_steps)) + var/matrix/door_transform = get_door_transform(angle, TRUE) + var/door_state + var/door_layer - if(I == 0) - door_obj_alt.transform = M + if (angle >= 90) + door_state = "[icon_door_override ? icon_door : icon_state]_back_alt" + door_layer = FLOAT_LAYER + else + door_state = default_door_icon + door_layer = ABOVE_HUMAN_LAYER + + if(step == 0) + door_obj_alt.transform = door_transform door_obj_alt.icon_state = door_state door_obj_alt.layer = door_layer - else if(I == 1) - animate(door_obj_alt, transform = M, icon_state = door_state, layer = door_layer, time = world.tick_lag, flags = ANIMATION_END_NOW) + else if(step == 1) + animate(door_obj_alt, transform = door_transform, icon_state = door_state, layer = door_layer, time = world.tick_lag, flags = ANIMATION_END_NOW) else - animate(transform = M, icon_state = door_state, layer = door_layer, time = world.tick_lag) - addtimer(CALLBACK(src, PROC_REF(end_door_animation_alt)),door_anim_time,TIMER_UNIQUE|TIMER_OVERRIDE) + animate(transform = door_transform, icon_state = door_state, layer = door_layer, time = world.tick_lag) + addtimer(CALLBACK(src, PROC_REF(end_door_animation_alt)), door_anim_time, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_CLIENT_TIME) /obj/structure/closet/proc/end_door_animation_alt() is_animating_door = FALSE // comment this out and the line below to manually tweak the animation end state by fiddling with the door_anim vars to match the open door icon @@ -689,11 +696,12 @@ update_icon() UpdateOverlays(src) -/obj/structure/closet/proc/get_door_transform(angle) +/obj/structure/closet/proc/get_door_transform(angle, var/inverse_hinge = FALSE) var/matrix/door_matrix = matrix() - door_matrix.Translate(-door_hinge_x, 0) - door_matrix.Multiply(matrix(cos(angle), 0, 0, -sin(angle) * door_anim_squish, 1, 0)) - door_matrix.Translate(door_hinge_x, 0) + var/matrix_door_hinge = inverse_hinge ? door_hinge_x_alt : door_hinge_x + door_matrix.Translate(-matrix_door_hinge, 0) + door_matrix.Multiply(matrix(cos(angle), 0, 0, ((matrix_door_hinge >= 0) ? sin(angle) : -sin(angle)) * door_anim_squish, 1, 0)) // this matrix door hinge >= 0 check is for door hinges on the right, so they swing out instead of upwards + door_matrix.Translate(matrix_door_hinge, 0) return door_matrix /obj/structure/closet/hear_talk(mob/M as mob, text, verb, datum/language/speaking) diff --git a/code/game/objects/structures/crates_lockers/closets/gimmick.dm b/code/game/objects/structures/crates_lockers/closets/gimmick.dm index 529f267a03e..8335169cdc0 100644 --- a/code/game/objects/structures/crates_lockers/closets/gimmick.dm +++ b/code/game/objects/structures/crates_lockers/closets/gimmick.dm @@ -7,7 +7,7 @@ storage_capacity = 45 //such a big closet deserves a little more capacity door_anim_angle = 160 door_anim_squish = 0.22 - door_hinge_alt = 7.5 + door_hinge_x_alt = 7.5 double_doors = TRUE /obj/structure/closet/cabinet/attackby(obj/item/attacking_item, mob/user) diff --git a/code/game/objects/structures/crates_lockers/closets/secure/bar.dm b/code/game/objects/structures/crates_lockers/closets/secure/bar.dm index 46431235f57..61f00b0e7a5 100644 --- a/code/game/objects/structures/crates_lockers/closets/secure/bar.dm +++ b/code/game/objects/structures/crates_lockers/closets/secure/bar.dm @@ -4,7 +4,7 @@ close_sound = 'sound/machines/wooden_closet_close.ogg' door_anim_angle = 160 door_anim_squish = 0.22 - door_hinge_alt = 7.5 + door_hinge_x_alt = 7.5 double_doors = TRUE /obj/structure/closet/secure_closet/cabinet/bar diff --git a/code/game/objects/structures/crates_lockers/closets/secure/personal.dm b/code/game/objects/structures/crates_lockers/closets/secure/personal.dm index b256bc7dbb4..a4c1c7ddd2d 100644 --- a/code/game/objects/structures/crates_lockers/closets/secure/personal.dm +++ b/code/game/objects/structures/crates_lockers/closets/secure/personal.dm @@ -32,7 +32,7 @@ close_sound = 'sound/machines/wooden_closet_close.ogg' door_anim_angle = 160 door_anim_squish = 0.22 - door_hinge_alt = 7.5 + door_hinge_x_alt = 7.5 double_doors = TRUE /obj/structure/closet/secure_closet/personal/cabinet/fill() diff --git a/html/changelogs/wezzy_cabinetfix.yml b/html/changelogs/wezzy_cabinetfix.yml new file mode 100644 index 00000000000..0f409e05bf6 --- /dev/null +++ b/html/changelogs/wezzy_cabinetfix.yml @@ -0,0 +1,58 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: Wowzewow (Wezzy) + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - bugfix: "Fixes double-door cabinet animations."