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-components-edit-view'
|
2014-08-07 21:49:39 -04:00
|
|
|
|
|
|
|
Level = require 'models/Level'
|
|
|
|
LevelComponent = require 'models/LevelComponent'
|
|
|
|
LevelSystem = require 'models/LevelSystem'
|
|
|
|
ComponentsCollection = require 'collections/ComponentsCollection'
|
|
|
|
ThangComponentConfigView = require './ThangComponentConfigView'
|
2014-08-11 16:24:08 -04:00
|
|
|
AddThangComponentsModal = require './AddThangComponentsModal'
|
2014-08-11 20:09:36 -04:00
|
|
|
nodes = require '../level/treema_nodes'
|
|
|
|
|
|
|
|
ThangType = require 'models/ThangType'
|
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
|
|
|
|
2014-09-02 14:29:24 -04:00
|
|
|
LC = (componentName, config) -> original: LevelComponent[componentName + 'ID'], majorVersion: 0, config: config
|
|
|
|
DEFAULT_COMPONENTS =
|
|
|
|
Unit: [LC('Equips')]
|
2014-10-29 18:54:51 -04:00
|
|
|
Hero: [LC('Equips')]
|
2014-09-02 14:29:24 -04:00
|
|
|
Floor: [
|
|
|
|
LC('Exists', stateless: true)
|
|
|
|
LC('Physical', width: 20, height: 17, depth: 2, shape: 'sheet', pos: {x: 10, y: 8.5, z: 1})
|
|
|
|
LC('Land')
|
|
|
|
]
|
|
|
|
Wall: [
|
|
|
|
LC('Exists', stateless: true)
|
|
|
|
LC('Physical', width: 4, height: 4, depth: 12, shape: 'box', pos: {x: 2, y: 2, z: 6})
|
|
|
|
LC('Collides', collisionType: 'static', collisionCategory: 'obstacles', mass: 1000, fixedRotation: true, restitution: 1)
|
|
|
|
]
|
|
|
|
Doodad: [
|
|
|
|
LC('Exists', stateless: true)
|
|
|
|
LC('Physical')
|
|
|
|
LC('Collides', collisionType: 'static', fixedRotation: true)
|
|
|
|
]
|
|
|
|
Misc: [LC('Exists'), LC('Physical')]
|
|
|
|
Mark: []
|
|
|
|
Item: [LC('Item')]
|
|
|
|
|
2014-08-14 18:09:10 -04:00
|
|
|
class ItemThangTypeSearchCollection extends CocoCollection
|
|
|
|
url: '/db/thang.type?view=items&project=original,name,version,slug,kind,components'
|
2014-08-11 20:09:36 -04:00
|
|
|
model: ThangType
|
2014-08-07 21:49:39 -04:00
|
|
|
|
|
|
|
module.exports = class ThangComponentsEditView extends CocoView
|
|
|
|
id: 'thang-components-edit-view'
|
|
|
|
template: template
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-09-02 14:29:24 -04:00
|
|
|
subscriptions:
|
|
|
|
'editor:thang-type-kind-changed': 'onThangTypeKindChanged'
|
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
events:
|
|
|
|
'click #add-components-button': 'onAddComponentsButtonClicked'
|
2014-08-07 21:49:39 -04:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
2014-08-22 14:40:31 -04:00
|
|
|
@originalsLoaded = {}
|
2014-08-07 21:49:39 -04:00
|
|
|
@components = options.components or []
|
|
|
|
@components = $.extend true, [], @components # just to be sure
|
2014-08-25 23:34:46 -04:00
|
|
|
@setThangType options.thangType
|
2014-08-07 21:49:39 -04:00
|
|
|
@lastComponentLength = @components.length
|
|
|
|
@world = options.world
|
|
|
|
@level = options.level
|
|
|
|
@loadComponents(@components)
|
2014-09-02 14:29:24 -04:00
|
|
|
|
2014-08-25 23:34:46 -04:00
|
|
|
setThangType: (@thangType) ->
|
|
|
|
return unless componentRefs = @thangType?.get('components')
|
|
|
|
@loadComponents(componentRefs)
|
2014-09-02 14:29:24 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
loadComponents: (components) ->
|
|
|
|
for componentRef in components
|
2014-08-22 14:40:31 -04:00
|
|
|
# just to handle if ever somehow the same component is loaded twice, through bad data and alike
|
|
|
|
continue if @originalsLoaded[componentRef.original]
|
|
|
|
@originalsLoaded[componentRef.original] = componentRef.original
|
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
levelComponent = new LevelComponent(componentRef)
|
2014-08-07 21:49:39 -04:00
|
|
|
url = "/db/level.component/#{componentRef.original}/version/#{componentRef.majorVersion}"
|
|
|
|
levelComponent.setURL(url)
|
|
|
|
resource = @supermodel.loadModel levelComponent, 'component'
|
2014-08-11 16:24:08 -04:00
|
|
|
continue unless resource.isLoading
|
2014-08-07 21:49:39 -04:00
|
|
|
@listenToOnce resource, 'loaded', ->
|
|
|
|
return if @handlingChange
|
2014-08-11 16:24:08 -04:00
|
|
|
@handlingChange = true
|
|
|
|
@onComponentsAdded()
|
|
|
|
@handlingChange = false
|
2014-08-07 21:49:39 -04:00
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
return unless @supermodel.finished()
|
2014-08-11 16:24:08 -04:00
|
|
|
@buildComponentsTreema()
|
2014-08-07 21:49:39 -04:00
|
|
|
@addThangComponentConfigViews()
|
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
buildComponentsTreema: ->
|
2014-08-25 23:34:46 -04:00
|
|
|
components = _.zipObject((c.original for c in @components), @components)
|
|
|
|
defaultValue = undefined
|
|
|
|
if thangTypeComponents = @thangType?.get('components', true)
|
|
|
|
defaultValue = _.zipObject((c.original for c in thangTypeComponents), thangTypeComponents)
|
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
treemaOptions =
|
|
|
|
supermodel: @supermodel
|
2014-08-25 23:34:46 -04:00
|
|
|
schema: {
|
|
|
|
type: 'object'
|
|
|
|
default: defaultValue
|
|
|
|
additionalProperties: Level.schema.properties.thangs.items.properties.components.items
|
2014-09-02 14:29:24 -04:00
|
|
|
},
|
2014-08-25 23:34:46 -04:00
|
|
|
data: $.extend true, {}, components
|
2014-08-07 21:49:39 -04:00
|
|
|
callbacks: {select: @onSelectComponent, change: @onComponentsTreemaChanged}
|
2014-08-26 16:27:17 -04:00
|
|
|
nodeClasses:
|
|
|
|
'object': ThangComponentsObjectNode
|
2014-08-07 21:49:39 -04:00
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
@componentsTreema = @$el.find('#thang-components-column .treema').treema treemaOptions
|
|
|
|
@componentsTreema.build()
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
onComponentsTreemaChanged: =>
|
|
|
|
return if @handlingChange
|
|
|
|
@handlingChange = true
|
|
|
|
componentMap = {}
|
|
|
|
for component in @components
|
|
|
|
componentMap[component.original] = component
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
newComponentsList = []
|
2014-08-25 23:34:46 -04:00
|
|
|
for component in _.values(@componentsTreema.data)
|
2014-08-07 21:49:39 -04:00
|
|
|
newComponentsList.push(componentMap[component.original] or component)
|
|
|
|
@components = newComponentsList
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
# update the components list here
|
|
|
|
@onComponentsChanged()
|
|
|
|
@handlingChange = false
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
onComponentsChanged: =>
|
|
|
|
# happens whenever the list of components changed, one way or another
|
|
|
|
# * if the treema gets changed
|
|
|
|
# * if components are added externally, like by a modal
|
|
|
|
# * if a dependency loads and is added to the list
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
if @components.length < @lastComponentLength
|
|
|
|
@onComponentsRemoved()
|
2014-08-27 20:29:28 -04:00
|
|
|
@onComponentsAdded()
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
onComponentsRemoved: ->
|
|
|
|
componentMap = {}
|
|
|
|
for component in @components
|
|
|
|
componentMap[component.original] = component
|
|
|
|
|
2014-08-26 12:48:33 -04:00
|
|
|
thangComponentMap = {}
|
|
|
|
if thangTypeComponents = @thangType?.get('components')
|
|
|
|
for thangTypeComponent in thangTypeComponents
|
|
|
|
thangComponentMap[thangTypeComponent.original] = thangTypeComponent
|
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
# Deleting components missing dependencies.
|
|
|
|
while true
|
|
|
|
removedSomething = false
|
|
|
|
for componentRef in _.values(componentMap)
|
|
|
|
componentModel = @supermodel.getModelByOriginalAndMajorVersion(
|
|
|
|
LevelComponent, componentRef.original, componentRef.majorVersion)
|
|
|
|
for dependency in componentModel.get('dependencies') or []
|
2014-08-26 12:48:33 -04:00
|
|
|
unless (componentMap[dependency.original] or thangComponentMap[dependency.original])
|
2014-08-07 21:49:39 -04:00
|
|
|
delete componentMap[componentRef.original]
|
|
|
|
component = @supermodel.getModelByOriginal(
|
|
|
|
LevelComponent, componentRef.original)
|
|
|
|
noty {
|
|
|
|
text: "Removed dependent component: #{component.get('name')}"
|
|
|
|
layout: 'topCenter'
|
|
|
|
timeout: 5000
|
|
|
|
type: 'information'
|
|
|
|
}
|
|
|
|
removedSomething = true
|
|
|
|
break if removedSomething
|
|
|
|
break unless removedSomething
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
@components = _.values(componentMap)
|
|
|
|
|
|
|
|
# Delete individual component config views that are no longer included.
|
|
|
|
for subview in _.values(@subviews)
|
|
|
|
continue unless subview instanceof ThangComponentConfigView
|
2014-08-26 12:48:33 -04:00
|
|
|
unless (componentMap[subview.component.get('original')] or thangComponentMap[subview.component.get('original')])
|
2014-08-07 21:49:39 -04:00
|
|
|
@removeSubView(subview)
|
|
|
|
|
|
|
|
@updateComponentsList()
|
|
|
|
@reportChanges()
|
|
|
|
|
|
|
|
updateComponentsList: ->
|
2014-08-22 14:40:31 -04:00
|
|
|
# Before I was setting the data to the existing treema but then we had some
|
|
|
|
# nasty sorting/callback bugs. This is less efficient, but it's also less bug prone.
|
|
|
|
@buildComponentsTreema()
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
onComponentsAdded: ->
|
2014-08-11 16:24:08 -04:00
|
|
|
return unless @componentsTreema
|
2014-08-07 21:49:39 -04:00
|
|
|
componentMap = {}
|
|
|
|
for component in @components
|
|
|
|
componentMap[component.original] = component
|
|
|
|
|
2014-08-26 12:48:33 -04:00
|
|
|
if thangTypeComponents = @thangType?.get('components')
|
|
|
|
for thangTypeComponent in thangTypeComponents
|
|
|
|
componentMap[thangTypeComponent.original] = thangTypeComponent
|
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
# Go through the map, adding missing dependencies.
|
|
|
|
while true
|
|
|
|
addedSomething = false
|
|
|
|
for componentRef in _.values(componentMap)
|
|
|
|
componentModel = @supermodel.getModelByOriginalAndMajorVersion(
|
|
|
|
LevelComponent, componentRef.original, componentRef.majorVersion)
|
2014-08-22 14:40:31 -04:00
|
|
|
if not componentModel?.loaded
|
|
|
|
@loadComponents([componentRef])
|
|
|
|
continue
|
2014-08-11 20:09:36 -04:00
|
|
|
for dependency in componentModel?.get('dependencies') or []
|
2014-08-07 21:49:39 -04:00
|
|
|
if not componentMap[dependency.original]
|
|
|
|
component = @supermodel.getModelByOriginalAndMajorVersion(
|
|
|
|
LevelComponent, dependency.original, dependency.majorVersion)
|
2014-08-22 14:40:31 -04:00
|
|
|
if not component?.loaded
|
2014-08-07 21:49:39 -04:00
|
|
|
@loadComponents([dependency])
|
|
|
|
# will run onComponentsAdded once more when the model loads
|
|
|
|
else
|
|
|
|
addedSomething = true
|
|
|
|
noty {
|
|
|
|
text: "Added dependency: #{component.get('name')}"
|
|
|
|
layout: 'topCenter'
|
|
|
|
timeout: 5000
|
|
|
|
type: 'information'
|
|
|
|
}
|
|
|
|
componentMap[dependency.original] = dependency
|
|
|
|
@components.push dependency
|
|
|
|
break unless addedSomething
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
|
|
|
|
# Sort the component list, reorder the component config views
|
|
|
|
@updateComponentsList()
|
|
|
|
@addThangComponentConfigViews()
|
2014-08-11 16:24:08 -04:00
|
|
|
@checkForMissingSystems()
|
2014-08-07 21:49:39 -04:00
|
|
|
@reportChanges()
|
|
|
|
|
|
|
|
addThangComponentConfigViews: ->
|
|
|
|
# Detach all component config views temporarily.
|
|
|
|
componentConfigViews = {}
|
|
|
|
for subview in _.values(@subviews)
|
|
|
|
continue unless subview instanceof ThangComponentConfigView
|
|
|
|
componentConfigViews[subview.component.get('original')] = subview
|
|
|
|
subview.$el.detach()
|
|
|
|
|
|
|
|
# Put back config views into the DOM based on the component list ordering,
|
|
|
|
# adding and registering new ones as needed.
|
|
|
|
configsEl = @$el.find('#thang-component-configs')
|
2014-08-25 23:34:46 -04:00
|
|
|
|
|
|
|
componentRefs = _.merge {}, @componentsTreema.data
|
|
|
|
if thangTypeComponents = @thangType?.get('components')
|
|
|
|
thangComponentRefs = _.zipObject((c.original for c in thangTypeComponents), thangTypeComponents)
|
|
|
|
for thangTypeComponent in thangTypeComponents
|
|
|
|
if componentRef = componentRefs[thangTypeComponent.original]
|
|
|
|
componentRef.additionalDefaults = thangTypeComponent.config
|
|
|
|
else
|
|
|
|
modifiedRef = _.merge {}, thangTypeComponent
|
|
|
|
modifiedRef.additionalDefaults = modifiedRef.config
|
2014-08-26 12:48:33 -04:00
|
|
|
delete modifiedRef.config
|
2014-08-25 23:34:46 -04:00
|
|
|
componentRefs[thangTypeComponent.original] = modifiedRef
|
|
|
|
|
|
|
|
for componentRef in _.values(componentRefs)
|
2014-08-07 21:49:39 -04:00
|
|
|
subview = componentConfigViews[componentRef.original]
|
|
|
|
if not subview
|
|
|
|
subview = @makeThangComponentConfigView(componentRef)
|
|
|
|
continue unless subview
|
|
|
|
@registerSubView(subview)
|
2014-08-25 23:34:46 -04:00
|
|
|
subview.setIsDefaultComponent(not @componentsTreema.data[componentRef.original])
|
2014-08-07 21:49:39 -04:00
|
|
|
configsEl.append(subview.$el)
|
|
|
|
|
|
|
|
makeThangComponentConfigView: (thangComponent) ->
|
|
|
|
component = @supermodel.getModelByOriginal(LevelComponent, thangComponent.original)
|
2014-08-22 14:40:31 -04:00
|
|
|
return unless component?.loaded
|
2014-08-07 21:49:39 -04:00
|
|
|
config = thangComponent.config ? {}
|
|
|
|
configView = new ThangComponentConfigView({
|
|
|
|
supermodel: @supermodel
|
|
|
|
level: @level
|
|
|
|
world: @world
|
|
|
|
config: config
|
|
|
|
component: component
|
2014-08-25 23:34:46 -04:00
|
|
|
additionalDefaults: thangComponent.additionalDefaults
|
2014-08-07 21:49:39 -04:00
|
|
|
})
|
|
|
|
configView.render()
|
|
|
|
@listenTo configView, 'changed', @onConfigChanged
|
|
|
|
configView
|
|
|
|
|
|
|
|
onConfigChanged: (e) ->
|
2014-08-25 23:34:46 -04:00
|
|
|
foundComponent = false
|
2014-08-07 21:49:39 -04:00
|
|
|
for thangComponent in @components
|
|
|
|
if thangComponent.original is e.component.get('original')
|
|
|
|
thangComponent.config = e.config
|
2014-08-25 23:34:46 -04:00
|
|
|
foundComponent = true
|
|
|
|
break
|
2014-09-02 14:29:24 -04:00
|
|
|
|
2014-08-25 23:34:46 -04:00
|
|
|
if not foundComponent
|
|
|
|
@components.push({
|
|
|
|
original: e.component.get('original')
|
|
|
|
majorVersion: e.component.get('version').major
|
|
|
|
config: e.config
|
|
|
|
})
|
2014-08-26 12:48:33 -04:00
|
|
|
|
|
|
|
for subview in _.values(@subviews)
|
|
|
|
continue unless subview instanceof ThangComponentConfigView
|
|
|
|
if subview.component.get('original') is e.component.get('original')
|
|
|
|
_.defer -> subview.setIsDefaultComponent(false)
|
|
|
|
break
|
2014-09-02 14:29:24 -04:00
|
|
|
|
2014-08-25 23:34:46 -04:00
|
|
|
@updateComponentsList()
|
2014-08-07 21:49:39 -04:00
|
|
|
@reportChanges()
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
onSelectComponent: (e, nodes) =>
|
2014-08-11 16:24:08 -04:00
|
|
|
@componentsTreema.$el.find('.dependent').removeClass('dependent')
|
2014-08-30 12:47:23 -04:00
|
|
|
@$el.find('.selected-component').removeClass('selected-component')
|
2014-08-07 21:49:39 -04:00
|
|
|
return unless nodes.length is 1
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
# find dependent components
|
|
|
|
dependents = {}
|
2014-08-25 23:34:46 -04:00
|
|
|
dependents[nodes[0].getData().original] = true
|
|
|
|
componentsToCheck = [nodes[0].getData().original]
|
2014-08-07 21:49:39 -04:00
|
|
|
while componentsToCheck.length
|
|
|
|
componentOriginal = componentsToCheck.pop()
|
|
|
|
for otherComponentRef in @components
|
|
|
|
continue if otherComponentRef.original is componentOriginal
|
|
|
|
continue if dependents[otherComponentRef.original]
|
|
|
|
otherComponent = @supermodel.getModelByOriginal(LevelComponent, otherComponentRef.original)
|
2014-08-25 23:34:46 -04:00
|
|
|
for dependency in otherComponent.get('dependencies', true)
|
2014-08-07 21:49:39 -04:00
|
|
|
if dependents[dependency.original]
|
|
|
|
dependents[otherComponentRef.original] = true
|
|
|
|
componentsToCheck.push otherComponentRef.original
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
# highlight them
|
2014-08-11 16:24:08 -04:00
|
|
|
for child in _.values(@componentsTreema.childrenTreemas)
|
2014-08-25 23:34:46 -04:00
|
|
|
if dependents[child.getData().original]
|
2014-08-07 21:49:39 -04:00
|
|
|
child.$el.addClass('dependent')
|
|
|
|
|
|
|
|
# scroll to the config
|
|
|
|
for subview in _.values(@subviews)
|
|
|
|
continue unless subview instanceof ThangComponentConfigView
|
2014-08-25 23:34:46 -04:00
|
|
|
if subview.component.get('original') is nodes[0].getData().original
|
2014-08-07 21:49:39 -04:00
|
|
|
subview.$el[0].scrollIntoView()
|
2014-08-30 12:47:23 -04:00
|
|
|
subview.$el.addClass('selected-component')
|
2014-08-07 21:49:39 -04:00
|
|
|
break
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
onChangeExtantComponents: =>
|
|
|
|
@buildAddComponentTreema()
|
|
|
|
@reportChanges()
|
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
checkForMissingSystems: ->
|
|
|
|
return unless @level
|
|
|
|
extantSystems =
|
|
|
|
(@supermodel.getModelByOriginalAndMajorVersion LevelSystem, sn.original, sn.majorVersion).attributes.name.toLowerCase() for idx, sn of @level.get('systems')
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
componentModels = (@supermodel.getModelByOriginal(LevelComponent, c.original) for c in @components)
|
|
|
|
componentSystems = (c.get('system') for c in componentModels when c)
|
2014-08-11 20:09:36 -04:00
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
for system in componentSystems
|
|
|
|
if system not in extantSystems
|
|
|
|
s = "Component requires system <strong>#{system}</strong> which is currently not included in this level."
|
2014-08-07 21:49:39 -04:00
|
|
|
noty({
|
2014-08-11 16:24:08 -04:00
|
|
|
text: s,
|
2014-08-07 21:49:39 -04:00
|
|
|
layout: 'bottomLeft',
|
|
|
|
type: 'warning'
|
|
|
|
})
|
|
|
|
|
|
|
|
reportChanges: ->
|
2014-08-11 16:24:08 -04:00
|
|
|
@lastComponentLength = @components.length
|
|
|
|
@trigger 'components-changed', $.extend(true, [], @components)
|
2014-08-07 21:49:39 -04:00
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
undo: -> @componentsTreema.undo()
|
2014-08-07 21:49:39 -04:00
|
|
|
|
2014-08-11 16:24:08 -04:00
|
|
|
redo: -> @componentsTreema.redo()
|
|
|
|
|
|
|
|
onAddComponentsButtonClicked: ->
|
|
|
|
modal = new AddThangComponentsModal({skipOriginals: (c.original for c in @components)})
|
|
|
|
@openModalView modal
|
|
|
|
@listenToOnce modal, 'hidden', ->
|
|
|
|
componentsToAdd = modal.getSelectedComponents()
|
|
|
|
sparseComponents = ({original: c.get('original'), majorVersion: c.get('version').major} for c in componentsToAdd)
|
|
|
|
@loadComponents(sparseComponents)
|
|
|
|
@components = @components.concat(sparseComponents)
|
|
|
|
@onComponentsChanged()
|
2014-09-02 14:29:24 -04:00
|
|
|
|
|
|
|
onThangTypeKindChanged: (e) ->
|
|
|
|
return unless defaultComponents = DEFAULT_COMPONENTS[e.kind]
|
|
|
|
for component in defaultComponents when not _.find(@components, original: component.original)
|
|
|
|
@components.push component
|
|
|
|
@onComponentsAdded()
|
|
|
|
|
2014-08-29 21:02:29 -04:00
|
|
|
destroy: ->
|
|
|
|
@componentsTreema?.destroy()
|
|
|
|
super()
|
2014-08-07 21:49:39 -04:00
|
|
|
|
2014-08-26 16:27:17 -04:00
|
|
|
class ThangComponentsObjectNode extends TreemaObjectNode
|
2014-08-26 16:48:57 -04:00
|
|
|
addNewChild: -> @addNewChildForKey('') # HACK to get the object adding to act more like adding to an array
|
2014-09-02 14:29:24 -04:00
|
|
|
|
2014-08-26 16:27:17 -04:00
|
|
|
getChildren: ->
|
|
|
|
children = super(arguments...)
|
|
|
|
children.sort(@sortFunction)
|
2014-09-02 14:29:24 -04:00
|
|
|
|
2014-08-07 21:49:39 -04:00
|
|
|
sortFunction: (a, b) =>
|
2014-08-26 16:27:17 -04:00
|
|
|
a = a.value ? a.defaultData
|
|
|
|
b = b.value ? b.defaultData
|
2014-08-07 21:49:39 -04:00
|
|
|
a = @settings.supermodel.getModelByOriginalAndMajorVersion(LevelComponent, a.original, a.majorVersion)
|
|
|
|
b = @settings.supermodel.getModelByOriginalAndMajorVersion(LevelComponent, b.original, b.majorVersion)
|
|
|
|
return 0 if not (a or b)
|
|
|
|
return 1 if not b
|
|
|
|
return -1 if not a
|
2014-08-26 17:15:21 -04:00
|
|
|
return 1 if a.get('system') > b.get('system')
|
|
|
|
return -1 if a.get('system') < b.get('system')
|
|
|
|
return 1 if a.get('name') > b.get('name')
|
|
|
|
return -1 if a.get('name') < b.get('name')
|
2014-08-11 20:09:36 -04:00
|
|
|
return 0
|