Files
Joshua Kidder 7a3ad79506 All camelCase (Brute|Burn|Fire|Tox|Oxy|Organ|Stamina)(Loss) procs now use snake_case. UNDERSCORES RULE! (#94111)
## About The Pull Request
It's just a partial cleanup of
anti-[STYLE](https://github.com/tgstation/tgstation/blob/master/.github/guides/STYLE.md)
code from /tg/'s ancient history. I compiled & tested with my helpful
assistant and damage is still working.

<img width="1920" height="1040" alt="image"
src="https://github.com/user-attachments/assets/26dabc17-088f-4008-b299-3ff4c27142c3"
/>


I'll upload the .cs script I used to do it shortly.

## Why It's Good For The Game
Just minor code cleanup.

Script used is located at https://metek.tech/camelTo-Snake.7z

EDIT 11/23/25: Updated the script to use multithreading and sequential
scan so it works a hell of a lot faster
```
/*
//
Copyright 2025 Joshua 'Joan Metekillot' Kidder

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
//
*/
using System.Text.RegularExpressions;
class Program
{
    static async Task Main(string[] args)
    {
        var readFile = new FileStreamOptions
        {
            Access = FileAccess.Read,
            Share = FileShare.ReadWrite,
            Options = FileOptions.Asynchronous | FileOptions.SequentialScan
        };
        FileStreamOptions writeFile = new FileStreamOptions
        {
            Share = FileShare.ReadWrite,
            Access = FileAccess.ReadWrite,
            Mode = FileMode.Truncate,
            Options = FileOptions.Asynchronous
        };
        RegexOptions regexOptions = RegexOptions.Multiline | RegexOptions.Compiled;
        Dictionary<string, int> changedProcs = new();
        string regexPattern = @"(?<=\P{L})([a-z]+)([A-Z]{1,2}[a-z]+)*(Brute|Burn|Fire|Tox|Oxy|Organ|Stamina)(Loss)([A-Z]{1,2}[a-z]+)*";
        Regex camelCaseProcRegex = new(regexPattern, regexOptions);

        string snakeify(Match matchingRegex)
        {
            var vals =
            matchingRegex.Groups.Cast<Group>().SelectMany(_ => _.Captures).Select(_ => _.Value).ToArray();
            var newVal = string.Join("_", vals.Skip(1).ToArray()).ToLower();
            string logString = $"{vals[0]} => {newVal}";
            if (changedProcs.TryGetValue(logString, out int value))
            {
                changedProcs[logString] = value + 1;
            }
            else
            {
                changedProcs.Add(logString, 1);
            }
            return newVal;
        }
        var dmFiles = Directory.EnumerateFiles(".", "*.dm", SearchOption.AllDirectories).ToAsyncEnumerable<string>();

        // uses default ParallelOptions
        // https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.paralleloptions?view=net-10.0#main
        await Parallel.ForEachAsync(dmFiles, async (filePath, UnusedCancellationToken) =>
        {
            var reader = new StreamReader(filePath, readFile);
            string oldContent = await reader.ReadToEndAsync();
            string newContent = camelCaseProcRegex.Replace(oldContent, new MatchEvaluator((Func<Match, string>)snakeify));
            if (oldContent != newContent)
            {
                var writer = new StreamWriter(filePath, writeFile);
                await writer.WriteAsync(newContent);
                await writer.DisposeAsync();
            }
            reader.Dispose();
        });
        var logToList = changedProcs.Cast<KeyValuePair<string, int>>().ToList();
        foreach (var pair in logToList)
        {
            Console.WriteLine($"{pair.Key}: {pair.Value} locations");
        }
    }
}

```

## Changelog
🆑 Bisar
code: All (Brute|Burn|Fire|Tox|Oxy|Organ|Stamina)(Loss) procs now use
snake_case, in-line with the STYLE guide. Underscores rule!
/🆑
2025-11-27 15:50:23 -05:00

149 lines
5.0 KiB
Plaintext

/**
* A component to reset the parent to its previous state after some time passes
*/
/datum/component/dejavu
dupe_mode = COMPONENT_DUPE_ALLOWED
///message sent when dejavu rewinds
var/rewind_message = "You remember a time not so long ago..."
///message sent when dejavu is out of rewinds
var/no_rewinds_message = "But the memory falls out of your reach."
/// The turf the parent was on when this components was applied, they get moved back here after the duration
var/turf/starting_turf
/// Determined by the type of the parent so different behaviours can happen per type
var/rewind_type
/// How many rewinds will happen before the effect ends
var/rewinds_remaining
/// How long to wait between each rewind
var/rewind_interval
/// Do we add a new component before teleporting the target to they teleport to the place where *we* teleported them from?
var/repeating_component
/// The starting value of toxin loss at the beginning of the effect
var/tox_loss = 0
/// The starting value of oxygen loss at the beginning of the effect
var/oxy_loss = 0
/// The starting value of stamina loss at the beginning of the effect
var/stamina_loss = 0
/// The starting value of brain loss at the beginning of the effect
var/brain_loss = 0
/// The starting value of brute loss at the beginning of the effect
/// This only applies to simple animals
var/brute_loss
/// The starting value of integrity at the beginning of the effect
/// This only applies to objects
var/integrity
/// A list of body parts saved at the beginning of the effect
var/list/datum/saved_bodypart/saved_bodyparts
/datum/component/dejavu/Initialize(rewinds = 1, interval = 10 SECONDS, add_component = FALSE)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
starting_turf = get_turf(parent)
rewinds_remaining = rewinds
rewind_interval = interval
repeating_component = add_component
if(isliving(parent))
var/mob/living/L = parent
tox_loss = L.get_tox_loss()
oxy_loss = L.get_oxy_loss()
stamina_loss = L.get_stamina_loss()
brain_loss = L.get_organ_loss(ORGAN_SLOT_BRAIN)
rewind_type = PROC_REF(rewind_living)
if(iscarbon(parent))
var/mob/living/carbon/C = parent
saved_bodyparts = C.save_bodyparts()
rewind_type = PROC_REF(rewind_carbon)
else if(isanimal_or_basicmob(parent))
var/mob/living/animal = parent
brute_loss = animal.bruteloss
rewind_type = PROC_REF(rewind_animal)
else if(isobj(parent))
var/obj/O = parent
integrity = O.get_integrity()
rewind_type = PROC_REF(rewind_obj)
addtimer(CALLBACK(src, rewind_type), rewind_interval)
/datum/component/dejavu/Destroy()
starting_turf = null
saved_bodyparts = null
return ..()
/datum/component/dejavu/proc/rewind()
to_chat(parent, span_notice(rewind_message))
//comes after healing so new limbs comically drop to the floor
if(starting_turf)
if(!check_teleport_valid(parent, starting_turf))
to_chat(parent, span_warning("For some reason, your head aches and fills with mental fog when you try to think of where you were... It feels like you're now going against some dull, unstoppable universal force."))
else
var/atom/movable/master = parent
master.forceMove(starting_turf)
rewinds_remaining --
if(rewinds_remaining || rewinds_remaining < 0)
addtimer(CALLBACK(src, rewind_type), rewind_interval)
else
to_chat(parent, span_notice(no_rewinds_message))
qdel(src)
/datum/component/dejavu/proc/rewind_living()
if (rewinds_remaining == 1 && repeating_component && !iscarbon(parent) && !isanimal_or_basicmob(parent))
parent.AddComponent(type, 1, rewind_interval, TRUE)
var/mob/living/master = parent
master.set_tox_loss(tox_loss)
master.set_oxy_loss(oxy_loss)
master.set_stamina_loss(stamina_loss)
master.set_organ_loss(ORGAN_SLOT_BRAIN, brain_loss)
rewind()
/datum/component/dejavu/proc/rewind_carbon()
if (rewinds_remaining == 1 && repeating_component)
parent.AddComponent(type, 1, rewind_interval, TRUE)
if(saved_bodyparts)
var/mob/living/carbon/master = parent
master.apply_saved_bodyparts(saved_bodyparts)
rewind_living()
/datum/component/dejavu/proc/rewind_animal()
if (rewinds_remaining == 1 && repeating_component)
parent.AddComponent(type, 1, rewind_interval, TRUE)
var/mob/living/master = parent
master.bruteloss = brute_loss
master.updatehealth()
rewind_living()
/datum/component/dejavu/proc/rewind_obj()
if (rewinds_remaining == 1 && repeating_component)
parent.AddComponent(type, 1, rewind_interval, TRUE)
var/obj/master = parent
master.update_integrity(integrity)
rewind()
///differently themed dejavu for modsuits.
/datum/component/dejavu/timeline
rewind_message = "Your suit rewinds, pulling you through spacetime!"
no_rewinds_message = "\"Rewind complete. You have arrived at: 10 seconds ago.\""
/datum/component/dejavu/timeline/rewind()
playsound(get_turf(parent), 'sound/items/modsuit/rewinder.ogg')
. = ..()
/datum/component/dejavu/wizard
rewind_message = "Your temporal ward activated, pulling you through spacetime!"
/datum/component/dejavu/wizard/rewind()
playsound(get_turf(parent), 'sound/items/modsuit/rewinder.ogg')
. = ..()