Merge pull request #4236 from Citadel-Station-13/upstream-merge-33274

[MIRROR] Removes ComponentActivated in favor of callbacks
This commit is contained in:
deathride58
2017-12-06 03:53:35 +00:00
committed by GitHub
14 changed files with 79 additions and 151 deletions

View File

@@ -10,11 +10,6 @@
#define COMPONENT_DUPE_ALLOWED 1 //duplicates allowed
#define COMPONENT_DUPE_UNIQUE 2 //new component is deleted
// Signal return value flags
// The other defines are under the signal they're used in
#define COMPONENT_ACTIVATED 1 // call parent.ComponentActivated(comp) and component.AfterComponentActivated()
// All signals. Format:
// When the signal is called: (signal arguments)
@@ -28,7 +23,7 @@
// /atom signals
#define COMSIG_PARENT_ATTACKBY "atom_attackby" //from base of atom/attackby(): (/obj/item, /mob/living, params)
#define COMPONENT_NO_AFTERATTACK 2 //Return this in response if you don't want afterattack to be called
#define COMPONENT_NO_AFTERATTACK 1 //Return this in response if you don't want afterattack to be called
#define COMSIG_ATOM_HULK_ATTACK "hulk_attack" //from base of atom/attack_hulk(): (/mob/living/carbon/human)
#define COMSIG_PARENT_EXAMINE "atom_examine" //from base of atom/examine(): (/mob)
#define COMSIG_ATOM_ENTERED "atom_entered" //from base of atom/Entered(): (/atom/movable, /atom)

View File

@@ -142,10 +142,6 @@
/datum/component/proc/OnTransfer(datum/new_parent)
return
/datum/component/proc/AfterComponentActivated()
set waitfor = FALSE
return
/datum/component/proc/_GetInverseTypeList(our_type = type)
#if DM_VERSION >= 513
#warning 512 is definitely stable now, remove the old code
@@ -176,28 +172,16 @@
var/datum/callback/CB = C.signal_procs[sigtype]
if(!CB)
return NONE
. = CB.InvokeAsync(arglist(arguments))
if(. & COMPONENT_ACTIVATED)
ComponentActivated(C)
C.AfterComponentActivated()
else
. = NONE
for(var/I in target)
var/datum/component/C = I
if(!C.enabled)
continue
var/datum/callback/CB = C.signal_procs[sigtype]
if(!CB)
continue
var/retval = CB.InvokeAsync(arglist(arguments))
. |= retval
if(retval & COMPONENT_ACTIVATED)
ComponentActivated(C)
C.AfterComponentActivated()
/datum/proc/ComponentActivated(datum/component/C)
set waitfor = FALSE
return
return CB.InvokeAsync(arglist(arguments))
. = NONE
for(var/I in target)
var/datum/component/C = I
if(!C.enabled)
continue
var/datum/callback/CB = C.signal_procs[sigtype]
if(!CB)
continue
. |= CB.InvokeAsync(arglist(arguments))
/datum/proc/GetComponent(c_type)
var/list/dc = datum_components

View File

@@ -3,10 +3,12 @@
var/list/archdrops
var/prob2drop
var/dug
var/datum/callback/callback
/datum/component/archaeology/Initialize(_prob2drop, list/_archdrops = list())
/datum/component/archaeology/Initialize(_prob2drop, list/_archdrops = list(), datum/callback/_callback)
prob2drop = Clamp(_prob2drop, 0, 100)
archdrops = _archdrops
callback = _callback
RegisterSignal(COMSIG_PARENT_ATTACKBY,.proc/Dig)
RegisterSignal(COMSIG_ATOM_EX_ACT, .proc/BombDig)
RegisterSignal(COMSIG_ATOM_SING_PULL, .proc/SingDig)
@@ -67,6 +69,8 @@
if(OT.slowdown) //Things like snow slow you down until you dig them.
OT.slowdown = 0
dug = TRUE
if(callback)
callback.Invoke()
/datum/component/archaeology/proc/SingDig(S, current_size)
switch(current_size)

View File

@@ -9,5 +9,4 @@
var/mob/living/carbon/victim = AM
if(istype(victim))
for(var/datum/disease/D in diseases)
victim.ContactContractDisease(D, "feet")
return COMPONENT_ACTIVATED
victim.ContactContractDisease(D, "feet")

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

