mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-31 20:11:56 +00:00
## About The Pull Request Adds /datum/element/sticker, and /datum/component/attached_sticker Sticker items now mostly operate off /datum/element/sticker The sticker element, hooks the whole "attach to stuff" and adds the attached_sticker component to its target The attached_sticker component, adds the overlay, hooks the clean and on-fire signals. ## Why It's Good For The Game Allows to check if a sticker is present on an object (which I will use later) Code is probably cleaner??? ## Changelog 🆑 refactor: Stickers use a component and an element now to do their sticking /🆑
46 lines
1.7 KiB
Plaintext
46 lines
1.7 KiB
Plaintext
/datum/element/sticker
|
|
///The typepath for our attached sticker component
|
|
var/stick_type = /datum/component/attached_sticker
|
|
///If TRUE, our attached_sticker can be washed off
|
|
var/washable = TRUE
|
|
|
|
/datum/element/sticker/Attach(datum/target, sticker_type, cleanable=TRUE)
|
|
. = ..()
|
|
if(!isitem(target))
|
|
return ELEMENT_INCOMPATIBLE
|
|
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(on_afterattack))
|
|
RegisterSignal(target, COMSIG_MOVABLE_IMPACT, PROC_REF(on_throw_impact))
|
|
if(sticker_type)
|
|
stick_type = sticker_type
|
|
washable = cleanable
|
|
|
|
/datum/element/sticker/Detach(datum/source)
|
|
. = ..()
|
|
UnregisterSignal(source, list(COMSIG_ITEM_AFTERATTACK, COMSIG_MOVABLE_IMPACT))
|
|
|
|
/datum/element/sticker/proc/on_afterattack(obj/item/source, atom/target, mob/living/user, prox, params)
|
|
SIGNAL_HANDLER
|
|
if(!prox)
|
|
return
|
|
if(!isatom(target))
|
|
return
|
|
var/list/parameters = params2list(params)
|
|
if(!LAZYACCESS(parameters, ICON_X) || !LAZYACCESS(parameters, ICON_Y))
|
|
return
|
|
var/divided_size = world.icon_size / 2
|
|
var/px = text2num(LAZYACCESS(parameters, ICON_X)) - divided_size
|
|
var/py = text2num(LAZYACCESS(parameters, ICON_Y)) - divided_size
|
|
|
|
user.do_attack_animation(target)
|
|
do_stick(source, target, user, px, py)
|
|
|
|
///Add our stick_type to the target with px and py as pixel x and pixel y respectively
|
|
/datum/element/sticker/proc/do_stick(obj/item/source, atom/target, mob/living/user, px, py)
|
|
target.AddComponent(stick_type, px, py, source, user, washable)
|
|
|
|
/datum/element/sticker/proc/on_throw_impact(obj/item/source, atom/hit_atom, datum/thrownthing/throwingdatum)
|
|
SIGNAL_HANDLER
|
|
if(prob(50))
|
|
do_stick(source, hit_atom, null, rand(-7,7), rand(-7,7))
|
|
source.balloon_alert_to_viewers("the sticker lands on its sticky side!")
|