update admin atom spawning (#7498)

update atom spawning menu, now with less ™️ lag
This commit is contained in:
Letter N
2026-01-24 14:31:15 -05:00
committed by GitHub
parent 6144b87b9a
commit f2bacf76c9
9 changed files with 724 additions and 93 deletions
@@ -22,6 +22,7 @@ GLOBAL_PROTECT(href_token)
var/href_token
var/datum/filter_editor/filteriffic
var/datum/spawn_menu/spawn_menu
/datum/admins/New(initial_rank = "Temporary Admin", initial_rights = 0, ckey)
if(!ckey)
+90
View File
@@ -0,0 +1,90 @@
/datum/spawn_menu
/// Does the menu default to a regex prefix?
var/regex_search = FALSE
/// Does the search include atom names?
var/name_search = TRUE
/// Should we display full typepaths or the condensed versions?
var/fancy_types = TRUE
/// Should abstract types be included in the search?
var/include_abstracts = FALSE
/// Initial search value from the latest command
var/init_value = null
/datum/spawn_menu/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if (!ui)
ui = new(user, src, "SpawnSearch")
ui.open()
/datum/spawn_menu/ui_state(mob/user)
return ADMIN_STATE(R_SPAWN)
/datum/spawn_menu/ui_act(action, params, datum/tgui/ui)
if (..() || !check_rights_for(ui.user.client, R_SPAWN))
return FALSE
switch (action)
if ("setRegexSearch")
regex_search = params["regexSearch"]
return TRUE
if ("setNameSearch")
name_search = params["searchNames"]
return TRUE
if ("setFancyTypes")
fancy_types = params["fancyTypes"]
return TRUE
if ("setIncludeAbstracts")
include_abstracts = params["includeAbstracts"]
return TRUE
if ("spawn")
var/path = text2path(params["type"])
if (!path)
return TRUE
var/amount = clamp(text2num(params["amount"]) || 1, 1, ADMIN_SPAWN_CAP)
var/turf/target_turf = get_turf(ui.user)
if(ispath(path, /turf))
target_turf.ChangeTurf(path)
else
for(var/i in 1 to amount)
new path(target_turf)
log_admin("[key_name(ui.user)] spawned [amount] x [path] at [AREACOORD(ui.user)]")
SStgui.close_uis(src)
return TRUE
if ("cancel")
SStgui.close_uis(src)
return TRUE
/datum/spawn_menu/ui_data(mob/user)
var/list/data = list()
data["initValue"] = init_value
data["searchNames"] = name_search
data["regexSearch"] = regex_search
data["fancyTypes"] = fancy_types
data["includeAbstracts"] = include_abstracts
return data
/datum/spawn_menu/ui_asset_injection(datum/tgui/ui, list/immediate, list/deferred)
immediate += /datum/asset_pack/json/spawn_menu
return ..()
/datum/asset_pack/json/spawn_menu
name = "spawn_menu_atom_data"
/datum/asset_pack/json/spawn_menu/generate()
var/list/data = list()
var/static/list/types_list
if (isnull(types_list))
var/list/local_types = list()
for (var/atom/atom_type as anything in subtypesof(/atom))
local_types[atom_type] = atom_type::name || ""
types_list = local_types
data["types"] = types_list
data["abstractTypes"] = get_abstract_types()
data["fancyTypes"] = GLOB.fancy_type_replacements
return data
+31 -38
View File
@@ -1,4 +1,4 @@
/client/proc/spawn_atom(query as text)
/client/proc/spawn_atom(object as text|null)
set category = "Debug"
set desc = "(atom path) Spawn an atom"
set name = "Spawn"
@@ -6,45 +6,38 @@
if(!check_rights(R_SPAWN))
return
if(length(query) < 5)
var/confirm = alert(
src,
"You haven't specified a long enough filter; this will take a while. Are you sure?",
"Mass Query Confirmation",
"No",
"Yes"
)
if(confirm != "Yes")
return
var/static/list/atom_types
if (isnull(atom_types))
atom_types = subtypesof(/atom)
var/list/matches = list()
for(var/path in typesof(/atom))
if(findtext("[path]", query))
matches += path
CHECK_TICK
var/chosen_path = null
var/list/preparsed = null
if (object)
preparsed = splittext(object, ":")
var/list/matches = filter_fancy_list(atom_types, preparsed[1])
if (length(matches) == 1)
chosen_path = matches[1]
if(!length(matches))
to_chat(src, SPAN_WARNING("Type query for '[query]' returned nothing."))
return
if(!chosen_path)
var/datum/spawn_menu/menu = holder.spawn_menu
if (!menu)
menu = new()
holder.spawn_menu = menu
menu.init_value = object
menu.ui_interact(mob)
// BLACKBOX_LOG_ADMIN_VERB("Spawn Atom")
return TRUE
// todo: special prefix handling like # / ! / similar for fast-pathing?
var/path_to_spawn
if(length(matches) == 1)
path_to_spawn = matches[1]
var/amount = 1
if (length(preparsed) > 1)
amount = clamp(text2num(preparsed[2]), 1, ADMIN_SPAWN_CAP)
var/turf/target_turf = get_turf(mob)
if (ispath(chosen_path, /turf))
target_turf.ChangeTurf(chosen_path)
else
var/list/processed_types = make_types_fancy(matches)
var/picked_name = input("Select an atom type", "Spawn Atom", matches[1]) as null|anything in processed_types
if(!picked_name)
return
path_to_spawn = processed_types[picked_name]
for (var/i in 1 to amount)
new chosen_path(target_turf)
if(!path_to_spawn)
return
if(ispath(path_to_spawn, /turf))
var/turf/T = get_turf(mob)
T.ChangeTurf(path_to_spawn)
else
new path_to_spawn(mob.loc)
log_and_message_admins("spawned [path_to_spawn] at ([usr.x],[usr.y],[usr.z])")
log_admin("[key_name(mob)] spawned [amount] x [chosen_path] at [AREACOORD(mob)]")
return TRUE