From 36677808711b402a4ecfbbc2edd3bf842db5cd67 Mon Sep 17 00:00:00 2001 From: Neerti Date: Sat, 16 Apr 2016 06:14:09 -0400 Subject: [PATCH] Adds verb to change eye color at will (if mechanical) Adds a verb used by humanoid mobs that have mechanical eyes, which allows them to pick a new color, and have it applied instantly. Adds some helper functions, specifically hex2rgb(), to convert hexadecimal colors to a list of numbers for r, g, and b. --- code/_helpers/type2type.dm | 20 ++++++++++++++++++++ code/modules/organs/organ_internal.dm | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/code/_helpers/type2type.dm b/code/_helpers/type2type.dm index ebdee3c659..0bcf546123 100644 --- a/code/_helpers/type2type.dm +++ b/code/_helpers/type2type.dm @@ -149,6 +149,26 @@ if (rights & R_MENTOR) . += "[seperator]+MENTOR" return . +// Converts a hexadecimal color (e.g. #FF0050) to a list of numbers for red, green, and blue (e.g. list(255,0,80) ). +/proc/hex2rgb(hex) + // Strips the starting #, in case this is ever supplied without one, so everything doesn't break. + if(findtext(hex,"#",1,2)) + hex = copytext(hex, 2) + return list(hex2rgb_r(hex), hex2rgb_g(hex), hex2rgb_b(hex)) + +// The three procs below require that the '#' part of the hex be stripped, which hex2rgb() does automatically. +/proc/hex2rgb_r(hex) + var/hex_to_work_on = copytext(hex,1,3) + return hex2num(hex_to_work_on) + +/proc/hex2rgb_g(hex) + var/hex_to_work_on = copytext(hex,3,5) + return hex2num(hex_to_work_on) + +/proc/hex2rgb_b(hex) + var/hex_to_work_on = copytext(hex,5,7) + return hex2num(hex_to_work_on) + // heat2color functions. Adapted from: http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/ /proc/heat2color(temp) return rgb(heat2color_r(temp), heat2color_g(temp), heat2color_b(temp)) diff --git a/code/modules/organs/organ_internal.dm b/code/modules/organs/organ_internal.dm index e4edadfe14..6975e747d0 100644 --- a/code/modules/organs/organ_internal.dm +++ b/code/modules/organs/organ_internal.dm @@ -104,6 +104,7 @@ icon = 'icons/obj/robot_component.dmi' icon_state = "camera" dead_icon = "camera_broken" + verbs |= /obj/item/organ/internal/eyes/proc/change_eye_color /obj/item/organ/internal/eyes/robot name = "optical sensor" @@ -112,6 +113,26 @@ ..() robotize() +/obj/item/organ/internal/eyes/proc/change_eye_color() + set name = "Change Eye Color" + set desc = "Changes your robotic eye color instantly." + set category = "IC" + set src in usr + + var/current_color = rgb(eye_colour[1],eye_colour[2],eye_colour[3]) + var/new_color = input("Pick a new color for your eyes.","Eye Color", current_color) as null|color + if(new_color && owner) + // input() supplies us with a hex color, which we can't use, so we convert it to rbg values. + var/list/new_color_rgb_list = hex2rgb(new_color) + // First, update mob vars. + owner.r_eyes = new_color_rgb_list[1] + owner.g_eyes = new_color_rgb_list[2] + owner.b_eyes = new_color_rgb_list[3] + // Now sync the organ's eye_colour list. + update_colour() + // Finally, update the eye icon on the mob. + owner.update_eyes() + /obj/item/organ/internal/eyes/replaced(var/mob/living/carbon/human/target) // Apply our eye colour to the target.