mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Thang editor now sets some default Components when you change the kind of a ThangType.
This commit is contained in:
parent
9c841991fd
commit
4b9bf22e22
5 changed files with 55 additions and 19 deletions
|
@ -3,10 +3,14 @@ CocoModel = require './CocoModel'
|
|||
module.exports = class LevelComponent extends CocoModel
|
||||
@className: 'LevelComponent'
|
||||
@schema: require 'schemas/models/level_component'
|
||||
|
||||
|
||||
@EquipsID: '53e217d253457600003e3ebb'
|
||||
@ItemID: '53e12043b82921000051cdf9'
|
||||
@AttacksID: '524b7ba57fc0f6d519000016'
|
||||
@PhysicalID: '524b75ad7fc0f6d519000001'
|
||||
@ExistsID: '524b4150ff92f1f4f8000024'
|
||||
@LandID: '524b7aff7fc0f6d519000006'
|
||||
@CollidesID: '524b7b857fc0f6d519000012'
|
||||
urlRoot: '/db/level.component'
|
||||
|
||||
set: (key, val, options) ->
|
||||
|
|
|
@ -45,3 +45,6 @@ module.exports =
|
|||
|
||||
'editor:random-terrain-generated': c.object {required: ['thangs']},
|
||||
thangs: c.array {}, {type: 'object'}
|
||||
|
||||
'editor:thang-type-kind-changed': c.object {required: ['kind']},
|
||||
kind: {type: 'string'}
|
||||
|
|
|
@ -12,6 +12,28 @@ nodes = require '../level/treema_nodes'
|
|||
ThangType = require 'models/ThangType'
|
||||
CocoCollection = require 'collections/CocoCollection'
|
||||
|
||||
LC = (componentName, config) -> original: LevelComponent[componentName + 'ID'], majorVersion: 0, config: config
|
||||
DEFAULT_COMPONENTS =
|
||||
Unit: [LC('Equips')]
|
||||
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')]
|
||||
|
||||
class ItemThangTypeSearchCollection extends CocoCollection
|
||||
url: '/db/thang.type?view=items&project=original,name,version,slug,kind,components'
|
||||
model: ThangType
|
||||
|
@ -20,6 +42,9 @@ module.exports = class ThangComponentsEditView extends CocoView
|
|||
id: 'thang-components-edit-view'
|
||||
template: template
|
||||
|
||||
subscriptions:
|
||||
'editor:thang-type-kind-changed': 'onThangTypeKindChanged'
|
||||
|
||||
events:
|
||||
'click #add-components-button': 'onAddComponentsButtonClicked'
|
||||
|
||||
|
@ -33,11 +58,11 @@ module.exports = class ThangComponentsEditView extends CocoView
|
|||
@world = options.world
|
||||
@level = options.level
|
||||
@loadComponents(@components)
|
||||
|
||||
|
||||
setThangType: (@thangType) ->
|
||||
return unless componentRefs = @thangType?.get('components')
|
||||
@loadComponents(componentRefs)
|
||||
|
||||
|
||||
loadComponents: (components) ->
|
||||
for componentRef in components
|
||||
# just to handle if ever somehow the same component is loaded twice, through bad data and alike
|
||||
|
@ -73,7 +98,7 @@ module.exports = class ThangComponentsEditView extends CocoView
|
|||
type: 'object'
|
||||
default: defaultValue
|
||||
additionalProperties: Level.schema.properties.thangs.items.properties.components.items
|
||||
},
|
||||
},
|
||||
data: $.extend true, {}, components
|
||||
callbacks: {select: @onSelectComponent, change: @onComponentsTreemaChanged}
|
||||
nodeClasses:
|
||||
|
@ -256,7 +281,7 @@ module.exports = class ThangComponentsEditView extends CocoView
|
|||
thangComponent.config = e.config
|
||||
foundComponent = true
|
||||
break
|
||||
|
||||
|
||||
if not foundComponent
|
||||
@components.push({
|
||||
original: e.component.get('original')
|
||||
|
@ -269,7 +294,7 @@ module.exports = class ThangComponentsEditView extends CocoView
|
|||
if subview.component.get('original') is e.component.get('original')
|
||||
_.defer -> subview.setIsDefaultComponent(false)
|
||||
break
|
||||
|
||||
|
||||
@updateComponentsList()
|
||||
@reportChanges()
|
||||
|
||||
|
@ -344,18 +369,24 @@ module.exports = class ThangComponentsEditView extends CocoView
|
|||
@loadComponents(sparseComponents)
|
||||
@components = @components.concat(sparseComponents)
|
||||
@onComponentsChanged()
|
||||
|
||||
|
||||
onThangTypeKindChanged: (e) ->
|
||||
return unless defaultComponents = DEFAULT_COMPONENTS[e.kind]
|
||||
for component in defaultComponents when not _.find(@components, original: component.original)
|
||||
@components.push component
|
||||
@onComponentsAdded()
|
||||
|
||||
destroy: ->
|
||||
@componentsTreema?.destroy()
|
||||
super()
|
||||
|
||||
class ThangComponentsObjectNode extends TreemaObjectNode
|
||||
addNewChild: -> @addNewChildForKey('') # HACK to get the object adding to act more like adding to an array
|
||||
|
||||
|
||||
getChildren: ->
|
||||
children = super(arguments...)
|
||||
children.sort(@sortFunction)
|
||||
|
||||
|
||||
sortFunction: (a, b) =>
|
||||
a = a.value ? a.defaultData
|
||||
b = b.value ? b.defaultData
|
||||
|
|
|
@ -15,11 +15,6 @@ ComponentsCollection = require 'collections/ComponentsCollection'
|
|||
MOVE_MARGIN = 0.15
|
||||
MOVE_SPEED = 13
|
||||
|
||||
# Essential component original ids
|
||||
componentOriginals =
|
||||
'existence.Exists': '524b4150ff92f1f4f8000024'
|
||||
'physics.Physical': '524b75ad7fc0f6d519000001'
|
||||
|
||||
# Let us place these on top of other Thangs
|
||||
overlappableThangTypeNames = ['Torch', 'Chains', 'Bird', 'Cloud 1', 'Cloud 2', 'Cloud 3', 'Waterfall', 'Obstacle']
|
||||
|
||||
|
@ -229,8 +224,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
@surface.camera.dragDisabled = false
|
||||
return unless @selectedExtantThang and e.thang?.id is @selectedExtantThang?.id
|
||||
pos = @selectedExtantThang.pos
|
||||
physicalOriginal = componentOriginals['physics.Physical']
|
||||
path = "id=#{@selectedExtantThang.id}/components/original=#{physicalOriginal}" # TODO: hack
|
||||
path = "id=#{@selectedExtantThang.id}/components/original=#{LevelComponent.PhysicalID}"
|
||||
physical = @thangsTreema.get path
|
||||
return if not physical or (physical.config.pos.x is pos.x and physical.config.pos.y is pos.y)
|
||||
@thangsTreema.set path + '/config/pos', x: pos.x, y: pos.y, z: pos.z
|
||||
|
@ -319,11 +313,11 @@ module.exports = class ThangsTabView extends CocoView
|
|||
|
||||
createEssentialComponents: (defaultComponents) ->
|
||||
physicalConfig = {pos: {x: 10, y: 10, z: 1}}
|
||||
if physicalOriginal = _.find(defaultComponents ? [], original: componentOriginals['physics.Physical'])
|
||||
if physicalOriginal = _.find(defaultComponents ? [], original: LevelComponent.PhysicalID)
|
||||
physicalConfig.pos.z = physicalOriginal.config?.pos?.z ? 1 # Get the z right
|
||||
[
|
||||
{original: componentOriginals['existence.Exists'], majorVersion: 0, config: {}}
|
||||
{original: componentOriginals['physics.Physical'], majorVersion: 0, config: physicalConfig}
|
||||
{original: LevelComponent.ExistsID, majorVersion: 0, config: {}}
|
||||
{original: LevelComponent.PhysicalID, majorVersion: 0, config: physicalConfig}
|
||||
]
|
||||
|
||||
createAddThang: ->
|
||||
|
|
|
@ -380,6 +380,7 @@ module.exports = class ThangTypeEditView extends RootView
|
|||
el = @$el.find('#thang-type-treema')
|
||||
@treema = @$el.find('#thang-type-treema').treema(options)
|
||||
@treema.build()
|
||||
@lastKind = data.kind
|
||||
|
||||
pushChangesToPreview: =>
|
||||
# TODO: This doesn't delete old Treema keys you deleted
|
||||
|
@ -389,6 +390,9 @@ module.exports = class ThangTypeEditView extends RootView
|
|||
@refreshAnimation()
|
||||
@updateDots()
|
||||
@updatePortrait()
|
||||
if (kind = @treema.data.kind) isnt @lastKind
|
||||
@lastKind = kind
|
||||
Backbone.Mediator.publish 'editor:thang-type-kind-changed', kind: kind
|
||||
|
||||
onSelectNode: (e, selected) =>
|
||||
selected = selected[0]
|
||||
|
|
Loading…
Reference in a new issue