Files
Bubberstation/code/modules/client/preferences/middleware/legacy_toggles.dm
SkyratBot 124ddd7cca [MIRROR] tgui Preferences Menu + total rewrite of the preferences backend (#8153)
* tgui Preferences Menu + total rewrite of the preferences backend

* nah, we dont need to ping those people

* trying to remove the funny stuff

* unmodularizing this

* prefs reset

* this may need to be reverted, who knows

* okay, this part

* perhaps

* EEEEEEEEE

* unsanitary

* E

* Stage 1 + loadout system

* more fixes

* E

* I mean, it launches?

* More fixes and reorganisation

* E

* customisation code is spaget.

* disable ERP prefs

* Update erp_preferences.dm

* Update erp_preferences.dm

* E

* Slowly getting there

* It may be time for help :)

* tri...colors... help

* preferences now pass preferences

* Update dna.dm

* Fuck this man

* missing savefile return, set_species works, removed dumb stuff from updateappearance

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8199

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8224

* https://github.com/tgstation/tgstation/pull/61519

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8278

* e

* le butonAZARAK HELLO

* hhh

* Proper recognition where it's due, MrMelbert!

* EEEE

* examine block

* Better gen hit sounds from whitedream

* final loadout touches, more bug fixes im sure to come

* i said there would be bugfixes

* Update LoadoutManager.js

* Missing preferences in the html menu

* LIVE TESTING PHASE BABY

* Update LoadoutManager.js

* EEE

* LAUNCH TEST FIRE

* Update job.dm

* Update new_player.dm

* 50gb DAY ONE PATCH

* EEE

* Update preferences.dm

* buggle fixes

* Update examine.dm

* >LOOC starts on

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Co-authored-by: jjpark-kb <55967837+jjpark-kb@users.noreply.github.com>
Co-authored-by: Gandalf <jzo123@hotmail.com>
Co-authored-by: Azarak <azarak10@gmail.com>
2021-09-23 00:40:37 +01:00

133 lines
4.1 KiB
Plaintext

/// In the before times, toggles were all stored in one bitfield.
/// In order to preserve this existing data (and code) without massive
/// migrations, this middleware attempts to handle this in a way
/// transparent to the preferences UI itself.
/// In the future, the existing toggles data should just be migrated to
/// individual `/datum/preference/toggle`s.
/datum/preference_middleware/legacy_toggles
// DO NOT ADD ANY NEW TOGGLES HERE!
// Use `/datum/preference/toggle` instead.
var/static/list/legacy_toggles = list(
"admin_ignore_cult_ghost" = ADMIN_IGNORE_CULT_GHOST,
"announce_login" = ANNOUNCE_LOGIN,
"combohud_lighting" = COMBOHUD_LIGHTING,
"deadmin_always" = DEADMIN_ALWAYS,
"deadmin_antagonist" = DEADMIN_ANTAGONIST,
"deadmin_position_head" = DEADMIN_POSITION_HEAD,
"deadmin_position_security" = DEADMIN_POSITION_SECURITY,
"deadmin_position_silicon" = DEADMIN_POSITION_SILICON,
"disable_arrivalrattle" = DISABLE_ARRIVALRATTLE,
"disable_deathrattle" = DISABLE_DEATHRATTLE,
"member_public" = MEMBER_PUBLIC,
"sound_adminhelp" = SOUND_ADMINHELP,
"sound_ambience" = SOUND_AMBIENCE,
"sound_announcements" = SOUND_ANNOUNCEMENTS,
"sound_combatmode" = SOUND_COMBATMODE,
"sound_endofround" = SOUND_ENDOFROUND,
"sound_instruments" = SOUND_INSTRUMENTS,
"sound_lobby" = SOUND_LOBBY,
"sound_midi" = SOUND_MIDI,
"sound_prayers" = SOUND_PRAYERS,
"sound_ship_ambience" = SOUND_SHIP_AMBIENCE,
"split_admin_tabs" = SPLIT_ADMIN_TABS,
)
var/list/legacy_chat_toggles = list(
"chat_bankcard" = CHAT_BANKCARD,
"chat_dead" = CHAT_DEAD,
"chat_ghostears" = CHAT_GHOSTEARS,
"chat_ghostlaws" = CHAT_GHOSTLAWS,
"chat_ghostpda" = CHAT_GHOSTPDA,
"chat_ghostradio" = CHAT_GHOSTRADIO,
"chat_ghostsight" = CHAT_GHOSTSIGHT,
"chat_ghostwhisper" = CHAT_GHOSTWHISPER,
"chat_login_logout" = CHAT_LOGIN_LOGOUT,
"chat_ooc" = CHAT_OOC,
"chat_prayer" = CHAT_PRAYER,
"chat_pullr" = CHAT_PULLR,
)
/datum/preference_middleware/legacy_toggles/get_character_preferences(mob/user)
if (preferences.current_window != PREFERENCE_TAB_GAME_PREFERENCES)
return list()
var/static/list/admin_only_legacy_toggles = list(
"admin_ignore_cult_ghost",
"announce_login",
"combohud_lighting",
"deadmin_always",
"deadmin_antagonist",
"deadmin_position_head",
"deadmin_position_security",
"deadmin_position_silicon",
"sound_adminhelp",
"sound_prayers",
"split_admin_tabs",
)
var/static/list/admin_only_chat_toggles = list(
"chat_dead",
"chat_prayer",
)
var/static/list/deadmin_flags = list(
"deadmin_antagonist",
"deadmin_position_head",
"deadmin_position_security",
"deadmin_position_silicon",
)
var/list/new_game_preferences = list()
var/is_admin = is_admin(user.client)
for (var/toggle_name in legacy_toggles)
if (!is_admin && (toggle_name in admin_only_legacy_toggles))
continue
if (is_admin && (toggle_name in deadmin_flags) && (preferences.toggles & DEADMIN_ALWAYS))
continue
if (toggle_name == "member_public" && !preferences.unlock_content)
continue
new_game_preferences[toggle_name] = (preferences.toggles & legacy_toggles[toggle_name]) != 0
for (var/toggle_name in legacy_chat_toggles)
if (!is_admin && (toggle_name in admin_only_chat_toggles))
continue
new_game_preferences[toggle_name] = (preferences.chat_toggles & legacy_chat_toggles[toggle_name]) != 0
return list(
PREFERENCE_CATEGORY_GAME_PREFERENCES = new_game_preferences,
)
/datum/preference_middleware/legacy_toggles/pre_set_preference(mob/user, preference, value)
var/legacy_flag = legacy_toggles[preference]
if (!isnull(legacy_flag))
if (value)
preferences.toggles |= legacy_flag
else
preferences.toggles &= ~legacy_flag
// I know this looks silly, but this is the only one that cares
// and NO NEW LEGACY TOGGLES should ever be added.
if (legacy_flag == SOUND_LOBBY)
if (value && isnewplayer(user))
user.client?.playtitlemusic()
else
user.stop_sound_channel(CHANNEL_LOBBYMUSIC)
return TRUE
var/legacy_chat_flag = legacy_chat_toggles[preference]
if (!isnull(legacy_chat_flag))
if (value)
preferences.chat_toggles |= legacy_chat_flag
else
preferences.chat_toggles &= ~legacy_chat_flag
return TRUE
return FALSE