Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
MosleyTheMalO committed Sep 28, 2023
2 parents 74c5478 + 502fbb6 commit 83918aa
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 24 deletions.
40 changes: 40 additions & 0 deletions code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,22 @@ GLOBAL_LIST_EMPTY(preferences_datums)

dat += "<HR>"

dat += "<center>"
var/client_file = user.client.Import()
var/savefile_name
if(client_file)
var/savefile/cache_savefile = new(user.client.Import())
if(!cache_savefile["deleted"] || savefile_needs_update(cache_savefile) != -2)
cache_savefile["real_name"] >> savefile_name
dat += "Local storage: [savefile_name ? savefile_name : "Empty"]"
dat += "<br />"
dat += "<a href='?_src_=prefs;preference=export_slot'>Export current slot</a>"
dat += "<a [savefile_name ? "href='?_src_=prefs;preference=import_slot' style='white-space:normal;'" : "class='linkOff'"]>Import into current slot</a>"
dat += "<a href='?_src_=prefs;preference=delete_local_copy' style='white-space:normal;background:#eb2e2e;'>Delete locally saved character</a>"
dat += "</center>"

dat += "<HR>"

dat += "<center>"
dat += "<a href='?_src_=prefs;preference=character_tab;tab=[GENERAL_CHAR_TAB]' [character_settings_tab == GENERAL_CHAR_TAB ? "class='linkOn'" : ""]>General</a>"
dat += "<a href='?_src_=prefs;preference=character_tab;tab=[APPEARANCE_CHAR_TAB]' [character_settings_tab == APPEARANCE_CHAR_TAB ? "class='linkOn'" : ""]>Appearance</a>"
Expand Down Expand Up @@ -3920,6 +3936,30 @@ GLOBAL_LIST_EMPTY(preferences_datums)
if("cumontopref")
cit_toggles ^= CUM_ONTO
//
if("export_slot")
var/savefile/S = save_character(export = TRUE)
if(istype(S, /savefile))
user.client.Export(S)
tgui_alert_async(user, "Successfully saved character slot")
else
tgui_alert_async(user, "Failed saving character slot")
return

if("import_slot")
var/savefile/S = new(user.client.Import())
if(istype(S, /savefile))
if(load_character(provided = S) == TRUE)
tgui_alert_async(user, "Successfully loaded character slot.")
else
tgui_alert_async(user, "Failed loading character slot")
return
else
tgui_alert_async(user, "Failed loading character slot")
return

if("delete_local_copy")
user.client.clear_export()
tgui_alert_async(user, "Local save data erased.")

if(href_list["preference"] == "gear")
if(href_list["clear_loadout"])
Expand Down
55 changes: 31 additions & 24 deletions code/modules/client/preferences_savefile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,10 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car

return 1

/datum/preferences/proc/load_character(slot, bypass_cooldown = FALSE)
if(!path)
return FALSE
/datum/preferences/proc/load_character(slot, bypass_cooldown = FALSE, savefile/provided)
if(!provided)
if(!path)
return FALSE
if(!bypass_cooldown)
if(world.time < loadcharcooldown) //This is before the check to see if the filepath exists to ensure that BYOND can't get hung up on read attempts when the hard drive is a little slow
if(istype(parent))
Expand All @@ -734,9 +735,30 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
loadcharcooldown = world.time + PREF_SAVELOAD_COOLDOWN
if(!fexists(path))
return FALSE
var/savefile/S = new /savefile(path)
var/savefile/S
if(provided)
S = provided
else
S = new /savefile(path)
if(!S)
return FALSE

S.cd = "/"
if(!slot)
slot = default_slot
slot = sanitize_integer(slot, 1, max_save_slots, initial(default_slot))
if(slot != default_slot)
default_slot = slot
WRITE_FILE(S["default_slot"] , slot)

if(!provided)
S.cd = "/character[slot]"
var/needs_update = savefile_needs_update(S)
if(needs_update == -2) //fatal, can't load any data
return FALSE

. = TRUE

features = list(
"mcolor" = "FFFFFF",
"mcolor2" = "FFFFFF",
Expand Down Expand Up @@ -829,22 +851,6 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
"neckfire_color" = "ffffff"
)


S.cd = "/"
if(!slot)
slot = default_slot
slot = sanitize_integer(slot, 1, max_save_slots, initial(default_slot))
if(slot != default_slot)
default_slot = slot
WRITE_FILE(S["default_slot"] , slot)

S.cd = "/character[slot]"
var/needs_update = savefile_needs_update(S)
if(needs_update == -2) //fatal, can't load any data
return FALSE

. = TRUE

//Species
var/species_id
S["species"] >> species_id
Expand Down Expand Up @@ -1311,7 +1317,7 @@ 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, export = FALSE)
if(!path)
return 0
if(!bypass_cooldown)
Expand All @@ -1320,10 +1326,11 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
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>")
return 0
savecharcooldown = world.time + PREF_SAVELOAD_COOLDOWN
var/savefile/S = new /savefile(path)
var/savefile/S = new /savefile(export ? null : path)
if(!S)
return 0
S.cd = "/character[default_slot]"
if(!export)
S.cd = "/character[default_slot]"

WRITE_FILE(S["version"] , SAVEFILE_VERSION_MAX) //load_character will sanitize any bad data, so assume up-to-date.)

Expand Down Expand Up @@ -1556,7 +1563,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car

splurt_character_pref_save(S)

return 1
return S


#undef SAVEFILE_VERSION_MAX
Expand Down
3 changes: 3 additions & 0 deletions html/changelogs/archive/2023-09.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@
remuluson2:
- rscadd: Added Messy trait, allowing you to cover stuff with cum while not meeting
size requirements.
2023-09-28:
SandPoot:
- rscadd: Added importing/exporting characters, they will be saved on your computer.
4 changes: 4 additions & 0 deletions modular_sand/code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/client/proc/clear_export()
var/savefile/S = new()
S["deleted"] << 1
Export(S)
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -4139,6 +4139,7 @@
#include "modular_sand\code\modules\cargo\packs\supply_pack.dm"
#include "modular_sand\code\modules\cargo\packs\vending.dm"
#include "modular_sand\code\modules\client\asset_cache.dm"
#include "modular_sand\code\modules\client\client_procs.dm"
#include "modular_sand\code\modules\client\preferences.dm"
#include "modular_sand\code\modules\client\preferences_savefile.dm"
#include "modular_sand\code\modules\client\loadout\_security.dm"
Expand Down

0 comments on commit 83918aa

Please sign in to comment.