2014-07-17 20:20:11 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/editor/level/settings_tab'
|
|
|
|
Level = require 'models/Level'
|
|
|
|
Surface = require 'lib/surface/Surface'
|
2014-07-23 10:02:45 -04:00
|
|
|
nodes = require './../treema_nodes'
|
2014-05-06 19:58:08 -04:00
|
|
|
{me} = require 'lib/auth'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-17 20:20:11 -04:00
|
|
|
module.exports = class SettingsTabView extends CocoView
|
2014-01-03 13:32:13 -05:00
|
|
|
id: 'editor-level-settings-tab-view'
|
|
|
|
className: 'tab-pane'
|
|
|
|
template: template
|
2014-03-23 13:00:16 -04:00
|
|
|
|
2014-03-07 16:13:58 -05:00
|
|
|
# not thangs or scripts or the backend stuff
|
|
|
|
editableSettings: [
|
|
|
|
'name', 'description', 'documentation', 'nextLevel', 'background', 'victory', 'i18n', 'icon', 'goals',
|
2014-09-02 17:16:36 -04:00
|
|
|
'type', 'terrain', 'showsGuide', 'banner', 'employerDescription'
|
2014-03-07 16:13:58 -05:00
|
|
|
]
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
subscriptions:
|
2014-08-27 15:24:03 -04:00
|
|
|
'editor:level-loaded': 'onLevelLoaded'
|
2014-08-27 21:43:17 -04:00
|
|
|
'editor:thangs-edited': 'onThangsEdited'
|
2014-09-02 17:16:36 -04:00
|
|
|
'editor:random-terrain-generated': 'onRandomTerrainGenerated'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
|
2014-04-16 02:28:59 -04:00
|
|
|
onLoaded: ->
|
2014-01-03 13:32:13 -05:00
|
|
|
onLevelLoaded: (e) ->
|
|
|
|
@level = e.level
|
|
|
|
data = _.pick @level.attributes, (value, key) => key in @editableSettings
|
2014-04-12 04:35:56 -04:00
|
|
|
schema = _.cloneDeep Level.schema
|
2014-01-03 13:32:13 -05:00
|
|
|
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
|
|
|
|
schema.required = _.intersection schema.required, @editableSettings
|
2014-08-26 13:14:36 -04:00
|
|
|
schema.default = _.pick schema.default, (value, key) => key in @editableSettings
|
2014-08-27 21:43:17 -04: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-04-24 20:25:16 -04:00
|
|
|
readOnly: me.get('anonymous')
|
2014-01-03 13:32:13 -05:00
|
|
|
callbacks: {change: @onSettingsChanged}
|
2014-08-27 21:43:17 -04:00
|
|
|
thangIDs: @thangIDs
|
2014-02-12 15:27:02 -05:00
|
|
|
nodeClasses:
|
2014-08-12 17:25:05 -04:00
|
|
|
object: SettingsNode
|
2014-02-12 15:27:02 -05:00
|
|
|
thang: nodes.ThangNode
|
2014-03-23 13:00:16 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
@settingsTreema = @$el.find('#settings-treema').treema treemaOptions
|
|
|
|
@settingsTreema.build()
|
|
|
|
@settingsTreema.open()
|
2014-09-02 17:16:36 -04:00
|
|
|
@lastTerrain = data.terrain
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-12 15:27:02 -05:00
|
|
|
getThangIDs: ->
|
2014-08-28 12:59:07 -04:00
|
|
|
(t.id for t in @level.get('thangs') ? [])
|
2014-02-12 15:27:02 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
onSettingsChanged: (e) =>
|
|
|
|
$('.level-title').text @settingsTreema.data.name
|
|
|
|
for key in @editableSettings
|
2014-06-03 15:27:53 -04:00
|
|
|
continue if @settingsTreema.data[key] is undefined
|
2014-01-03 13:32:13 -05:00
|
|
|
@level.set key, @settingsTreema.data[key]
|
2014-09-02 17:16:36 -04:00
|
|
|
if (terrain = @settingsTreema.data.terrain) isnt @lastTerrain
|
|
|
|
@lastTerrain = terrain
|
|
|
|
Backbone.Mediator.publish 'editor:terrain-changed', terrain: terrain
|
2014-09-02 20:28:40 -04:00
|
|
|
for goal, index in @settingsTreema.data.goals ? []
|
|
|
|
continue if goal.id
|
|
|
|
goalIndex = index
|
|
|
|
goalID = "goal-#{goalIndex}"
|
|
|
|
goalID = "goal-#{++goalIndex}" while _.find @settingsTreema.get("goals"), id: goalID
|
|
|
|
@settingsTreema.disableTracking()
|
|
|
|
@settingsTreema.set "/goals/#{index}/id", goalID
|
|
|
|
@settingsTreema.set "/goals/#{index}/name", _.string.humanize goalID
|
|
|
|
@settingsTreema.enableTracking()
|
2014-07-24 15:36:41 -04:00
|
|
|
|
2014-08-27 21:43:17 -04:00
|
|
|
onThangsEdited: (e) ->
|
|
|
|
# Update in-place so existing Treema nodes refer to the same array.
|
2014-08-29 01:32:55 -04:00
|
|
|
@thangIDs?.splice(0, @thangIDs.length, @getThangIDs()...)
|
2014-09-02 17:16:36 -04:00
|
|
|
|
|
|
|
onRandomTerrainGenerated: (e) ->
|
|
|
|
@settingsTreema.set '/terrain', e.terrain
|
|
|
|
|
2014-08-29 21:02:29 -04:00
|
|
|
destroy: ->
|
|
|
|
@settingsTreema?.destroy()
|
|
|
|
super()
|
2014-08-27 21:43:17 -04:00
|
|
|
|
|
|
|
|
2014-08-12 17:25:05 -04:00
|
|
|
class SettingsNode extends TreemaObjectNode
|
2014-08-27 15:24:03 -04:00
|
|
|
nodeDescription: 'Settings'
|