From f4c200d3fb368292662ef9e4a9670afab3d23712 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 31 Dec 2019 10:26:29 +0800 Subject: [PATCH] optimize autosave --- libs/control.js | 9 ++++++--- libs/core.js | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/control.js b/libs/control.js index 0072ff2d..b0f58cdf 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1621,9 +1621,12 @@ control.prototype.autosave = function (removeLast) { control.prototype.checkAutosave = function () { if (!core.animateFrame || !core.saves || !core.saves.autosave) return; core.setLocalStorage('totalTime', core.animateFrame.totalTime); - if (core.saves.autosave.data == null || !core.saves.autosave.updated) return; - core.saves.autosave.updated = false; - core.setLocalForage("autoSave", core.saves.autosave.data); + var autosave = core.saves.autosave; + if (autosave.data == null || !autosave.updated || !autosave.storage) return; + autosave.updated = false; + if (autosave.data.length >= 1) { + core.setLocalForage("autoSave", autosave.data[autosave.data.length - 1]); + } } ////// 实际进行存读档事件 ////// diff --git a/libs/core.js b/libs/core.js index a97fb8e5..f02616ac 100644 --- a/libs/core.js +++ b/libs/core.js @@ -106,6 +106,7 @@ function core() { "data": null, "time": 0, "updated": false, + "storage": true, // 是否把自动存档写入文件a "max": 10, // 自动存档最大回退数 }, "favorite": [],