Light Sensitivity Refactor (#22386)

The last time the Light Sensitivity code was changed, I remarked in a
review that "This should probably be a component so that its code isn't
being run on every mob forever". Well I've gotten around to doing that
myself, except I figured out it's even better off as an Element in this
situation rather than a Component. So this is now my first time adding
Elements to the repo. It turns out they're really awesome when paired
with signals.

This PR removes the hardcoded check for the light senstivity and dark
phobia traits from the Life() path, replacing them instead with two
Elements which hook into the pre-existing signal used to handle vision
updates for human mobs. I've mainly done this to help cut down on the
overwhelmingly high cost of the Life() codepath, which is currently one
of the most expensive paths we have.

While I was at it with refactoring these two, I noticed that there
wasn't a trait selection for either of them, so I added selections for
both traits to the disabilities tab so that players can opt-in to being
light sensitive or afraid of the dark!

<img width="318" height="336" alt="image"
src="https://github.com/user-attachments/assets/a1e60e83-d899-44df-8ea3-0cd5a87c231c"
/>
This commit is contained in:
VMSolidus
2026-05-18 15:21:19 -04:00
committed by GitHub
parent e8d1eedc11
commit 3b6d0f20ec
12 changed files with 175 additions and 78 deletions
@@ -28,9 +28,13 @@
possible_accents = list(ACCENT_HIMEO)
possible_citizenships = CITIZENSHIPS_COALITION
possible_religions = RELIGIONS_COALITION
origin_traits = list(TRAIT_ORIGIN_COLD_RESISTANCE, TRAIT_ORIGIN_LIGHT_SENSITIVE)
origin_traits = list(TRAIT_ORIGIN_COLD_RESISTANCE)
origin_traits_descriptions = list("are more acclimatised to the cold.", "are more sensitive to bright lights")
/singleton/origin_item/origin/himeo/on_apply(mob/living/carbon/human/H)
. = ..()
H.AddElement(/datum/element/light_sensitivity)
/singleton/origin_item/origin/vysoka
name = "Free System of Vysoka"
desc = "The agricultural center of the Coalition of Colonies, the Free System of Vysoka is generally conservative and often seen as heavily traditional by the broader Coalition. Most Vysokans live in rural environments, and few cities can be found across the planet's surface. Vysoka is also home to large semi-nomadic communities known as \"Hosts,\" that are not connected with any particular community or city. Religion and spiritualism are important aspects of Vysokan life, particularly for its rural population."
@@ -96,9 +100,12 @@
possible_accents = list(ACCENT_ASSUNZIONE)
possible_citizenships = CITIZENSHIPS_COALITION
possible_religions = list(RELIGION_LUCEISM)
origin_traits = list(TRAIT_ORIGIN_DARK_AFRAID)
origin_traits_descriptions = list("tend to feel nervous in the dark")
/singleton/origin_item/origin/assunzione/on_apply(mob/living/carbon/human/H)
. = ..()
H.AddElement(/datum/element/dark_afraid)
/singleton/origin_item/origin/ncf
name = "Non-Coalition Frontier"
desc = "The frontier beyond the Coalition of Colonies before unexplored \"deadspace,\" has seen limited human colonization, but still dwells mostly outside of the influence of any government. Most residents of this distant frontier that drift back to the more populated Orion Spur eventually claim citizenship with the Coalition of Colonies due to its ease of acquisition."
@@ -92,9 +92,13 @@
possible_accents = list(ACCENT_EUROPA)
possible_citizenships = CITIZENSHIPS_SOLARIAN
possible_religions = RELIGIONS_SOLARIAN
origin_traits = list(TRAIT_ORIGIN_COLD_RESISTANCE, TRAIT_ORIGIN_LIGHT_SENSITIVE)
origin_traits = list(TRAIT_ORIGIN_COLD_RESISTANCE)
origin_traits_descriptions = list("are more acclimatised to the cold.", "are more sensitive to bright lights")
/singleton/origin_item/origin/jupiter_eur/on_apply(mob/living/carbon/human/H)
. = ..()
H.AddElement(/datum/element/light_sensitivity)
/singleton/origin_item/origin/saturn
name = "Saturn"
desc = "The moons of Saturn, while not as populated as the Jovian moons of Jupiter, are an important part of the Alliance and major population centers in the Sol System. Many tourists visit Saturn to see its massive rings, the largest and most complex in the Solar System."