View File

@@ -1,18 +1,15 @@
/datum/component/slippery
var/intensity
var/lube_flags
var/mob/slip_victim
var/datum/callback/callback
/datum/component/slippery/Initialize(_intensity, _lube_flags = NONE)
/datum/component/slippery/Initialize(_intensity, _lube_flags = NONE, datum/callback/_callback)
intensity = max(_intensity, 0)
lube_flags = _lube_flags
callback = _callback
RegisterSignal(list(COMSIG_MOVABLE_CROSSED, COMSIG_ATOM_ENTERED), .proc/Slip)
/datum/component/slippery/proc/Slip(atom/movable/AM)
var/mob/victim = AM
if(istype(victim) && !victim.is_flying() && victim.slip(intensity, parent, lube_flags))
slip_victim = victim
return COMPONENT_ACTIVATED
/datum/component/slippery/AfterComponentActivated()
slip_victim = null
if(istype(victim) && !victim.is_flying() && victim.slip(intensity, parent, lube_flags) && callback)
callback.Invoke(victim)

View File

@@ -46,7 +46,7 @@
)
/obj/machinery/autolathe/Initialize()
AddComponent(/datum/component/material_container, list(MAT_METAL, MAT_GLASS))
AddComponent(/datum/component/material_container, list(MAT_METAL, MAT_GLASS), 0, FALSE, null, null, CALLBACK(src, .proc/AfterMaterialInsert))
. = ..()
wires = new /datum/wires/autolathe(src)
@@ -124,23 +124,17 @@
return ..()
/obj/machinery/mecha_part_fabricator/ComponentActivated(datum/component/C)
..()
if(istype(C, /datum/component/material_container))
var/datum/component/material_container/M = C
if(!M.last_insert_success)
return
var/lit = M.last_inserted_type
if(ispath(lit, /obj/item/ore/bluespace_crystal))
use_power(max(500,M.last_amount_inserted/10))
else
switch(M.last_inserted_id)
if (MAT_METAL)
flick("autolathe_o",src)//plays metal insertion animation
if (MAT_GLASS)
flick("autolathe_r",src)//plays glass insertion animation
use_power(M.last_amount_inserted*100)
updateUsrDialog()
/obj/machinery/autolathe/proc/AfterMaterialInsert(type_inserted, id_inserted, amount_inserted)
if(ispath(type_inserted, /obj/item/ore/bluespace_crystal))
use_power(max(500, amount_inserted / 10))
else
switch(id_inserted)
if (MAT_METAL)
flick("autolathe_o",src)//plays metal insertion animation
if (MAT_GLASS)
flick("autolathe_r",src)//plays glass insertion animation
use_power(amount_inserted * 100)
updateUsrDialog()
/obj/machinery/autolathe/Topic(href, href_list)
if(..())

View File

@@ -35,12 +35,11 @@
)
/obj/machinery/mecha_part_fabricator/Initialize()
var/datum/component/material_container/materials = AddComponent(/datum/component/material_container,
list(MAT_METAL, MAT_GLASS, MAT_SILVER, MAT_GOLD, MAT_DIAMOND, MAT_PLASMA, MAT_URANIUM, MAT_BANANIUM, MAT_TITANIUM, MAT_BLUESPACE),
FALSE, list(/obj/item/stack, /obj/item/ore/bluespace_crystal), CALLBACK(src, .proc/is_insertion_ready))
materials.precise_insertion = TRUE
. = ..()
files = new /datum/research(src) //Setup the research data holder.
var/datum/component/material_container/materials = AddComponent(/datum/component/material_container,
list(MAT_METAL, MAT_GLASS, MAT_SILVER, MAT_GOLD, MAT_DIAMOND, MAT_PLASMA, MAT_URANIUM, MAT_BANANIUM, MAT_TITANIUM, MAT_BLUESPACE),
FALSE, list(/obj/item/stack, /obj/item/ore/bluespace_crystal), CALLBACK(src, .proc/is_insertion_ready), CALLBACK(src, .proc/AfterMaterialInsert))
materials.precise_insertion = TRUE
return ..()
/obj/machinery/mecha_part_fabricator/RefreshParts()
var/T = 0
@@ -415,16 +414,11 @@
materials.retrieve_all()
..()
/obj/machinery/mecha_part_fabricator/ComponentActivated(datum/component/C)
..()
if(istype(C, /datum/component/material_container))
var/datum/component/material_container/M = C
if(!M.last_insert_success)
return
var/stack_name = material2name(M.last_inserted_id)
add_overlay("fab-load-[stack_name]")
addtimer(CALLBACK(src, /atom/proc/cut_overlay, "fab-load-[stack_name]"), 10)
updateUsrDialog()
/obj/machinery/mecha_part_fabricator/proc/AfterMaterialInsert(type_inserted, id_inserted, amount_inserted)
var/stack_name = material2name(id_inserted)
add_overlay("fab-load-[stack_name]")
addtimer(CALLBACK(src, /atom/proc/cut_overlay, "fab-load-[stack_name]"), 10)
updateUsrDialog()
/obj/machinery/mecha_part_fabricator/attackby(obj/item/W, mob/user, params)
if(default_deconstruction_screwdriver(user, "fab-o", "fab-idle", W))

