This commit is contained in:
SandPoot
2024-01-05 00:18:21 -03:00
parent a8be340925
commit 05e2cc0979
9 changed files with 93 additions and 37 deletions

View File

@@ -41,10 +41,10 @@ GLOBAL_LIST_EMPTY(preferences_datums)
var/last_custom_holoform = 0
//Cooldowns for saving/loading. These are four are all separate due to loading code calling these one after another
var/saveprefcooldown
var/loadprefcooldown
var/savecharcooldown
var/loadcharcooldown
COOLDOWN_DECLARE(saveprefcooldown)
COOLDOWN_DECLARE(loadprefcooldown)
COOLDOWN_DECLARE(savecharcooldown)
COOLDOWN_DECLARE(loadcharcooldown)
//game-preferences
var/lastchangelog = "" //Saved changlog filesize to detect if there was a change
@@ -267,6 +267,9 @@ GLOBAL_LIST_EMPTY(preferences_datums)
var/loadout_errors = 0
var/pref_queue
var/char_queue
/datum/preferences/New(client/C)
parent = C
@@ -3212,6 +3215,8 @@ GLOBAL_LIST_EMPTY(preferences_datums)
load_character()
if("changeslot")
if(char_queue != -1)
deltimer(char_queue) // Do not dare.
if(!load_character(text2num(href_list["num"])))
random_character()
real_name = random_unique_name(gender)

View File

@@ -401,7 +401,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
if(istype(parent))
to_chat(parent, "<span class='warning'>You're attempting to load your preferences a little too fast. Wait half a second, then try again.</span>")
return FALSE
loadprefcooldown = world.time + PREF_SAVELOAD_COOLDOWN
COOLDOWN_START(src, loadprefcooldown, PREF_LOAD_COOLDOWN)
if(!fexists(path))
return FALSE
@@ -593,15 +593,17 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
if(!GLOB.keybindings_by_name[bindname])
modless_key_bindings -= key
/datum/preferences/proc/save_preferences(bypass_cooldown = FALSE)
/datum/preferences/proc/save_preferences(bypass_cooldown = FALSE, silent = FALSE)
if(!path)
return 0
if(!bypass_cooldown)
if(world.time < saveprefcooldown)
if(istype(parent))
to_chat(parent, "<span class='warning'>You're attempting to save your preferences a little too fast. Wait half a second, then try again.</span>")
queue_save_pref(PREF_SAVE_COOLDOWN, silent)
return 0
saveprefcooldown = world.time + PREF_SAVELOAD_COOLDOWN
COOLDOWN_START(src, saveprefcooldown, PREF_SAVE_COOLDOWN)
if(pref_queue != -1)
deltimer(pref_queue)
var/savefile/S = new /savefile(path)
if(!S)
return 0
@@ -673,7 +675,17 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
else
WRITE_FILE(S["unlockable_loadout"], safe_json_encode(list()))
return 1
if(parent && !silent)
to_chat(parent, span_notice("Saved preferences!"))
return TRUE
/datum/preferences/proc/queue_save_pref(save_in, silent)
if(parent && !silent)
to_chat(parent, span_notice("Saving preferences in [save_in * 0.1] second\s."))
if(pref_queue != -1)
deltimer(pref_queue)
pref_queue = addtimer(CALLBACK(src, PROC_REF(save_preferences), TRUE, silent), save_in)
/datum/preferences/proc/load_character(slot, bypass_cooldown = FALSE)
if(!path)
@@ -683,7 +695,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
if(istype(parent))
to_chat(parent, "<span class='warning'>You're attempting to load your character a little too fast. Wait half a second, then try again.</span>")
return "SLOW THE FUCK DOWN" //the reason this isn't null is to make sure that people don't have their character slots overridden by random chars if they accidentally double-click a slot
loadcharcooldown = world.time + PREF_SAVELOAD_COOLDOWN
COOLDOWN_START(src, loadcharcooldown, PREF_LOAD_COOLDOWN)
if(!fexists(path))
return FALSE
var/savefile/S = new /savefile(path)
@@ -1083,15 +1095,17 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
return 1
/datum/preferences/proc/save_character(bypass_cooldown = FALSE)
/datum/preferences/proc/save_character(bypass_cooldown = FALSE, silent = FALSE)
if(!path)
return 0
if(!bypass_cooldown)
if(world.time < savecharcooldown)
if(istype(parent))
to_chat(parent, "<span class='warning'>You're attempting to save your character a little too fast. Wait half a second, then try again.</span>")
queue_save_char(PREF_SAVE_COOLDOWN, silent)
return 0
savecharcooldown = world.time + PREF_SAVELOAD_COOLDOWN
COOLDOWN_START(src, savecharcooldown, PREF_SAVE_COOLDOWN)
if(char_queue != -1)
deltimer(char_queue)
var/savefile/S = new /savefile(path)
if(!S)
return 0
@@ -1278,8 +1292,17 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
cit_character_pref_save(S)
if(parent && !silent)
to_chat(parent, span_notice("Saved character slot!"))
return 1
/datum/preferences/proc/queue_save_char(save_in, silent)
if(parent && !silent)
to_chat(parent, span_notice("Saving character in [save_in * 0.1] second\s."))
if(char_queue != -1)
deltimer(char_queue)
char_queue = addtimer(CALLBACK(src, PROC_REF(save_character), TRUE, silent), save_in)
#undef SAVEFILE_VERSION_MAX
#undef SAVEFILE_VERSION_MIN