Removes ComponentActivated in favor of callbacks

This commit is contained in:
Jordan Brown
2017-12-05 16:41:56 -05:00
committed by CitadelStationBot
parent a6aa181161
commit e1f658a50d
14 changed files with 190 additions and 98 deletions
+9 -13
View File
@@ -16,20 +16,19 @@
var/list/materials
var/show_on_examine
var/list/allowed_typecache
var/last_inserted_type
var/last_inserted_id
var/last_amount_inserted
var/last_insert_success
var/precise_insertion = FALSE
var/datum/callback/precondition
var/datum/callback/after_insert
/datum/component/material_container/Initialize(list/mat_list, max_amt = 0, _show_on_examine = FALSE, list/allowed_types, datum/callback/_precondition)
/datum/component/material_container/Initialize(list/mat_list, max_amt = 0, _show_on_examine = FALSE, list/allowed_types, datum/callback/_precondition, datum/callback/_after_insert)
materials = list()
max_amount = max(0, max_amt)
show_on_examine = _show_on_examine
if(allowed_types)
allowed_typecache = typecacheof(allowed_types)
precondition = _precondition
after_insert = _after_insert
RegisterSignal(COMSIG_PARENT_ATTACKBY, .proc/OnAttackBy)
RegisterSignal(COMSIG_PARENT_EXAMINE, .proc/OnExamine)
@@ -57,8 +56,7 @@
if((I.flags_2 & (HOLOGRAM_2 | NO_MAT_REDEMPTION_2)) || (tc && !is_type_in_typecache(I, tc)))
to_chat(user, "<span class='warning'>[parent] won't accept [I]!</span>")
return
. = COMPONENT_ACTIVATED | COMPONENT_NO_AFTERATTACK
last_insert_success = FALSE
. = COMPONENT_NO_AFTERATTACK
var/datum/callback/pc = precondition
if(pc && !pc.Invoke())
return
@@ -69,11 +67,12 @@
if(!has_space(material_amount))
to_chat(user, "<span class='warning'>[parent] is full. Please remove metal or glass from [parent] in order to insert more.</span>")
return
INVOKE_ASYNC(src, .proc/user_insert, I, user)
user_insert(I, user)
/datum/component/material_container/proc/user_insert(obj/item/I, mob/living/user)
var/requested_amount
if(istype(I, /obj/item/stack) && precise_insertion)
var/Itype = I.type
if(ispath(Itype, /obj/item/stack) && precise_insertion)
var/atom/current_parent = parent
requested_amount = input(user, "How much do you want to insert?", "Inserting sheets") as num|null
if(isnull(requested_amount) || (requested_amount <= 0))
@@ -85,7 +84,6 @@
return
var/inserted = insert_item(I, stack_amt = requested_amount)
if(inserted)
last_insert_success = TRUE
if(istype(I, /obj/item/stack))
to_chat(user, "<span class='notice'>You insert [inserted] sheet[inserted>1 ? "s" : ""] into [parent].</span>")
if(!QDELETED(I))
@@ -93,6 +91,8 @@
else
to_chat(user, "<span class='notice'>You insert a material total of [inserted] into [parent].</span>")
qdel(I)
if(after_insert)
after_insert.Invoke(Itype, last_inserted_id, inserted)
else
user.put_in_active_hand(I)
@@ -132,9 +132,7 @@
return FALSE
last_inserted_id = insert_materials(S,amt)
last_inserted_type = S.type
S.use(amt)
last_amount_inserted = amt
return amt
/datum/component/material_container/proc/insert_item(obj/item/I, multiplier = 1, stack_amt)
@@ -148,8 +146,6 @@
return FALSE
last_inserted_id = insert_materials(I, multiplier)
last_inserted_type = I.type
last_amount_inserted = material_amount
return material_amount
/datum/component/material_container/proc/insert_materials(obj/item/I, multiplier = 1) //for internal usage only