2014-01-03 13:32:13 -05:00
View = require ' views/kinds/CocoView '
template = require ' templates/editor/level/settings_tab '
Level = require ' models/Level '
Surface = require ' lib/surface/Surface '
2014-02-12 15:27:02 -05:00
nodes = require ' ./treema_nodes '
2014-01-03 13:32:13 -05:00
module.exports = class SettingsTabView extends View
id: ' editor-level-settings-tab-view '
className: ' tab-pane '
template: template
2014-02-12 15:27:02 -05:00
editableSettings: [ ' name ' , ' description ' , ' documentation ' , ' nextLevel ' , ' background ' , ' victory ' , ' i18n ' , ' icon ' , ' goals ' ] # not thangs or scripts or the backend stuff
2014-01-03 13:32:13 -05:00
subscriptions:
' level-loaded ' : ' onLevelLoaded '
constructor: (options) ->
super options
@world = options . world
onLevelLoaded: (e) ->
@level = e . level
data = _ . pick @ level . attributes , (value, key) => key in @ editableSettings
schema = _ . cloneDeep Level . schema . attributes
schema.properties = _ . pick schema . properties , (value, key) => key in @ editableSettings
schema.required = _ . intersection schema . required , @ editableSettings
2014-02-12 15:27:02 -05:00
thangIDs = @ getThangIDs ( )
2014-01-03 13:32:13 -05:00
treemaOptions =
filePath: " db/level/ #{ @ level . get ( ' original ' ) } "
supermodel: @ supermodel
schema: schema
data: data
2014-03-03 16:21:56 -05:00
readOnly: true unless me . isAdmin ( ) or @ level . hasWriteAccess ( me )
2014-01-03 13:32:13 -05:00
callbacks: { change: @ onSettingsChanged }
2014-02-12 15:27:02 -05:00
thangIDs: thangIDs
nodeClasses:
thang: nodes . ThangNode
2014-01-03 13:32:13 -05:00
@settingsTreema = @ $el . find ( ' # settings-treema ' ) . treema treemaOptions
@ settingsTreema . build ( )
@ settingsTreema . open ( )
2014-02-12 15:27:02 -05:00
getThangIDs: ->
( t . id for t in @ level . get ( ' thangs ' ) when t . id isnt ' Interface ' )
2014-01-03 13:32:13 -05:00
onSettingsChanged: (e) =>
$ ( ' .level-title ' ) . text @ settingsTreema . data . name
for key in @ editableSettings
@ level . set key , @ settingsTreema . data [ key ]