From 3eb53be29ee4e10d76d51c0abf8481f18fa0123b Mon Sep 17 00:00:00 2001 From: larentoun <31931237+larentoun@users.noreply.github.com> Date: Sun, 6 Aug 2023 03:56:24 +0900 Subject: [PATCH] [REFACTOR] Pixel Shift Component (#22564) * Pixel Shift - Move to Component * oops return ais * more refactor * update authors * remove more unused signals! * one more little refactor * update override and readme * update dme * move addcomponent to login * review * more review fixes * more changes, now qdels on unpixel_shift * remove unnecessary * update readme * return signal * update documentation? --------- Co-authored-by: Bloop --- code/__DEFINES/~skyrat_defines/keybindings.dm | 3 +- code/__DEFINES/~skyrat_defines/living.dm | 7 ++ code/datums/keybinding/mob.dm | 2 +- code/modules/mob/mob_movement.dm | 7 -- .../code/datums/keybinding/mob.dm | 2 + .../code/modules/mob/living/living.dm | 7 ++ .../modules/mob/living/living_movement.dm | 4 + .../modules/pixel_shift/code/pixel_shift.dm | 97 ----------------- .../pixel_shift/code/pixel_shift_component.dm | 100 ++++++++++++++++++ .../pixel_shift/code/pixel_shift_keybind.dm | 17 +++ .../pixel_shift/code/pixel_shift_mob.dm | 6 ++ modular_skyrat/modules/pixel_shift/readme.md | 21 ++-- tgstation.dme | 8 +- 13 files changed, 168 insertions(+), 113 deletions(-) create mode 100644 code/__DEFINES/~skyrat_defines/living.dm create mode 100644 modular_skyrat/master_files/code/datums/keybinding/mob.dm create mode 100644 modular_skyrat/master_files/code/modules/mob/living/living.dm create mode 100644 modular_skyrat/master_files/code/modules/mob/living/living_movement.dm delete mode 100644 modular_skyrat/modules/pixel_shift/code/pixel_shift.dm create mode 100644 modular_skyrat/modules/pixel_shift/code/pixel_shift_component.dm create mode 100644 modular_skyrat/modules/pixel_shift/code/pixel_shift_keybind.dm create mode 100644 modular_skyrat/modules/pixel_shift/code/pixel_shift_mob.dm diff --git a/code/__DEFINES/~skyrat_defines/keybindings.dm b/code/__DEFINES/~skyrat_defines/keybindings.dm index b747ca432bf..5a205f4f0f8 100644 --- a/code/__DEFINES/~skyrat_defines/keybindings.dm +++ b/code/__DEFINES/~skyrat_defines/keybindings.dm @@ -1,4 +1,5 @@ -#define COMSIG_KB_MOB_PIXELSHIFT "keybinding_mob_pixelshift" +#define COMSIG_KB_MOB_PIXEL_SHIFT_DOWN "keybinding_mob_pixel_shift_down" +#define COMSIG_KB_MOB_PIXEL_SHIFT_UP "keybinding_mob_pixel_shift_up" #define COMSIG_KB_CLIENT_LOOC_DOWN "keybinding_client_looc_down" #define COMSIG_KB_CLIENT_WHISPER_DOWN "keybinding_client_whisper_down" #define COMSIG_KB_LIVING_COMBAT_INDICATOR "keybinding_living_combat_indicator" diff --git a/code/__DEFINES/~skyrat_defines/living.dm b/code/__DEFINES/~skyrat_defines/living.dm new file mode 100644 index 00000000000..f2bb97bfe1e --- /dev/null +++ b/code/__DEFINES/~skyrat_defines/living.dm @@ -0,0 +1,7 @@ +//from base of living/set_pull_offset(): (mob/living/pull_target, grab_state) +#define COMSIG_LIVING_SET_PULL_OFFSET "living_set_pull_offset" +//from base of living/reset_pull_offsets(): (mob/living/pull_target, override) +#define COMSIG_LIVING_RESET_PULL_OFFSETS "living_reset_pull_offsets" +//from base of living/CanAllowThrough(): (atom/movable/mover, border_dir) +#define COMSIG_LIVING_CAN_ALLOW_THROUGH "living_can_allow_through" + #define COMPONENT_LIVING_PASSABLE (1<<0) diff --git a/code/datums/keybinding/mob.dm b/code/datums/keybinding/mob.dm index 879c90ff1b9..9c2a15a41e5 100644 --- a/code/datums/keybinding/mob.dm +++ b/code/datums/keybinding/mob.dm @@ -200,7 +200,7 @@ keybind_signal = COMSIG_KB_MOB_TARGETLEFTLEG_DOWN /datum/keybinding/mob/prevent_movement - hotkey_keys = list("Ctrl") //SKYRAT EDIT CHANGE ALT > CTRL - PIXEL_SHIFT + hotkey_keys = list("Alt") name = "block_movement" full_name = "Block movement" description = "Prevents you from moving" diff --git a/code/modules/mob/mob_movement.dm b/code/modules/mob/mob_movement.dm index 25adeeef125..dc314a6a103 100644 --- a/code/modules/mob/mob_movement.dm +++ b/code/modules/mob/mob_movement.dm @@ -85,13 +85,6 @@ return FALSE if(SEND_SIGNAL(mob, COMSIG_MOB_CLIENT_PRE_LIVING_MOVE, new_loc, direct) & COMSIG_MOB_CLIENT_BLOCK_PRE_LIVING_MOVE) return FALSE - //SKYRAT EDIT ADDITION BEGIN - PIXEL_SHIFT - if(mob.shifting) - mob.pixel_shift(direct) - return FALSE - else if(mob.is_shifted) - mob.unpixel_shift() - //SKYRAT EDIT ADDITION END var/mob/living/L = mob //Already checked for isliving earlier if(L.incorporeal_move && !is_secret_level(mob.z)) //Move though walls diff --git a/modular_skyrat/master_files/code/datums/keybinding/mob.dm b/modular_skyrat/master_files/code/datums/keybinding/mob.dm new file mode 100644 index 00000000000..00bae582b4a --- /dev/null +++ b/modular_skyrat/master_files/code/datums/keybinding/mob.dm @@ -0,0 +1,2 @@ +/datum/keybinding/mob/prevent_movement + hotkey_keys = list("Ctrl") diff --git a/modular_skyrat/master_files/code/modules/mob/living/living.dm b/modular_skyrat/master_files/code/modules/mob/living/living.dm new file mode 100644 index 00000000000..04aea1e3642 --- /dev/null +++ b/modular_skyrat/master_files/code/modules/mob/living/living.dm @@ -0,0 +1,7 @@ +/mob/living/set_pull_offsets(mob/living/pull_target, grab_state) + . = ..() + SEND_SIGNAL(pull_target, COMSIG_LIVING_SET_PULL_OFFSET) + +/mob/living/reset_pull_offsets(mob/living/pull_target, override) + . = ..() + SEND_SIGNAL(pull_target, COMSIG_LIVING_RESET_PULL_OFFSETS) diff --git a/modular_skyrat/master_files/code/modules/mob/living/living_movement.dm b/modular_skyrat/master_files/code/modules/mob/living/living_movement.dm new file mode 100644 index 00000000000..a2efb7be0ec --- /dev/null +++ b/modular_skyrat/master_files/code/modules/mob/living/living_movement.dm @@ -0,0 +1,4 @@ +/mob/living/CanAllowThrough(atom/movable/mover, border_dir) + if(SEND_SIGNAL(src, COMSIG_LIVING_CAN_ALLOW_THROUGH, mover, border_dir) & COMPONENT_LIVING_PASSABLE) + return TRUE + return ..() diff --git a/modular_skyrat/modules/pixel_shift/code/pixel_shift.dm b/modular_skyrat/modules/pixel_shift/code/pixel_shift.dm deleted file mode 100644 index a26fa210513..00000000000 --- a/modular_skyrat/modules/pixel_shift/code/pixel_shift.dm +++ /dev/null @@ -1,97 +0,0 @@ -#define MAXIMUM_PIXEL_SHIFT 16 -#define PASSABLE_SHIFT_THRESHOLD 8 - -/mob - /// Whether the mob is pixel shifted or not - var/is_shifted = FALSE - /// If we are in the shifting setting. - var/shifting = FALSE - - /// Takes the four cardinal direction defines. Any atoms moving into this atom's tile will be allowed to from the added directions. - var/passthroughable = NONE - -/datum/keybinding/mob/pixel_shift - hotkey_keys = list("B") - name = "pixel_shift" - full_name = "Pixel Shift" - description = "Shift your characters offset." - category = CATEGORY_MOVEMENT - keybind_signal = COMSIG_KB_MOB_PIXELSHIFT - -/datum/keybinding/mob/pixel_shift/down(client/user) - . = ..() - if(.) - return - var/mob/M = user.mob - M.shifting = TRUE - return TRUE - -/datum/keybinding/mob/pixel_shift/up(client/user) - . = ..() - if(.) - return - var/mob/M = user.mob - M.shifting = FALSE - return TRUE - -/mob/proc/unpixel_shift() - return - -/mob/living/unpixel_shift() - . = ..() - passthroughable = NONE - if(is_shifted) - is_shifted = FALSE - pixel_x = body_position_pixel_x_offset + base_pixel_x - pixel_y = body_position_pixel_y_offset + base_pixel_y - -/mob/proc/pixel_shift(direction) - return - -/mob/living/set_pull_offsets(mob/living/pull_target, grab_state) - pull_target.unpixel_shift() - return ..() - -/mob/living/reset_pull_offsets(mob/living/pull_target, override) - pull_target.unpixel_shift() - return ..() - -/mob/living/pixel_shift(direction) - passthroughable = NONE - switch(direction) - if(NORTH) - if(pixel_y <= MAXIMUM_PIXEL_SHIFT + base_pixel_y) - pixel_y++ - is_shifted = TRUE - if(EAST) - if(pixel_x <= MAXIMUM_PIXEL_SHIFT + base_pixel_x) - pixel_x++ - is_shifted = TRUE - if(SOUTH) - if(pixel_y >= -MAXIMUM_PIXEL_SHIFT + base_pixel_y) - pixel_y-- - is_shifted = TRUE - if(WEST) - if(pixel_x >= -MAXIMUM_PIXEL_SHIFT + base_pixel_x) - pixel_x-- - is_shifted = TRUE - - // Yes, I know this sets it to true for everything if more than one is matched. - // Movement doesn't check diagonals, and instead just checks EAST or WEST, depending on where you are for those. - if(pixel_y > PASSABLE_SHIFT_THRESHOLD) - passthroughable |= EAST | SOUTH | WEST - if(pixel_x > PASSABLE_SHIFT_THRESHOLD) - passthroughable |= NORTH | SOUTH | WEST - if(pixel_y < -PASSABLE_SHIFT_THRESHOLD) - passthroughable |= NORTH | EAST | WEST - if(pixel_x < -PASSABLE_SHIFT_THRESHOLD) - passthroughable |= NORTH | EAST | SOUTH - -/mob/living/CanAllowThrough(atom/movable/mover, border_dir) - // Make sure to not allow projectiles of any kind past where they normally wouldn't. - if(!istype(mover, /obj/projectile) && !mover.throwing && passthroughable & border_dir) - return TRUE - return ..() - -#undef MAXIMUM_PIXEL_SHIFT -#undef PASSABLE_SHIFT_THRESHOLD diff --git a/modular_skyrat/modules/pixel_shift/code/pixel_shift_component.dm b/modular_skyrat/modules/pixel_shift/code/pixel_shift_component.dm new file mode 100644 index 00000000000..9603d3d5a20 --- /dev/null +++ b/modular_skyrat/modules/pixel_shift/code/pixel_shift_component.dm @@ -0,0 +1,100 @@ +/datum/component/pixel_shift + dupe_mode = COMPONENT_DUPE_UNIQUE + /// Whether the mob is pixel shifted or not + var/is_shifted = FALSE + /// If we are in the shifting setting. + var/shifting = TRUE + /// Takes the four cardinal direction defines. Any atoms moving into this atom's tile will be allowed to from the added directions. + var/passthroughable = NONE + /// The maximum amount of pixels allowed to move in the turf. + var/maximum_pixel_shift = 16 + /// The amount of pixel shift required to make the parent passthroughable. + var/passable_shift_threshold = 8 + +/datum/component/pixel_shift/Initialize(...) + . = ..() + if(!isliving(parent)) + return COMPONENT_INCOMPATIBLE + +/datum/component/pixel_shift/RegisterWithParent() + RegisterSignal(parent, COMSIG_KB_MOB_PIXEL_SHIFT_DOWN, PROC_REF(pixel_shift_down)) + RegisterSignal(parent, COMSIG_KB_MOB_PIXEL_SHIFT_UP, PROC_REF(pixel_shift_up)) + RegisterSignals(parent, list(COMSIG_LIVING_RESET_PULL_OFFSETS, COMSIG_LIVING_SET_PULL_OFFSET, COMSIG_MOVABLE_MOVED), PROC_REF(unpixel_shift)) + RegisterSignal(parent, COMSIG_MOB_CLIENT_PRE_LIVING_MOVE, PROC_REF(pre_move_check)) + RegisterSignal(parent, COMSIG_LIVING_CAN_ALLOW_THROUGH, PROC_REF(check_passable)) + +/datum/component/pixel_shift/UnregisterFromParent() + UnregisterSignal(parent, COMSIG_KB_MOB_PIXEL_SHIFT_DOWN) + UnregisterSignal(parent, COMSIG_KB_MOB_PIXEL_SHIFT_UP) + UnregisterSignal(parent, COMSIG_LIVING_RESET_PULL_OFFSETS) + UnregisterSignal(parent, COMSIG_LIVING_SET_PULL_OFFSET) + UnregisterSignal(parent, COMSIG_MOVABLE_MOVED) + UnregisterSignal(parent, COMSIG_MOB_CLIENT_PRE_LIVING_MOVE) + UnregisterSignal(parent, COMSIG_LIVING_CAN_ALLOW_THROUGH) + +/// Overrides Move to Pixel Shift. +/datum/component/pixel_shift/proc/pre_move_check(mob/source, new_loc, direct) + SIGNAL_HANDLER + if(shifting) + pixel_shift(source, direct) + return COMSIG_MOB_CLIENT_BLOCK_PRE_LIVING_MOVE + +/// Checks if the parent is considered passthroughable from a direction. Projectiles will ignore the check and hit. +/datum/component/pixel_shift/proc/check_passable(mob/source, atom/movable/mover, border_dir) + SIGNAL_HANDLER + if(!isprojectile(mover) && !mover.throwing && passthroughable & border_dir) + return COMPONENT_LIVING_PASSABLE + +/// Activates Pixel Shift on Keybind down. Only Pixel Shift movement will be allowed. +/datum/component/pixel_shift/proc/pixel_shift_down() + SIGNAL_HANDLER + shifting = TRUE + return COMSIG_KB_ACTIVATED + +/// Disables Pixel Shift on Keybind up. Allows to Move. +/datum/component/pixel_shift/proc/pixel_shift_up() + SIGNAL_HANDLER + shifting = FALSE + +/// Sets parent pixel offsets to default and deletes the component. +/datum/component/pixel_shift/proc/unpixel_shift() + SIGNAL_HANDLER + passthroughable = NONE + if(is_shifted) + var/mob/living/owner = parent + owner.pixel_x = owner.body_position_pixel_x_offset + owner.base_pixel_x + owner.pixel_y = owner.body_position_pixel_y_offset + owner.base_pixel_y + qdel(src) + +/// In-turf pixel movement which can allow things to pass through if the threshold is met. +/datum/component/pixel_shift/proc/pixel_shift(mob/source, direct) + passthroughable = NONE + var/mob/living/owner = parent + switch(direct) + if(NORTH) + if(owner.pixel_y <= maximum_pixel_shift + owner.base_pixel_y) + owner.pixel_y++ + is_shifted = TRUE + if(EAST) + if(owner.pixel_x <= maximum_pixel_shift + owner.base_pixel_x) + owner.pixel_x++ + is_shifted = TRUE + if(SOUTH) + if(owner.pixel_y >= -maximum_pixel_shift + owner.base_pixel_y) + owner.pixel_y-- + is_shifted = TRUE + if(WEST) + if(owner.pixel_x >= -maximum_pixel_shift + owner.base_pixel_x) + owner.pixel_x-- + is_shifted = TRUE + + // Yes, I know this sets it to true for everything if more than one is matched. + // Movement doesn't check diagonals, and instead just checks EAST or WEST, depending on where you are for those. + if(owner.pixel_y > passable_shift_threshold) + passthroughable |= EAST | SOUTH | WEST + else if(owner.pixel_y < -passable_shift_threshold) + passthroughable |= NORTH | EAST | WEST + if(owner.pixel_x > passable_shift_threshold) + passthroughable |= NORTH | SOUTH | WEST + else if(owner.pixel_x < -passable_shift_threshold) + passthroughable |= NORTH | EAST | SOUTH diff --git a/modular_skyrat/modules/pixel_shift/code/pixel_shift_keybind.dm b/modular_skyrat/modules/pixel_shift/code/pixel_shift_keybind.dm new file mode 100644 index 00000000000..2375b350a33 --- /dev/null +++ b/modular_skyrat/modules/pixel_shift/code/pixel_shift_keybind.dm @@ -0,0 +1,17 @@ +/datum/keybinding/mob/pixel_shift + hotkey_keys = list("B") + name = "pixel_shift" + full_name = "Pixel Shift" + description = "Shift your characters offset." + category = CATEGORY_MOVEMENT + keybind_signal = COMSIG_KB_MOB_PIXEL_SHIFT_DOWN + +/datum/keybinding/mob/pixel_shift/down(client/user) + . = ..() + if(.) + return + user.mob.add_pixel_shift_component() + +/datum/keybinding/mob/pixel_shift/up(client/user) + . = ..() + SEND_SIGNAL(user.mob, COMSIG_KB_MOB_PIXEL_SHIFT_UP) diff --git a/modular_skyrat/modules/pixel_shift/code/pixel_shift_mob.dm b/modular_skyrat/modules/pixel_shift/code/pixel_shift_mob.dm new file mode 100644 index 00000000000..dbdd1e8d83f --- /dev/null +++ b/modular_skyrat/modules/pixel_shift/code/pixel_shift_mob.dm @@ -0,0 +1,6 @@ +/// Adds pixel_shift component on call. Default proc does nothing. +/mob/proc/add_pixel_shift_component() + return + +/mob/living/add_pixel_shift_component() + AddComponent(/datum/component/pixel_shift) diff --git a/modular_skyrat/modules/pixel_shift/readme.md b/modular_skyrat/modules/pixel_shift/readme.md index acca12e7d03..296058a4141 100644 --- a/modular_skyrat/modules/pixel_shift/readme.md +++ b/modular_skyrat/modules/pixel_shift/readme.md @@ -1,3 +1,5 @@ +https://github.com/Skyrat-SS13/Skyrat-tg/pull/870 + ## Title: Pixel shifting for RP positioning MODULE ID: PIXEL_SHIFT @@ -6,20 +8,27 @@ MODULE ID: PIXEL_SHIFT Adds the ability for living mobs to shift their sprite to fit an RP situation better (standing against a wall for example). Not appended to proc due to it being a busy proc -### TG Proc Changes: +### TG Proc/File Changes: - - ADDITION: \code\modules\mob\living > /mob/living/Moved() - - CHANGE: Skyrat-tg\code\datums\keybinding\mob.dm > /datum/keybinding/mob/prevent_movement - Keybind changed to ctrl. +- N/A + +### Modular Overrides: + +- `modular_skyrat/master_files/code/datums/keybinding/mob.dm`: `var/list/hotkey_keys` +- `modular_skyrat/master_files/code/modules/mob/living/living.dm`: `proc/set_pull_offsets`, `proc/reset_pull_offsets` +- `modular_skyrat/master_files/code/modules/mob/living/living_movement.dm`: `proc/CanAllowThrough` ### Defines: - - Skyrat-tg\code\modules\mob\mob_movement.dm > /client/Move(n, direct) +- `code/__DEFINES/~skyrat_defines/keybindings.dm`: `COMSIG_KB_MOB_PIXEL_SHIFT_DOWN`, `COMSIG_KB_MOB_PIXEL_SHIFT_UP` +- `code/__DEFINES/~skyrat_defines/living.dm`: `COMSIG_LIVING_SET_PULL_OFFSET`, `COMSIG_LIVING_RESET_PULL_OFFSETS`, `COMSIG_LIVING_CAN_ALLOW_THROUGH`, `COMPONENT_LIVING_PASSABLE` -### Included files: +### Included files that are not contained in this module: -N/A +- N/A ### Credits: Azarak - Porting Gandalf2k15 - Refactoring +Larentoun - Moved to Component diff --git a/tgstation.dme b/tgstation.dme index 3ad1d627cc1..7e88c9cfa6a 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -396,6 +396,7 @@ #include "code\__DEFINES\~skyrat_defines\lazy_templates.dm" #include "code\__DEFINES\~skyrat_defines\lewd_defines.dm" #include "code\__DEFINES\~skyrat_defines\liquids.dm" +#include "code\__DEFINES\~skyrat_defines\living.dm" #include "code\__DEFINES\~skyrat_defines\loadouts.dm" #include "code\__DEFINES\~skyrat_defines\logging.dm" #include "code\__DEFINES\~skyrat_defines\manufacturer_strings.dm" @@ -5600,6 +5601,7 @@ #include "modular_skyrat\master_files\code\datums\id_trim\jobs.dm" #include "modular_skyrat\master_files\code\datums\id_trim\solfed.dm" #include "modular_skyrat\master_files\code\datums\id_trim\syndicate.dm" +#include "modular_skyrat\master_files\code\datums\keybinding\mob.dm" #include "modular_skyrat\master_files\code\datums\mood_events\generic_negative_events.dm" #include "modular_skyrat\master_files\code\datums\mood_events\needs_events.dm" #include "modular_skyrat\master_files\code\datums\mutations\_mutations.dm" @@ -5778,7 +5780,9 @@ #include "modular_skyrat\master_files\code\modules\mob\living\blood.dm" #include "modular_skyrat\master_files\code\modules\mob\living\emote_popup.dm" #include "modular_skyrat\master_files\code\modules\mob\living\examine_tgui.dm" +#include "modular_skyrat\master_files\code\modules\mob\living\living.dm" #include "modular_skyrat\master_files\code\modules\mob\living\living_defines.dm" +#include "modular_skyrat\master_files\code\modules\mob\living\living_movement.dm" #include "modular_skyrat\master_files\code\modules\mob\living\carbon\death.dm" #include "modular_skyrat\master_files\code\modules\mob\living\carbon\human.dm" #include "modular_skyrat\master_files\code\modules\mob\living\carbon\human_helpers.dm" @@ -7075,7 +7079,9 @@ #include "modular_skyrat\modules\oversized\code\door.dm" #include "modular_skyrat\modules\oversized\code\oversized_quirk.dm" #include "modular_skyrat\modules\panicbunker\code\panicbunker.dm" -#include "modular_skyrat\modules\pixel_shift\code\pixel_shift.dm" +#include "modular_skyrat\modules\pixel_shift\code\pixel_shift_component.dm" +#include "modular_skyrat\modules\pixel_shift\code\pixel_shift_keybind.dm" +#include "modular_skyrat\modules\pixel_shift\code\pixel_shift_mob.dm" #include "modular_skyrat\modules\pod_locking\pod_locking.dm" #include "modular_skyrat\modules\polarized_windows\capacitor.dm" #include "modular_skyrat\modules\polarized_windows\polarization_controller.dm"