Makes tool colors work, despaghettifies code (#9231)

I finally figured out how to make tool inhands and inhand coloring work properly, so custom colors can apply to inhands! (yes, even the stuff from loadout.)

Code-wise, this guts the superfluous our_color variable.
This cuts it out from screwdrivers, wirecutters, cable, and everything else which uses this shit.
I'm pretty sure testing this has taken out a day out of my life.

Also I fixed up the cable examine to be less crappy. (so you can finally see cable descriptions.)

Don't mind the commits, I just built this on top the handcuff noose PR.
This commit is contained in:
Wowzewow (Wezzy)
2020-07-02 20:40:17 +03:00
committed by GitHub
parent f4aad0a7ff
commit 3160508c1a
17 changed files with 181 additions and 162 deletions
+3
View File
@@ -61,6 +61,8 @@
//var/item_state = null // Used to specify the item state for the on-mob overlays.
var/item_state_slots //overrides the default item_state for particular slots.
var/build_from_parts = FALSE // when it uses coloration and a part of it wants to remain uncolored. e.g., handle of the screwdriver is colored while the head is not.
var/worn_overlay = null // used similarly as above, except for inhands.
//ITEM_ICONS ARE DEPRECATED. USE CONTAINED SPRITES IN FUTURE
// Used to specify the icon file to be used when the item is worn. If not set the default icon for that slot will be used.
@@ -85,6 +87,7 @@
var/icon_override //Used to override hardcoded clothing dmis in human clothing pr
var/charge_failure_message = " cannot be recharged."
var/cleaving = FALSE
+5 -4
View File
@@ -58,10 +58,11 @@
/obj/item/stack/examine(mob/user)
if(..(user, 1))
if(!uses_charge)
to_chat(user, "There [src.amount == 1 ? "is" : "are"] [src.amount] [src.singular_name]\s in the stack.")
else
to_chat(user, "There is enough charge for [get_amount()].")
if(!iscoil())
if(!uses_charge)
to_chat(user, "There [src.amount == 1 ? "is" : "are"] [src.amount] [src.singular_name]\s in the stack.")
else
to_chat(user, "You have enough charge to produce <b>[get_amount()]</b>.")
/obj/item/stack/attack_self(mob/user as mob)
list_recipes(user)
+23 -25
View File
@@ -121,6 +121,8 @@
name = "cable restraints"
desc = "Looks like some cables tied together. Could be used to tie something up."
icon_state = "cablecuff"
item_state = "coil"
color = COLOR_RED
item_icons = list(
slot_l_hand_str = 'icons/mob/items/stacks/lefthand_materials.dmi',
slot_r_hand_str = 'icons/mob/items/stacks/righthand_materials.dmi',
@@ -129,47 +131,43 @@
cuff_sound = 'sound/weapons/cablecuff.ogg'
cuff_type = "cable restraints"
elastic = TRUE
var/our_color
var/build_from_parts = TRUE
build_from_parts = TRUE
worn_overlay = "end"
/obj/item/handcuffs/cable/Initialize(mapload, new_color)
. = ..()
if(new_color)
our_color = new_color
update_icon()
color = new_color
/obj/item/handcuffs/cable/update_icon()
if(build_from_parts) //random colors!
if(!our_color)
our_color = pick(possible_cable_coil_colours)
var/color_hex = possible_cable_coil_colours[our_color]
color = color_hex
item_state = "coil-[our_color]" // hardcoded. sucks, but inhands are hard and I can't be bothered.
if(!color)
color = pick(COLOR_RED, COLOR_BLUE, COLOR_LIME, COLOR_ORANGE, COLOR_WHITE, COLOR_PINK, COLOR_YELLOW, COLOR_CYAN)
add_overlay(overlay_image(icon, "[initial(icon_state)]_end", flags=RESET_COLOR))
/obj/item/handcuffs/cable/yellow
our_color = "Yellow"
/obj/item/handcuffs/cable/green
our_color = "Green"
/obj/item/handcuffs/cable/pink
our_color = "Pink"
color = COLOR_YELLOW
/obj/item/handcuffs/cable/blue
our_color = "Blue"
color = COLOR_BLUE
/obj/item/handcuffs/cable/green
color = COLOR_GREEN
/obj/item/handcuffs/cable/pink
color = COLOR_PINK
/obj/item/handcuffs/cable/orange
our_color = "Orange"
color = COLOR_ORANGE
/obj/item/handcuffs/cable/cyan
our_color = "Cyan"
/obj/item/handcuffs/cable/red
our_color = "Red"
color = COLOR_CYAN
/obj/item/handcuffs/cable/white
our_color = "White"
color = COLOR_WHITE
/obj/item/handcuffs/cable/random/Initialize()
color = pick(COLOR_RED, COLOR_BLUE, COLOR_LIME, COLOR_ORANGE, COLOR_WHITE, COLOR_PINK, COLOR_YELLOW, COLOR_CYAN)
. = ..()
/obj/item/handcuffs/cable/attackby(var/obj/item/I, mob/user as mob)
..()
@@ -184,7 +182,7 @@
else if(I.iswirecutter())
user.visible_message("[user] cuts the [src].", SPAN_NOTICE("You cut the [src]."))
playsound(src.loc, 'sound/items/Wirecutter.ogg', 50, 1)
new/obj/item/stack/cable_coil(get_turf(src), 15, our_color)
new/obj/item/stack/cable_coil(get_turf(src), 15, color)
qdel(src)
update_icon(user)
+9 -41
View File
@@ -66,25 +66,14 @@
drop_sound = 'sound/items/drop/screwdriver.ogg'
pickup_sound = 'sound/items/pickup/screwdriver.ogg'
lock_picking_level = 5
var/build_from_parts = TRUE //if the tool uses random coloring
var/tool_colors = list( //if you're wondering why "blue" = COLOR_BLUE, it's so that inhands work.
"blue" = COLOR_BLUE,
"red" = COLOR_RED,
"purple" = COLOR_PURPLE,
"brown" = COLOR_BROWN,
"green" = COLOR_GREEN,
"cyan" = COLOR_CYAN,
"yellow" = COLOR_YELLOW
)
build_from_parts = TRUE
worn_overlay = "head"
/obj/item/screwdriver/Initialize()
. = ..()
if(build_from_parts) //random colors!
var/our_color = pick(tool_colors)
var/color_hex = tool_colors[our_color]
color = color_hex
item_state = "[initial(icon_state)]-[our_color]" // hardcoded. sucks, but inhands are hard and I can't be bothered.
add_overlay(overlay_image(icon, "[initial(icon_state)]_head", flags=RESET_COLOR))
color = pick(COLOR_BLUE, COLOR_RED, COLOR_PURPLE, COLOR_BROWN, COLOR_GREEN, COLOR_CYAN, COLOR_YELLOW)
add_overlay(overlay_image(icon, "[initial(icon_state)]_[worn_overlay]", flags=RESET_COLOR))
/obj/item/screwdriver/update_icon()
var/matrix/tf = matrix()
@@ -144,25 +133,14 @@
drop_sound = 'sound/items/drop/wirecutter.ogg'
pickup_sound = 'sound/items/pickup/wirecutter.ogg'
var/bomb_defusal_chance = 30 // 30% chance to safely defuse a bomb
var/build_from_parts = TRUE
var/tool_colors = list(
"blue" = COLOR_BLUE,
"red" = COLOR_RED,
"purple" = COLOR_PURPLE,
"brown" = COLOR_BROWN,
"green" = COLOR_GREEN,
"cyan" = COLOR_CYAN,
"yellow" = COLOR_YELLOW
)
build_from_parts = TRUE
worn_overlay = "head"
/obj/item/wirecutters/Initialize()
. = ..()
if(build_from_parts)
var/our_color = pick(tool_colors)
var/color_hex = tool_colors[our_color]
color = color_hex
item_state = "[initial(icon_state)]-[our_color]" // hardcoded. sucks, but inhands are hard and I can't be bothered.
add_overlay(overlay_image(icon, "[initial(icon_state)]_head", flags=RESET_COLOR))
color = pick(COLOR_BLUE, COLOR_RED, COLOR_PURPLE, COLOR_BROWN, COLOR_GREEN, COLOR_CYAN, COLOR_YELLOW)
add_overlay(overlay_image(icon, "[initial(icon_state)]_[worn_overlay]", flags=RESET_COLOR))
/obj/item/wirecutters/update_icon()
var/matrix/tf = matrix()
@@ -734,7 +712,6 @@
w_class = ITEMSIZE_SMALL
toolspeed = 3
usesound = 'sound/items/drill_use.ogg'
var/drillcolor = null
var/current_tool = 1
var/list/tools = list(
"screwdriverbit",
@@ -744,16 +721,7 @@
/obj/item/powerdrill/Initialize()
. = ..()
switch(pick("red", "blue", "yellow", "green"))
if ("red")
drillcolor = "red"
if ("blue")
drillcolor = "blue"
if ("green")
drillcolor = "green"
if ("yellow")
drillcolor = "yellow"
var/drillcolor = pick("red", "blue", "yellow", "green")
icon_state = "powerdrill[drillcolor]"
item_state = "powerdrill[drillcolor]"