mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
Adds client verb to access the character setup screen from anywhere. Moves name validation to species level, making it possible for IPCs to have numbers in their name. Adds gender validation, also adds support to add neuter/plural genders in the future if ever desired. Now sanitizes preferences before applying them to a mob. Fixes #11433. (cherry picked from commit e40246e9dfc9feb28b8c5a0a7ce765fd063c4f7e)
94 lines
2.9 KiB
Plaintext
94 lines
2.9 KiB
Plaintext
#define SAVEFILE_VERSION_MIN 8
|
|
#define SAVEFILE_VERSION_MAX 11
|
|
|
|
//handles converting savefiles to new formats
|
|
//MAKE SURE YOU KEEP THIS UP TO DATE!
|
|
//If the sanity checks are capable of handling any issues. Only increase SAVEFILE_VERSION_MAX,
|
|
//this will mean that savefile_version will still be over SAVEFILE_VERSION_MIN, meaning
|
|
//this savefile update doesn't run everytime we load from the savefile.
|
|
//This is mainly for format changes, such as the bitflags in toggles changing order or something.
|
|
//if a file can't be updated, return 0 to delete it and start again
|
|
//if a file was updated, return 1
|
|
/datum/preferences/proc/savefile_update()
|
|
if(savefile_version < 8) //lazily delete everything + additional files so they can be saved in the new format
|
|
for(var/ckey in preferences_datums)
|
|
var/datum/preferences/D = preferences_datums[ckey]
|
|
if(D == src)
|
|
var/delpath = "data/player_saves/[copytext(ckey,1,2)]/[ckey]/"
|
|
if(delpath && fexists(delpath))
|
|
fdel(delpath)
|
|
break
|
|
return 0
|
|
|
|
if(savefile_version == SAVEFILE_VERSION_MAX) //update successful.
|
|
save_preferences()
|
|
save_character()
|
|
return 1
|
|
return 0
|
|
|
|
/datum/preferences/proc/load_path(ckey,filename="preferences.sav")
|
|
if(!ckey) return
|
|
path = "data/player_saves/[copytext(ckey,1,2)]/[ckey]/[filename]"
|
|
savefile_version = SAVEFILE_VERSION_MAX
|
|
|
|
/datum/preferences/proc/load_preferences()
|
|
if(!path) return 0
|
|
if(!fexists(path)) return 0
|
|
var/savefile/S = new /savefile(path)
|
|
if(!S) return 0
|
|
S.cd = "/"
|
|
|
|
S["version"] >> savefile_version
|
|
//Conversion
|
|
if(!savefile_version || !isnum(savefile_version) || savefile_version < SAVEFILE_VERSION_MIN || savefile_version > SAVEFILE_VERSION_MAX)
|
|
if(!savefile_update()) //handles updates
|
|
savefile_version = SAVEFILE_VERSION_MAX
|
|
save_preferences()
|
|
save_character()
|
|
return 0
|
|
|
|
player_setup.load_preferences(S)
|
|
return 1
|
|
|
|
/datum/preferences/proc/save_preferences()
|
|
if(!path) return 0
|
|
var/savefile/S = new /savefile(path)
|
|
if(!S) return 0
|
|
S.cd = "/"
|
|
|
|
S["version"] << savefile_version
|
|
player_setup.save_preferences(S)
|
|
return 1
|
|
|
|
/datum/preferences/proc/load_character(slot)
|
|
if(!path) return 0
|
|
if(!fexists(path)) return 0
|
|
var/savefile/S = new /savefile(path)
|
|
if(!S) return 0
|
|
S.cd = "/"
|
|
if(!slot) slot = default_slot
|
|
slot = sanitize_integer(slot, 1, config.character_slots, initial(default_slot))
|
|
if(slot != default_slot)
|
|
default_slot = slot
|
|
S["default_slot"] << slot
|
|
S.cd = "/character[slot]"
|
|
|
|
player_setup.load_character(S)
|
|
return 1
|
|
|
|
/datum/preferences/proc/save_character()
|
|
if(!path) return 0
|
|
var/savefile/S = new /savefile(path)
|
|
if(!S) return 0
|
|
S.cd = "/character[default_slot]"
|
|
|
|
player_setup.save_character(S)
|
|
return 1
|
|
|
|
/datum/preferences/proc/sanitize_preferences()
|
|
player_setup.sanitize_setup()
|
|
return 1
|
|
|
|
#undef SAVEFILE_VERSION_MAX
|
|
#undef SAVEFILE_VERSION_MIN
|