Add load from server to settings, rename save button

This commit is contained in:
Johannes
2026-03-13 00:05:16 +01:00
parent 73257bec74
commit d3ad761c0b

View File

@@ -5539,7 +5539,8 @@
.querySelector("html") .querySelector("html")
.addEventListener("navigationFinished", function (e) { .addEventListener("navigationFinished", function (e) {
($("#settings-container select[multiple]").selectpicker(), ($("#settings-container select[multiple]").selectpicker(),
E.updateServiceWorkerStatus()); E.updateServiceWorkerStatus(),
E.populateServerSaves());
}); });
const e = s.getInstance(), const e = s.getInstance(),
t = n.canCompress(); t = n.canCompress();
@@ -5624,7 +5625,7 @@
() => { () => {
E.exportSavegamePrivateBin(); E.exportSavegamePrivateBin();
}, },
)}"><i class="fas fa-file-export"></i> ${e.T("settings-share-save-button", "Export save without file")}</button>\n <div id="savegameQR"></div>\n --\x3e\n </div>\n <div class="form-group">\n <h5 class="py-2 text-warning">Named Save</h5>\n <div class="input-group">\n <input type="text" class="form-control bg-dark text-white" id="named-save-input" placeholder="Save name...">\n <div class="input-group-append">\n <button class="btn btn-outline-success" onclick="${wi.register(() => { E.exportNamedSave(); })}"><i class="fas fa-save"></i> Save</button>\n </div>\n </div>\n <small class="form-text text-muted">Save a complete export with a custom name.</small>\n </div>\n </div>\n </div>`; )}"><i class="fas fa-file-export"></i> ${e.T("settings-share-save-button", "Export save without file")}</button>\n <div id="savegameQR"></div>\n --\x3e\n </div>\n <div class="form-group">\n <h5 class="py-2 text-warning">Server Saves</h5>\n <div class="input-group mb-2">\n <input type="text" class="form-control bg-dark text-white" id="named-save-input" placeholder="Save name...">\n <div class="input-group-append">\n <button class="btn btn-outline-success" onclick="${wi.register(() => { E.exportNamedSave(); })}"><i class="fas fa-cloud-upload-alt"></i> Save on server</button>\n </div>\n </div>\n <small class="form-text text-muted mb-3">Upload a complete export to the server under a custom name.</small>\n <div class="input-group mt-2">\n <select class="form-control bg-dark text-white" id="server-saves-select"><option value="">Loading saves...</option></select>\n <div class="input-group-append">\n <button class="btn btn-outline-warning" onclick="${wi.register(() => { E.importNamedSave(); })}"><i class="fas fa-cloud-download-alt"></i> Load from server</button>\n </div>\n </div>\n <small class="form-text text-muted">Load a previously saved game from the server. This will overwrite your current progress.</small>\n </div>\n </div>\n </div>`;
} }
static mapManagementFormView() { static mapManagementFormView() {
const e = s.getInstance(); const e = s.getInstance();
@@ -5889,6 +5890,36 @@
n.setSetting("completeExports", orig_complete); n.setSetting("completeExports", orig_complete);
n.setSetting("compressExports", orig_compress); n.setSetting("compressExports", orig_compress);
} }
static async populateServerSaves() {
try {
const res = await fetch("https://pu-saves.burrson.de/saves");
const saves = await res.json();
const select = $("#server-saves-select");
if (!select.length) return;
select.empty();
if (saves.length === 0) {
select.append('<option value="">No saves found</option>');
} else {
saves.forEach(name => select.append(`<option value="${name}">${name}</option>`));
}
} catch (e) {
$("#server-saves-select").empty().append('<option value="">Could not load saves</option>');
}
}
static async importNamedSave() {
const save_name = $("#server-saves-select").val();
if (!save_name) return;
try {
const res = await fetch(`https://pu-saves.burrson.de/saves/${encodeURIComponent(save_name)}`);
if (!res.ok) throw "Not found";
const text = await res.text();
if (n.hasScript(text)) throw "Script found!";
const data = JSON.parse(n.decompressJsonFromString(text));
E.importSaveGame(data);
} catch (e) {
n.showToast("Load failed", "Could not load the save from the server.", "danger");
}
}
static async importSaveGameClipboard() { static async importSaveGameClipboard() {
const e = s.getInstance(), const e = s.getInstance(),
t = { t = {