Port material containers to datum components (#29268)

* Ports /vg/'s component system

* Fix component signalling itself for addition

* Fix the list arrangement for removal

* Whoops

* Return the existing component if the created one was deleted

* These can't be ints

* ,

* returning TRUE from a callback will mark the event as handled

* Small refactor

* Add powered components

* R e f a c t o r

* More wip

* Fixes et al

* Pure pain

* When bae tells you she was tabs but she was actually spaces

* RReee

* Needs arglist

* Fax

* Fax

* More better

* You fail me yet again git commit

* Some kajiggering, but there we go

* No more 3rd param = variadic

* fix

* Sanity

* Whoops

* Minor thing

* Whoops

* fax

* Better describe the function, + add ..()s

* Fix

* Port to Initialize

* fuk in git
This commit is contained in:
Jordan Brown
2017-08-30 15:11:34 +02:00
committed by AnturK
parent 455cf37e52
commit 2c92735520
17 changed files with 255 additions and 348 deletions
+7 -3
View File
@@ -66,7 +66,6 @@
density = TRUE
anchored = TRUE
var/obj/machinery/mineral/CONSOLE = null
var/datum/material_container/materials
var/on = FALSE
var/selected_material = MAT_METAL
var/selected_alloy = null
@@ -75,12 +74,11 @@
/obj/machinery/mineral/processing_unit/Initialize()
. = ..()
proximity_monitor = new(src, 1)
materials = new(src, list(MAT_METAL, MAT_GLASS, MAT_SILVER, MAT_GOLD, MAT_DIAMOND, MAT_PLASMA, MAT_URANIUM, MAT_BANANIUM, MAT_TITANIUM, MAT_BLUESPACE),INFINITY)
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), INFINITY)
files = new /datum/research/smelter(src)
/obj/machinery/mineral/processing_unit/Destroy()
CONSOLE = null
QDEL_NULL(materials)
QDEL_NULL(files)
return ..()
@@ -89,6 +87,7 @@
process_ore(AM)
/obj/machinery/mineral/processing_unit/proc/process_ore(obj/item/ore/O)
GET_COMPONENT(materials, /datum/component/material_container)
var/material_amount = materials.get_item_material_amount(O)
if(!materials.has_space(material_amount))
unload_mineral(O)
@@ -100,6 +99,7 @@
/obj/machinery/mineral/processing_unit/proc/get_machine_data()
var/dat = "<b>Smelter control console</b><br><br>"
GET_COMPONENT(materials, /datum/component/material_container)
for(var/mat_id in materials.materials)
var/datum/material/M = materials.materials[mat_id]
dat += "<span class=\"res_name\">[M.name]: </span>[M.amount] cm&sup3;"
@@ -165,6 +165,7 @@
continue*/
/obj/machinery/mineral/processing_unit/proc/smelt_ore()
GET_COMPONENT(materials, /datum/component/material_container)
var/datum/material/mat = materials.materials[selected_material]
if(mat)
var/sheets_to_remove = (mat.amount >= (MINERAL_MATERIAL_AMOUNT * SMELT_AMOUNT) ) ? SMELT_AMOUNT : round(mat.amount / MINERAL_MATERIAL_AMOUNT)
@@ -187,6 +188,7 @@
on = FALSE
return
GET_COMPONENT(materials, /datum/component/material_container)
materials.use_amount(alloy.materials, amount)
generate_mineral(alloy.build_path)
@@ -197,6 +199,7 @@
var/build_amount = SMELT_AMOUNT
GET_COMPONENT(materials, /datum/component/material_container)
for(var/mat_id in D.materials)
var/M = D.materials[mat_id]
@@ -214,6 +217,7 @@
unload_mineral(O)
/obj/machinery/mineral/processing_unit/on_deconstruction()
GET_COMPONENT(materials, /datum/component/material_container)
materials.retrieve_all()
..()
+8 -10
View File
@@ -22,17 +22,15 @@
var/list/ore_values = list(MAT_GLASS = 1, MAT_METAL = 1, MAT_PLASMA = 15, MAT_SILVER = 16, MAT_GOLD = 18, MAT_TITANIUM = 30, MAT_URANIUM = 30, MAT_DIAMOND = 50, MAT_BLUESPACE = 50, MAT_BANANIUM = 60)
var/message_sent = FALSE
var/list/ore_buffer = list()
var/datum/material_container/materials
var/datum/research/files
var/obj/item/disk/design_disk/inserted_disk
/obj/machinery/mineral/ore_redemption/Initialize()
. = ..()
materials = new(src, list(MAT_METAL, MAT_GLASS, MAT_SILVER, MAT_GOLD, MAT_DIAMOND, MAT_PLASMA, MAT_URANIUM, MAT_BANANIUM, MAT_TITANIUM, MAT_BLUESPACE),INFINITY)
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),INFINITY)
files = new /datum/research/smelter(src)
/obj/machinery/mineral/ore_redemption/Destroy()
QDEL_NULL(materials)
QDEL_NULL(files)
return ..()
@@ -57,6 +55,7 @@
if(O && O.refined_type)
points += O.points * point_upgrade
GET_COMPONENT(materials, /datum/component/material_container)
var/material_amount = materials.get_item_material_amount(O)
if(!material_amount)
@@ -75,6 +74,7 @@
var/build_amount = 0
GET_COMPONENT(materials, /datum/component/material_container)
for(var/mat_id in D.materials)
var/M = D.materials[mat_id]
var/datum/material/redemption_mat = materials.materials[mat_id]
@@ -110,6 +110,7 @@
var/has_minerals = FALSE
GET_COMPONENT(materials, /datum/component/material_container)
for(var/mat_id in materials.materials)
var/datum/material/M = materials.materials[mat_id]
var/mineral_amount = M.amount / MINERAL_MATERIAL_AMOUNT
@@ -148,6 +149,7 @@
/obj/machinery/mineral/ore_redemption/attackby(obj/item/W, mob/user, params)
if(exchange_parts(user, W))
return
GET_COMPONENT(materials, /datum/component/material_container)
if(default_pry_open(W))
materials.retrieve_all()
return
@@ -181,16 +183,10 @@
if(user.transferItemToLoc(W, src))
inserted_disk = W
return TRUE
if(istype(W, /obj/item/stack/sheet))
var/obj/item/stack/sheet/S = W
var/inserted = materials.insert_stack(S, S.amount)
to_chat(user, "<span class='notice'>You add [inserted] [S] sheets to \the [src].</span>")
return
return ..()
/obj/machinery/mineral/ore_redemption/on_deconstruction()
GET_COMPONENT(materials, /datum/component/material_container)
materials.retrieve_all()
..()
@@ -213,6 +209,7 @@
data["claimedPoints"] = inserted_id.mining_points
data["materials"] = list()
GET_COMPONENT(materials, /datum/component/material_container)
for(var/mat_id in materials.materials)
var/datum/material/M = materials.materials[mat_id]
var/sheet_amount = M.amount ? M.amount / MINERAL_MATERIAL_AMOUNT : "0"
@@ -236,6 +233,7 @@
/obj/machinery/mineral/ore_redemption/ui_act(action, params)
if(..())
return
GET_COMPONENT(materials, /datum/component/material_container)
switch(action)
if("Eject")
if(!inserted_id)
+5 -9
View File
@@ -7,7 +7,6 @@
icon_state = "coinpress0"
density = TRUE
anchored = TRUE
var/datum/material_container/materials
var/newCoins = 0 //how many coins the machine made in it's last load
var/processing = FALSE
var/chosen = MAT_METAL //which material will be used to make coins
@@ -17,25 +16,21 @@
/obj/machinery/mineral/mint/Initialize()
. = ..()
materials = new /datum/material_container(src,
list(MAT_METAL, MAT_PLASMA, MAT_SILVER, MAT_GOLD, MAT_URANIUM, MAT_DIAMOND, MAT_BANANIUM),
max_amt = MINERAL_MATERIAL_AMOUNT*50)
/obj/machinery/mineral/mint/Destroy()
QDEL_NULL(materials)
return ..()
AddComponent(/datum/component/material_container, list(MAT_METAL, MAT_PLASMA, MAT_SILVER, MAT_GOLD, MAT_URANIUM, MAT_DIAMOND, MAT_BANANIUM), MINERAL_MATERIAL_AMOUNT * 50)
/obj/machinery/mineral/mint/process()
var/turf/T = get_step(src, input_dir)
if(!T)
return
GET_COMPONENT(materials, /datum/component/material_container)
for(var/obj/item/stack/sheet/O in T)
materials.insert_stack(O, O.amount)
/obj/machinery/mineral/mint/attack_hand(mob/user)
var/dat = "<b>Coin Press</b><br>"
GET_COMPONENT(materials, /datum/component/material_container)
for(var/mat_id in materials.materials)
var/datum/material/M = materials.materials[mat_id]
if(!M.amount && chosen != mat_id)
@@ -68,6 +63,7 @@
if(processing==1)
to_chat(usr, "<span class='notice'>The machine is processing.</span>")
return
GET_COMPONENT(materials, /datum/component/material_container)
if(href_list["choose"])
if(materials.materials[href_list["choose"]])
chosen = href_list["choose"]