summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/blueprint/BlueprintView.js
blob: e249c91163d9d8b001313431423fef9f50ae404f (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
94
95
96
97
var BlueprintView = View.extend({
	el: "#blueprintView",

	action: "/api/blueprint/show/",

	events: {
	},
	
	initialize: function(){
// 		this.colorControl = new ColorControl ({ parent: this })
// 		this.cursor = new HelpCursor({ parent: this })
    this.map = this.buildMap()
		this.editor = new BlueprintEditor ({ parent: this })
		this.toolbar = new BlueprintToolbar ({ parent: this })
    this.uploader = new BlueprintUploader ({ parent: this })
    this.scaler = new BlueprintScaler ({ parent: this })
		this.info = new BlueprintInfo ({ parent: this })
		this.settings = new BlueprintSettings ({ parent: this })
		this.notice = new BlueprintNotice ({ parent: this })
		Rooms.shapesMode = true
	},

	load: function(name){
		name = sanitize(name) || "new"
    this.uploader.load(name)
// 		name = sanitize(name)
// 		$.get(this.action + name, this.ready.bind(this))
	},

  orbiting: true,
	startPosition: {},
	quantizeStartPosition: function(){
	  //
	  var regions = RegionList.build()
	  var pos = this.startPosition
	  var startPositionIsInARoom = regions.some(function(region){
	    return region.contains(pos.x, pos.z)
	  })
	  if (startPositionIsInARoom) {
	    return this.startPosition
	  }
	  else {
	    var center = regions[0].center()
	    return {
	      x: center.a,
	      y: viewHeight,
	      z: center.b,
        rotationX: 0,
        rotationY: Math.PI/2,
	    }
	  }
	},
	
	buildMap: function(){
	  // i forget if this has to be global
    map = new Map ({
      type: "ortho",
      el: document.querySelector("#orthographic"),
      width: window.innerWidth/2,
      height: window.innerHeight,
      zoom: -2,
      zoom_min: -6.2,
      zoom_max: 1,
    })
    map.ui.add_tool("arrow", new ArrowTool)
    map.ui.add_tool("polyline", new PolylineTool)
    map.ui.add_tool("ortho-polyline", new OrthoPolylineTool)
    map.ui.add_tool("eraser", new EraserTool)
    map.ui.add_tool("position", new PositionTool)
    map.ui.add_tool("start-position", new StartPositionTool)
    map.ui.placing = false
    return map
	},
	
	ready: function(data){
	  this.data = data
		this.info.load(data)
		this.settings.load(data)
	  this.editor.loadFloorplan(data)
	  if (! data.shapes || data.shapes.length == 0) {
	    this.startPosition = { x: 0, y: 0, z: 0, rotationX: 0, rotationY: Math.PI/2 }
	  }
	  else {
	    this.startPosition = data.startPosition
	  }
    this.notice.hide()
    this.settings.show()
	},
	
	hideExtras: function(){
	},
	
	pickWall: function(wall, pos){
	},

})