Add save export functionality.

This commit is contained in:
Montessquio
2024-02-10 22:15:06 -06:00
parent a9aa2ab219
commit 5bf6e29acc
6 changed files with 42 additions and 3 deletions
+3 -3
View File
@@ -274,9 +274,9 @@ var/list/preferences_datums = list()
dat += "<a href='?src=\ref[src];save=1'>Save slot</a> - "
dat += "<a href='?src=\ref[src];reload=1'>Reload slot</a> - "
dat += "<a href='?src=\ref[src];resetslot=1'>Reset slot</a> - "
dat += "<a href='?src=\ref[src];copy=1'>Copy slot</a>"
dat += "<a href='?src=\ref[src];export=1'>Save &amp; export slot</a>" // YW Edit - "Add option to export character to JSON"
dat += "<a href='?src=\ref[src];copy=1'>Copy slot</a> - "
dat += "<a href='?src=\ref[src];export=1'>Save &amp; export all</a>" // YW Edit - "Add option to export character to JSON"
//dat += "<a href='?src=\ref[src];import=1'>Import all</a>" // YW Edit - "Add option to import character from JSON"
else
dat += "Please create an account to save your preferences."
+35
View File
@@ -34,4 +34,39 @@
if(!fexists(path)) return 0
var/savefile/S = new /savefile(path)
if(!S) return 0
if(tgui_alert(usr, "This will save and export all your character slots and user preferences to a file. Are you sure?","Export All",list("Yes","No"))=="No")
return
S.cd = "/"
var/save_json = rustg_savefile_to_json(S.ExportText())
var/datum/browser/popup = new(usr, "saveexport", "Save Export", 350, 380, src)
popup.set_content({"<script>
const raw = [save_json];
// Old browser, need to use blob builder
window.BlobBuilder = window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder;
var blob;
if (window.BlobBuilder) {
var bb = new BlobBuilder();
bb.append(JSON.stringify(raw, null, 2));
blob = bb.getBlob("application/pdf");
}
else {
window.alert("Failed to auto-download. Please copy-paste from the form in the window.");
}
if(blob) {
window.navigator.msSaveOrOpenBlob(blob, "save.json");
}
else {
window.alert("Failed to auto-download. Please copy-paste from the form in the window.");
}
</script>
<pre>[html_encode(save_json)]</pre>
"})
popup.open()