mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-01 00:15:00 -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 = {}
|
@handledDisplayEvents = {}
|
||||||
@age = 0
|
@age = 0
|
||||||
@stillLoading = true
|
@stillLoading = true
|
||||||
@setNameLabel @thang.id if @thang?.showsName
|
@setNameLabel @thang.id if @thang?.showsName and not @thang.health <= 0
|
||||||
if @thangType.isFullyLoaded()
|
if @thangType.isFullyLoaded()
|
||||||
@setUpSprite()
|
@setUpSprite()
|
||||||
else
|
else
|
||||||
|
@ -531,13 +531,15 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
relatedActions[direction]
|
relatedActions[direction]
|
||||||
|
|
||||||
updateStats: ->
|
updateStats: ->
|
||||||
|
return unless @thang and @thang.health isnt @lastHealth
|
||||||
|
@lastHealth = @thang.health
|
||||||
if bar = @healthBar
|
if bar = @healthBar
|
||||||
return if @thang.health is @lastHealth
|
|
||||||
@lastHealth = @thang.health
|
|
||||||
healthPct = Math.max(@thang.health / @thang.maxHealth, 0)
|
healthPct = Math.max(@thang.health / @thang.maxHealth, 0)
|
||||||
bar.scaleX = healthPct / bar.baseScale
|
bar.scaleX = healthPct / bar.baseScale
|
||||||
healthOffset = @getOffset 'aboveHead'
|
healthOffset = @getOffset 'aboveHead'
|
||||||
[bar.x, bar.y] = [healthOffset.x - bar.width / 2, healthOffset.y]
|
[bar.x, bar.y] = [healthOffset.x - bar.width / 2, healthOffset.y]
|
||||||
|
if @thang.showsName
|
||||||
|
@setNameLabel(if @thang.health <= 0 then '' else @thang.id)
|
||||||
|
|
||||||
configureMouse: ->
|
configureMouse: ->
|
||||||
@imageObject.cursor = 'pointer' if @thang?.isSelectable
|
@imageObject.cursor = 'pointer' if @thang?.isSelectable
|
||||||
|
|
|
@ -24,6 +24,10 @@ module.exports =
|
||||||
'editor:edit-level-thang': c.object {required: ['thangID']},
|
'editor:edit-level-thang': c.object {required: ['thangID']},
|
||||||
thangID: {type: 'string'}
|
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']},
|
'editor:level-thang-done-editing': c.object {required: ['thangData', 'oldPath']},
|
||||||
thangData: {type: 'object'}
|
thangData: {type: 'object'}
|
||||||
oldPath: {type: 'string'}
|
oldPath: {type: 'string'}
|
||||||
|
|
|
@ -19,6 +19,8 @@ module.exports = class LevelThangEditView extends CocoView
|
||||||
'click #thang-type-link span': 'toggleTypeEdit'
|
'click #thang-type-link span': 'toggleTypeEdit'
|
||||||
'blur #thang-name-link input': 'toggleNameEdit'
|
'blur #thang-name-link input': 'toggleNameEdit'
|
||||||
'blur #thang-type-link input': 'toggleTypeEdit'
|
'blur #thang-type-link input': 'toggleTypeEdit'
|
||||||
|
'keydown #thang-name-link input': 'toggleNameEditIfReturn'
|
||||||
|
'keydown #thang-type-link input': 'toggleTypeEditIfReturn'
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
options ?= {}
|
options ?= {}
|
||||||
|
@ -27,6 +29,7 @@ module.exports = class LevelThangEditView extends CocoView
|
||||||
@thangData = $.extend true, {}, options.thangData ? {}
|
@thangData = $.extend true, {}, options.thangData ? {}
|
||||||
@level = options.level
|
@level = options.level
|
||||||
@oldPath = options.oldPath
|
@oldPath = options.oldPath
|
||||||
|
@reportChanges = _.debounce @reportChanges, 1000
|
||||||
|
|
||||||
getRenderData: (context={}) ->
|
getRenderData: (context={}) ->
|
||||||
context = super(context)
|
context = super(context)
|
||||||
|
@ -83,5 +86,16 @@ module.exports = class LevelThangEditView extends CocoView
|
||||||
if thangType and wasEditing
|
if thangType and wasEditing
|
||||||
@thangData.thangType = thangType.get('original')
|
@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) =>
|
onComponentsChanged: (components) =>
|
||||||
@thangData.components = 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-over': 'onSurfaceMouseOver'
|
||||||
'surface:mouse-out': 'onSurfaceMouseOut'
|
'surface:mouse-out': 'onSurfaceMouseOut'
|
||||||
'editor:edit-level-thang': 'editThang'
|
'editor:edit-level-thang': 'editThang'
|
||||||
|
'editor:level-thang-edited': 'onLevelThangEdited'
|
||||||
'editor:level-thang-done-editing': 'onLevelThangDoneEditing'
|
'editor:level-thang-done-editing': 'onLevelThangDoneEditing'
|
||||||
'editor:view-switched': 'onViewSwitched'
|
'editor:view-switched': 'onViewSwitched'
|
||||||
'sprite:dragged': 'onSpriteDragged'
|
'sprite:dragged': 'onSpriteDragged'
|
||||||
|
@ -573,14 +574,19 @@ module.exports = class ThangsTabView extends CocoView
|
||||||
onLevelThangDoneEditing: (e) ->
|
onLevelThangDoneEditing: (e) ->
|
||||||
@removeSubView @editThangView
|
@removeSubView @editThangView
|
||||||
@editThangView = null
|
@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
|
@hush = true
|
||||||
@thangsTreema.delete e.oldPath
|
@thangsTreema.delete oldPath
|
||||||
@populateFoldersForThang(newThang)
|
@populateFoldersForThang(newThang)
|
||||||
@thangsTreema.set(@pathForThang(newThang), newThang)
|
@thangsTreema.set(@pathForThang(newThang), newThang)
|
||||||
@hush = false
|
@hush = false
|
||||||
@onThangsChanged()
|
@onThangsChanged()
|
||||||
@$el.find('>').show()
|
|
||||||
|
|
||||||
preventDefaultContextMenu: (e) ->
|
preventDefaultContextMenu: (e) ->
|
||||||
return unless $(e.target).closest('#canvas-wrapper').length
|
return unless $(e.target).closest('#canvas-wrapper').length
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue