Both enabled and disabled preferences are now stored.

The purpose is to ensure that new preferences that are in neither list get the appropriate enabled/disabled setting without having to utilize the savefile update path.

Also attempts to optimize the acquirement of the preference mob.
This commit is contained in:
PsiOmegaDelta
2016-03-07 18:33:36 +01:00
committed by Yoshax
parent 78abc7f790
commit f3cde3af01
3 changed files with 56 additions and 24 deletions

View File

@@ -1,29 +1,52 @@
/datum/preferences /datum/preferences
var/preferences = null var/preferences_enabled = null
var/preferences_disabled = null
/datum/category_item/player_setup_item/player_global/settings /datum/category_item/player_setup_item/player_global/settings
name = "Settings" name = "Settings"
sort_order = 2 sort_order = 2
/datum/category_item/player_setup_item/player_global/settings/load_preferences(var/savefile/S) /datum/category_item/player_setup_item/player_global/settings/load_preferences(var/savefile/S)
S["lastchangelog"] >> pref.lastchangelog S["lastchangelog"] >> pref.lastchangelog
S["default_slot"] >> pref.default_slot S["default_slot"] >> pref.default_slot
S["preferences"] >> pref.preferences S["preferences"] >> pref.preferences_enabled
S["preferences_disabled"] >> pref.preferences_disabled
/datum/category_item/player_setup_item/player_global/settings/save_preferences(var/savefile/S) /datum/category_item/player_setup_item/player_global/settings/save_preferences(var/savefile/S)
S["lastchangelog"] << pref.lastchangelog S["lastchangelog"] << pref.lastchangelog
S["default_slot"] << pref.default_slot S["default_slot"] << pref.default_slot
S["preferences"] << pref.preferences S["preferences"] << pref.preferences_enabled
S["preferences_disabled"] << pref.preferences_disabled
/datum/category_item/player_setup_item/player_global/settings/sanitize_preferences() /datum/category_item/player_setup_item/player_global/settings/sanitize_preferences()
if(!istype(pref.preferences, /list)) var/mob/pref_mob = preference_mob()
pref.preferences = list()
var/mob/pref_mob = preference_mob() // Ensure our preferences are lists.
for(var/cp in get_client_preferences()) if(!istype(pref.preferences_enabled, /list))
var/datum/client_preference/client_pref = cp pref.preferences_enabled = list()
if(!client_pref.enabled_by_default || !client_pref.may_toggle(pref_mob)) if(!istype(pref.preferences_disabled, /list))
continue pref.preferences_disabled = list()
pref.preferences += client_pref.key
// Arrange preferences that have never been enabled/disabled.
var/list/client_preference_keys = list()
for(var/cp in get_client_preferences())
var/datum/client_preference/client_pref = cp
client_preference_keys += client_pref.key
if((client_pref.key in pref.preferences_enabled) || (client_pref.key in pref.preferences_disabled))
continue
if(client_pref.enabled_by_default && client_pref.may_toggle(pref_mob))
pref.preferences_enabled += client_pref.key
else
pref.preferences_disabled += client_pref.key
// Clean out preferences that no longer exist.
for(var/key in pref.preferences_enabled)
if(!(key in client_preference_keys))
pref.preferences_enabled -= key
for(var/key in pref.preferences_disabled)
if(!(key in client_preference_keys))
pref.preferences_disabled -= key
pref.lastchangelog = sanitize_text(pref.lastchangelog, initial(pref.lastchangelog)) pref.lastchangelog = sanitize_text(pref.lastchangelog, initial(pref.lastchangelog))
pref.default_slot = sanitize_integer(pref.default_slot, 1, config.character_slots, initial(pref.default_slot)) pref.default_slot = sanitize_integer(pref.default_slot, 1, config.character_slots, initial(pref.default_slot))
@@ -46,7 +69,6 @@
. += "</tr>" . += "</tr>"
. += "</table>" . += "</table>"
return jointext(., "") return jointext(., "")
/datum/category_item/player_setup_item/player_global/settings/OnTopic(var/href,var/list/href_list, var/mob/user) /datum/category_item/player_setup_item/player_global/settings/OnTopic(var/href,var/list/href_list, var/mob/user)
@@ -60,13 +82,12 @@
return ..() return ..()
/client/proc/is_preference_enabled(var/preference) /client/proc/is_preference_enabled(var/preference)
if(ispath(preference)) if(ispath(preference))
var/datum/client_preference/cp = get_client_preference_by_type(preference) var/datum/client_preference/cp = get_client_preference_by_type(preference)
preference = cp.key preference = cp.key
return (preference in prefs.preferences) return (preference in prefs.preferences_enabled)
/client/proc/set_preference(var/preference, var/set_preference) /client/proc/set_preference(var/preference, var/set_preference)
var/datum/client_preference/cp var/datum/client_preference/cp
@@ -79,12 +100,14 @@
return FALSE return FALSE
var/enabled var/enabled
if(set_preference && !(preference in prefs.preferences)) if(set_preference && !(preference in prefs.preferences_enabled))
prefs.preferences += preference prefs.preferences_enabled += preference
prefs.preferences_disabled -= preference
enabled = TRUE enabled = TRUE
. = TRUE . = TRUE
else if(!set_preference && (preference in prefs.preferences)) else if(!set_preference && (preference in prefs.preferences_enabled))
prefs.preferences -= preference prefs.preferences_enabled -= preference
prefs.preferences_disabled |= preference
enabled = FALSE enabled = FALSE
. = TRUE . = TRUE
if(.) if(.)

View File

@@ -227,4 +227,11 @@
return TOPIC_NOACTION return TOPIC_NOACTION
/datum/category_item/player_setup_item/proc/preference_mob() /datum/category_item/player_setup_item/proc/preference_mob()
return get_mob_by_key(pref.client_ckey) if(!pref.client)
for(var/client/C)
if(C.ckey == pref.client_ckey)
pref.client = C
break
if(pref.client)
return pref.client.mob

View File

@@ -109,6 +109,7 @@ datum/preferences
// OOC Metadata: // OOC Metadata:
var/metadata = "" var/metadata = ""
var/client/client = null
var/client_ckey = null var/client_ckey = null
// Communicator identity data // Communicator identity data
@@ -125,6 +126,7 @@ datum/preferences
gear = list() gear = list()
if(istype(C)) if(istype(C))
client = C
client_ckey = C.ckey client_ckey = C.ckey
if(!IsGuestKey(C.key)) if(!IsGuestKey(C.key))
load_path(C.ckey) load_path(C.ckey)