mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-26 14:03:28 -04:00
Thang config edits are saved while the edit view is up. Dead Thangs don't display their names. Enter now finalizes Thang name/type edits.
This commit is contained in:
parent
1f71a1eaf9
commit
d96d0d65f3
4 changed files with 32 additions and 6 deletions
app
lib/surface
schemas/subscriptions
views/editor/level/thangs
|
@ -79,7 +79,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@handledDisplayEvents = {}
|
||||
@age = 0
|
||||
@stillLoading = true
|
||||
@setNameLabel @thang.id if @thang?.showsName
|
||||
@setNameLabel @thang.id if @thang?.showsName and not @thang.health <= 0
|
||||
if @thangType.isFullyLoaded()
|
||||
@setUpSprite()
|
||||
else
|
||||
|
@ -531,13 +531,15 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
relatedActions[direction]
|
||||
|
||||
updateStats: ->
|
||||
return unless @thang and @thang.health isnt @lastHealth
|
||||
@lastHealth = @thang.health
|
||||
if bar = @healthBar
|
||||
return if @thang.health is @lastHealth
|
||||
@lastHealth = @thang.health
|
||||
healthPct = Math.max(@thang.health / @thang.maxHealth, 0)
|
||||
bar.scaleX = healthPct / bar.baseScale
|
||||
healthOffset = @getOffset 'aboveHead'
|
||||
[bar.x, bar.y] = [healthOffset.x - bar.width / 2, healthOffset.y]
|
||||
if @thang.showsName
|
||||
@setNameLabel(if @thang.health <= 0 then '' else @thang.id)
|
||||
|
||||
configureMouse: ->
|
||||
@imageObject.cursor = 'pointer' if @thang?.isSelectable
|
||||
|
|
|
@ -24,6 +24,10 @@ module.exports =
|
|||
'editor:edit-level-thang': c.object {required: ['thangID']},
|
||||
thangID: {type: 'string'}
|
||||
|
||||
'editor:level-thang-edited': c.object {required: ['thangData', 'oldPath']},
|
||||
thangData: {type: 'object'}
|
||||
oldPath: {type: 'string'}
|
||||
|
||||
'editor:level-thang-done-editing': c.object {required: ['thangData', 'oldPath']},
|
||||
thangData: {type: 'object'}
|
||||
oldPath: {type: 'string'}
|
||||
|
|
|
@ -19,6 +19,8 @@ module.exports = class LevelThangEditView extends CocoView
|
|||
'click #thang-type-link span': 'toggleTypeEdit'
|
||||
'blur #thang-name-link input': 'toggleNameEdit'
|
||||
'blur #thang-type-link input': 'toggleTypeEdit'
|
||||
'keydown #thang-name-link input': 'toggleNameEditIfReturn'
|
||||
'keydown #thang-type-link input': 'toggleTypeEditIfReturn'
|
||||
|
||||
constructor: (options) ->
|
||||
options ?= {}
|
||||
|
@ -27,6 +29,7 @@ module.exports = class LevelThangEditView extends CocoView
|
|||
@thangData = $.extend true, {}, options.thangData ? {}
|
||||
@level = options.level
|
||||
@oldPath = options.oldPath
|
||||
@reportChanges = _.debounce @reportChanges, 1000
|
||||
|
||||
getRenderData: (context={}) ->
|
||||
context = super(context)
|
||||
|
@ -83,5 +86,16 @@ module.exports = class LevelThangEditView extends CocoView
|
|||
if thangType and wasEditing
|
||||
@thangData.thangType = thangType.get('original')
|
||||
|
||||
toggleNameEditIfReturn: (e) ->
|
||||
@$el.find('#thang-name-link input').blur() if e.which is 13
|
||||
|
||||
toggleTypeEditIfReturn: (e) ->
|
||||
@$el.find('#thang-type-link input').blur() if e.which is 13
|
||||
|
||||
onComponentsChanged: (components) =>
|
||||
@thangData.components = components
|
||||
@reportChanges()
|
||||
|
||||
reportChanges: =>
|
||||
return if @destroyed
|
||||
Backbone.Mediator.publish 'editor:level-thang-edited', {thangData: $.extend(true, {}, @thangData), oldPath: @oldPath}
|
||||
|
|
|
@ -33,6 +33,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
'surface:mouse-over': 'onSurfaceMouseOver'
|
||||
'surface:mouse-out': 'onSurfaceMouseOut'
|
||||
'editor:edit-level-thang': 'editThang'
|
||||
'editor:level-thang-edited': 'onLevelThangEdited'
|
||||
'editor:level-thang-done-editing': 'onLevelThangDoneEditing'
|
||||
'editor:view-switched': 'onViewSwitched'
|
||||
'sprite:dragged': 'onSpriteDragged'
|
||||
|
@ -573,14 +574,19 @@ module.exports = class ThangsTabView extends CocoView
|
|||
onLevelThangDoneEditing: (e) ->
|
||||
@removeSubView @editThangView
|
||||
@editThangView = null
|
||||
newThang = e.thangData
|
||||
@updateEditedThang e.thangData, e.oldPath
|
||||
@$el.find('>').show()
|
||||
|
||||
onLevelThangEdited: (e) ->
|
||||
@updateEditedThang e.thangData, e.oldPath
|
||||
|
||||
updateEditedThang: (newThang, oldPath) ->
|
||||
@hush = true
|
||||
@thangsTreema.delete e.oldPath
|
||||
@thangsTreema.delete oldPath
|
||||
@populateFoldersForThang(newThang)
|
||||
@thangsTreema.set(@pathForThang(newThang), newThang)
|
||||
@hush = false
|
||||
@onThangsChanged()
|
||||
@$el.find('>').show()
|
||||
|
||||
preventDefaultContextMenu: (e) ->
|
||||
return unless $(e.target).closest('#canvas-wrapper').length
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue