mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-09 16:05:07 +00:00
About The Pull Request I've reworked multiz. This was done because our current implementation of multiz flattens planes down into just the openspace plane. This breaks any effects we attach to plane masters (including lighting), but it also totally kills the SIDE_MAP map format, which we NEED for wallening (A major 3/4ths resprite of all wall and wall adjacent things, making them more then one tile high. Without sidemap we would be unable to display things both in from of and behind objects on map. Stupid.) This required MASSIVE changes. Both to all uses of the plane var for reasons I'll discuss later, and to a ton of different systems that interact with rendering. I'll do my best to keep this compact, but there's only so much I can do. Sorry brother. Core idea OK: first thing. vis_contents as it works now squishes the planes of everything inside it down into the plane of the vis_loc. This is bad. But how to do better? It's trivially easy to make copies of our existing plane masters but offset, and relay them to the bottom of the plane above. Not a problem. The issue is how to get the actual atoms on the map to "land" on them properly. We could use FLOAT_PLANE to offset planes based off how they're being seen, in theory this would allow us to create lens for how objects are viewed. But that's not a stable thing to do, because properly "landing" a plane on a desired plane master would require taking into account every bit of how it's being seen, would inherently break this effect. Ok so we need to manually edit planes based off "z layer" (IE: what layer of a z stack are you on). That's the key conceit of this pr. Implementing the plane cube, and ensuring planes are always offset properly. Everything else is just gravy. About the Plane Cube Each plane master (except ones that opt out) is copied down by some constant value equal to the max absolute change between the first and the last plane. We do this based off the max z stack size detected by SSmapping. This is also where updates come from, and where all our updating logic will live. As mentioned, plane masters can choose to opt out of being mirrored down. In this case, anything that interacts with them assuming that they'll be offset will instead just get back the valid plane value. This works for render targets too, since I had to work them into the system as well. Plane masters can also be temporarily hidden from the client's screen. This is done as an attempt at optimization, and applies to anything used in niche cases, or planes only used if there's a z layer below you. About Plane Master Groups BYOND supports having different "maps" on screen at once (IE: groups of items/turfs/etc) Plane masters cannot cover 2 maps at once, since their location is determined by their screen_loc. So we need to maintain a mirror of each plane for every map we have open. This was quite messy, so I've refactored it (and maps too) to be a bit more modular. Rather then storing a list of plane masters, we store a list of plane master group datums. Each datum is in charge of the plane masters for its particular map, both creating them, and managing them. Like I mentioned, I also refactored map views. Adding a new mapview is now as simple as newing a /atom/movable/screen/map_view, calling generate_view with the appropriate map id, setting things you want to display in its vis_contents, and then calling display_to on it, passing in the mob to show ourselves to. Much better then the hardcoded pattern we used to use. So much duplicated code man. Oh and plane master controllers, that system we have that allows for applying filters to sets of plane masters? I've made it use lookups on plane master groups now, rather then hanging references to all impacted planes. This makes logic easier, and prevents the need to manage references and update the controllers. image In addition, I've added a debug ui for plane masters. It allows you to view all of your own plane masters and short descriptions of what they do, alongside tools for editing them and their relays. It ALSO supports editing someone elses plane masters, AND it supports (in a very fragile and incomplete manner) viewing literally through someone else's eyes, including their plane masters. This is very useful, because it means you can debug "hey my X is yorked" issues yourself, on live. In order to accomplish this I have needed to add setters for an ungodly amount of visual impacting vars. Sight flags, eye, see_invis, see_in_dark, etc. It also comes with an info dump about the ui, and plane masters/relays in general. Sort of on that note. I've documented everything I know that's niche/useful about our visual effects and rendering system. My hope is this will serve to bring people up to speed on what can be done more quickly, alongside making my sin here less horrible. See https://github.com/LemonInTheDark/tgstation/blob/multiz-hell/.github/guides/VISUALS.md. "Landing" planes Ok so I've explained the backend, but how do we actually land planes properly? Most of the time this is really simple. When a plane var is set, we need to provide some spokesperson for the appearance's z level. We can use this to derive their z layer, and thus what offset to use. This is just a lot of gruntwork, but it's occasionally more complex. Sometimes we need to cache a list of z layer -> effect, and then use that. Also a LOT of updating on z move. So much z move shit. Oh. and in order to make byond darkness work properly, I needed to add SEE_BLACKNESS to all sight flags. This draws darkness to plane 0, which means I'm able to relay it around and draw it on different z layers as is possible. fun darkness ripple effects incoming someday I also need to update mob overlays on move. I do this by realiizing their appearances, mutating their plane, and then readding the overlay in the correct order. The cost of this is currently 3N. I'm convinced this could be improved, but I've not got to it yet. It can also occasionally cause overlays to corrupt. This is fixed by laying a protective ward of overlays.Copy in the sand, but that spell makes the compiler confused, so I'll have to bully lummy about fixing it at some point. Behavior changes We've had to give up on the already broken gateway "see through" effect. Won't work without managing gateway plane masters or something stupid. Not worth it. So instead we display the other side as a ui element. It's worse, but not that bad. Because vis_contents no longer flattens planes (most of the time), some uses of it now have interesting behavior. The main thing that comes to mind is alert popups that display mobs. They can impact the lighting plane. I don't really care, but it should be fixable, I think, given elbow grease. Ah and I've cleaned up layers and plane defines to make them a bit easier to read/reason about, at least I think. Why It's Good For The Game <visual candy> Fixes #65800 Fixes #68461 Changelog cl refactor: Refactored... well a lot really. Map views, anything to do with planes, multiz, a shit ton of rendering stuff. Basically if you see anything off visually report it admin: VV a mob, and hit View/Edit Planes in the dropdown to steal their view, and modify it as you like. You can do the same to yourself using the Edit/Debug Planes verb /cl
483 lines
15 KiB
Plaintext
483 lines
15 KiB
Plaintext
GLOBAL_LIST_EMPTY(preferences_datums)
|
|
|
|
/datum/preferences
|
|
var/client/parent
|
|
//doohickeys for savefiles
|
|
var/path
|
|
var/default_slot = 1 //Holder so it doesn't default to slot 1, rather the last one used
|
|
var/max_save_slots = 3
|
|
|
|
//non-preference stuff
|
|
var/muted = 0
|
|
var/last_ip
|
|
var/last_id
|
|
|
|
//game-preferences
|
|
var/lastchangelog = "" //Saved changlog filesize to detect if there was a change
|
|
|
|
//Antag preferences
|
|
var/list/be_special = list() //Special role selection
|
|
|
|
/// Custom keybindings. Map of keybind names to keyboard inputs.
|
|
/// For example, by default would have "swap_hands" -> list("X")
|
|
var/list/key_bindings = list()
|
|
|
|
/// Cached list of keybindings, mapping keys to actions.
|
|
/// For example, by default would have "X" -> list("swap_hands")
|
|
var/list/key_bindings_by_key = list()
|
|
|
|
var/toggles = TOGGLES_DEFAULT
|
|
var/db_flags
|
|
var/chat_toggles = TOGGLES_DEFAULT_CHAT
|
|
var/ghost_form = "ghost"
|
|
|
|
//character preferences
|
|
var/slot_randomized //keeps track of round-to-round randomization of the character slot, prevents overwriting
|
|
|
|
var/list/randomise = list()
|
|
|
|
//Quirk list
|
|
var/list/all_quirks = list()
|
|
|
|
//Job preferences 2.0 - indexed by job title , no key or value implies never
|
|
var/list/job_preferences = list()
|
|
|
|
/// The current window, PREFERENCE_TAB_* in [`code/__DEFINES/preferences.dm`]
|
|
var/current_window = PREFERENCE_TAB_CHARACTER_PREFERENCES
|
|
|
|
var/unlock_content = 0
|
|
|
|
var/list/ignoring = list()
|
|
|
|
var/list/exp = list()
|
|
|
|
var/action_buttons_screen_locs = list()
|
|
|
|
///Someone thought we were nice! We get a little heart in OOC until we join the server past the below time (we can keep it until the end of the round otherwise)
|
|
var/hearted
|
|
///If we have a hearted commendations, we honor it every time the player loads preferences until this time has been passed
|
|
var/hearted_until
|
|
///What outfit typepaths we've favorited in the SelectEquipment menu
|
|
var/list/favorite_outfits = list()
|
|
|
|
/// A preview of the current character
|
|
var/atom/movable/screen/map_view/char_preview/character_preview_view
|
|
|
|
/// A list of instantiated middleware
|
|
var/list/datum/preference_middleware/middleware = list()
|
|
|
|
/// The savefile relating to core preferences, PREFERENCE_PLAYER
|
|
var/savefile/game_savefile
|
|
|
|
/// The savefile relating to character preferences, PREFERENCE_CHARACTER
|
|
var/savefile/character_savefile
|
|
|
|
/// A list of keys that have been updated since the last save.
|
|
var/list/recently_updated_keys = list()
|
|
|
|
/// A cache of preference entries to values.
|
|
/// Used to avoid expensive READ_FILE every time a preference is retrieved.
|
|
var/value_cache = list()
|
|
|
|
/// If set to TRUE, will update character_profiles on the next ui_data tick.
|
|
var/tainted_character_profiles = FALSE
|
|
|
|
/datum/preferences/Destroy(force, ...)
|
|
QDEL_NULL(character_preview_view)
|
|
QDEL_LIST(middleware)
|
|
value_cache = null
|
|
return ..()
|
|
|
|
/datum/preferences/New(client/C)
|
|
parent = C
|
|
|
|
for (var/middleware_type in subtypesof(/datum/preference_middleware))
|
|
middleware += new middleware_type(src)
|
|
|
|
if(istype(C))
|
|
if(!is_guest_key(C.key))
|
|
load_path(C.ckey)
|
|
unlock_content = !!C.IsByondMember()
|
|
if(unlock_content)
|
|
max_save_slots = 8
|
|
|
|
// give them default keybinds and update their movement keys
|
|
key_bindings = deep_copy_list(GLOB.default_hotkeys)
|
|
key_bindings_by_key = get_key_bindings_by_key(key_bindings)
|
|
randomise = get_default_randomization()
|
|
|
|
var/loaded_preferences_successfully = load_preferences()
|
|
if(loaded_preferences_successfully)
|
|
if(load_character())
|
|
return
|
|
//we couldn't load character data so just randomize the character appearance + name
|
|
randomise_appearance_prefs() //let's create a random character then - rather than a fat, bald and naked man.
|
|
if(C)
|
|
apply_all_client_preferences()
|
|
C.set_macros()
|
|
|
|
if(!loaded_preferences_successfully)
|
|
save_preferences()
|
|
save_character() //let's save this new random character so it doesn't keep generating new ones.
|
|
|
|
/datum/preferences/ui_interact(mob/user, datum/tgui/ui)
|
|
// There used to be code here that readded the preview view if you "rejoined"
|
|
// I'm making the assumption that ui close will be called whenever a user logs out, or loses a window
|
|
// If this isn't the case, kill me and restore the code, thanks
|
|
|
|
ui = SStgui.try_update_ui(user, src, ui)
|
|
if(!ui)
|
|
character_preview_view = create_character_preview_view(user)
|
|
|
|
ui = new(user, src, "PreferencesMenu")
|
|
ui.set_autoupdate(FALSE)
|
|
ui.open()
|
|
|
|
// HACK: Without this the character starts out really tiny because of some BYOND bug.
|
|
// You can fix it by changing a preference, so let's just forcably update the body to emulate this.
|
|
// Lemon from the future: this issue appears to replicate if the byond map (what we're relaying here)
|
|
// Is shown while the client's mouse is on the screen. As soon as their mouse enters the main map, it's properly scaled
|
|
// I hate this place
|
|
addtimer(CALLBACK(character_preview_view, /atom/movable/screen/map_view/char_preview/proc/update_body), 1 SECONDS)
|
|
|
|
/datum/preferences/ui_state(mob/user)
|
|
return GLOB.always_state
|
|
|
|
// Without this, a hacker would be able to edit other people's preferences if
|
|
// they had the ref to Topic to.
|
|
/datum/preferences/ui_status(mob/user, datum/ui_state/state)
|
|
return user.client == parent ? UI_INTERACTIVE : UI_CLOSE
|
|
|
|
/datum/preferences/ui_data(mob/user)
|
|
var/list/data = list()
|
|
|
|
if (tainted_character_profiles)
|
|
data["character_profiles"] = create_character_profiles()
|
|
tainted_character_profiles = FALSE
|
|
|
|
data["character_preferences"] = compile_character_preferences(user)
|
|
|
|
data["active_slot"] = default_slot
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
data += preference_middleware.get_ui_data(user)
|
|
|
|
return data
|
|
|
|
/datum/preferences/ui_static_data(mob/user)
|
|
var/list/data = list()
|
|
|
|
data["character_profiles"] = create_character_profiles()
|
|
|
|
data["character_preview_view"] = character_preview_view.assigned_map
|
|
data["overflow_role"] = SSjob.GetJobType(SSjob.overflow_role).title
|
|
data["window"] = current_window
|
|
|
|
data["content_unlocked"] = unlock_content
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
data += preference_middleware.get_ui_static_data(user)
|
|
|
|
return data
|
|
|
|
/datum/preferences/ui_assets(mob/user)
|
|
var/list/assets = list(
|
|
get_asset_datum(/datum/asset/spritesheet/preferences),
|
|
get_asset_datum(/datum/asset/json/preferences),
|
|
)
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
assets += preference_middleware.get_ui_assets()
|
|
|
|
return assets
|
|
|
|
/datum/preferences/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
|
|
. = ..()
|
|
if (.)
|
|
return
|
|
|
|
switch (action)
|
|
if ("change_slot")
|
|
// Save existing character
|
|
save_character()
|
|
|
|
// SAFETY: `load_character` performs sanitization the slot number
|
|
if (!load_character(params["slot"]))
|
|
tainted_character_profiles = TRUE
|
|
randomise_appearance_prefs()
|
|
save_character()
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
preference_middleware.on_new_character(usr)
|
|
|
|
character_preview_view.update_body()
|
|
|
|
return TRUE
|
|
if ("rotate")
|
|
character_preview_view.dir = turn(character_preview_view.dir, -90)
|
|
|
|
return TRUE
|
|
if ("set_preference")
|
|
var/requested_preference_key = params["preference"]
|
|
var/value = params["value"]
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
if (preference_middleware.pre_set_preference(usr, requested_preference_key, value))
|
|
return TRUE
|
|
|
|
var/datum/preference/requested_preference = GLOB.preference_entries_by_key[requested_preference_key]
|
|
if (isnull(requested_preference))
|
|
return FALSE
|
|
|
|
// SAFETY: `update_preference` performs validation checks
|
|
if (!update_preference(requested_preference, value))
|
|
return FALSE
|
|
|
|
if (istype(requested_preference, /datum/preference/name))
|
|
tainted_character_profiles = TRUE
|
|
|
|
return TRUE
|
|
if ("set_color_preference")
|
|
var/requested_preference_key = params["preference"]
|
|
|
|
var/datum/preference/requested_preference = GLOB.preference_entries_by_key[requested_preference_key]
|
|
if (isnull(requested_preference))
|
|
return FALSE
|
|
|
|
if (!istype(requested_preference, /datum/preference/color))
|
|
return FALSE
|
|
|
|
var/default_value = read_preference(requested_preference.type)
|
|
|
|
// Yielding
|
|
var/new_color = input(
|
|
usr,
|
|
"Select new color",
|
|
null,
|
|
default_value || COLOR_WHITE,
|
|
) as color | null
|
|
|
|
if (!new_color)
|
|
return FALSE
|
|
|
|
if (!update_preference(requested_preference, new_color))
|
|
return FALSE
|
|
|
|
return TRUE
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
var/delegation = preference_middleware.action_delegations[action]
|
|
if (!isnull(delegation))
|
|
return call(preference_middleware, delegation)(params, usr)
|
|
|
|
return FALSE
|
|
|
|
/datum/preferences/ui_close(mob/user)
|
|
save_character()
|
|
save_preferences()
|
|
QDEL_NULL(character_preview_view)
|
|
|
|
/datum/preferences/Topic(href, list/href_list)
|
|
. = ..()
|
|
if (.)
|
|
return
|
|
|
|
if (href_list["open_keybindings"])
|
|
current_window = PREFERENCE_TAB_KEYBINDINGS
|
|
update_static_data(usr)
|
|
ui_interact(usr)
|
|
return TRUE
|
|
|
|
/datum/preferences/proc/create_character_preview_view(mob/user)
|
|
character_preview_view = new(null, src)
|
|
character_preview_view.generate_view("character_preview_[REF(character_preview_view)]")
|
|
character_preview_view.update_body()
|
|
character_preview_view.display_to(user)
|
|
|
|
return character_preview_view
|
|
|
|
/datum/preferences/proc/compile_character_preferences(mob/user)
|
|
var/list/preferences = list()
|
|
|
|
for (var/datum/preference/preference as anything in get_preferences_in_priority_order())
|
|
if (!preference.is_accessible(src))
|
|
continue
|
|
|
|
LAZYINITLIST(preferences[preference.category])
|
|
|
|
var/value = read_preference(preference.type)
|
|
var/data = preference.compile_ui_data(user, value)
|
|
|
|
preferences[preference.category][preference.savefile_key] = data
|
|
|
|
for (var/datum/preference_middleware/preference_middleware as anything in middleware)
|
|
var/list/append_character_preferences = preference_middleware.get_character_preferences(user)
|
|
if (isnull(append_character_preferences))
|
|
continue
|
|
|
|
for (var/category in append_character_preferences)
|
|
if (category in preferences)
|
|
preferences[category] += append_character_preferences[category]
|
|
else
|
|
preferences[category] = append_character_preferences[category]
|
|
|
|
return preferences
|
|
|
|
/// Applies all PREFERENCE_PLAYER preferences
|
|
/datum/preferences/proc/apply_all_client_preferences()
|
|
for (var/datum/preference/preference as anything in get_preferences_in_priority_order())
|
|
if (preference.savefile_identifier != PREFERENCE_PLAYER)
|
|
continue
|
|
|
|
value_cache -= preference.type
|
|
preference.apply_to_client(parent, read_preference(preference.type))
|
|
|
|
/// A preview of a character for use in the preferences menu
|
|
/atom/movable/screen/map_view/char_preview
|
|
name = "character_preview"
|
|
|
|
/// The body that is displayed
|
|
var/mob/living/carbon/human/dummy/body
|
|
/// The preferences this refers to
|
|
var/datum/preferences/preferences
|
|
|
|
/atom/movable/screen/map_view/char_preview/Initialize(mapload, datum/preferences/preferences)
|
|
. = ..()
|
|
src.preferences = preferences
|
|
|
|
/atom/movable/screen/map_view/char_preview/Destroy()
|
|
QDEL_NULL(body)
|
|
preferences?.character_preview_view = null
|
|
preferences = null
|
|
return ..()
|
|
|
|
/// Updates the currently displayed body
|
|
/atom/movable/screen/map_view/char_preview/proc/update_body()
|
|
if (isnull(body))
|
|
create_body()
|
|
else
|
|
body.wipe_state()
|
|
appearance = preferences.render_new_preview_appearance(body)
|
|
|
|
/atom/movable/screen/map_view/char_preview/proc/create_body()
|
|
QDEL_NULL(body)
|
|
|
|
body = new
|
|
|
|
// Without this, it doesn't show up in the menu
|
|
body.appearance_flags &= ~KEEP_TOGETHER
|
|
|
|
/datum/preferences/proc/create_character_profiles()
|
|
var/list/profiles = list()
|
|
|
|
var/savefile/savefile = new(path)
|
|
for (var/index in 1 to max_save_slots)
|
|
// It won't be updated in the savefile yet, so just read the name directly
|
|
if (index == default_slot)
|
|
profiles += read_preference(/datum/preference/name/real_name)
|
|
continue
|
|
|
|
savefile.cd = "/character[index]"
|
|
|
|
var/name
|
|
READ_FILE(savefile["real_name"], name)
|
|
|
|
if (isnull(name))
|
|
profiles += null
|
|
continue
|
|
|
|
profiles += name
|
|
|
|
return profiles
|
|
|
|
/datum/preferences/proc/set_job_preference_level(datum/job/job, level)
|
|
if (!job)
|
|
return FALSE
|
|
|
|
if (level == JP_HIGH)
|
|
var/datum/job/overflow_role = SSjob.overflow_role
|
|
var/overflow_role_title = initial(overflow_role.title)
|
|
|
|
for(var/other_job in job_preferences)
|
|
if(job_preferences[other_job] == JP_HIGH)
|
|
// Overflow role needs to go to NEVER, not medium!
|
|
if(other_job == overflow_role_title)
|
|
job_preferences[other_job] = null
|
|
else
|
|
job_preferences[other_job] = JP_MEDIUM
|
|
|
|
job_preferences[job.title] = level
|
|
|
|
return TRUE
|
|
|
|
/datum/preferences/proc/GetQuirkBalance()
|
|
var/bal = 0
|
|
for(var/V in all_quirks)
|
|
var/datum/quirk/T = SSquirks.quirks[V]
|
|
bal -= initial(T.value)
|
|
return bal
|
|
|
|
/datum/preferences/proc/GetPositiveQuirkCount()
|
|
. = 0
|
|
for(var/q in all_quirks)
|
|
if(SSquirks.quirk_points[q] > 0)
|
|
.++
|
|
|
|
/datum/preferences/proc/validate_quirks()
|
|
if(GetQuirkBalance() < 0)
|
|
all_quirks = list()
|
|
|
|
/// Sanitizes the preferences, applies the randomization prefs, and then applies the preference to the human mob.
|
|
/datum/preferences/proc/safe_transfer_prefs_to(mob/living/carbon/human/character, icon_updates = TRUE, is_antag = FALSE)
|
|
apply_character_randomization_prefs(is_antag)
|
|
apply_prefs_to(character, icon_updates)
|
|
|
|
/// Applies the given preferences to a human mob.
|
|
/datum/preferences/proc/apply_prefs_to(mob/living/carbon/human/character, icon_updates = TRUE)
|
|
character.dna.features = list()
|
|
|
|
for (var/datum/preference/preference as anything in get_preferences_in_priority_order())
|
|
if (preference.savefile_identifier != PREFERENCE_CHARACTER)
|
|
continue
|
|
|
|
preference.apply_to_human(character, read_preference(preference.type))
|
|
|
|
character.dna.real_name = character.real_name
|
|
|
|
if(icon_updates)
|
|
character.icon_render_keys = list()
|
|
character.update_body(is_creating = TRUE)
|
|
|
|
|
|
/// Returns whether the parent mob should have the random hardcore settings enabled. Assumes it has a mind.
|
|
/datum/preferences/proc/should_be_random_hardcore(datum/job/job, datum/mind/mind)
|
|
if(!read_preference(/datum/preference/toggle/random_hardcore))
|
|
return FALSE
|
|
if(job.departments_bitflags & DEPARTMENT_BITFLAG_COMMAND) //No command staff
|
|
return FALSE
|
|
for(var/datum/antagonist/antag as anything in mind.antag_datums)
|
|
if(antag.get_team()) //No team antags
|
|
return FALSE
|
|
return TRUE
|
|
|
|
/// Inverts the key_bindings list such that it can be used for key_bindings_by_key
|
|
/datum/preferences/proc/get_key_bindings_by_key(list/key_bindings)
|
|
var/list/output = list()
|
|
|
|
for (var/action in key_bindings)
|
|
for (var/key in key_bindings[action])
|
|
LAZYADD(output[key], action)
|
|
|
|
return output
|
|
|
|
/// Returns the default `randomise` variable ouptut
|
|
/datum/preferences/proc/get_default_randomization()
|
|
var/list/default_randomization = list()
|
|
|
|
for (var/preference_key in GLOB.preference_entries_by_key)
|
|
var/datum/preference/preference = GLOB.preference_entries_by_key[preference_key]
|
|
if (preference.is_randomizable() && preference.randomize_by_default)
|
|
default_randomization[preference_key] = RANDOM_ENABLED
|
|
|
|
return default_randomization
|