forked from MMM-CalendarExt2/MMM-CalendarExt2
/
CALEXT2_Scene.js
39 lines (37 loc) · 1.01 KB
/
CALEXT2_Scene.js
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
class Scene {
constructor(uid, cfgs) {
var scene = cfgs.scenes[uid]
var sceneLength = cfgs.scenes.length
this.config = cfgs
this.name = scene.name
this.className = scene.className
this.uid = uid
this.nextUid = (uid == sceneLength - 1) ? 0 : uid + 1
this.previousUid = (uid == 0) ? (sceneLength - 1) : uid - 1
this.viewNames
= (!scene.views || scene.views.length == 0)
? (cfgs.views.map((v)=>{return v.name})): scene.views
this.views = []
}
draw(events) {
this.clearViews()
var viewId = 0
this.viewNames.forEach((viewName)=>{
var viewConfig = this.config.views.find((config)=>{
if (config.name == viewName) return true
})
viewConfig.sceneClassName = this.className
var view = View.makeByName(viewConfig, events)
if (view) {
this.views.push(view)
view.draw()
}
})
}
clearViews() {
for (let i = 0; i < this.views.length; i++) {
var view = this.views[i]
view.destroy()
}
}
}