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

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

		var urls = [
			"http://okfocus.s3.amazonaws.com/office/ducks/duck1.jpg",
			"http://okfocus.s3.amazonaws.com/office/ducks/duck2.jpg",
			"http://okfocus.s3.amazonaws.com/office/ducks/duck3.jpg",
			"http://okfocus.s3.amazonaws.com/office/ducks/duck4.jpg",
			"http://okfocus.s3.amazonaws.com/office/ducks/duck5.jpg",
		]
		var loader = new Loader(function(){
			base.load(loader.images)
		})
		// loader.preloadImages(urls)
	}
	
	base.load = function(images){
		images.forEach(function(img){
			img.width = 300
			img.height = ~~(300 * img.naturalHeight/img.naturalWidth)
		})
		
		Rooms.forEach(function(room){
			room.walls.forEach(function(wall){
				var img = choice(images)
				if (wall.fits(img)) {
					var scene_img = new Scenery.image (wall, img)
					base.images.push(scene_img)
					scene_img.init()
				}
			})
		})
	}

	base.add = function(wall, media){
		var scene_media
		switch (media.type) {
			case 'image':
				scene_media = new Scenery.image (wall, media)
				break
			
			case 'youtube':
			case 'vimeo':
				scene_media = new Scenery.video (wall, media)
				break
		}
		base.media.push(scene_media)
		scene_img.init()
	}
	base.addNextToWall = function(wall){
		base.add(wall, base.nextMedia)
		console.log("add next to wall")
		base.nextMedia = null
	}
	
	base.remove = function(id){
		base.images.splcie(id)
	}

	return base
}