2014-11-28 20:49:41 -05:00
|
|
|
CocoView = require 'views/core/CocoView'
|
2014-08-11 16:24:08 -04:00
|
|
|
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'
|
2014-11-29 20:51:32 -05:00
|
|
|
require 'vendor/treema'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class ThangComponentConfigView extends CocoView
|
2014-08-07 21:49:39 -04:00
|
|
|
className: 'thang-component-config-view'
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
|
|
|
changed: false
|
2014-08-11 01:09:13 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@component = options.component
|
|
|
|
@config = options.config or {}
|
2014-08-25 23:34:46 -04:00
|
|
|
@additionalDefaults = options.additionalDefaults
|
2014-08-28 16:53:00 -04:00
|
|
|
@isDefaultComponent = false
|
2014-01-03 13:32:13 -05:00
|
|
|
@world = options.world
|
|
|
|
@level = options.level
|
|
|
|
@callback = options.callback
|
2014-08-11 01:09:13 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@buildTreema()
|
2014-09-01 16:51:30 -04:00
|
|
|
|
2014-08-27 20:29:28 -04:00
|
|
|
setConfig: (config) ->
|
|
|
|
@handlingChange = true
|
|
|
|
@editThangTreema.set('/', config)
|
|
|
|
@handlingChange = false
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-08-25 23:34:46 -04:00
|
|
|
setIsDefaultComponent: (isDefaultComponent) ->
|
|
|
|
changed = @isDefaultComponent isnt isDefaultComponent
|
2014-08-26 12:48:33 -04:00
|
|
|
if isDefaultComponent then @config = undefined
|
2014-08-25 23:34:46 -04:00
|
|
|
@isDefaultComponent = isDefaultComponent
|
|
|
|
@render() if changed
|
|
|
|
|
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)
|
2014-08-15 15:27:56 -04:00
|
|
|
schema = $.extend true, {}, @component.get('configSchema')
|
2014-08-25 23:34:46 -04:00
|
|
|
schema.default ?= {}
|
|
|
|
_.merge schema.default, @additionalDefaults if @additionalDefaults
|
2014-09-01 16:51:30 -04:00
|
|
|
|
2016-06-19 23:23:32 -04:00
|
|
|
if @level?.get('type', true) in ['hero', 'hero-ladder', 'hero-coop', 'course', 'course-ladder', 'game-dev', 'hero-practice']
|
2014-08-15 15:27:56 -04:00
|
|
|
schema.required = []
|
2014-01-03 13:32:13 -05:00
|
|
|
treemaOptions =
|
|
|
|
supermodel: @supermodel
|
2014-08-15 15:27:56 -04:00
|
|
|
schema: schema
|
2014-08-26 12:48:33 -04:00
|
|
|
data: @config
|
2014-01-03 13:32:13 -05:00
|
|
|
callbacks: {change: @onConfigEdited}
|
|
|
|
world: @world
|
|
|
|
view: @
|
|
|
|
thangIDs: thangIDs
|
|
|
|
teams: teams
|
|
|
|
superteams: superteams
|
|
|
|
nodeClasses:
|
2014-08-13 03:09:21 -04:00
|
|
|
object: ComponentConfigNode
|
2014-01-03 13:32:13 -05:00
|
|
|
'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
|
2014-09-01 16:51:30 -04:00
|
|
|
'thang-type': nodes.ThangTypeNode
|
2014-08-11 01:09:13 -04:00
|
|
|
'item-thang-type': nodes.ItemThangTypeNode
|
2016-01-06 16:48:54 -05:00
|
|
|
'solutions': SolutionsNode
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
@editThangTreema = @$el.find('.treema').treema treemaOptions
|
|
|
|
@editThangTreema.build()
|
|
|
|
@editThangTreema.open(2)
|
2014-08-11 01:09:13 -04:00
|
|
|
if _.isEqual(@editThangTreema.data, {}) and not @editThangTreema.canAddChild()
|
2014-08-07 21:49:39 -04:00
|
|
|
@$el.find('.panel-body').hide()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onConfigEdited: =>
|
2014-08-28 18:42:46 -04:00
|
|
|
return if @destroyed or @handlingChange
|
2014-08-28 16:53:00 -04:00
|
|
|
@config = @data()
|
2014-01-03 13:32:13 -05:00
|
|
|
@changed = true
|
2014-08-28 16:53:00 -04:00
|
|
|
@trigger 'changed', { component: @component, config: @config }
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
data: -> @editThangTreema.data
|
2014-09-01 16:51:30 -04:00
|
|
|
|
2014-08-29 21:02:29 -04:00
|
|
|
destroy: ->
|
|
|
|
@editThangTreema?.destroy()
|
|
|
|
super()
|
2014-08-13 03:09:21 -04:00
|
|
|
|
|
|
|
class ComponentConfigNode extends TreemaObjectNode
|
2014-08-15 15:27:56 -04:00
|
|
|
nodeDescription: 'Component Property'
|
2016-01-06 16:48:54 -05:00
|
|
|
|
|
|
|
class SolutionsNode extends TreemaArrayNode
|
|
|
|
buildValueForDisplay: (valEl, data) ->
|
|
|
|
btn = $('<button class="btn btn-default btn-xs">Fill defaults</button>')
|
|
|
|
btn.on('click', @onClickFillDefaults)
|
|
|
|
valEl.append(btn)
|
|
|
|
|
|
|
|
onClickFillDefaults: (e) =>
|
|
|
|
e.preventDefault()
|
2016-01-22 13:41:12 -05:00
|
|
|
|
2016-01-06 16:48:54 -05:00
|
|
|
sources = { javascript: @parent.data.source }
|
|
|
|
_.extend sources, @parent.data.languages or {}
|
|
|
|
solutions = _.clone(@data)
|
2016-01-22 13:41:12 -05:00
|
|
|
solutions = _.filter(solutions, (solution) -> not _.isEmpty(solution) )
|
2016-01-06 16:48:54 -05:00
|
|
|
for language in _.keys(sources)
|
|
|
|
source = sources[language]
|
|
|
|
solution = _.findWhere(solutions, {language: language})
|
|
|
|
continue if solution
|
|
|
|
solutions.push({
|
|
|
|
source: source
|
|
|
|
language: language
|
2016-04-07 17:49:55 -04:00
|
|
|
succeeds: true
|
2016-01-06 16:48:54 -05:00
|
|
|
})
|
2016-01-22 13:41:12 -05:00
|
|
|
|
2016-06-06 18:35:10 -04:00
|
|
|
@set('/', solutions)
|