From 76e7caad33f5c10e478dee0a3a7615393a99346e Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Fri, 11 Dec 2020 04:54:30 -0700 Subject: [PATCH] colormates --- code/__HELPERS/icons.dm | 15 +++ code/game/machinery/colormate.dm | 208 +++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 code/game/machinery/colormate.dm diff --git a/code/__HELPERS/icons.dm b/code/__HELPERS/icons.dm index 90864cf359..338f27208b 100644 --- a/code/__HELPERS/icons.dm +++ b/code/__HELPERS/icons.dm @@ -1235,3 +1235,18 @@ GLOBAL_DATUM_INIT(dummySave, /savefile, new("tmp/dummySave.sav")) //Cache of ico var/icon/I = getFlatIcon(thing) return icon2html(I, target, sourceonly = sourceonly) +/* Gives the result RGB of a RGB string after a matrix transformation. No alpha. + * Input: rr, rg, rb, gr, gg, gb, br, bg, bb, cr, cg, cb + * Output: RGB string + */ +/proc/RGBMatrixTransform(list/color, list/cm) + ASSERT(cm.len >= 9) + if(cm.len < 12) // fill in the rest + for(var/i in 1 to (12 - cm.len)) + cm += 0 + if(!islist(color)) + color = ReadRGB(color) + color[1] = color[1] * cm[1] + color[2] * cm[2] + color[3] * cm[3] + cm[10] + color[2] = color[1] * cm[4] + color[2] * cm[5] + color[3] * cm[6] + cm[11] + color[3] = color[1] * cm[7] + color[2] * cm[8] + color[3] * cm[9] + cm[12] + return rgb(arglist(color)) diff --git a/code/game/machinery/colormate.dm b/code/game/machinery/colormate.dm new file mode 100644 index 0000000000..522cf17468 --- /dev/null +++ b/code/game/machinery/colormate.dm @@ -0,0 +1,208 @@ +/obj/machinery/gear_painter + name = "\improper Color Mate" + desc = "A machine to give your apparel a fresh new color! Recommended to use with white items for best results." + icon = 'icons/obj/vending_vr.dmi' + icon_state = "colormate" + density = TRUE + anchored = TRUE + var/obj/item/inserted + var/activecolor = "#FFFFFF" + var/list/color_matrix_last + var/matrix_mode = FALSE + /// Minimum lightness for normal mode + var/minimum_normal_lightness = 50 + /// Minimum lightness for matrix mode, tested using 4 test colors of full red, green, blue, white. + var/minimum_matrix_lightness = 75 + /// Minimum matrix tests that must pass for something to be considered a valid color (see above) + var/minimum_matrix_tests = 2 + var/list/allowed_types = list( + /obj/item/clothing, + /obj/item/storage/backpack, + /obj/item/storage/belt + ) + +/obj/machinery/gear_painter/Initialize(mapload) + . = ..() + color_matrix_last = list( + 1, 0, 0, + 0, 1, 0, + 0, 0, 1, + 0, 0, 0 + ) + +/obj/machinery/gear_painter/update_icon() + if(panel_open) + icon_state = "colormate_open" + else if(inoperable()) + icon_state = "colormate_off" + else if(inserted) + icon_state = "colormate_active" + else + icon_state = "colormate" + +/obj/machinery/gear_painter/Destroy() + inserted.forceMove(drop_location()) + return ..() + +/obj/machinery/gear_painter/attackby(obj/item/I, mob/living/user) + if(inserted) + to_chat(user, "The machine is already loaded.") + return + if(default_deconstruction_screwdriver(user, I)) + return + if(default_deconstruction_crowbar(user, I)) + return + if(default_unfasten_wrench(user, I, 40)) + return + if(user.a_intent == INTENT_HARM) + return ..() + + if(is_type_in_list(I, allowed_types) && !inoperable()) + if(!user.transferItemToLoc(I, src)) + to_chat(user, "[I] is stuck to your hand!") + return + user.visible_message("[user] inserts [I] into [src]'s receptable.") + + inserted = I + update_icon() + +/obj/machinery/gear_painter/ui_interact(mob/user) + if(inoperable()) + return + user.set_machine(src) + var/list/dat = "Color Mate Control Panel
" + if(!processing.len) + dat += "No item inserted." + else + for(var/atom/movable/O in processing) + dat += "Item inserted: [O]
" + dat += "Matrix mode: [matrix_mode? "On" : "Off"]" + if(!matrix_mode) + dat += "Select new color.
" + dat += "Color: " + dat += "Apply new color.

" + else + // POGGERS +#define MATRIX_FIELD(field, default) " " + dat += "
" + dat += "" + dat += "[color] is far too dark!") + return FALSE + return TRUE + else // matrix + // We test using full red, green, blue, and white + // A predefined number of them must pass to be considered valid + var/passed = 0 + var/list/HSV +#define TEST(color) \ + HSV = ReadHSV(RGBMatrixTransform(testing, color)); \ + if(HSV[3] >= minimum_matrix_lightness) { \ + passed++; \ + } + TEST("FF0000") + TEST("00FF00") + TEST("0000FF") + TEST("FFFFFF") +#undef TEST + if(passed < minimum_matrix_tests) + to_chat(user, "[english_list(color)] is not allowed.") + return FALSE + return TRUE