summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/reader/ReaderView.js
blob: 4c532268b1c4131d15c1ee9894ec08f4e4a760e2 (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
89
90
91
92
93
var ReaderView = View.extend({
	el: "#readerView",
	
	projectAction: "/api/project/",

	events: {
	},
	
	initialize: function(){
		this.mediaPlayer = new MediaPlayer ({ parent: this })
		this.shareView = new shareView ({ parent: this })
	},

	load: function(name){
		if (window.location.search.indexOf("noui") !== -1) {
			$(".logo,.topLinks,#editorView").hide()
		}
		else {
		  this.tracker = new Tracker ()
		}
		if (window.location.search.indexOf("mute") !== -1) {
			app.muted = true
		}
		name = sanitize(name)
		$.get(this.projectAction + name, this.ready.bind(this))
	},
	
	ready: function(data){
		$("#map").hide()

		data.rooms && Rooms.deserialize(data.rooms)
		data.walls && Walls.deserialize(data.walls)
		data.media && Scenery.deserialize(data.media)
		data.startPosition && scene.camera.move(data.startPosition)
		
		cam.y = window.viewHeight = data.viewHeight || app.defaults.viewHeight
		
		var colors = data.colors || app.defaults.colors
    var modes = [ "wall", "outline", "floor", "ceiling" ]
    modes.forEach(function(mode){
      Walls.setColor[mode](colors[mode])
    })

		editor.permissions.clear()
		
		this.listen()
	},
	
	listen: function(){
		var base = this
		
		$(window).on('message', function(event){
			if (event.originalEvent.origin !== window.location.origin) {
				return
			}
			var message = event.originalEvent.data
			switch (message) {
				case "spin-on":
					base.spinning = true
					break
				case "spin-off":
					base.spinning = false
					break
			}
		})
		
		requestAnimationFrame(this.spin.bind(this))
	},
	
	spinning: false,
	spin: function(){
		requestAnimationFrame(this.spin.bind(this))
		if (this.spinning) {
			scene.camera.rotationY -= 1/180
		}
	},

	pick: function(scenery){
		this.mediaPlayer.pick(scenery)
    app.tube("pick-scenery", { scenery: scenery })
	},

	pickWall: function(wall, pos){
		this.hideExtras()
	},

	hideExtras: function(){
		this.mediaPlayer.hide()
    app.tube("close-scenery")
	}

})