View File

@@ -10,16 +10,11 @@
/obj/item/device/pda/clown/Initialize()
. = ..()
AddComponent(/datum/component/slippery, 120, NO_SLIP_WHEN_WALKING)
AddComponent(/datum/component/slippery, 120, NO_SLIP_WHEN_WALKING, CALLBACK(src, .proc/AfterSlip))
/obj/item/device/pda/clown/ComponentActivated(datum/component/C)
..()
var/datum/component/slippery/S = C
if(!istype(S))
return
var/mob/living/carbon/human/M = S.slip_victim
if (istype(M) && (M.real_name != src.owner))
slipvictims |= M
/obj/item/device/pda/clown/proc/AfterSlip(mob/living/carbon/human/M)
if (istype(M) && (M.real_name != owner))
slipvictims |=M
var/obj/item/cartridge/virus/clown/cart = cartridge
if(istype(cart) && cart.charges < 5)
cart.charges++

View File

@@ -275,17 +275,12 @@
else
qdel(GetComponent(/datum/component/slippery))
return
var/datum/component/slippery/S = LoadComponent(/datum/component/slippery)
var/datum/component/slippery/S = LoadComponent(/datum/component/slippery, NONE, CALLBACK(src, .proc/AfterSlip))
S.intensity = intensity
S.lube_flags = lube_flags
/turf/open/ComponentActivated(datum/component/C)
..()
var/datum/component/slippery/S = C
if(!istype(S))
return
/turf/open/proc/AfterSlip(mob/living/L)
if(wet == TURF_WET_LUBE)
var/mob/living/L = S.slip_victim
L.confused = max(L.confused, 8)
/turf/open/proc/MakeDry(wet_setting = TURF_WET_WATER)

View File

@@ -87,6 +87,9 @@
/turf/open/floor/plating/asteroid/basalt/Initialize()
. = ..()
set_basalt_light(src)
GET_COMPONENT(arch, /datum/component/archaeology)
ASSERT(isnull(arch.callback))
arch.callback = CALLBACK(src, /atom/proc/set_light, 0)
/proc/set_basalt_light(turf/open/floor/B)
switch(B.icon_state)
@@ -95,12 +98,6 @@
if("basalt5", "basalt9")
B.set_light(1.4, 0.6, LIGHT_COLOR_LAVA) //barely anything!
/turf/open/floor/plating/asteroid/basalt/ComponentActivated(datum/component/C)
..()
if(istype(C, /datum/component/archaeology))
set_light(0)
///////Surface. The surface is warm, but survivable without a suit. Internals are required. The floors break to chasms, which drop you into the underground.
/turf/open/floor/plating/asteroid/basalt/lava_land_surface

View File

