mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-15 18:14:22 +01:00
7a3ad79506
## 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! /🆑
172 lines
5.9 KiB
Plaintext
172 lines
5.9 KiB
Plaintext
#define MENU_OPERATION 1
|
|
#define MENU_SURGERIES 2
|
|
|
|
/obj/machinery/computer/operating
|
|
name = "operating computer"
|
|
desc = "Monitors patient vitals and displays surgery steps. Can be loaded with surgery disks to perform experimental procedures. Automatically syncs to operating tables within its line of sight for surgical tech advancement."
|
|
icon_screen = "crew"
|
|
icon_keyboard = "med_key"
|
|
circuit = /obj/item/circuitboard/computer/operating
|
|
interaction_flags_machine = parent_type::interaction_flags_machine | INTERACT_MACHINE_REQUIRES_STANDING
|
|
|
|
var/obj/structure/table/optable/table
|
|
var/list/advanced_surgeries = list()
|
|
var/datum/techweb/linked_techweb
|
|
light_color = LIGHT_COLOR_BLUE
|
|
|
|
var/datum/component/experiment_handler/experiment_handler
|
|
|
|
/obj/machinery/computer/operating/Initialize(mapload)
|
|
. = ..()
|
|
find_table()
|
|
return INITIALIZE_HINT_LATELOAD
|
|
|
|
/obj/machinery/computer/operating/post_machine_initialize()
|
|
. = ..()
|
|
if(!CONFIG_GET(flag/no_default_techweb_link) && !linked_techweb)
|
|
CONNECT_TO_RND_SERVER_ROUNDSTART(linked_techweb, src)
|
|
|
|
var/list/operating_signals = list(
|
|
COMSIG_OPERATING_COMPUTER_AUTOPSY_COMPLETE = TYPE_PROC_REF(/datum/component/experiment_handler, try_run_autopsy_experiment),
|
|
)
|
|
experiment_handler = AddComponent(
|
|
/datum/component/experiment_handler, \
|
|
allowed_experiments = list(/datum/experiment/autopsy), \
|
|
config_flags = EXPERIMENT_CONFIG_ALWAYS_ACTIVE, \
|
|
config_mode = EXPERIMENT_CONFIG_ALTCLICK, \
|
|
experiment_signals = operating_signals, \
|
|
)
|
|
|
|
/obj/machinery/computer/operating/Destroy()
|
|
for(var/direction in GLOB.alldirs)
|
|
table = locate(/obj/structure/table/optable) in get_step(src, direction)
|
|
if(table && table.computer == src)
|
|
table.computer = null
|
|
QDEL_NULL(experiment_handler)
|
|
return ..()
|
|
|
|
/obj/machinery/computer/operating/multitool_act(mob/living/user, obj/item/multitool/tool)
|
|
if(!QDELETED(tool.buffer) && istype(tool.buffer, /datum/techweb))
|
|
linked_techweb = tool.buffer
|
|
return TRUE
|
|
|
|
/obj/machinery/computer/operating/attackby(obj/item/O, mob/user, list/modifiers, list/attack_modifiers)
|
|
if(istype(O, /obj/item/disk/surgery))
|
|
user.visible_message(span_notice("[user] begins to load \the [O] in \the [src]..."), \
|
|
span_notice("You begin to load a surgery protocol from \the [O]..."), \
|
|
span_hear("You hear the chatter of a floppy drive."))
|
|
var/obj/item/disk/surgery/D = O
|
|
if(do_after(user, 1 SECONDS, target = src))
|
|
advanced_surgeries |= D.surgeries
|
|
return TRUE
|
|
return ..()
|
|
|
|
/obj/machinery/computer/operating/proc/sync_surgeries()
|
|
if(!linked_techweb)
|
|
return
|
|
for(var/i in linked_techweb.researched_designs)
|
|
var/datum/design/surgery/D = SSresearch.techweb_design_by_id(i)
|
|
if(!istype(D))
|
|
continue
|
|
advanced_surgeries |= D.surgery
|
|
|
|
/obj/machinery/computer/operating/proc/find_table()
|
|
for(var/direction in GLOB.alldirs)
|
|
table = locate(/obj/structure/table/optable) in get_step(src, direction)
|
|
if(table)
|
|
table.computer = src
|
|
break
|
|
|
|
/obj/machinery/computer/operating/ui_state(mob/user)
|
|
return GLOB.standing_state
|
|
|
|
/obj/machinery/computer/operating/ui_interact(mob/user, datum/tgui/ui)
|
|
. = ..()
|
|
ui = SStgui.try_update_ui(user, src, ui)
|
|
if(!ui)
|
|
ui = new(user, src, "OperatingComputer", name)
|
|
ui.open()
|
|
|
|
/obj/machinery/computer/operating/ui_data(mob/user)
|
|
var/list/data = list()
|
|
var/list/all_surgeries = list()
|
|
for(var/datum/surgery/surgeries as anything in advanced_surgeries)
|
|
var/list/surgery = list()
|
|
surgery["name"] = initial(surgeries.name)
|
|
surgery["desc"] = initial(surgeries.desc)
|
|
all_surgeries += list(surgery)
|
|
data["surgeries"] = all_surgeries
|
|
|
|
//If there's no patient just hop to it yeah?
|
|
if(!table)
|
|
data["patient"] = null
|
|
return data
|
|
|
|
data["table"] = table
|
|
data["patient"] = list()
|
|
data["procedures"] = list()
|
|
if(!table.patient)
|
|
return data
|
|
var/mob/living/carbon/patient = table.patient
|
|
|
|
switch(patient.stat)
|
|
if(CONSCIOUS)
|
|
data["patient"]["stat"] = "Conscious"
|
|
data["patient"]["statstate"] = "good"
|
|
if(SOFT_CRIT)
|
|
data["patient"]["stat"] = "Conscious"
|
|
data["patient"]["statstate"] = "average"
|
|
if(UNCONSCIOUS, HARD_CRIT)
|
|
data["patient"]["stat"] = "Unconscious"
|
|
data["patient"]["statstate"] = "average"
|
|
if(DEAD)
|
|
data["patient"]["stat"] = "Dead"
|
|
data["patient"]["statstate"] = "bad"
|
|
data["patient"]["health"] = patient.health
|
|
data["patient"]["blood_type"] = patient.get_bloodtype()?.name || "UNKNOWN"
|
|
data["patient"]["maxHealth"] = patient.maxHealth
|
|
data["patient"]["minHealth"] = HEALTH_THRESHOLD_DEAD
|
|
data["patient"]["bruteLoss"] = patient.get_brute_loss()
|
|
data["patient"]["fireLoss"] = patient.get_fire_loss()
|
|
data["patient"]["toxLoss"] = patient.get_tox_loss()
|
|
data["patient"]["oxyLoss"] = patient.get_oxy_loss()
|
|
if(patient.surgeries.len)
|
|
for(var/datum/surgery/procedure in patient.surgeries)
|
|
var/datum/surgery_step/surgery_step = GLOB.surgery_steps[procedure.steps[procedure.status]]
|
|
var/chems_needed = surgery_step.get_chem_list()
|
|
var/alternative_step
|
|
var/alt_chems_needed = ""
|
|
var/alt_chems_present = FALSE
|
|
if(surgery_step.repeatable)
|
|
var/datum/surgery_step/next_step = procedure.get_surgery_next_step()
|
|
if(next_step)
|
|
alternative_step = capitalize(next_step.name)
|
|
alt_chems_needed = next_step.get_chem_list()
|
|
alt_chems_present = next_step.chem_check(patient)
|
|
else
|
|
alternative_step = "Finish operation"
|
|
data["procedures"] += list(list(
|
|
"name" = capitalize("[patient.parse_zone_with_bodypart(procedure.location)] [procedure.name]"),
|
|
"next_step" = capitalize(surgery_step.name),
|
|
"chems_needed" = chems_needed,
|
|
"alternative_step" = alternative_step,
|
|
"alt_chems_needed" = alt_chems_needed,
|
|
"chems_present" = surgery_step.chem_check(patient),
|
|
"alt_chems_present" = alt_chems_present
|
|
))
|
|
return data
|
|
|
|
/obj/machinery/computer/operating/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
|
|
. = ..()
|
|
if(.)
|
|
return
|
|
switch(action)
|
|
if("sync")
|
|
sync_surgeries()
|
|
if("open_experiments")
|
|
experiment_handler.ui_interact(usr)
|
|
return TRUE
|
|
|
|
#undef MENU_OPERATION
|
|
#undef MENU_SURGERIES
|