mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-02-04 05:18:12 +00:00
## About The Pull Request
Mouse drag & drop has been refactored into its own attack chain. The
flowchart below summarizes it

Brief summary of each proc is as follows
**1. `atom/MouseDrop()`**
- It is now non overridable. No subtype should ever touch this proc
because it performs 2 basic checks
a) Measures the time between mouse down & mouse release. If its less
than `LENIENCY_TIME`(0.1 seconds) then the operation is not considered a
drag but a simple click
b) Measures the distance squared between the drag start & end point. If
its less than `LENIENCY_DISTANCE`(16 pixels screen space) then the drag
is considered too small and is discarded
- These 2 sanity checks for drag & drop are applied across all
operations without fail
**2. `atom/base_mouse_drop_handler()`**
- This is where atoms handle mouse drag & drop inside the world. Ideally
it is non overridable in most cases because it also performs 2 checks
- Is the dragged object & the drop target adjacent to the player?.
Screen elements always return true for this case
- Additional checks can be enforced by `can_perform_action()` done only
on the dragged object. It uses the combined flags of
`interaction_flags_mouse_drop` for both the dragged object & drop target
to determine if the operation is feasible.
We do this only on the dragged object because if both the dragged object
& drop target are adjacent to the player then `can_perform_action()`
will return the same results when done on either object so it makes no
difference.
Checks can be bypassed via the `IGNORE_MOUSE_DROP_CHECKS` which is used
by huds & screen elements or in case you want to implement your own
unique checks
**3. `atom/mouse_drop_dragged()`**
- Called on the object that is being dragged, drop target passed here as
well, subtypes do their stuff here
- `COMSIG_MOUSEDROP_ONTO` is sent afterwards. It does not require
subtypes to call their parent proc
**4. `atom/mouse_drop_receive()`**
- Called on the drop target that is receiving the dragged object,
subtypes do their stuff here
- `COMSIG_MOUSEDROPPED_ONTO` is sent afterwards. It does not require
subtypes to call their parent proc
## Why It's Good For The Game
Implements basic sanity checks across all drag & drop operations. Allows
us to reduce code like this
8c8311e624/code/game/machinery/dna_scanner.dm (L144-L145)
Into this
```
if(!iscarbon(target))
return
```
I'm tired of seeing this code pattern `!Adjacent(user) ||
!user.Adjacent(target)` copy pasted all over the place. Let's just write
that at the atom level & be done with it
## Changelog
🆑
refactor: Mouse drag & drop attack chain has been refactored. Report any
bugs on GitHub
fix: You cannot close the cryo tube on yourself with Alt click like
before
/🆑
---------
Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
127 lines
3.4 KiB
Plaintext
127 lines
3.4 KiB
Plaintext
//Dead mobs can exist whenever. This is needful
|
|
|
|
INITIALIZE_IMMEDIATE(/mob/dead)
|
|
|
|
/mob/dead
|
|
sight = SEE_TURFS | SEE_MOBS | SEE_OBJS | SEE_SELF
|
|
move_resist = INFINITY
|
|
interaction_flags_atom = parent_type::interaction_flags_atom | INTERACT_ATOM_MOUSEDROP_IGNORE_CHECKS
|
|
throwforce = 0
|
|
|
|
/mob/dead/Initialize(mapload)
|
|
SHOULD_CALL_PARENT(FALSE)
|
|
if(flags_1 & INITIALIZED_1)
|
|
stack_trace("Warning: [src]([type]) initialized multiple times!")
|
|
flags_1 |= INITIALIZED_1
|
|
// Initial is non standard here, but ghosts move before they get here so it's needed. this is a cold path too so it's ok
|
|
SET_PLANE_IMPLICIT(src, initial(plane))
|
|
add_to_mob_list()
|
|
|
|
prepare_huds()
|
|
|
|
if(length(CONFIG_GET(keyed_list/cross_server)))
|
|
add_verb(src, /mob/dead/proc/server_hop)
|
|
set_focus(src)
|
|
become_hearing_sensitive()
|
|
log_mob_tag("TAG: [tag] CREATED: [key_name(src)] \[[src.type]\]")
|
|
return INITIALIZE_HINT_NORMAL
|
|
|
|
/mob/dead/canUseStorage()
|
|
return FALSE
|
|
|
|
/mob/dead/get_status_tab_items()
|
|
. = ..()
|
|
if(SSticker.HasRoundStarted())
|
|
return
|
|
var/time_remaining = SSticker.GetTimeLeft()
|
|
if(time_remaining > 0)
|
|
. += "Time To Start: [round(time_remaining/10)]s"
|
|
else if(time_remaining == -10)
|
|
. += "Time To Start: DELAYED"
|
|
else
|
|
. += "Time To Start: SOON"
|
|
|
|
. += "Players: [LAZYLEN(GLOB.clients)]"
|
|
if(client.holder)
|
|
. += "Players Ready: [SSticker.totalPlayersReady]"
|
|
. += "Admins Ready: [SSticker.total_admins_ready] / [length(GLOB.admins)]"
|
|
|
|
#define SERVER_HOPPER_TRAIT "server_hopper"
|
|
|
|
/mob/dead/proc/server_hop()
|
|
set category = "OOC"
|
|
set name = "Server Hop"
|
|
set desc= "Jump to the other server"
|
|
if(HAS_TRAIT(src, TRAIT_NO_TRANSFORM)) // in case the round is ending and a cinematic is already playing we don't wanna clash with that (yes i know)
|
|
return
|
|
var/list/our_id = CONFIG_GET(string/cross_comms_name)
|
|
var/list/csa = CONFIG_GET(keyed_list/cross_server) - our_id
|
|
var/pick
|
|
switch(length(csa))
|
|
if(0)
|
|
remove_verb(src, /mob/dead/proc/server_hop)
|
|
to_chat(src, span_notice("Server Hop has been disabled."))
|
|
if(1)
|
|
pick = csa[1]
|
|
else
|
|
pick = tgui_input_list(src, "Server to jump to", "Server Hop", csa)
|
|
|
|
if(isnull(pick))
|
|
return
|
|
|
|
var/addr = csa[pick]
|
|
|
|
if(tgui_alert(usr, "Jump to server [pick] ([addr])?", "Server Hop", list("Yes", "No")) != "Yes")
|
|
return
|
|
|
|
var/client/C = client
|
|
to_chat(C, span_notice("Sending you to [pick]."))
|
|
new /atom/movable/screen/splash(null, null, C)
|
|
|
|
ADD_TRAIT(src, TRAIT_NO_TRANSFORM, SERVER_HOPPER_TRAIT)
|
|
sleep(2.9 SECONDS) //let the animation play
|
|
REMOVE_TRAIT(src, TRAIT_NO_TRANSFORM, SERVER_HOPPER_TRAIT)
|
|
|
|
if(!C)
|
|
return
|
|
|
|
winset(src, null, "command=.options") //other wise the user never knows if byond is downloading resources
|
|
|
|
C << link("[addr]")
|
|
|
|
#undef SERVER_HOPPER_TRAIT
|
|
|
|
/**
|
|
* updates the Z level for dead players
|
|
* If they don't have a new z, we'll keep the old one, preventing bugs from ghosting and re-entering, among others
|
|
*/
|
|
/mob/dead/proc/update_z(new_z)
|
|
if(registered_z == new_z)
|
|
return
|
|
if(registered_z)
|
|
SSmobs.dead_players_by_zlevel[registered_z] -= src
|
|
if(isnull(client))
|
|
registered_z = null
|
|
return
|
|
registered_z = new_z
|
|
SSmobs.dead_players_by_zlevel[new_z] += src
|
|
|
|
/mob/dead/Login()
|
|
. = ..()
|
|
if(!. || !client)
|
|
return FALSE
|
|
var/turf/T = get_turf(src)
|
|
if (isturf(T))
|
|
update_z(T.z)
|
|
|
|
/mob/dead/auto_deadmin_on_login()
|
|
return
|
|
|
|
/mob/dead/Logout()
|
|
update_z(null)
|
|
return ..()
|
|
|
|
/mob/dead/on_changed_z_level(turf/old_turf, turf/new_turf, same_z_layer, notify_contents)
|
|
..()
|
|
update_z(new_turf?.z)
|