-
Notifications
You must be signed in to change notification settings - Fork 498
Expand file tree
/
Copy pathautosave.js
More file actions
88 lines (55 loc) · 2.11 KB
/
Copy pathautosave.js
File metadata and controls
88 lines (55 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var localStorage = window.hasOwnProperty('localStorage') ? window.localStorage : false;
import { loadProject } from '../actions/project-actions';
var TIMEOUT_DELAY = 500;
var timeout = null;
export default function autosave(autosaveKey, delay,selectPanicButton,plan) {
return function (store, stateExtractor) {
delay = delay || TIMEOUT_DELAY;
if (!autosaveKey) return;
if (!localStorage) return;
//revert
// var data = localStorage.getItem(autosaveKey);
// var json = JSON.parse(data);
// console.log(plan,"plan")
// store.dispatch(loadProject(plan));
//update
store.subscribe(function () {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function () {
var state = stateExtractor(store.getState());
let json=state.scene.toJS()
console.log(state.scene.toJS(),"state")
localStorage.setItem(autosaveKey, JSON.stringify(state.scene.toJS()));
let items =json["layers"]["layer-1"]["items"]
for (var key in items) {
let item= items[key]
if (item["selected"]==true){
selectPanicButton(item["id"],false)
// store.dispatch(loadProject(json));
}
}
let areas=json["layers"]["layer-1"]["areas"]
for (var key in areas) {
let area= areas[key]
if (area["selected"]==true){
let vertices=area["vertices"]
let x=0
let y=0
// console.log("vertices",vertices)
vertices.map((vertex)=>{
x+=json["layers"]["layer-1"]["vertices"][vertex]["x"]
y+=json["layers"]["layer-1"]["vertices"][vertex]["y"]
})
// console.log("x= ",x/vertices.length,"y= ",y/vertices.length)
// store.dispatch(loadProject(json));
}
}
/*let scene = state.sceneHistory.last;
if (scene) {
let json = JSON.stringify(scene.toJS());
localStorage.setItem(autosaveKey, json);
}*/
}, 100);
});
};
}