mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
- Instead of using expensive getFlatIcon() calls, character previews are now shown using screen objects in a second map window. - Edited skin to add a named window for preferences setup that contains a browser plus a new map window to show the previews. - Mannequins are still generated the same way, but now a MA is applied to four screen objects which are shown in the second map window. - The screen objects are deleted on close of the preferences window. So we do make sure to close it when spawning.
123 lines
3.8 KiB
Plaintext
123 lines
3.8 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
|
|
if(slot != SAVE_RESET) // SAVE_RESET will reset the slot as though it does not exist, but keep the current slot for saving purposes.
|
|
slot = sanitize_integer(slot, 1, config.character_slots, initial(default_slot))
|
|
if(slot != default_slot)
|
|
default_slot = slot
|
|
S["default_slot"] << slot
|
|
else
|
|
S["default_slot"] << default_slot
|
|
|
|
if(slot != SAVE_RESET)
|
|
S.cd = "/character[slot]"
|
|
player_setup.load_character(S)
|
|
else
|
|
player_setup.load_character(S)
|
|
S.cd = "/character[default_slot]"
|
|
player_setup.save_character(S)
|
|
sanitize_preferences()
|
|
|
|
player_setup.load_character(S)
|
|
clear_character_previews() // Recalculate them on next show
|
|
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/overwrite_character(slot)
|
|
if(!path) return 0
|
|
if(!fexists(path)) return 0
|
|
var/savefile/S = new /savefile(path)
|
|
if(!S) return 0
|
|
if(!slot) slot = default_slot
|
|
if(slot != SAVE_RESET)
|
|
slot = sanitize_integer(slot, 1, config.character_slots, initial(default_slot))
|
|
if(slot != default_slot)
|
|
default_slot = slot
|
|
nif_path = nif_durability = nif_savedata = null //VOREStation Add - Don't copy NIF
|
|
S["default_slot"] << slot
|
|
|
|
else
|
|
S["default_slot"] << default_slot
|
|
|
|
return 1
|
|
|
|
/datum/preferences/proc/sanitize_preferences()
|
|
player_setup.sanitize_setup()
|
|
return 1
|
|
|
|
#undef SAVEFILE_VERSION_MAX
|
|
#undef SAVEFILE_VERSION_MIN |