codecombat/app/views/editor/component/ThangComponentConfigView.coffee

81 lines
2.3 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
CocoView = require 'views/kinds/CocoView'
template = require 'templates/editor/component/thang-component-config-view'
2014-01-03 13:32:13 -05:00
Level = require 'models/Level'
LevelComponent = require 'models/LevelComponent'
nodes = require '../level/treema_nodes'
module.exports = class ThangComponentConfigView extends CocoView
className: 'thang-component-config-view'
2014-01-03 13:32:13 -05:00
template: template
changed: false
events:
'click .treema-shortened': -> console.log 'clicked treema root'
2014-01-03 13:32:13 -05:00
constructor: (options) ->
super options
@component = options.component
@config = options.config or {}
@world = options.world
@level = options.level
@callback = options.callback
2014-02-11 17:58:45 -05:00
getRenderData: (context={}) ->
2014-01-03 13:32:13 -05:00
context = super(context)
context.component = @component.attributes
2014-01-03 13:32:13 -05:00
context.configProperties = []
context
afterRender: ->
super()
@buildTreema()
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
buildTreema: ->
thangs = if @level? then @level.get('thangs') else []
thangIDs = _.filter(_.pluck(thangs, 'id'))
teams = _.filter(_.pluck(thangs, 'team'))
superteams = _.filter(_.pluck(thangs, 'superteam'))
superteams = _.union(teams, superteams)
treemaOptions =
supermodel: @supermodel
schema: @component.attributes.configSchema
2014-01-03 13:32:13 -05:00
data: _.cloneDeep @config
callbacks: {change: @onConfigEdited}
world: @world
view: @
thangIDs: thangIDs
teams: teams
superteams: superteams
nodeClasses:
'point2d': nodes.WorldPointNode
'viewport': nodes.WorldViewportNode
'bounds': nodes.WorldBoundsNode
'radians': nodes.RadiansNode
'team': nodes.TeamNode
'superteam': nodes.SuperteamNode
'meters': nodes.MetersNode
'kilograms': nodes.KilogramsNode
'seconds': nodes.SecondsNode
'speed': nodes.SpeedNode
'acceleration': nodes.AccelerationNode
'item-thang-type': nodes.ItemThangTypeNode
2014-01-03 13:32:13 -05:00
@editThangTreema = @$el.find('.treema').treema treemaOptions
@editThangTreema.build()
@editThangTreema.open(2)
if _.isEqual(@editThangTreema.data, {}) and not @editThangTreema.canAddChild()
@$el.find('.panel-body').hide()
2014-01-03 13:32:13 -05:00
onConfigEdited: =>
@changed = true
@trigger 'changed', { component: @component, config: @data() }
2014-06-30 22:16:26 -04:00
undo: ->
@editThangTreema.undo()
redo: ->
@editThangTreema.redo()
2014-01-03 13:32:13 -05:00
data: -> @editThangTreema.data