From 075cd60828fa449a43f6a252c5edf3f48625a67d Mon Sep 17 00:00:00 2001 From: Trigg <36010999+TriggeredBoi@users.noreply.github.com> Date: Thu, 15 Apr 2021 17:53:27 -0300 Subject: [PATCH] Centralized dummy lookalike generation (#58366) --- code/modules/admin/outfit_editor.dm | 11 +++------- code/modules/admin/verbs/selectequipment.dm | 16 +++++--------- code/modules/mob/living/carbon/human/dummy.dm | 22 +++++++++++++++++++ .../mob/living/carbon/human/human_defines.dm | 1 + .../mob/living/carbon/human/human_helpers.dm | 7 ++++++ 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/code/modules/admin/outfit_editor.dm b/code/modules/admin/outfit_editor.dm index 68d9ad93ea9..9a99d8b20ee 100644 --- a/code/modules/admin/outfit_editor.dm +++ b/code/modules/admin/outfit_editor.dm @@ -37,12 +37,7 @@ /datum/outfit_editor/proc/init_dummy() dummy_key = "outfit_editor_[owner]" - var/mob/living/carbon/human/dummy/dummy = generate_or_wait_for_human_dummy(dummy_key) - var/mob/living/carbon/carbon_target = owner.mob - if(istype(carbon_target)) - carbon_target.dna.transfer_identity(dummy) - dummy.updateappearance() - + generate_dummy_lookalike(dummy_key, owner.mob) unset_busy_human_dummy(dummy_key) /datum/outfit_editor/ui_interact(mob/user, datum/tgui/ui) @@ -78,9 +73,9 @@ data["outfit"] = serialize_outfit() data["saveable"] = !GLOB.custom_outfits.Find(drip) - var/datum/preferences/prefs = owner.prefs + if(!dummy_key) + init_dummy() var/icon/dummysprite = get_flat_human_icon(null, - prefs = prefs, dummy_key = dummy_key, showDirs = list(SOUTH), outfit_override = drip) diff --git a/code/modules/admin/verbs/selectequipment.dm b/code/modules/admin/verbs/selectequipment.dm index 8e8c8b323db..4184fed68ff 100644 --- a/code/modules/admin/verbs/selectequipment.dm +++ b/code/modules/admin/verbs/selectequipment.dm @@ -23,7 +23,6 @@ var/mob/target_mob var/dummy_key - var/mob/living/carbon/human/dummy/dummy //static list to share all the outfit typepaths between all instances of this datum. var/static/list/cached_outfits @@ -63,12 +62,7 @@ /datum/select_equipment/proc/init_dummy() dummy_key = "selectequipmentUI_[target_mob]" - dummy = generate_or_wait_for_human_dummy(dummy_key) - var/mob/living/carbon/carbon_target = target_mob - if(istype(carbon_target)) - carbon_target.dna.transfer_identity(dummy) - dummy.updateappearance() - + generate_dummy_lookalike(dummy_key, target_mob) unset_busy_human_dummy(dummy_key) return @@ -112,14 +106,16 @@ /datum/select_equipment/ui_data(mob/user) var/list/data = list() - if(!dummy) + if(!dummy_key) init_dummy() - var/datum/preferences/prefs = target_mob?.client?.prefs - var/icon/dummysprite = get_flat_human_icon(null, prefs=prefs, dummy_key = dummy_key, outfit_override = selected_outfit) + var/icon/dummysprite = get_flat_human_icon(null, + dummy_key = dummy_key, + outfit_override = selected_outfit) data["icon64"] = icon2base64(dummysprite) data["name"] = target_mob + var/datum/preferences/prefs = user?.client?.prefs data["favorites"] = list() if(prefs) data["favorites"] = prefs.favorite_outfits diff --git a/code/modules/mob/living/carbon/human/dummy.dm b/code/modules/mob/living/carbon/human/dummy.dm index 360efeb0d7c..c668624a897 100644 --- a/code/modules/mob/living/carbon/human/dummy.dm +++ b/code/modules/mob/living/carbon/human/dummy.dm @@ -45,6 +45,28 @@ GLOBAL_LIST_EMPTY(dummy_mob_list) D.in_use = TRUE return D +/proc/generate_dummy_lookalike(slotkey, mob/target) + if(!istype(target)) + return generate_or_wait_for_human_dummy(slotkey) + + var/mob/living/carbon/human/dummy/copycat = generate_or_wait_for_human_dummy(slotkey) + + if(iscarbon(target)) + var/mob/living/carbon/carbon_target = target + carbon_target.dna.transfer_identity(copycat, transfer_SE = TRUE) + + if(ishuman(target)) + var/mob/living/carbon/human/human_target = target + human_target.copy_clothing_prefs(copycat) + + copycat.updateappearance(icon_update=TRUE, mutcolor_update=TRUE, mutations_overlay_update=TRUE) + else + //even if target isn't a carbon, if they have a client we can make the + //dummy look like what their human would look like based on their prefs + target?.client?.prefs?.copy_to(copycat, icon_updates=TRUE, roundstart_checks=FALSE, character_setup=TRUE) + + return copycat + /proc/unset_busy_human_dummy(slotkey) if(!slotkey) return diff --git a/code/modules/mob/living/carbon/human/human_defines.dm b/code/modules/mob/living/carbon/human/human_defines.dm index 49eecdb37bb..b888984884d 100644 --- a/code/modules/mob/living/carbon/human/human_defines.dm +++ b/code/modules/mob/living/carbon/human/human_defines.dm @@ -32,6 +32,7 @@ var/age = 30 //Player's age + //consider updating /mob/living/carbon/human/copy_clothing_prefs() if adding more of these var/underwear = "Nude" //Which underwear the player wants var/underwear_color = "000" var/undershirt = "Nude" //Which undershirt the player wants diff --git a/code/modules/mob/living/carbon/human/human_helpers.dm b/code/modules/mob/living/carbon/human/human_helpers.dm index 85584f5b247..91a14957e76 100644 --- a/code/modules/mob/living/carbon/human/human_helpers.dm +++ b/code/modules/mob/living/carbon/human/human_helpers.dm @@ -231,3 +231,10 @@ else return "[t_He] [t_is] limp and unresponsive; there are no signs of life and [t_his] soul has departed..." +///copies over clothing preferences like underwear to another human +/mob/living/carbon/human/proc/copy_clothing_prefs(mob/living/carbon/human/destination) + destination.underwear = underwear + destination.underwear_color = underwear_color + destination.undershirt = undershirt + destination.socks = socks + destination.jumpsuit_style = jumpsuit_style