Files
Bubberstation/code/modules/client/preferences/middleware/quirks.dm
GoldenAlpharex 1b17b304f2 SQL-Based Player Ranks and Player Ranks Subsystem (#23099)
* Initial draft, most of the stuff is implemented, not really tested or cleaned up yet

* Refactors the handling into a datum-based approach, for more abstraction

* Added migration, properly hooked up the verb to the new system

* Removed some more dead code

* Fixes some missing stuff from the .dme because VSC is stupid sometimes with merge conflicts

* Fixes the schema

* Wow I was really getting tired huh

* A fool, I say, a fool!

* I hate lists of lists I hate lists of lists I hate lists of lists

* I somehow missed this one twice. TWICE!

* This won't actually work if it's defaulting to true, lmao

* Makes it not log stuff if the adding or removing of players is unsuccessful

* Adds a way to update all of the unlock_contents for preferences datums once the donator list is initialized

* Runs update_prefs_unlock_content on mob Login() (hopefully this helps)

* Fixes the bajillion of runtimes caused by my dumb ass trying to make some client calls on ckeys

* Man I was really tired that day

* I had this ready for three hours and forgot to push it
2023-08-29 16:12:01 +02:00

106 lines
3.2 KiB
Plaintext

/// Middleware to handle quirks
/datum/preference_middleware/quirks
var/tainted = FALSE
action_delegations = list(
"give_quirk" = PROC_REF(give_quirk),
"remove_quirk" = PROC_REF(remove_quirk),
)
/datum/preference_middleware/quirks/get_ui_static_data(mob/user)
if (preferences.current_window != PREFERENCE_TAB_CHARACTER_PREFERENCES)
return list()
var/list/data = list()
data["selected_quirks"] = get_selected_quirks()
return data
/datum/preference_middleware/quirks/get_ui_data(mob/user)
var/list/data = list()
if (tainted)
tainted = FALSE
data["selected_quirks"] = get_selected_quirks()
return data
/datum/preference_middleware/quirks/get_constant_data()
var/list/quirk_info = list()
var/list/quirks = SSquirks.get_quirks()
for (var/quirk_name in quirks)
var/datum/quirk/quirk = quirks[quirk_name]
quirk_info[sanitize_css_class_name(quirk_name)] = list(
"description" = initial(quirk.desc),
"icon" = initial(quirk.icon),
"name" = quirk_name,
"value" = initial(quirk.value),
"veteran_only" = initial(quirk.veteran_only), // SKYRAT EDIT - Veteran quirks
)
return list(
"max_positive_quirks" = MAX_QUIRKS,
"quirk_info" = quirk_info,
"quirk_blacklist" = GLOB.quirk_string_blacklist,
)
/datum/preference_middleware/quirks/on_new_character(mob/user)
tainted = TRUE
/datum/preference_middleware/quirks/proc/give_quirk(list/params, mob/user)
var/quirk_name = params["quirk"]
//SKYRAT EDIT ADDITION
var/list/quirks = SSquirks.get_quirks()
var/datum/quirk/quirk = quirks[quirk_name]
if(initial(quirk.veteran_only) && !SSplayer_ranks.is_veteran(preferences?.parent))
return FALSE
//SKYRAT EDIT END
var/list/new_quirks = preferences.all_quirks | quirk_name
if (SSquirks.filter_invalid_quirks(new_quirks, preferences.augments) != new_quirks)// SKYRAT EDIT - AUGMENTS+
// If the client is sending an invalid give_quirk, that means that
// something went wrong with the client prediction, so we should
// catch it back up to speed.
preferences.update_static_data(user)
return TRUE
preferences.all_quirks = new_quirks
preferences.character_preview_view?.update_body()
return TRUE
/datum/preference_middleware/quirks/proc/remove_quirk(list/params, mob/user)
var/quirk_name = params["quirk"]
var/list/new_quirks = preferences.all_quirks - quirk_name
if (!(quirk_name in preferences.all_quirks) || SSquirks.filter_invalid_quirks(new_quirks, preferences.augments) != new_quirks)// SKYRAT EDIT - AUGMENTS+
// If the client is sending an invalid remove_quirk, that means that
// something went wrong with the client prediction, so we should
// catch it back up to speed.
preferences.update_static_data(user)
return TRUE
preferences.all_quirks = new_quirks
preferences.character_preview_view?.update_body()
return TRUE
/datum/preference_middleware/quirks/proc/get_selected_quirks()
var/list/selected_quirks = list()
for (var/quirk in preferences.all_quirks)
//SKYRAT EDIT ADDITION
var/list/quirks = SSquirks.get_quirks()
var/datum/quirk/quirk_datum = quirks[quirk]
if(initial(quirk_datum.veteran_only) && !SSplayer_ranks.is_veteran(preferences?.parent))
preferences.all_quirks -= quirk
continue
//SKYRAT EDIT END
selected_quirks += sanitize_css_class_name(quirk)
return selected_quirks