Integrated circuit fixes and code improvements

This commit is contained in:
ACCount
2017-11-21 12:04:09 +03:00
committed by CitadelStationBot
parent 065a816183
commit 8a64287249
21 changed files with 720 additions and 555 deletions
@@ -1,47 +1,44 @@
/obj/item/integrated_circuit/proc/setup_io(var/list/io_list, var/io_type, var/list/io_default_list)
/obj/item/integrated_circuit/proc/setup_io(list/io_list, io_type, list/io_default_list, pin_type)
var/list/io_list_copy = io_list.Copy()
io_list.Cut()
for(var/i in 1 to io_list_copy.len)
var/io_entry = io_list_copy[i]
var/default_data = null
var/io_type_override = null
// Override the default data.
if(io_default_list && io_default_list.len) // List containing special pin types that need to be added.
if(length(io_default_list)) // List containing special pin types that need to be added.
default_data = io_default_list["[i]"] // This is deliberately text because the index is a number in text form.
// Override the pin type.
if(io_list_copy[io_entry])
io_type_override = io_list_copy[io_entry]
if(io_type_override)
io_list.Add(new io_type_override(src, io_entry, default_data))
io_list.Add(new io_type_override(src, io_entry, default_data, pin_type))
else
io_list.Add(new io_type(src, io_entry, default_data))
io_list.Add(new io_type(src, io_entry, default_data, pin_type))
/obj/item/integrated_circuit/proc/set_pin_data(var/pin_type, var/pin_number, datum/new_data)
/obj/item/integrated_circuit/proc/set_pin_data(pin_type, pin_number, datum/new_data)
if (istype(new_data) && !isweakref(new_data))
new_data = WEAKREF(new_data)
var/datum/integrated_io/pin = get_pin_ref(pin_type, pin_number)
return pin.write_data_to_pin(new_data)
/obj/item/integrated_circuit/proc/get_pin_data(var/pin_type, var/pin_number)
/obj/item/integrated_circuit/proc/get_pin_data(pin_type, pin_number)
var/datum/integrated_io/pin = get_pin_ref(pin_type, pin_number)
return pin.get_data()
/obj/item/integrated_circuit/proc/get_pin_data_as_type(var/pin_type, var/pin_number, var/as_type)
/obj/item/integrated_circuit/proc/get_pin_data_as_type(pin_type, pin_number, as_type)
var/datum/integrated_io/pin = get_pin_ref(pin_type, pin_number)
return pin.data_as_type(as_type)
/obj/item/integrated_circuit/proc/activate_pin(var/pin_number)
/obj/item/integrated_circuit/proc/activate_pin(pin_number)
var/datum/integrated_io/activate/A = activators[pin_number]
A.push_data()
/datum/integrated_io/proc/get_data()
if(isweakref(data))
return data.resolve()
return data
/obj/item/integrated_circuit/proc/get_pin_ref(var/pin_type, var/pin_number)
/obj/item/integrated_circuit/proc/get_pin_ref(pin_type, pin_number)
switch(pin_type)
if(IC_INPUT)
if(pin_number > inputs.len)
@@ -72,60 +69,75 @@
return FALSE
/obj/item/integrated_circuit/proc/asc2b64(var/S)
var/static/list/b64 = list(
"A"=0,"B"=1,"C"=2,"D"=3,
"E"=4,"F"=5,"G"=6,"H"=7,
"I"=8,"J"=9,"K"=10,"L"=11,
"M"=12,"N"=13,"O"=14,"P"=15,
"Q"=16,"R"=17,"S"=18,"T"=19,
"U"=20,"V"=21,"W"=22,"X"=23,
"Y"=24,"Z"=25,"a"=26,"b"=27,
"c"=28,"d"=29,"e"=30,"f"=31,
"g"=32,"h"=33,"i"=34,"j"=35,
"k"=36,"l"=37,"m"=38,"n"=39,
"o"=40,"p"=41,"q"=42,"r"=43,
"s"=44,"t"=45,"u"=46,"v"=47,
"w"=48,"x"=49,"y"=50,"z"=51,
"0"=52,"1"=53,"2"=54,"3"=55,
"4"=56,"5"=57,"6"=58,"7"=59,
"8"=60,"9"=61,","=62,"."=63
)
var/ls = lentext(S)
var/c
var/i=1
while(i <= ls)
var/sb1=text2ascii(S,i)
var/sb2=text2ascii(S,i+1)
var/sb3=text2ascii(S,i+2)
var/cb1 = (sb1 & 252)>>2
var/cb2 = ((sb1 & 3)<<6 | (sb2 & 240)>>2)>>2
var/cb3 = (sb2 & 15)<<2 | (sb3 & 192)>>6
var/cb4 = (sb3 & 63)
c=c+b64[cb1+1]+b64[cb2+1]+b64[cb3+1]+b64[cb4+1]
i=i+3
return c
/datum/integrated_io/proc/get_data()
if(isweakref(data))
return data.resolve()
return data
/obj/item/integrated_circuit/proc/b642asc(var/S)
var/static/list/b64 = list("A"=1,"B"=2,"C"=3,"D"=4,"E"=5,"F"=6,"G"=7,"H"=8,"I"=9,"J"=10,"K"=11,"L"=12,"M"=13,"N"=14,"O"=15,"P"=16,"Q"=17,"R"=18,
"S"=19,"T"=20,"U"=21,"V"=22,"W"=23,"X"=24,"Y"=25,"Z"=26,"a"=27,"b"=28,"c"=29,"d"=30,"e"=31,"f"=32,"g"=33,"h"=34,"i"=35,"j"=36,"k"=37,"l"=38,"m"=39,"n"=40,"o"=41,
"p"=42,"q"=43,"r"=44,"s"=45,"t"=46,"u"=47,"v"=48,"w"=49,"x"=50,"y"=51,"z"=52,"0"=53,"1"=54,"2"=55,"3"=56,"4"=57,"5"=58,"6"=59,"7"=60,"8"=61,"9"=62,","=63,"."=64)
var/ls = lentext(S)
var/c
var/i=1
while(i<=ls)
var/cb1=b64[copytext(S,i,i+1)]-1
var/cb2=b64[copytext(S,i+1,i+2)]-1
var/cb3=b64[copytext(S,i+2,i+3)]-1
var/cb4=b64[copytext(S,i+3,i+4)]-1
var/sb1=cb1<<2 | (cb2 & 48)>>4
var/sb2=(cb2 & 15) <<4 | (cb3 & 60)>>2
var/sb3=(cb3 & 3)<<6 | cb4
c=c+ascii2text(sb1)+ascii2text(sb2)+ascii2text(sb3)
i=i+4
return c
/proc/XorEncrypt(string,key)
// Returns a list of parameters necessary to locate a pin in the assembly: component number, pin type and pin number
// Components list can be supplied from the outside, for use in savefiles or for extra performance if you are calling this multiple times
/datum/integrated_io/proc/get_pin_parameters(list/components)
if(!holder)
return
if(!components)
if(!holder.assembly)
return
components = holder.assembly.return_all_components()
var/component_number = components.Find(holder)
var/list/pin_holder_list
switch(pin_type)
if(IC_INPUT)
pin_holder_list = holder.inputs
if(IC_OUTPUT)
pin_holder_list = holder.outputs
if(IC_ACTIVATOR)
pin_holder_list = holder.activators
else
return
var/pin_number = pin_holder_list.Find(src)
return list(component_number, pin_type, pin_number)
// Locates a pin in the assembly when given component number, pin type and pin number
// Components list can be supplied from the outside, for use in savefiles or for extra performance if you are calling this multiple times
/obj/item/device/electronic_assembly/proc/get_pin_ref(component_number, pin_type, pin_number, list/components)
if(!components)
components = return_all_components()
if(component_number > components.len)
return
var/obj/item/integrated_circuit/component = components[component_number]
return component.get_pin_ref(pin_type, pin_number)
// Same as get_pin_ref, but takes in a list of 3 parameters (same format as get_pin_parameters)
// and performs extra sanity checks on parameters list and index numbers
/obj/item/device/electronic_assembly/proc/get_pin_ref_list(list/parameters, list/components)
if(!islist(parameters) || parameters.len != 3)
return
// Those are supposed to be list indexes, check them for sanity
if(!isnum(parameters[1]) || parameters[1] % 1 || parameters[1] < 1)
return
if(!isnum(parameters[3]) || parameters[3] % 1 || parameters[3] < 1)
return
return get_pin_ref(parameters[1], parameters[2], parameters[3], components)
// Used to obfuscate object refs imported/exported as strings.
// Not very secure, but if someone still finds a way to abuse refs, they deserve it.
/proc/XorEncrypt(string, key)
if(!string || !key ||!istext(string)||!istext(key))
return
var/r