compress h5save & h5route

This commit is contained in:
ckcz123 2021-08-31 10:26:31 +08:00
parent 575cd37ce3
commit 83548759b5
4 changed files with 37 additions and 19 deletions

View File

@ -2759,7 +2759,8 @@ actions.prototype._clickLocalSaveSelect = function (x, y) {
"version": core.firstData.version,
"data": saves
}
core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5save", JSON.stringify(content));
core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5save",
LZString.compressToBase64(JSON.stringify(content)));
}
};
if (selection == 0) core.getAllSaves(callback);
@ -2913,12 +2914,13 @@ actions.prototype._clickReplay_replayRemain = function () {
actions.prototype._clickReplay_download = function () {
// if (core.hasFlag('debug')) return core.drawText("\t[系统提示]调试模式下无法下载录像");
core.download(core.firstData.name + "_" + core.formatDate2() + ".h5route", JSON.stringify({
'name': core.firstData.name,
'hard': core.status.hard,
'seed': core.getFlag('__seed__'),
'route': core.encodeRoute(core.status.route)
}));
core.download(core.firstData.name + "_" + core.formatDate2() + ".h5route",
LZString.compressToBase64(JSON.stringify({
'name': core.firstData.name,
'hard': core.status.hard,
'seed': core.getFlag('__seed__'),
'route': core.encodeRoute(core.status.route)
})));
}

View File

@ -2136,7 +2136,7 @@ control.prototype._syncSave_http = function (type, saves) {
var formData = new FormData();
formData.append('type', 'save');
formData.append('name', core.firstData.name);
formData.append('data', JSON.stringify(saves));
formData.append('data', LZString.compressToBase64(JSON.stringify(saves)));
formData.append('shorten', '1');
core.http("POST", "/games/sync.php", formData, function (data) {
@ -2181,7 +2181,19 @@ control.prototype._syncLoad_http = function (id, password) {
core.http("POST", "/games/sync.php", formData, function (data) {
var response = JSON.parse(data);
if (response.code == 0) {
core.control._syncLoad_write(JSON.parse(response.msg));
var msg = null;
try {
msg = JSON.parse(LZString.decompressFromBase64(response.msg));
} catch (e) {
try {
msg = JSON.parse(response.msg);
} catch (e) {}
}
if (msg) {
core.control._syncLoad_write(msg);
} else {
core.drawText("出错啦!\n存档解析失败");
}
}
else {
core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因"+response.msg);

View File

@ -217,7 +217,8 @@ events.prototype._gameOver_confirmDownload = function (ending) {
'seed': core.getFlag('__seed__'),
'route': core.encodeRoute(core.status.route)
}
core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route", JSON.stringify(obj));
core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route",
LZString.compressToBase64(JSON.stringify(obj)));
core.events._gameOver_askRate(ending);
}, function () {
core.events._gameOver_askRate(ending);

View File

@ -1019,19 +1019,22 @@ utils.prototype.readFileContent = function (content) {
core.platform.successCallback(content);
return;
}
// 检查base64
try {
obj = JSON.parse(content);
if (obj) {
if (core.platform.successCallback)
core.platform.successCallback(obj);
return;
obj = JSON.parse(LZString.decompressFromBase64(content));
} catch (e) {
try {
obj = JSON.parse(content);
} catch (e) {
main.log(e)
}
}
catch (e) {
main.log(e);
alert(e);
if (obj) {
if (core.platform.successCallback)
core.platform.successCallback(obj);
return;
}
// alert("不是有效的JSON文件");
if (core.platform.errorCallback)
core.platform.errorCallback();