|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import { IMapEditor } from "@map"; |
|
|
|
|
import { Action } from "redux"; |
|
|
|
|
import { message, Modal } from "antd"; |
|
|
|
|
import SparkMD5 from "spark-md5"; |
|
|
|
|
import { |
|
|
|
|
registerHotkey, |
|
|
|
|
downloadJSON, |
|
|
|
@ -25,6 +26,7 @@ export class EditorAction {
|
|
|
|
|
mapEditor: IMapEditor | null = null; |
|
|
|
|
store: IStore; |
|
|
|
|
id: string; |
|
|
|
|
tempId: string = ""; |
|
|
|
|
autoSaveTimer: number = -1; |
|
|
|
|
|
|
|
|
|
constructor(store: IStore) { |
|
|
|
@ -63,7 +65,11 @@ export class EditorAction {
|
|
|
|
|
this._openProject(JSON.parse(cached)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.autoSaveTimer = setTimeout(() => this.saveTemp(), AutoCacheInterval); |
|
|
|
|
// 自动的不强制save
|
|
|
|
|
this.autoSaveTimer = setTimeout( |
|
|
|
|
() => this.saveTemp(false), |
|
|
|
|
AutoCacheInterval |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ---------- public methods -------------
|
|
|
|
@ -127,11 +133,21 @@ export class EditorAction {
|
|
|
|
|
downloadJSON(mapOptions, "fine.fgd"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async saveTemp() { |
|
|
|
|
async saveTemp(forceSave = true) { |
|
|
|
|
clearTimeout(this.autoSaveTimer); |
|
|
|
|
await setItem(this.id, JSON.stringify(this._getMapOptions())); |
|
|
|
|
message.success("暂存成功~"); |
|
|
|
|
this.autoSaveTimer = setTimeout(() => this.saveTemp(), AutoCacheInterval); |
|
|
|
|
const tempContent = JSON.stringify(this._getMapOptions()); |
|
|
|
|
|
|
|
|
|
const tempId = SparkMD5.hash(tempContent); |
|
|
|
|
const hasChanged = this.tempId !== tempId; |
|
|
|
|
this.tempId = tempId; |
|
|
|
|
if (hasChanged || forceSave) { |
|
|
|
|
await setItem(this.id, tempContent); |
|
|
|
|
message.success("暂存成功~"); |
|
|
|
|
} |
|
|
|
|
this.autoSaveTimer = setTimeout( |
|
|
|
|
() => this.saveTemp(false), |
|
|
|
|
AutoCacheInterval |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
clearOverlays() { |
|
|
|
|