Ports pandemic to tgui

This commit is contained in:
CitadelStationBot
2017-05-21 22:28:16 -05:00
parent 5fd5e32628
commit d7f0b9494b
3 changed files with 266 additions and 282 deletions

View File

@@ -1,285 +1,183 @@
/obj/machinery/computer/pandemic
name = "PanD.E.M.I.C 2200"
desc = "Used to work with viruses."
density = 1
anchored = 1
density = TRUE
anchored = TRUE
icon = 'icons/obj/chemical.dmi'
icon_state = "mixer0"
circuit = /obj/item/weapon/circuitboard/computer/pandemic
use_power = 1
use_power = TRUE
idle_power_usage = 20
resistance_flags = ACID_PROOF
var/temp_html = ""
var/wait = null
var/obj/item/weapon/reagent_containers/beaker = null
var/wait
var/obj/item/weapon/reagent_containers/beaker
/obj/machinery/computer/pandemic/Initialize()
. = ..()
update_icon()
/obj/machinery/computer/pandemic/proc/GetVirusByIndex(index)
if(beaker && beaker.reagents)
if(beaker.reagents.reagent_list.len)
var/datum/reagent/blood/BL = locate() in beaker.reagents.reagent_list
if(BL)
if(BL.data && BL.data["viruses"])
var/list/viruses = BL.data["viruses"]
return viruses[index]
return null
/obj/machinery/computer/pandemic/Destroy()
QDEL_NULL(beaker)
return ..()
/obj/machinery/computer/pandemic/proc/GetResistancesByIndex(index)
if(beaker && beaker.reagents)
if(beaker.reagents.reagent_list.len)
var/datum/reagent/blood/BL = locate() in beaker.reagents.reagent_list
if(BL)
if(BL.data && BL.data["resistances"])
var/list/resistances = BL.data["resistances"]
return resistances[index]
return null
/obj/machinery/computer/pandemic/proc/get_by_index(thing, index)
if(!beaker || !beaker.reagents)
return
var/datum/reagent/blood/B = locate() in beaker.reagents.reagent_list
if(B && B.data[thing])
return B.data[thing][index]
/obj/machinery/computer/pandemic/proc/GetVirusTypeByIndex(index)
var/datum/disease/D = GetVirusByIndex(index)
/obj/machinery/computer/pandemic/proc/get_virus_id_by_index(index)
var/datum/disease/D = get_by_index("viruses", index)
if(D)
return D.GetDiseaseID()
return null
/obj/machinery/computer/pandemic/proc/replicator_cooldown(waittime)
wait = 1
/obj/machinery/computer/pandemic/proc/get_viruses_data(datum/reagent/blood/B)
. = list()
if(!islist(B.data["viruses"]))
return
var/list/V = B.data["viruses"]
var/index = 1
for(var/virus in V)
var/datum/disease/D = virus
if(!istype(D) || D.visibility_flags & HIDDEN_PANDEMIC)
continue
var/list/this = list()
this["name"] = D.name
if(istype(D, /datum/disease/advance))
var/datum/disease/advance/A = SSdisease.archive_diseases[D.GetDiseaseID()]
if(A.name == "Unknown")
this["can_rename"] = TRUE
this["name"] = A.name
this["is_adv"] = TRUE
this["resistance"] = A.totalResistance()
this["stealth"] = A.totalStealth()
this["stage_speed"] = A.totalStageSpeed()
this["transmission"] = A.totalTransmittable()
this["symptoms"] = list()
for(var/symptom in A.symptoms)
var/datum/symptom/S = symptom
var/list/this_symptom = list()
this_symptom["name"] = S.name
this["symptoms"] += list(this_symptom)
this["index"] = index++
this["agent"] = D.agent
this["description"] = D.desc || "none"
this["spread"] = D.spread_text || "none"
this["cure"] = D.cure_text || "none"
. += list(this)
/obj/machinery/computer/pandemic/proc/get_resistance_data(datum/reagent/blood/B)
. = list()
if(!islist(B.data["resistances"]))
return
var/list/resistances = B.data["resistances"]
for(var/id in resistances)
var/list/this = list()
var/datum/disease/D = SSdisease.archive_diseases[id]
if(D)
this["id"] = id
this["name"] = D.name
. += list(this)
/obj/machinery/computer/pandemic/proc/reset_replicator_cooldown()
wait = FALSE
update_icon()
spawn(waittime)
wait = null
update_icon()
playsound(src.loc, 'sound/machines/ping.ogg', 30, 1)
playsound(loc, 'sound/machines/ping.ogg', 30, 1)
/obj/machinery/computer/pandemic/update_icon()
if(stat & BROKEN)
icon_state = (beaker ? "mixer1_b" : "mixer0_b")
return
icon_state = "mixer[(beaker)?"1":"0"][(powered()) ? "" : "_nopower"]"
icon_state = "mixer[(beaker) ? "1" : "0"][powered() ? "" : "_nopower"]"
if(wait)
cut_overlays()
else
add_overlay("waitlight")
/obj/machinery/computer/pandemic/Topic(href, href_list)
/obj/machinery/computer/pandemic/proc/eject_beaker()
beaker.forceMove(get_turf(src))
beaker = null
update_icon()
/obj/machinery/computer/pandemic/ui_interact(mob/user, ui_key = "main", datum/tgui/ui, force_open = FALSE, datum/tgui/master_ui, datum/ui_state/state = GLOB.default_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "pandemic", name, 575, 500, master_ui, state)
ui.open()
/obj/machinery/computer/pandemic/ui_data(mob/user)
var/list/data = list()
data["is_ready"] = !wait
if(beaker)
data["has_beaker"] = TRUE
if(!beaker.reagents.total_volume || !beaker.reagents.reagent_list)
data["beaker_empty"] = TRUE
var/datum/reagent/blood/B = locate() in beaker.reagents.reagent_list
if(B)
data["has_blood"] = TRUE
data["blood"] = list()
data["blood"]["dna"] = B.data["blood_DNA"] || "none"
data["blood"]["type"] = B.data["blood_type"] || "none"
data["viruses"] = get_viruses_data(B)
data["resistances"] = get_resistance_data(B)
return data
/obj/machinery/computer/pandemic/ui_act(action, params)
if(..())
return
usr.set_machine(src)
if(!beaker) return
if (href_list["create_vaccine"])
if(!src.wait)
var/obj/item/weapon/reagent_containers/glass/bottle/B = new/obj/item/weapon/reagent_containers/glass/bottle(src.loc)
if(B)
B.pixel_x = rand(-3, 3)
B.pixel_y = rand(-3, 3)
var/path = GetResistancesByIndex(text2num(href_list["create_vaccine"]))
var/vaccine_type = path
var/vaccine_name = "Unknown"
if(!ispath(vaccine_type))
if(SSdisease.archive_diseases[path])
var/datum/disease/D = SSdisease.archive_diseases[path]
if(D)
vaccine_name = D.name
vaccine_type = path
else if(vaccine_type)
var/datum/disease/D = new vaccine_type(0, null)
if(D)
vaccine_name = D.name
if(vaccine_type)
B.name = "[vaccine_name] vaccine bottle"
B.reagents.add_reagent("vaccine", 15, list(vaccine_type))
replicator_cooldown(200)
else
temp_html = "The replicator is not ready yet."
updateUsrDialog()
return
else if (href_list["create_virus_culture"])
if(!wait)
var/type = GetVirusTypeByIndex(text2num(href_list["create_virus_culture"]))//the path is received as string - converting
var/datum/disease/D = null
if(!ispath(type))
D = GetVirusByIndex(text2num(href_list["create_virus_culture"]))
var/datum/disease/advance/A = SSdisease.archive_diseases[D.GetDiseaseID()]
if(A)
D = new A.type(0, A)
else if(type)
if(type in SSdisease.diseases) // Make sure this is a disease
D = new type(0, null)
if(!D)
return
var/name = stripped_input(usr,"Name:","Name the culture",D.name,MAX_NAME_LEN)
if(name == null || wait)
return
var/obj/item/weapon/reagent_containers/glass/bottle/B = new/obj/item/weapon/reagent_containers/glass/bottle(src.loc)
B.icon_state = "bottle3"
B.pixel_x = rand(-3, 3)
B.pixel_y = rand(-3, 3)
replicator_cooldown(50)
var/list/data = list("viruses"=list(D))
B.name = "[name] culture bottle"
B.desc = "A small bottle. Contains [D.agent] culture in synthblood medium."
B.reagents.add_reagent("blood",20,data)
updateUsrDialog()
else
temp_html = "The replicator is not ready yet."
updateUsrDialog()
return
else if (href_list["empty_beaker"])
beaker.reagents.clear_reagents()
updateUsrDialog()
return
else if (href_list["eject"])
beaker.forceMove(get_turf(loc))
beaker = null
icon_state = "mixer0"
updateUsrDialog()
return
else if (href_list["emptyeject_beaker"])
beaker.reagents.clear_reagents()
beaker.forceMove(get_turf(loc))
beaker = null
icon_state = "mixer0"
updateUsrDialog()
return
else if(href_list["clear"])
temp_html = ""
updateUsrDialog()
return
else if(href_list["name_disease"])
var/new_name = stripped_input(usr, "Name the Disease", "New Name", "", MAX_NAME_LEN)
if(!new_name)
return
if(..())
return
var/id = GetVirusTypeByIndex(text2num(href_list["name_disease"]))
if(SSdisease.archive_diseases[id])
switch(action)
if("eject_beaker")
eject_beaker()
. = TRUE
if("empty_beaker")
beaker.reagents.clear_reagents()
. = TRUE
if("empty_eject_beaker")
beaker.reagents.clear_reagents()
eject_beaker()
. = TRUE
if("rename_disease")
var/id = get_virus_id_by_index(text2num(params["index"]))
var/datum/disease/advance/A = SSdisease.archive_diseases[id]
A.AssignName(new_name)
for(var/datum/disease/advance/AD in SSdisease.processing)
AD.Refresh()
updateUsrDialog()
else
usr << browse(null, "window=pandemic")
updateUsrDialog()
return
add_fingerprint(usr)
return
/obj/machinery/computer/pandemic/attack_hand(mob/user)
if(..())
return
user.set_machine(src)
var/dat = ""
if(temp_html)
dat = "[src.temp_html]<BR><BR><A href='?src=\ref[src];clear=1'>Main Menu</A>"
else if(!beaker)
dat += "Please insert beaker.<BR>"
dat += "<A href='?src=\ref[user];mach_close=pandemic'>Close</A>"
else
var/datum/reagents/R = beaker.reagents
var/datum/reagent/blood/Blood = null
for(var/datum/reagent/blood/B in R.reagent_list)
if(B)
Blood = B
break
if(!R.total_volume||!R.reagent_list.len)
dat += "The beaker is empty<BR>"
else if(!Blood)
dat += "No blood sample found in beaker."
else if(!Blood.data)
dat += "No blood data found in beaker."
else
dat += "<h3>Blood sample data:</h3>"
dat += "<b>Blood DNA:</b> [(Blood.data["blood_DNA"]||"none")]<BR>"
dat += "<b>Blood Type:</b> [(Blood.data["blood_type"]||"none")]<BR>"
if(Blood.data["viruses"])
var/list/vir = Blood.data["viruses"]
if(vir.len)
var/i = 0
for(var/datum/disease/D in Blood.data["viruses"])
i++
if(!(D.visibility_flags & HIDDEN_PANDEMIC))
if(istype(D, /datum/disease/advance))
var/datum/disease/advance/A = D
D = SSdisease.archive_diseases[A.GetDiseaseID()]
if(D && D.name == "Unknown")
dat += "<b><a href='?src=\ref[src];name_disease=[i]'>Name Disease</a></b><BR>"
if(!D)
CRASH("We weren't able to get the advance disease from the archive.")
dat += "<b>Disease Agent:</b> [D?"[D.agent] - <A href='?src=\ref[src];create_virus_culture=[i]'>Create virus culture bottle</A>":"none"]<BR>"
dat += "<b>Common name:</b> [(D.name||"none")]<BR>"
dat += "<b>Description: </b> [(D.desc||"none")]<BR>"
dat += "<b>Spread:</b> [(D.spread_text||"none")]<BR>"
dat += "<b>Possible cure:</b> [(D.cure_text||"none")]<BR><BR>"
if(istype(D, /datum/disease/advance))
var/datum/disease/advance/A = D
dat += "<b>Stealth:</b> [(A.totalStealth())]<BR>"
dat += "<b>Resistance:</b> [(A.totalResistance())]<BR>"
dat += "<b>Stage Speed:</b> [(A.totalStageSpeed())]<BR>"
dat += "<b>Transmission:</b> [(A.totalTransmittable())]<BR><BR>"
dat += "<b>Symptoms:</b> "
var/english_symptoms = list()
for(var/datum/symptom/S in A.symptoms)
english_symptoms += S.name
dat += english_list(english_symptoms)
else
dat += "No detectable virus in the sample."
else
dat += "No detectable virus in the sample."
dat += "<BR><b>Contains antibodies to:</b> "
if(Blood.data["resistances"])
var/list/res = Blood.data["resistances"]
if(res.len)
dat += "<ul>"
var/i = 0
for(var/type in Blood.data["resistances"])
i++
var/disease_name = "Unknown"
if(!ispath(type))
var/datum/disease/advance/A = SSdisease.archive_diseases[type]
if(A)
disease_name = A.name
else
var/datum/disease/D = new type(0, null)
disease_name = D.name
dat += "<li>[disease_name] - <A href='?src=\ref[src];create_vaccine=[i]'>Create vaccine bottle</A></li>"
dat += "</ul><BR>"
else
dat += "nothing<BR>"
else
dat += "nothing<BR>"
dat += "<BR><A href='?src=\ref[src];eject=1'>Eject beaker</A>[((R.total_volume&&R.reagent_list.len) ? "-- <A href='?src=\ref[src];empty_beaker=1'>Empty beaker</A>":"")]"
dat += "[((R.total_volume&&R.reagent_list.len) ? "-- <A href='?src=\ref[src];emptyeject_beaker=1'>Empty and Eject beaker</A>":"")]<BR>"
dat += "<A href='?src=\ref[user];mach_close=pandemic'>Close</A>"
user << browse("<TITLE>[src.name]</TITLE><BR>[dat]", "window=pandemic;size=575x400")
onclose(user, "pandemic")
return
if(A)
var/new_name = stripped_input(usr, "Name the disease", "New name", "", MAX_NAME_LEN)
if(!new_name || ..())
return
A.AssignName(new_name)
for(var/datum/disease/advance/AD in SSdisease.processing)
AD.Refresh()
. = TRUE
if("create_culture_bottle")
var/id = get_virus_id_by_index(text2num(params["index"]))
var/datum/disease/advance/A = new(FALSE, SSdisease.archive_diseases[id])
var/list/data = list("viruses" = list(A))
var/obj/item/weapon/reagent_containers/glass/bottle/B = new(get_turf(src))
B.name = "[A.name] culture bottle"
B.desc = "A small bottle. Contains [A.agent] culture in synthblood medium."
B.reagents.add_reagent("blood", 20, data)
wait = TRUE
update_icon()
addtimer(CALLBACK(src, .proc/reset_replicator_cooldown), 50)
. = TRUE
if("create_vaccine_bottle")
var/index = params["index"]
var/datum/disease/D = SSdisease.archive_diseases[index]
var/obj/item/weapon/reagent_containers/glass/bottle/B = new(get_turf(src))
B.name = "[D.name] vaccine bottle"
B.reagents.add_reagent("vaccine", 15, list(index))
wait = TRUE
update_icon()
addtimer(CALLBACK(src, .proc/reset_replicator_cooldown), 200)
. = TRUE
/obj/machinery/computer/pandemic/attackby(obj/item/I, mob/user, params)
if(istype(I, /obj/item/weapon/reagent_containers) && (I.container_type & OPENCONTAINER))
. = 1 //no afterattack
. = TRUE //no afterattack
if(stat & (NOPOWER|BROKEN))
return
if(beaker)
@@ -288,15 +186,15 @@
if(!user.drop_item())
return
beaker = I
beaker.loc = src
beaker = I
beaker.forceMove(src)
to_chat(user, "<span class='notice'>You add the beaker to the machine.</span>")
updateUsrDialog()
icon_state = "mixer1"
update_icon()
else
return ..()
/obj/machinery/computer/pandemic/on_deconstruction()
if(beaker)
beaker.loc = get_turf(src)
..()
beaker.forceMove(get_turf(src))
beaker = null
. = ..()

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,84 @@
<ui-display title='Beaker' button>
{{#partial button}}
<ui-button icon='remove' state='{{data.has_beaker ? null : "disabled"}}' action='empty_eject_beaker'>
Empty and eject
</ui-button>
<ui-button icon='trash' state='{{data.has_beaker ? null : "disabled"}}' action='empty_beaker'>
Empty
</ui-button>
<ui-button icon='eject' state='{{data.has_beaker ? null : "disabled"}}' action='eject_beaker'>
Eject
</ui-button>
{{/partial}}
{{#if data.has_beaker}}
<ui-section>
{{#if data.beaker_empty}}
<span class='bad'>The beaker is empty!</span>
{{else}}
<ui-subdisplay title='Blood'>
{{#if data.has_blood}}
<ui-section label='Blood DNA'>{{data.blood.dna}}</ui-section>
<ui-section label='Blood type'>{{data.blood.type}}</ui-section>
{{else}}
<ui-section>
<span class='average'>No blood sample detected.</span>
</ui-section>
{{/if}}
</ui-subdisplay>
{{/if}}
</ui-section>
{{else}}
<ui-section>
<span class='bad'>No beaker loaded.</span>
</ui-section>
{{/if}}
</ui-display>
{{#if data.has_blood}}
<ui-display title='Diseases'>
{{#each data.viruses}}
<ui-display title='{{name}}' button>
{{#partial button}}
{{#if is_adv}}
<ui-button icon='pencil' action='rename_disease' state='{{can_rename ? "" : "disabled"}}' params='{"index": {{index}}}'>
Name advanced disease
</ui-button>
{{/if}}
<ui-button icon='flask' action='create_culture_bottle' state='{{data.is_ready ? "" : "disabled"}}' params='{"index": {{index}}}'>
Create virus culture bottle
</ui-button>
{{/partial}}
<ui-section label='Disease agent'>{{agent}}</ui-section>
<ui-section label='Description'>{{description}}</ui-section>
<ui-section label='Spread'>{{spread}}</ui-section>
<ui-section label='Possible cure'>{{cure}} </ui-section>
{{#if is_adv}}
<ui-section label='Resistance'>{{resistance}}</ui-section>
<ui-section label='Stealth'>{{stealth}}</ui-section>
<ui-section label='Stage speed'>{{stage_speed}}</ui-section>
<ui-section label='Symptoms'>
{{#each symptoms}}
<span>{{name}}</span><br />
{{/each}}
</ui-section>
{{/if}}
</ui-display>
{{else}}
<ui-section>
<span class='average'>No detectable virus in the blood sample.</span>
</ui-section>
{{/each}}
</ui-display>
<ui-display title='Antibodies'>
{{#each data.resistances}}
<ui-section label='{{name}}'>
<ui-button icon='eyedropper' state='{{data.is_ready ? "" : "disabled"}}' action='create_vaccine_bottle' params='{"index": {{id}}}'>
Create vaccine bottle
</ui-button>
</ui-section>
{{else}}
<ui-section>
<span class='average'>No antibodies detected in the blood sample.</span>
</ui-section>
{{/each}}
</ui-display>
{{/if}}