diff --git a/app/lib/surface/CocoSprite.coffee b/app/lib/surface/CocoSprite.coffee index 277f70497..f76caa2e4 100644 --- a/app/lib/surface/CocoSprite.coffee +++ b/app/lib/surface/CocoSprite.coffee @@ -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 diff --git a/app/schemas/subscriptions/editor.coffee b/app/schemas/subscriptions/editor.coffee index db490f17c..2665438be 100644 --- a/app/schemas/subscriptions/editor.coffee +++ b/app/schemas/subscriptions/editor.coffee @@ -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'} diff --git a/app/views/editor/level/thangs/LevelThangEditView.coffee b/app/views/editor/level/thangs/LevelThangEditView.coffee index 635b6b9c4..d5debf33b 100644 --- a/app/views/editor/level/thangs/LevelThangEditView.coffee +++ b/app/views/editor/level/thangs/LevelThangEditView.coffee @@ -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} diff --git a/app/views/editor/level/thangs/ThangsTabView.coffee b/app/views/editor/level/thangs/ThangsTabView.coffee index 8814b48bf..6a9b3376d 100644 --- a/app/views/editor/level/thangs/ThangsTabView.coffee +++ b/app/views/editor/level/thangs/ThangsTabView.coffee @@ -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