summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/editor/Presets.js
blob: be86af3a1f4226843b1175b563547562af70535f (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
98
99
100
101
102
var Presets = View.extend({
	el: "#presets",
	
	events: {
		"mousedown": "stopPropagation",
    "click .presets span": "selectPreset",
    "click .swatches span": "selectColor",
	},
	
  presets: {
    wireframe: {
      wall: [255,255,255],
      outline: [0,0,0],
      floor: [246,246,246],
      ceiling: [255,255,255],
    },
    shaded: {
      wall: [205,205,204],
      outline: [0,0,0],
      floor: [109,116,106],
      ceiling: [159,163,157],
      background: [109,116,106],
    },
    "p.Funk": {
      wall: [255,63,78],
      outline: [255,246,0],
      floor: [255,255,0],
      ceiling: [225,118,252],
    },
    inverse: {
      wall: [0,0,0],
      outline: [255,255,255],
      floor: [0,0,0],
      ceiling: [0,0,0],
    },
    matrix: {
    	wall: { src: "http://dump.fm/images/20130225/1361818675427-dumpfm-melipone-matrixremixtransfast.gif", scale: 4.0, color: [0,0,0] },
    	outline: [0,0,0],
      floor: [10,15,10],
      ceiling: [0,0,0],
    },
  },
  
  initialize: function(opt){
    this.parent = opt.parent
    
		this.$presets = this.$(".presets")
  	_.keys(this.presets).forEach(function(name){
			var $swatch = $("<span>")
			$swatch.html(capitalize(name))
			$swatch.data('preset', name)
			this.$presets.append($swatch)
  	}.bind(this))
  },

  toggle: function(state){
    this.$el.toggleClass("active", state)
    this.parent.cursor.message(state ? "presets" : "start")
  },
  
  show: function(){
    this.toggle(true)
  },
  
  hide: function(){
    this.toggle(false)
  },

  selectPreset: function(e){
    var preset = $(e.currentTarget).data('preset')
    if (! this.presets[preset]) return
    this.$(".active").removeClass('active')
    $(e.currentTarget).addClass('active')
    this.load(this.presets[preset])
  },
  
  selectColor: function(e){
    var preset = $(e.currentTarget).data('color')
    console.log(preset)
  },
  
  lastPreset: {wall:[1],outline:[1],floor:[1],ceiling:[1]},
  load: function(preset){
    this.parent.colorControl.modes.forEach(function(mode){
    	if (! preset[mode].length) {
    		Walls.setWallpaper[mode](preset[mode])
				Walls.setColor[mode](preset[mode].color)
			}
			else {
				if (preset[mode].length) {
					Walls.clearWallpaper[mode]()
				}
				Walls.setColor[mode](preset[mode])
				this.parent.colorControl.$swatch[ mode ].css("background-color", rgb_string(preset[mode]))
    	}
    }.bind(this))
    this.parent.colorControl.setMode(preset.wall.color ? "wall" : "floor")
    Walls.setBodyColor()
    this.lastPreset = preset
  },

})