From a0a07e9f4072d2785c2cd39f8b6c1baf1313586f Mon Sep 17 00:00:00 2001
From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Date: Fri, 25 Apr 2025 14:36:34 -0700
Subject: [PATCH] Unfucks /datum/browse code (#89994)
## About The Pull Request
What it was doing was by and large fine, HOW it was doing it SUCKED
I've cleaned it up and the nearby code some, notable hits include:
- random if check in secrets ui that was totally unused
- proc called add that actually set
- lists not defined as such
- stupid var names
- proc args which did nothing
- code which did nothing
- oververbose code
- proc/var names with no spacing at all
Note: This might have changed behavior accidentally, I've done my best
to test but we'll need to look out for issue reports in coming days.
## Why It's Good For The Game
I was working on bitflag code and saw red, now it's 2 hours later.
## Changelog
:cl:
code: Brought browser code up to standard with the rest of the codebase
admin: Hey lads, I cleaned up how non TGUI windows work on the backend,
please let me know if anything is broken! PING ME MOTHERFUCKER
/:cl:
---
code/datums/browser.dm | 506 +++++++++---------
code/game/atom/atom_vv.dm | 41 +-
.../game/objects/structures/detectiveboard.dm | 6 +-
code/modules/admin/permissionedit.dm | 4 +-
code/modules/admin/verbs/ert.dm | 281 +++++-----
code/modules/admin/verbs/secrets.dm | 93 ++--
code/modules/admin/verbs/spawnobjasmob.dm | 64 +--
code/modules/discord/accountlink.dm | 2 +-
code/modules/error_handler/error_viewer.dm | 2 +-
code/modules/tgui_panel/external.dm | 4 +-
interface/interface.dm | 4 +-
11 files changed, 504 insertions(+), 503 deletions(-)
diff --git a/code/datums/browser.dm b/code/datums/browser.dm
index c935a7a9f93..a143be58501 100644
--- a/code/datums/browser.dm
+++ b/code/datums/browser.dm
@@ -1,44 +1,48 @@
/datum/browser
var/mob/user
- var/title
- var/window_id // window_id is used as the window name for browse and onclose
+ var/title = ""
+ /// window_id is used as the window name for browse and onclose
+ var/window_id
var/width = 0
var/height = 0
- var/datum/weakref/ref = null
- var/window_options = "can_close=1;can_minimize=1;can_maximize=0;can_resize=1;titlebar=1;" // window option is set using window_id
- var/stylesheets[0]
- var/scripts[0]
+ var/datum/weakref/source_ref = null
+ /// window option is set using window_id
+ var/window_options = "can_close=1;can_minimize=1;can_maximize=0;can_resize=1;titlebar=1;"
+ var/list/stylesheets = list()
+ var/list/scripts = list()
var/head_elements
var/body_elements
var/head_content = ""
var/content = ""
-/datum/browser/New(nuser, nwindow_id, ntitle = 0, nwidth = 0, nheight = 0, atom/nref = null)
- if(IS_CLIENT_OR_MOCK(nuser))
- var/client/client_user = nuser
+/datum/browser/New(mob/user, window_id, title = "", width = 0, height = 0, atom/source = null)
+ if(IS_CLIENT_OR_MOCK(user))
+ var/client/client_user = user
user = client_user.mob
- else
- user = nuser
+ src.user = user
RegisterSignal(user, COMSIG_QDELETING, PROC_REF(user_deleted))
- window_id = nwindow_id
- if (ntitle)
- title = format_text(ntitle)
- if (nwidth)
- width = nwidth
- if (nheight)
- height = nheight
- if (nref)
- ref = WEAKREF(nref)
+ src.window_id = window_id
+ if (title)
+ src.title = format_text(title)
+ if (width)
+ src.width = width
+ if (height)
+ src.height = height
+ if (source)
+ src.source_ref = WEAKREF(source)
/datum/browser/proc/user_deleted(datum/source)
SIGNAL_HANDLER
user = null
-/datum/browser/proc/add_head_content(nhead_content)
- head_content = nhead_content
+/datum/browser/proc/add_head_content(head_content)
+ src.head_content += head_content
-/datum/browser/proc/set_window_options(nwindow_options)
- window_options = nwindow_options
+/datum/browser/proc/set_head_content(head_content)
+ src.head_content = head_content
+
+/datum/browser/proc/set_window_options(window_options)
+ src.window_options = window_options
/datum/browser/proc/add_stylesheet(name, file)
if (istype(name, /datum/asset/spritesheet))
@@ -59,21 +63,21 @@
scripts["[ckey(name)].js"] = file
SSassets.transport.register_asset("[ckey(name)].js", file)
-/datum/browser/proc/set_content(ncontent)
- content = ncontent
+/datum/browser/proc/set_content(content)
+ src.content = content
-/datum/browser/proc/add_content(ncontent)
- content += ncontent
+/datum/browser/proc/add_content(content)
+ src.content += content
/datum/browser/proc/get_header()
var/datum/asset/simple/namespaced/common/common_asset = get_asset_datum(/datum/asset/simple/namespaced/common)
- var/file
- head_content += ""
- for (file in stylesheets)
- head_content += ""
+ var/list/new_head_content = list()
+ new_head_content += ""
+ for (var/file in stylesheets)
+ new_head_content += ""
if(user.client?.window_scaling && user.client?.window_scaling != 1 && !user.client?.prefs.read_preference(/datum/preference/toggle/ui_scale) && width && height)
- head_content += {"
+ new_head_content += {"
"}
- for (file in scripts)
- head_content += ""
+ for (var/file in scripts)
+ new_head_content += ""
+ head_content += new_head_content.Join()
return {"
@@ -96,6 +101,7 @@
[title ? "
[title]
" : ""]
"}
+
//" This is here because else the rest of the file looks like a string in notepad++.
/datum/browser/proc/get_footer()
return {"
@@ -106,16 +112,17 @@
/datum/browser/proc/get_content()
return {"
- [get_header()]
- [content]
- [get_footer()]
+ [get_header()]
+ [content]
+ [get_footer()]
"}
-/datum/browser/proc/open(use_onclose = TRUE)
+/datum/browser/proc/open(use_on_close = TRUE)
if(isnull(window_id)) //null check because this can potentially nuke goonchat
WARNING("Browser [title] tried to open with a null ID")
to_chat(user, span_userdanger("The [title] browser you tried to open failed a sanity check! Please report this on GitHub!"))
return
+
var/window_size = ""
if(width && height)
if(user.client?.prefs?.read_preference(/datum/preference/toggle/ui_scale))
@@ -123,27 +130,28 @@
window_size = "size=[width * scaling]x[height * scaling];"
else
window_size = "size=[width]x[height];"
+
var/datum/asset/simple/namespaced/common/common_asset = get_asset_datum(/datum/asset/simple/namespaced/common)
common_asset.send(user)
- if (stylesheets.len)
+ if (length(stylesheets))
SSassets.transport.send_assets(user, stylesheets)
- if (scripts.len)
+ if (length(scripts))
SSassets.transport.send_assets(user, scripts)
DIRECT_OUTPUT(user, browse(get_content(), "window=[window_id];[window_size][window_options]"))
- if (use_onclose)
+ if (use_on_close)
setup_onclose()
/datum/browser/proc/setup_onclose()
set waitfor = 0 //winexists sleeps, so we don't need to.
for (var/i in 1 to 10)
- if (user?.client && winexists(user, window_id))
- var/atom/send_ref
- if(ref)
- send_ref = ref.resolve()
- if(!send_ref)
- ref = null
- onclose(user, window_id, send_ref)
- break
+ if (!user?.client || !winexists(user, window_id))
+ continue
+ var/atom/send_ref
+ if(source_ref)
+ send_ref = source_ref.resolve()
+ if(!send_ref)
+ source_ref = null
+ onclose(user, window_id, send_ref)
/datum/browser/proc/close()
if(!isnull(window_id))//null check because this can potentially nuke goonchat
@@ -151,106 +159,106 @@
else
WARNING("Browser [title] tried to close with a null ID")
-/datum/browser/modal/alert/New(User,Message,Title,Button1="Ok",Button2,Button3,StealFocus = 1,Timeout=6000)
- if (!User)
+/datum/browser/modal/alert/New(user, message, title, button_1 = "Ok", button_2, button_3, steal_focus = TRUE, timeout = 600 SECONDS)
+ if (!user)
return
- var/output = {"