Files
Bubberstation/code/modules/admin/force_event.dm
Lucy d656f0f4ec Refactor GLOB.admin/debug/fun_state into cached /datum/ui_state/admin_state instances (#89417)
## About The Pull Request

So, some admin verbs/tools that used tguis, i.e edit/debug planes, were
available to admins with +DEBUG... but the ui_state used
`GLOB.admin_state`, which checks for +ADMIN - meaning that if they
_only_ had +DEBUG, they would have the verb... but it would do nothing
when they used it.

I've refactored `GLOB.admin_state`, `GLOB.debug_state`, and
`GLOB.fun_state` into a merged `/datum/ui_state/admin_state`, with a var
for which specific permissions are being checked for.

You now use the `ADMIN_STATE(perms)` macro to get the UI state for those
specific perms, i.e `admin_state(R_ADMIN)` or `admin_state(R_DEBUG)`,
and the resulting UI state will check for _those specific perms_.

These are initialized and cached in `GLOB.admin_states` (which should
never be directly accessed).

So, I've went thru every single usage of `GLOB.admin_state`,
`GLOB.fun_state`, and `GLOB.debug_state`, and made them all use
`ADMIN_STATE()` with the actual permission flags needed to use said UI
in the first place.

## Why It's Good For The Game

Kinda dumb for specific admin permissions to be granted verbs that don't
let them use it anyways.

## Changelog
🆑
admin: Certain UI-based tools (plane debugger, filter editor, etc) that
were given to admins with only +VAREDIT or +DEBUG, but refused to open
without +ADMIN, now actually work for admins that have the needed
permission.
/🆑
2025-02-17 00:54:00 +01:00

95 lines
3.0 KiB
Plaintext

ADMIN_VERB(force_event, R_FUN, "Trigger Event", "Forces an event to occur.", ADMIN_CATEGORY_EVENTS)
user.holder.forceEvent()
///Opens up the Force Event Panel
/datum/admins/proc/forceEvent()
if(!check_rights(R_FUN))
return
var/datum/force_event/ui = new(usr)
ui.ui_interact(usr)
/// Force Event Panel
/datum/force_event
/datum/force_event/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "ForceEvent")
ui.open()
/datum/force_event/ui_state(mob/user)
return ADMIN_STATE(R_FUN)
/datum/force_event/ui_static_data(mob/user)
var/static/list/category_to_icons
if(!category_to_icons)
category_to_icons = list(
EVENT_CATEGORY_AI = "robot",
EVENT_CATEGORY_ANOMALIES = "cloud-bolt",
EVENT_CATEGORY_BUREAUCRATIC = "print",
EVENT_CATEGORY_ENGINEERING = "wrench",
EVENT_CATEGORY_ENTITIES = "ghost",
EVENT_CATEGORY_FRIENDLY = "face-smile",
EVENT_CATEGORY_HEALTH = "brain",
EVENT_CATEGORY_HOLIDAY = "calendar",
EVENT_CATEGORY_INVASION = "user-group",
EVENT_CATEGORY_JANITORIAL = "bath",
EVENT_CATEGORY_SPACE = "meteor",
EVENT_CATEGORY_WIZARD = "hat-wizard",
)
var/list/data = list()
var/list/categories_seen = list()
var/list/categories = list()
var/list/events = list()
for(var/datum/round_event_control/event_control as anything in SSevents.control)
//add category
if(!categories_seen[event_control.category])
categories_seen[event_control.category] = TRUE
UNTYPED_LIST_ADD(categories, list(
"name" = event_control.category,
"icon" = category_to_icons[event_control.category],
))
//add event, with one value matching up the category
UNTYPED_LIST_ADD(events, list(
"name" = event_control.name,
"description" = event_control.description,
"type" = event_control.type,
"category" = event_control.category,
"has_customization" = !!length(event_control.admin_setup),
))
data["categories"] = categories
data["events"] = events
return data
/datum/force_event/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
if(..())
return
if(!check_rights(R_FUN))
return
switch(action)
if("forceevent")
var/announce_event = params["announce"]
var/string_path = params["type"]
if(!string_path)
return
var/event_to_run_type = text2path(string_path)
if(!event_to_run_type)
return
var/datum/round_event_control/event = locate(event_to_run_type) in SSevents.control
if(!event)
return
if(length(event.admin_setup))
for(var/datum/event_admin_setup/admin_setup_datum as anything in event.admin_setup)
if(admin_setup_datum.prompt_admins() == ADMIN_CANCEL_EVENT)
return
var/always_announce_chance = 100
var/no_announce_chance = 0
event.run_event(announce_chance_override = announce_event ? always_announce_chance : no_announce_chance, admin_forced = TRUE)
message_admins("[key_name_admin(usr)] has triggered an event. ([event.name])")
log_admin("[key_name(usr)] has triggered an event. ([event.name])")