mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -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
|
@ -7,6 +7,10 @@ module.exports = class LevelComponent extends CocoModel
|
||||||
@EquipsID: '53e217d253457600003e3ebb'
|
@EquipsID: '53e217d253457600003e3ebb'
|
||||||
@ItemID: '53e12043b82921000051cdf9'
|
@ItemID: '53e12043b82921000051cdf9'
|
||||||
@AttacksID: '524b7ba57fc0f6d519000016'
|
@AttacksID: '524b7ba57fc0f6d519000016'
|
||||||
|
@PhysicalID: '524b75ad7fc0f6d519000001'
|
||||||
|
@ExistsID: '524b4150ff92f1f4f8000024'
|
||||||
|
@LandID: '524b7aff7fc0f6d519000006'
|
||||||
|
@CollidesID: '524b7b857fc0f6d519000012'
|
||||||
urlRoot: '/db/level.component'
|
urlRoot: '/db/level.component'
|
||||||
|
|
||||||
set: (key, val, options) ->
|
set: (key, val, options) ->
|
||||||
|
|
|
@ -45,3 +45,6 @@ module.exports =
|
||||||
|
|
||||||
'editor:random-terrain-generated': c.object {required: ['thangs']},
|
'editor:random-terrain-generated': c.object {required: ['thangs']},
|
||||||
thangs: c.array {}, {type: 'object'}
|
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'
|
ThangType = require 'models/ThangType'
|
||||||
CocoCollection = require 'collections/CocoCollection'
|
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
|
class ItemThangTypeSearchCollection extends CocoCollection
|
||||||
url: '/db/thang.type?view=items&project=original,name,version,slug,kind,components'
|
url: '/db/thang.type?view=items&project=original,name,version,slug,kind,components'
|
||||||
model: ThangType
|
model: ThangType
|
||||||
|
@ -20,6 +42,9 @@ module.exports = class ThangComponentsEditView extends CocoView
|
||||||
id: 'thang-components-edit-view'
|
id: 'thang-components-edit-view'
|
||||||
template: template
|
template: template
|
||||||
|
|
||||||
|
subscriptions:
|
||||||
|
'editor:thang-type-kind-changed': 'onThangTypeKindChanged'
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click #add-components-button': 'onAddComponentsButtonClicked'
|
'click #add-components-button': 'onAddComponentsButtonClicked'
|
||||||
|
|
||||||
|
@ -345,6 +370,12 @@ module.exports = class ThangComponentsEditView extends CocoView
|
||||||
@components = @components.concat(sparseComponents)
|
@components = @components.concat(sparseComponents)
|
||||||
@onComponentsChanged()
|
@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: ->
|
destroy: ->
|
||||||
@componentsTreema?.destroy()
|
@componentsTreema?.destroy()
|
||||||
super()
|
super()
|
||||||
|
|
|
@ -15,11 +15,6 @@ ComponentsCollection = require 'collections/ComponentsCollection'
|
||||||
MOVE_MARGIN = 0.15
|
MOVE_MARGIN = 0.15
|
||||||
MOVE_SPEED = 13
|
MOVE_SPEED = 13
|
||||||
|
|
||||||
# Essential component original ids
|
|
||||||
componentOriginals =
|
|
||||||
'existence.Exists': '524b4150ff92f1f4f8000024'
|
|
||||||
'physics.Physical': '524b75ad7fc0f6d519000001'
|
|
||||||
|
|
||||||
# Let us place these on top of other Thangs
|
# Let us place these on top of other Thangs
|
||||||
overlappableThangTypeNames = ['Torch', 'Chains', 'Bird', 'Cloud 1', 'Cloud 2', 'Cloud 3', 'Waterfall', 'Obstacle']
|
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
|
@surface.camera.dragDisabled = false
|
||||||
return unless @selectedExtantThang and e.thang?.id is @selectedExtantThang?.id
|
return unless @selectedExtantThang and e.thang?.id is @selectedExtantThang?.id
|
||||||
pos = @selectedExtantThang.pos
|
pos = @selectedExtantThang.pos
|
||||||
physicalOriginal = componentOriginals['physics.Physical']
|
path = "id=#{@selectedExtantThang.id}/components/original=#{LevelComponent.PhysicalID}"
|
||||||
path = "id=#{@selectedExtantThang.id}/components/original=#{physicalOriginal}" # TODO: hack
|
|
||||||
physical = @thangsTreema.get path
|
physical = @thangsTreema.get path
|
||||||
return if not physical or (physical.config.pos.x is pos.x and physical.config.pos.y is pos.y)
|
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
|
@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) ->
|
createEssentialComponents: (defaultComponents) ->
|
||||||
physicalConfig = {pos: {x: 10, y: 10, z: 1}}
|
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
|
physicalConfig.pos.z = physicalOriginal.config?.pos?.z ? 1 # Get the z right
|
||||||
[
|
[
|
||||||
{original: componentOriginals['existence.Exists'], majorVersion: 0, config: {}}
|
{original: LevelComponent.ExistsID, majorVersion: 0, config: {}}
|
||||||
{original: componentOriginals['physics.Physical'], majorVersion: 0, config: physicalConfig}
|
{original: LevelComponent.PhysicalID, majorVersion: 0, config: physicalConfig}
|
||||||
]
|
]
|
||||||
|
|
||||||
createAddThang: ->
|
createAddThang: ->
|
||||||
|
|
|
@ -380,6 +380,7 @@ module.exports = class ThangTypeEditView extends RootView
|
||||||
el = @$el.find('#thang-type-treema')
|
el = @$el.find('#thang-type-treema')
|
||||||
@treema = @$el.find('#thang-type-treema').treema(options)
|
@treema = @$el.find('#thang-type-treema').treema(options)
|
||||||
@treema.build()
|
@treema.build()
|
||||||
|
@lastKind = data.kind
|
||||||
|
|
||||||
pushChangesToPreview: =>
|
pushChangesToPreview: =>
|
||||||
# TODO: This doesn't delete old Treema keys you deleted
|
# TODO: This doesn't delete old Treema keys you deleted
|
||||||
|
@ -389,6 +390,9 @@ module.exports = class ThangTypeEditView extends RootView
|
||||||
@refreshAnimation()
|
@refreshAnimation()
|
||||||
@updateDots()
|
@updateDots()
|
||||||
@updatePortrait()
|
@updatePortrait()
|
||||||
|
if (kind = @treema.data.kind) isnt @lastKind
|
||||||
|
@lastKind = kind
|
||||||
|
Backbone.Mediator.publish 'editor:thang-type-kind-changed', kind: kind
|
||||||
|
|
||||||
onSelectNode: (e, selected) =>
|
onSelectNode: (e, selected) =>
|
||||||
selected = selected[0]
|
selected = selected[0]
|
||||||
|
|
Loading…
Reference in a new issue