Skip to content

Commit

Permalink
[MIRROR] Dynamic material colors applied for insertion animation into…
Browse files Browse the repository at this point in the history
… lathes (#1412)

* Dynamic material colors applied for insertion animation into lathes (#81692)

## About The Pull Request
So you've noticed that when we insert say uranium into a techfab it
shows us the proper green sheet getting consumed as the animation but
when you insert that same uranium into an autolathe is shows us a blue
sheet animation instead?

Yup not realistic, this is because the autolathe has only 2 animation
types one for inserting iron & the other for glass. Every material type
would have to share these 2 animations making it look bland.

Now the material color is blended on the icon itself allowing for the
right color to be applied on the insertion animation

Plus this also trims the sizes of our dmi files so it's a win overall


https://github.com/tgstation/tgstation/assets/110812394/bb643691-8d3b-4822-8371-346c2d5e5be3

## Changelog
:cl:
fix: inserting a material sheet into an lathes should show the correct
animation color
/:cl:

* Dynamic material colors applied for insertion animation into lathes

---------

Co-authored-by: SyncIt21 <[email protected]>
  • Loading branch information
2 people authored and StealsThePRs committed Mar 12, 2024
1 parent a062f16 commit 7ad868a
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 19 deletions.
15 changes: 12 additions & 3 deletions code/game/machinery/autolathe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,19 @@
/obj/machinery/autolathe/proc/AfterMaterialInsert(container, obj/item/item_inserted, last_inserted_id, mats_consumed, amount_inserted, atom/context)
SIGNAL_HANDLER

flick("autolathe_[item_inserted.has_material_type(/datum/material/glass) ? "r" : "o"]", src)

//we use initial(active_power_usage) because higher tier parts will have higher active usage but we have no benifit from it
directly_use_power(ROUND_UP((amount_inserted / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * 0.01 * initial(active_power_usage)))
if(directly_use_power(ROUND_UP((amount_inserted / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * 0.02 * initial(active_power_usage))))
flick_overlay_view(mutable_appearance('icons/obj/machines/lathes.dmi', "autolathe_mat"), 1 SECONDS)

var/datum/material/highest_mat_ref
var/highest_mat = 0
for(var/datum/material/mat as anything in mats_consumed)
var/present_mat = mats_consumed[mat]
if(present_mat > highest_mat)
highest_mat = present_mat
highest_mat_ref = mat

flick_overlay_view(material_insertion_animation(highest_mat_ref.greyscale_colors), 1 SECONDS)

/obj/machinery/autolathe/ui_interact(mob/user, datum/tgui/ui)
if(!is_operational)
Expand Down
22 changes: 22 additions & 0 deletions code/game/objects/effects/material_insert.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Creates a mutable appearance with the material color applied for its insertion animation into an autolathe or techfab
* Arguments
*
* * color - the material color that will be applied
*/
/proc/material_insertion_animation(color)
RETURN_TYPE(/mutable_appearance)

var/static/list/mutable_appearance/apps = list()

var/mutable_appearance/cached_app = apps[color]
if(isnull(cached_app))
var/icon/modified_icon = icon('icons/obj/machines/research.dmi', "material_insertion")

//assuming most of the icon is white we find what ratio to scale the intensity of each part roughly
var/list/rgb_list = rgb2num(color)
modified_icon.SetIntensity(rgb_list[1] / 255, rgb_list[2] / 255, rgb_list[3] / 255)
cached_app = mutable_appearance(modified_icon, "material_insertion")

apps[color] = cached_app
return cached_app
31 changes: 16 additions & 15 deletions code/modules/research/machinery/_production.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/datum/component/remote_materials, \
mapload, \
mat_container_signals = list( \
COMSIG_MATCONTAINER_ITEM_CONSUMED = TYPE_PROC_REF(/obj/machinery/rnd, local_material_insert)
COMSIG_MATCONTAINER_ITEM_CONSUMED = TYPE_PROC_REF(/obj/machinery/rnd/production, local_material_insert)
) \
)

Expand All @@ -49,7 +49,6 @@
cached_designs = null
return ..()


// Stuff for the stripe on the department machines
/obj/machinery/rnd/production/default_deconstruction_screwdriver(mob/user, icon_state_open, icon_state_closed, obj/item/screwdriver)
. = ..()
Expand Down Expand Up @@ -128,7 +127,7 @@
addtimer(CALLBACK(src, PROC_REF(update_designs)), 2 SECONDS, TIMER_UNIQUE | TIMER_OVERRIDE)

///When materials are instered via silo link
/obj/machinery/rnd/proc/silo_material_insert(obj/machinery/rnd/machine, container, obj/item/item_inserted, last_inserted_id, list/mats_consumed, amount_inserted)
/obj/machinery/rnd/production/proc/silo_material_insert(obj/machinery/rnd/machine, container, obj/item/item_inserted, last_inserted_id, list/mats_consumed, amount_inserted)
SIGNAL_HANDLER

process_item(item_inserted, mats_consumed, amount_inserted)
Expand All @@ -141,37 +140,39 @@
* * list/mats_consumed - list of mats consumed
* * amount_inserted - amount of material actually processed
*/
/obj/machinery/rnd/proc/process_item(obj/item/item_inserted, list/mats_consumed, amount_inserted)
/obj/machinery/rnd/production/proc/process_item(obj/item/item_inserted, list/mats_consumed, amount_inserted)
PRIVATE_PROC(TRUE)

//we use initial(active_power_usage) because higher tier parts will have higher active usage but we have no benifit from it
if(directly_use_power(ROUND_UP((amount_inserted / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * 0.01 * initial(active_power_usage))))
var/mat_name = "iron"
if(directly_use_power(ROUND_UP((amount_inserted / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * 0.02 * initial(active_power_usage))))
var/datum/material/highest_mat_ref

var/highest_mat = 0
for(var/datum/material/mat as anything in mats_consumed)
var/present_mat = mats_consumed[mat]
if(present_mat > highest_mat)
mat_name = initial(mat.name)
if(mat_name == "silver" || mat_name == "titanium" || mat_name == "plastic") //these materials have similar appearances so use an common overlay for them
mat_name = "shiny"
highest_mat = present_mat
highest_mat_ref = mat

flick_animation(mat_name)
flick_animation(highest_mat_ref)
/**
* Plays an visual animation when materials are inserted
* Arguments
*
* * mat_name - the name of the material we are trying to animate on the machine
* * mat - the material ref we are trying to animate on the machine
*/
/obj/machinery/rnd/proc/flick_animation(mat_name)
/obj/machinery/rnd/production/proc/flick_animation(datum/material/mat_ref)
PROTECTED_PROC(TRUE)
SHOULD_CALL_PARENT(FALSE)

flick_overlay_view(mutable_appearance('icons/obj/machines/research.dmi', "protolathe_[mat_name]"), 1 SECONDS)
//first play the insertion animation
flick_overlay_view(material_insertion_animation(mat_ref.greyscale_colors), 1 SECONDS)

//now play the progress bar animation
flick_overlay_view(mutable_appearance('icons/obj/machines/research.dmi', "protolathe_progress"), 1 SECONDS)

///When materials are instered into local storage
/obj/machinery/rnd/proc/local_material_insert(container, obj/item/item_inserted, last_inserted_id, list/mats_consumed, amount_inserted, atom/context)
/obj/machinery/rnd/production/proc/local_material_insert(container, obj/item/item_inserted, last_inserted_id, list/mats_consumed, amount_inserted, atom/context)
SIGNAL_HANDLER

process_item(item_inserted, mats_consumed, amount_inserted)
Expand Down Expand Up @@ -288,7 +289,7 @@
return

//we use initial(active_power_usage) because higher tier parts will have higher active usage but we have no benifit from it
if(!directly_use_power(ROUND_UP((amount / MAX_STACK_SIZE) * 0.01 * initial(active_power_usage))))
if(!directly_use_power(ROUND_UP((amount / MAX_STACK_SIZE) * 0.02 * initial(active_power_usage))))
say("No power to dispense sheets")
return

Expand Down
2 changes: 1 addition & 1 deletion code/modules/research/machinery/circuit_imprinter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

return 0.5 ** max(rating - 1, 0) // One sheet, half sheet, quarter sheet, eighth sheet.

/obj/machinery/rnd/production/circuit_imprinter/flick_animation(mat_name)
/obj/machinery/rnd/production/circuit_imprinter/flick_animation(datum/material/mat)
return //we presently have no animation

/obj/machinery/rnd/production/circuit_imprinter/offstation
Expand Down
Binary file modified icons/obj/machines/lathes.dmi
Binary file not shown.
Binary file modified icons/obj/machines/research.dmi
Binary file not shown.
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,7 @@
#include "code\game\objects\effects\info.dm"
#include "code\game\objects\effects\landmarks.dm"
#include "code\game\objects\effects\lighting.dm"
#include "code\game\objects\effects\material_insert.dm"
#include "code\game\objects\effects\mines.dm"
#include "code\game\objects\effects\misc.dm"
#include "code\game\objects\effects\overlays.dm"
Expand Down

0 comments on commit 7ad868a

Please sign in to comment.