2014-01-03 13:32:13 -05:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
|
|
|
template = require 'templates/editor/components/config'
|
|
|
|
|
|
|
|
Level = require 'models/Level'
|
|
|
|
LevelComponent = require 'models/LevelComponent'
|
|
|
|
nodes = require '../level/treema_nodes'
|
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class ThangComponentConfigView extends CocoView
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'component-config-column-view'
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
|
|
|
className: 'column'
|
|
|
|
changed: false
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@component = options.component
|
|
|
|
@config = options.config or {}
|
|
|
|
@world = options.world
|
|
|
|
@level = options.level
|
|
|
|
@editing = options.editing
|
|
|
|
@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
|
|
|
|
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.configSchema
|
|
|
|
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
|
|
|
|
treemaOptions.readOnly = not @editing
|
|
|
|
|
|
|
|
@editThangTreema = @$el.find('.treema').treema treemaOptions
|
|
|
|
@editThangTreema.build()
|
|
|
|
@editThangTreema.open(2)
|
2014-04-17 22:41:07 -04:00
|
|
|
@hideLoading()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onConfigEdited: =>
|
|
|
|
@changed = true
|
|
|
|
@callback?(@data())
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
data: -> @editThangTreema.data
|