summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
blob: b4a38f8a347153a3fb1dfeab924dcca9f88ccecf (plain)
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 Scenery = new function(){
	
	var base = this;

	base.list = {}
	base.nextMedia = null
	
	base.mouse = new mouse ({ use_offset: false })
	
	base.init = function(){
		base.resize.init()
	}

	base.add = function(opt){
		var scene_media
		switch (opt.media.type) {
			case 'image':
				scene_media = new Scenery.types.image (opt)
				break
			
			case 'video':
			case 'youtube':
			case 'vimeo':
				scene_media = new Scenery.types.video (opt)
				break
		}
		base.list[scene_media.id] = scene_media
		return scene_media
	}
	
	base.addNextToWall = function(wall, mx){
		base.add({
			wall: wall,
			media: base.nextMedia,
			mx: mx
		})
		base.nextMedia = null
		return media
	}

	base.find = function(id){
		return base.list[id] || null
	}
		
	base.remove = function(id){
		var media = base.list[id]
		delete base.list[id]
		media && media.destroy()
	}

	base.uid = new UidGenerator(base.list)
	
	base.forEach = function(f){
		return base.values().forEach(f)
	}
	
	base.map = function(f){
		return base.values().map(f)
	}
	
	base.values = function(){
		return _.values(base.list)
	}
	
	base.serialize = function(){
		var scenery = base.map(function(media){
			return media.serialize()
		})
		return scenery
	}

	base.deserialize = function(scenery_data){
		scenery_data.forEach(function(data){
			var wall = Rooms.walls[data.wall_id]
			var scene_media = base.add({
			  data: data,
				wall: wall,
				media: data.media,
				id: data.id
			})
		})
	}

	return base
}

Scenery.types = {}