@@ -27,9 +27,11 @@ using metal and glass, it uses glass and reagents (usually sulfuric acis).
"Computer Parts"
)
var/datum/component/material_container/materials
/obj/machinery/r_n_d/circuit_imprinter/Initialize()
var/datum/component/material_container/materials = AddComponent(/datum/component/material_container, list(MAT_GLASS, MAT_GOLD, MAT_DIAMOND, MAT_METAL, MAT_BLUESPACE),
FALSE, list(/obj/item/stack, /obj/item/ore/bluespace_crystal), CALLBACK(src, .proc/is_insertion_ready))
materials = AddComponent(/datum/component/material_container, list(MAT_GLASS, MAT_GOLD, MAT_DIAMOND, MAT_METAL, MAT_BLUESPACE),
FALSE, list(/obj/item/stack, /obj/item/ore/bluespace_crystal), CALLBACK(src, .proc/is_insertion_ready), CALLBACK(src, .proc/AfterMaterialInsert))
materials.precise_insertion = TRUE
create_reagents(0)
return ..()
@@ -76,21 +78,3 @@ using metal and glass, it uses glass and reagents (usually sulfuric acis).
/obj/machinery/r_n_d/circuit_imprinter/disconnect_console()
linked_console.linked_imprinter = null
..()
/obj/machinery/r_n_d/circuit_imprinter/ComponentActivated(datum/component/C)
..()
if(istype(C, /datum/component/material_container))
var/datum/component/material_container/M = C
if(!M.last_insert_success)
return
var/lit = M.last_inserted_type
var/stack_name
if(ispath(lit, /obj/item/ore/bluespace_crystal))
stack_name = "bluespace"
use_power(MINERAL_MATERIAL_AMOUNT / 10)
else
var/obj/item/stack/S = lit
stack_name = initial(S.name)
use_power(max(1000, (MINERAL_MATERIAL_AMOUNT * M.last_amount_inserted / 10)))
add_overlay("protolathe_[stack_name]")
addtimer(CALLBACK(src, /atom/proc/cut_overlay, "protolathe_[stack_name]"), 10)

View File

@@ -35,7 +35,7 @@ Note: Must be placed west/left of and R&D console to function.
create_reagents(0)
var/datum/component/material_container/materials = AddComponent(/datum/component/material_container,
list(MAT_METAL, MAT_GLASS, MAT_SILVER, MAT_GOLD, MAT_DIAMOND, MAT_PLASMA, MAT_URANIUM, MAT_BANANIUM, MAT_TITANIUM, MAT_BLUESPACE),
FALSE, list(/obj/item/stack, /obj/item/ore/bluespace_crystal), CALLBACK(src, .proc/is_insertion_ready))
FALSE, list(/obj/item/stack, /obj/item/ore/bluespace_crystal), CALLBACK(src, .proc/is_insertion_ready), CALLBACK(src, .proc/AfterMaterialInsert))
materials.precise_insertion = TRUE
return ..()
@@ -77,21 +77,3 @@ Note: Must be placed west/left of and R&D console to function.
/obj/machinery/r_n_d/protolathe/disconnect_console()
linked_console.linked_lathe = null
..()
/obj/machinery/r_n_d/protolathe/ComponentActivated(datum/component/C)
..()
if(istype(C, /datum/component/material_container))
var/datum/component/material_container/M = C
if(!M.last_insert_success)
return
var/lit = M.last_inserted_type
var/stack_name
if(ispath(lit, /obj/item/ore/bluespace_crystal))
stack_name = "bluespace"
use_power(MINERAL_MATERIAL_AMOUNT / 10)
else
var/obj/item/stack/S = lit
stack_name = initial(S.name)
use_power(max(1000, (MINERAL_MATERIAL_AMOUNT * M.last_amount_inserted / 10)))
add_overlay("protolathe_[stack_name]")
addtimer(CALLBACK(src, /atom/proc/cut_overlay, "protolathe_[stack_name]"), 10)

View File

@@ -106,3 +106,15 @@
if(loaded_item)
loaded_item.forceMove(loc)
..()
/obj/machinery/r_n_d/proc/AfterMaterialInsert(type_inserted, id_inserted, amount_inserted)
var/stack_name
if(ispath(type_inserted, /obj/item/ore/bluespace_crystal))
stack_name = "bluespace"
use_power(MINERAL_MATERIAL_AMOUNT / 10)
else
var/obj/item/stack/S = type_inserted
stack_name = initial(S.name)
use_power(max(1000, (MINERAL_MATERIAL_AMOUNT * amount_inserted / 10)))
add_overlay("protolathe_[stack_name]")
addtimer(CALLBACK(src, /atom/proc/cut_overlay, "protolathe_[stack_name]"), 10)