From f8d510e7f5a8aeb495cca81996b3b3dce8877d94 Mon Sep 17 00:00:00 2001 From: dearmochi <1496804+dearmochi@users.noreply.github.com> Date: Thu, 15 Jul 2021 23:07:24 +0200 Subject: [PATCH] Lightly refactors human Initialize() (#15738) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactors human Initialize * spelling * use ComponentInitialize() * 🇬🇧 --- code/_onclick/hud/human.dm | 2 +- code/modules/mob/living/carbon/carbon.dm | 4 ++ code/modules/mob/living/carbon/human/human.dm | 61 +++++++++++-------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/code/_onclick/hud/human.dm b/code/_onclick/hud/human.dm index 8f125079d6b..39807d6a8c5 100644 --- a/code/_onclick/hud/human.dm +++ b/code/_onclick/hud/human.dm @@ -376,7 +376,7 @@ for(var/obj/screen/craft/crafting in static_inventory) if(!S.can_craft) crafting.invisibility = INVISIBILITY_ABSTRACT - H.handcrafting.close(H) + H.handcrafting?.close(H) else crafting.invisibility = initial(crafting.invisibility) diff --git a/code/modules/mob/living/carbon/carbon.dm b/code/modules/mob/living/carbon/carbon.dm index 9815d9573f9..22562eb6633 100644 --- a/code/modules/mob/living/carbon/carbon.dm +++ b/code/modules/mob/living/carbon/carbon.dm @@ -404,6 +404,10 @@ /mob/living/carbon/proc/tintcheck() return 0 +/mob/living/carbon/proc/create_dna() + if(!dna) + dna = new() + /mob/living/carbon/proc/getDNA() return dna diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index ee5b3b561fd..839efbb02cc 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -14,38 +14,47 @@ . = ..() /mob/living/carbon/human/Initialize(mapload, datum/species/new_species = /datum/species/human) - if(!dna) - dna = new /datum/dna(null) - // Species name is handled by set_species() + create_dna() . = ..() - set_species(new_species, 1, delay_icon_update = 1, skip_same_check = TRUE) - - if(dna.species) - real_name = dna.species.get_random_name(gender) - name = real_name - if(mind) - mind.name = real_name - - create_reagents(330) - - handcrafting = new() - - // Set up DNA. - if(dna) - dna.ready_dna(src) - dna.real_name = real_name - sync_organ_dna(1) - - physiology = new() - - AddComponent(/datum/component/footstep, FOOTSTEP_MOB_HUMAN, 1, -6) + setup_dna(new_species) + setup_other() UpdateAppearance() GLOB.human_list += src +/** + * Sets up DNA and species. + * + * Arguments: + * * new_species - The new species to assign. + */ +/mob/living/carbon/human/proc/setup_dna(datum/species/new_species) + set_species(new_species, use_default_color = TRUE, delay_icon_update = TRUE, skip_same_check = TRUE) + // Name + real_name = dna.species.get_random_name(gender) + name = real_name + if(mind) + mind.name = real_name + // DNA ready + dna.ready_dna(src) + dna.real_name = real_name + sync_organ_dna() + +/** + * Sets up other variables and components that may be needed for gameplay. + */ +/mob/living/carbon/human/proc/setup_other() + create_reagents(330) + physiology = new() + +/mob/living/carbon/human/ComponentInitialize() + AddComponent(/datum/component/footstep, FOOTSTEP_MOB_HUMAN, 1, -6) + /mob/living/carbon/human/OpenCraftingMenu() + if(!handcrafting) + handcrafting = new() handcrafting.ui_interact(src) /mob/living/carbon/human/prepare_data_huds() @@ -1211,7 +1220,7 @@ sec_hud_set_ID() -/mob/living/carbon/human/proc/set_species(datum/species/new_species, default_colour, delay_icon_update = FALSE, skip_same_check = FALSE, retain_damage = FALSE, transformation = FALSE) +/mob/living/carbon/human/proc/set_species(datum/species/new_species, use_default_color = FALSE, delay_icon_update = FALSE, skip_same_check = FALSE, retain_damage = FALSE, transformation = FALSE) if(!skip_same_check) if(dna.species.name == initial(new_species.name)) return @@ -1246,7 +1255,7 @@ hunger_drain = dna.species.hunger_drain digestion_ratio = dna.species.digestion_ratio - if(dna.species.base_color && default_colour) + if(dna.species.base_color && use_default_color) //Apply colour. skin_colour = dna.species.base_color else