2014-11-28 20:49:41 -05:00
|
|
|
CocoView = require 'views/core/CocoView'
|
2014-09-02 19:50:09 -04:00
|
|
|
template = require 'templates/editor/level/systems-tab-view'
|
2014-01-03 13:32:13 -05:00
|
|
|
Level = require 'models/Level'
|
|
|
|
LevelSystem = require 'models/LevelSystem'
|
2014-07-23 10:02:45 -04:00
|
|
|
LevelSystemEditView = require './LevelSystemEditView'
|
|
|
|
NewLevelSystemModal = require './NewLevelSystemModal'
|
|
|
|
AddLevelSystemModal = require './AddLevelSystemModal'
|
2014-09-18 18:26:06 -04:00
|
|
|
nodes = require '../treema_nodes'
|
2014-11-29 20:51:32 -05:00
|
|
|
require 'vendor/treema'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-17 20:20:11 -04:00
|
|
|
module.exports = class SystemsTabView extends CocoView
|
2014-09-02 19:50:09 -04:00
|
|
|
id: 'systems-tab-view'
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
|
|
|
className: 'tab-pane'
|
|
|
|
|
|
|
|
subscriptions:
|
2014-08-27 15:24:03 -04:00
|
|
|
'editor:level-system-added': 'onLevelSystemAdded'
|
|
|
|
'editor:edit-level-system': 'editLevelSystem'
|
|
|
|
'editor:level-system-editing-ended': 'onLevelSystemEditingEnded'
|
|
|
|
'editor:level-loaded': 'onLevelLoaded'
|
2014-09-02 17:16:36 -04:00
|
|
|
'editor:terrain-changed': 'onTerrainChanged'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
|
|
|
'click #add-system-button': 'addLevelSystem'
|
|
|
|
'click #create-new-system-button': 'createNewLevelSystem'
|
2014-04-17 14:02:00 -04:00
|
|
|
'click #create-new-system': 'createNewLevelSystem'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
for system in @buildDefaultSystems()
|
|
|
|
url = "/db/level.system/#{system.original}/version/#{system.majorVersion}"
|
2014-04-26 15:54:03 -04:00
|
|
|
ls = new LevelSystem().setURL(url)
|
|
|
|
@supermodel.loadModel(ls, 'system')
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-04-26 15:54:03 -04:00
|
|
|
afterRender: ->
|
|
|
|
@buildSystemsTreema()
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-04-16 02:28:59 -04:00
|
|
|
onLoaded: ->
|
2014-04-26 15:54:03 -04:00
|
|
|
super()
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
onLevelLoaded: (e) ->
|
|
|
|
@level = e.level
|
|
|
|
@buildSystemsTreema()
|
|
|
|
|
|
|
|
buildSystemsTreema: ->
|
2014-04-26 15:54:03 -04:00
|
|
|
return unless @level and @supermodel.finished()
|
2014-03-18 16:47:51 -04:00
|
|
|
systems = $.extend(true, [], @level.get('systems') ? [])
|
2014-01-03 13:32:13 -05:00
|
|
|
unless systems.length
|
|
|
|
systems = @buildDefaultSystems()
|
|
|
|
insertedDefaults = true
|
2014-04-19 19:30:17 -04:00
|
|
|
systems = @getSortedByName systems
|
2014-09-18 18:26:06 -04:00
|
|
|
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-01-03 13:32:13 -05:00
|
|
|
treemaOptions =
|
|
|
|
supermodel: @supermodel
|
2014-04-12 04:35:56 -04:00
|
|
|
schema: Level.schema.properties.systems
|
2014-01-03 13:32:13 -05:00
|
|
|
data: systems
|
2014-04-24 20:25:16 -04:00
|
|
|
readOnly: me.get('anonymous')
|
2014-09-18 18:26:06 -04:00
|
|
|
world: @options.world
|
|
|
|
view: @
|
|
|
|
thangIDs: thangIDs
|
|
|
|
teams: teams
|
|
|
|
superteams: superteams
|
2014-01-03 13:32:13 -05:00
|
|
|
callbacks:
|
|
|
|
change: @onSystemsChanged
|
|
|
|
select: @onSystemSelected
|
|
|
|
nodeClasses:
|
|
|
|
'level-system': LevelSystemNode
|
|
|
|
'level-system-configuration': LevelSystemConfigurationNode
|
2014-09-18 18:26:06 -04: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
|
|
|
|
'thang-type': nodes.ThangTypeNode
|
|
|
|
'item-thang-type': nodes.ItemThangTypeNode
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
@systemsTreema = @$el.find('#systems-treema').treema treemaOptions
|
|
|
|
@systemsTreema.build()
|
|
|
|
@systemsTreema.open()
|
|
|
|
@onSystemsChanged() if insertedDefaults
|
|
|
|
|
|
|
|
onSystemsChanged: (e) =>
|
2014-04-19 19:30:17 -04:00
|
|
|
systems = @getSortedByName @systemsTreema.data
|
|
|
|
@level.set 'systems', systems
|
|
|
|
|
|
|
|
getSortedByName: (systems) =>
|
|
|
|
systemModels = @supermodel.getModels LevelSystem
|
|
|
|
systemModelMap = {}
|
|
|
|
systemModelMap[sys.get('original')] = sys.get('name') for sys in systemModels
|
|
|
|
_.sortBy systems, (sys) -> systemModelMap[sys.original]
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onSystemSelected: (e, selected) =>
|
|
|
|
selected = if selected.length > 1 then selected[0].getLastSelectedTreema() else selected[0]
|
|
|
|
unless selected
|
|
|
|
@removeSubView @levelSystemEditView if @levelSystemEditView
|
|
|
|
@levelSystemEditView = null
|
|
|
|
return
|
2014-08-29 15:29:42 -04:00
|
|
|
until (data = selected.getData()) and data.original
|
2014-01-03 13:32:13 -05:00
|
|
|
selected = selected.parent
|
2014-08-29 15:29:42 -04:00
|
|
|
@editLevelSystem original: data.original, majorVersion: data.majorVersion
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onLevelSystemAdded: (e) ->
|
|
|
|
@systemsTreema.insert '/', e.system
|
|
|
|
|
|
|
|
addLevelSystem: (e) ->
|
2014-07-23 10:02:45 -04:00
|
|
|
@openModalView new AddLevelSystemModal supermodel: @supermodel, extantSystems: _.cloneDeep @systemsTreema.data
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'editor:view-switched', {}
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
createNewLevelSystem: (e) ->
|
2014-07-23 10:02:45 -04:00
|
|
|
@openModalView new NewLevelSystemModal supermodel: @supermodel
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'editor:view-switched', {}
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
editLevelSystem: (e) ->
|
|
|
|
@levelSystemEditView = @insertSubView new LevelSystemEditView(original: e.original, majorVersion: e.majorVersion, supermodel: @supermodel)
|
|
|
|
|
|
|
|
onLevelSystemEditingEnded: (e) ->
|
|
|
|
@removeSubView @levelSystemEditView
|
|
|
|
@levelSystemEditView = null
|
|
|
|
|
2014-09-02 17:16:36 -04:00
|
|
|
onTerrainChanged: (e) ->
|
2015-01-16 15:50:10 -05:00
|
|
|
defaultPathfinding = e.terrain in ['Dungeon', 'Indoor', 'Mountain']
|
2014-11-26 13:51:30 -05:00
|
|
|
changed = false
|
|
|
|
if AI = @systemsTreema.get 'original=528110f30268d018e3000001'
|
|
|
|
unless AI.config?.findsPaths is defaultPathfinding
|
|
|
|
AI.config ?= {}
|
|
|
|
AI.config.findsPaths = defaultPathfinding
|
|
|
|
@systemsTreema.set 'original=528110f30268d018e3000001', AI
|
|
|
|
changed = true
|
|
|
|
if Vision = @systemsTreema.get 'original=528115040268d018e300001b'
|
|
|
|
unless Vision.config?.checksLineOfSight is defaultPathfinding
|
|
|
|
Vision.config ?= {}
|
|
|
|
Vision.config.checksLineOfSight = defaultPathfinding
|
|
|
|
@systemsTreema.set 'original=528115040268d018e300001b', Vision
|
|
|
|
changed = true
|
|
|
|
if changed
|
|
|
|
noty {
|
|
|
|
text: "AI/Vision System defaulted pathfinding/line-of-sight to #{defaultPathfinding} for terrain #{e.terrain}."
|
|
|
|
layout: 'topCenter'
|
|
|
|
timeout: 5000
|
|
|
|
type: 'information'
|
|
|
|
}
|
2014-09-02 17:16:36 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
buildDefaultSystems: ->
|
|
|
|
[
|
2014-06-30 22:16:26 -04:00
|
|
|
{original: '528112c00268d018e3000008', majorVersion: 0} # Event
|
2014-08-29 15:29:42 -04:00
|
|
|
{original: '5280f83b8ae1581b66000001', majorVersion: 0} # Existence
|
2014-06-30 22:16:26 -04:00
|
|
|
{original: '5281146f0268d018e3000014', majorVersion: 0} # Programming
|
|
|
|
{original: '528110f30268d018e3000001', majorVersion: 0} # AI
|
|
|
|
{original: '52810ffa33e01a6e86000012', majorVersion: 0} # Action
|
|
|
|
{original: '528114b20268d018e3000017', majorVersion: 0} # Targeting
|
|
|
|
{original: '528105f833e01a6e86000007', majorVersion: 0} # Collision
|
2014-08-29 15:29:42 -04:00
|
|
|
{original: '528113240268d018e300000c', majorVersion: 0} # Movement
|
2014-06-30 22:16:26 -04:00
|
|
|
{original: '528112530268d018e3000007', majorVersion: 0} # Combat
|
|
|
|
{original: '52810f4933e01a6e8600000c', majorVersion: 0} # Hearing
|
|
|
|
{original: '528115040268d018e300001b', majorVersion: 0} # Vision
|
|
|
|
{original: '5280dc4d251616c907000001', majorVersion: 0} # Inventory
|
|
|
|
{original: '528111b30268d018e3000004', majorVersion: 0} # Alliance
|
|
|
|
{original: '528114e60268d018e300001a', majorVersion: 0} # UI
|
|
|
|
{original: '528114040268d018e3000011', majorVersion: 0} # Physics
|
2014-09-02 17:16:36 -04:00
|
|
|
{original: '52ae4f02a4dcd4415200000b', majorVersion: 0} # Display
|
|
|
|
{original: '52e953e81b2028d102000004', majorVersion: 0} # Effect
|
|
|
|
{original: '52f1354370fb890000000005', majorVersion: 0} # Magic
|
2014-01-03 13:32:13 -05:00
|
|
|
]
|
2014-09-02 00:58:22 -04:00
|
|
|
|
2014-08-29 21:02:29 -04:00
|
|
|
destroy: ->
|
|
|
|
@systemsTreema?.destroy()
|
|
|
|
super()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
class LevelSystemNode extends TreemaObjectNode
|
|
|
|
valueClass: 'treema-level-system'
|
|
|
|
constructor: ->
|
|
|
|
super(arguments...)
|
|
|
|
@grabDBComponent()
|
|
|
|
@collection = @system?.attributes?.configSchema?.properties?
|
|
|
|
|
|
|
|
grabDBComponent: ->
|
2014-08-22 14:11:05 -04:00
|
|
|
data = @getData()
|
|
|
|
@system = @settings.supermodel.getModelByOriginalAndMajorVersion(LevelSystem, data.original, data.majorVersion)
|
|
|
|
console.error 'Couldn\'t find system for', data.original, data.majorVersion, 'from models', @settings.supermodel.models unless @system
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
getChildSchema: (key) ->
|
|
|
|
return @system.attributes.configSchema if key is 'config'
|
|
|
|
return super(key)
|
|
|
|
|
2014-08-22 14:11:05 -04:00
|
|
|
buildValueForDisplay: (valEl, data) ->
|
|
|
|
return super valEl unless data.original and @system
|
2014-09-02 00:58:22 -04:00
|
|
|
name = @system.get 'name'
|
|
|
|
name += " v#{@system.get('version').major}" if @system.get('version').major
|
|
|
|
@buildValueForDisplaySimply valEl, name
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-04-11 20:36:15 -04:00
|
|
|
onEnterPressed: (e) ->
|
|
|
|
super e
|
2014-08-22 14:11:05 -04:00
|
|
|
data = @getData()
|
2014-08-28 12:59:07 -04:00
|
|
|
Backbone.Mediator.publish 'editor:edit-level-system', original: data.original, majorVersion: data.majorVersion
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-04-11 20:36:15 -04:00
|
|
|
open: (depth) ->
|
|
|
|
super depth
|
2014-01-03 13:32:13 -05:00
|
|
|
cTreema = @childrenTreemas.config
|
|
|
|
if cTreema? and (cTreema.getChildren().length or cTreema.canAddChild())
|
|
|
|
cTreema.open()
|
|
|
|
# No easy way to flatten the config object, so for now just keep it longer than it needs to be
|
|
|
|
|
|
|
|
class LevelSystemConfigurationNode extends TreemaObjectNode
|
|
|
|
valueClass: 'treema-level-system-configuration'
|
2014-08-22 14:11:05 -04:00
|
|
|
buildValueForDisplay: -> return
|