Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monty/character export #1426

Merged
merged 5 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions code/__defines/rust_g_yw.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

// savefile ser/de //
#define rustg_savefile_to_json(save_string) call(RUST_G, "savefile_to_json")(save_string)
12 changes: 10 additions & 2 deletions code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +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];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."

Expand Down Expand Up @@ -383,6 +384,13 @@ var/list/preferences_datums = list()
// User closed preferences window, cleanup anything we need to.
clear_character_previews()
return 1
// YW Edit - "Add option to export character to JSON"
else if(href_list["export"])
save_preferences()
save_character()
export_prefs_json()
return 1
// YW Edit End
else
return 0

Expand Down
42 changes: 42 additions & 0 deletions code/modules/client/preferences_yw.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,45 @@
popup.set_content(dat)
popup.open()


/datum/preferences/proc/export_prefs_json()
if(!path) return 0
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()
1 change: 1 addition & 0 deletions vorestation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "code\__defines\research.dm"
#include "code\__defines\roguemining_vr.dm"
#include "code\__defines\rust_g.dm"
#include "code\__defines\rust_g_yw.dm"
#include "code\__defines\shadekin.dm"
#include "code\__defines\shields.dm"
#include "code\__defines\shuttle.dm"
Expand Down
Loading