Files
Bubberstation/code/datums/elements/food/processable.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

44 lines
2.0 KiB
Plaintext

// If an item has the processable item, it can be processed into another item with a specific tool. This adds generic behavior for those actions to make it easier to set-up generically.
/datum/element/processable
element_flags = ELEMENT_BESPOKE
id_arg_index = 2
///The type of atom this creates when the processing recipe is used.
var/atom/result_atom_type
///The tool behaviour for this processing recipe
var/tool_behaviour
///Time to process the atom
var/time_to_process
///Amount of the resulting actor this will create
var/amount_created
/datum/element/processable/Attach(datum/target, tool_behaviour, result_atom_type, amount_created = 3, time_to_process = 20)
. = ..()
if(!isatom(target))
return ELEMENT_INCOMPATIBLE
src.tool_behaviour = tool_behaviour
src.amount_created = amount_created
src.time_to_process = time_to_process
src.result_atom_type = result_atom_type
RegisterSignal(target, COMSIG_ATOM_TOOL_ACT(tool_behaviour), .proc/try_process)
RegisterSignal(target, COMSIG_PARENT_EXAMINE, .proc/OnExamine)
/datum/element/processable/Detach(datum/target)
. = ..()
UnregisterSignal(target, list(COMSIG_ATOM_TOOL_ACT(tool_behaviour), COMSIG_PARENT_EXAMINE))
/datum/element/processable/proc/try_process(datum/source, mob/living/user, obj/item/I, list/mutable_recipes)
SIGNAL_HANDLER
mutable_recipes += list(list(TOOL_PROCESSING_RESULT = result_atom_type, TOOL_PROCESSING_AMOUNT = amount_created, TOOL_PROCESSING_TIME = time_to_process))
///So people know what the frick they're doing without reading from a wiki page (I mean they will inevitably but i'm trying to help, ok?)
/datum/element/processable/proc/OnExamine(atom/source, mob/user, list/examine_list)
SIGNAL_HANDLER
if(amount_created > 1)
examine_list += span_notice("It can be turned into [amount_created] [initial(result_atom_type.name)]s with <b>[tool_behaviour_name(tool_behaviour)]</b>!")
else
examine_list += span_notice("It can be turned into \a [initial(result_atom_type.name)] with <b>[tool_behaviour_name(tool_behaviour)]</b>!")