Files
Bubberstation/code/datums/components/itempicky.dm
Watermelon914 375a20e49b Refactors most spans into span procs (#59645)
Converts most spans into span procs. Mostly used regex for this and sorted out any compile time errors afterwards so there could be some bugs.
Was initially going to do defines, but ninja said to make it into a proc, and if there's any overhead, they can easily be changed to defines.

Makes it easier to control the formatting and prevents typos when creating spans as it'll runtime if you misspell instead of silently failing.
Reduces the code you need to write when writing spans, as you don't need to close the span as that's automatically handled by the proc.

(Note from Lemon: This should be converted to defines once we update the minimum version to 514. Didn't do it now because byond pain and such)
2021-06-14 13:03:53 -07:00

36 lines
1.2 KiB
Plaintext

/// You can only hold whitelisted items
/datum/component/itempicky
can_transfer = TRUE
/// Typecache of items you can hold
var/whitelist
/// Message shown if you try to pick up an item not in the whitelist
var/message = "You don't like %TARGET, why would you hold it?"
/datum/component/itempicky/Initialize(whitelist, message)
if(!ismob(parent))
return COMPONENT_INCOMPATIBLE
src.whitelist = whitelist
if(message)
src.message = message
/datum/component/itempicky/RegisterWithParent()
RegisterSignal(parent, COMSIG_LIVING_TRY_PUT_IN_HAND, .proc/particularly)
/datum/component/itempicky/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_LIVING_TRY_PUT_IN_HAND)
/datum/component/itempicky/PostTransfer()
if(!ismob(parent))
return COMPONENT_INCOMPATIBLE
/datum/component/itempicky/InheritComponent(datum/component/itempicky/friend, i_am_original, list/arguments)
if(i_am_original)
whitelist = friend.whitelist
message = friend.message
/datum/component/itempicky/proc/particularly(datum/source, obj/item/pickingup)
SIGNAL_HANDLER
if(!is_type_in_typecache(pickingup, whitelist))
to_chat(source, span_warning("[replacetext(message, "%TARGET", pickingup)]"))
return COMPONENT_LIVING_CANT_PUT_IN_HAND