Fix multiple pref issues (#18083)

* fix tail alyering pref

* .

* .

* .

* .

* -

* return

* fix that

* write needs save after

* urg

* ban slot change mid round

* -

* .

* properly save

* .

* queue to ss

* read current

* performance

* .

* .

* bit better optimized

* no resetsploit

* this works at least but is it proper (#13)

* this works at least but is it proper

* Update changeling.dm

* this too...

* dont be private

* fix asset ss

---------

Co-authored-by: C.L. <killer65311@gmail.com>
This commit is contained in:
Kashargul
2025-08-10 04:13:15 +02:00
committed by GitHub
parent 7303f34565
commit d9787e171e
15 changed files with 107 additions and 55 deletions
@@ -317,8 +317,9 @@ GLOBAL_LIST_INIT(preference_entries_by_key, init_preference_entries_by_key())
return client?.prefs?.read_preference(preference_type)
/// Write a /datum/preference type and return its value directly to the json.
/mob/proc/write_preference_directly(preference_type, preference_value)
var/success = client?.prefs?.write_preference_by_type(preference_type, preference_value)
/// Please use SScharacter_setup.queue_preferences_save(prefs) when you edit multiple at once and set direct_write to WRITE_PREF_MANUAL
/mob/proc/write_preference_directly(preference_type, preference_value, write_mode = WRITE_PREF_INSTANT)
var/success = client?.prefs?.write_preference_by_type(preference_type, preference_value, write_mode)
if(success)
client?.prefs?.value_cache[preference_type] = preference_value
return success
@@ -336,7 +337,7 @@ GLOBAL_LIST_INIT(preference_entries_by_key, init_preference_entries_by_key())
/// Writes a value and saves to disk immediately
/// Used by things that need to directly write to the player savefile things that aren't "really" prefs
/datum/preferences/proc/write_preference_by_type(preference_type, preference_value)
/datum/preferences/proc/write_preference_by_type(preference_type, preference_value, write_mode = WRITE_PREF_NORMAL)
var/datum/preference/preference_entry = GLOB.preference_entries[preference_type]
if(isnull(preference_entry))
CRASH("Preference type `[preference_type]` is invalid!")
@@ -344,7 +345,10 @@ GLOBAL_LIST_INIT(preference_entries_by_key, init_preference_entries_by_key())
if(!write_preference(preference_entry, preference_entry.pref_serialize(preference_value)))
return
if(preference_entry.savefile_identifier == PREFERENCE_CHARACTER)
if(write_mode == WRITE_PREF_MANUAL)
return TRUE
if(preference_entry.savefile_identifier == PREFERENCE_CHARACTER && write_mode != WRITE_PREF_INSTANT)
var/save_data = get_save_data_for_savefile_identifier(preference_entry.savefile_identifier)
player_setup.save_character(save_data)
else
@@ -213,16 +213,17 @@
return 255 //no randomization here.
///Tail style.
/datum/preference/numeric/human/tail_layering
/datum/preference/choiced/human/tail_layering
category = PREFERENCE_CATEGORY_MANUALLY_RENDERED
savefile_identifier = PREFERENCE_CHARACTER
savefile_key = "tail_layering"
can_randomize = FALSE
minimum = TAIL_UPPER_LAYER
maximum = TAIL_UPPER_LAYER_HIGH
/datum/preference/numeric/human/tail_layering/create_default_value()
return TAIL_UPPER_LAYER
/datum/preference/choiced/human/tail_layering/init_possible_values()
return assoc_to_keys(GLOB.tail_layer_options)
/datum/preference/numeric/human/tail_layering/apply_to_human(mob/living/carbon/human/target, value)
target.tail_layering = value
/datum/preference/choiced/human/tail_layering/create_default_value()
return GLOB.tail_layer_options[2]
/datum/preference/choiced/human/tail_layering/apply_to_human(mob/living/carbon/human/target, value)
target.tail_layering = GLOB.tail_layer_options[value]