mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Improve CampaignEditor saving, particularly level order
* Do not cache campaign * Instead have an on leave message if there are unsaved changes * Propagate campaignIndex values to campaign and levels so that they signal a change in order The save modal seems to have a lot of issues with identifying what models have changed. I tried using different methods, but none were consistent. Moving on to other bugs.
This commit is contained in:
parent
d36908f8c1
commit
d4c5d418ff
4 changed files with 23 additions and 3 deletions
|
@ -8,7 +8,6 @@ module.exports = class Campaign extends CocoModel
|
|||
@className: 'Campaign'
|
||||
@schema: schema
|
||||
urlRoot: '/db/campaign'
|
||||
saveBackups: true
|
||||
@denormalizedLevelProperties: _.keys(_.omit(schema.properties.levels.additionalProperties.properties, ['unlocks', 'position', 'rewards']))
|
||||
@denormalizedCampaignProperties: ['name', 'i18n', 'slug']
|
||||
|
||||
|
|
|
@ -60,6 +60,14 @@ module.exports = class CampaignEditorView extends RootView
|
|||
@listenToOnce @levels, 'sync', @onFundamentalLoaded
|
||||
@listenToOnce @achievements, 'sync', @onFundamentalLoaded
|
||||
|
||||
onLeaveMessage: ->
|
||||
@propagateCampaignIndexes()
|
||||
for model in @toSave.models
|
||||
diff = model.getDelta()
|
||||
if _.size(diff)
|
||||
console.log 'model, diff', model, diff
|
||||
return 'You have changes!'
|
||||
|
||||
loadThangTypeNames: ->
|
||||
# Load the names of the ThangTypes that this level's Treema nodes might want to display.
|
||||
originals = []
|
||||
|
@ -144,6 +152,19 @@ module.exports = class CampaignEditorView extends RootView
|
|||
|
||||
super()
|
||||
|
||||
propagateCampaignIndexes: ->
|
||||
campaignLevels = $.extend({}, @campaign.get('levels'))
|
||||
|
||||
index = 0
|
||||
for levelOriginal, campaignLevel of campaignLevels
|
||||
level = @levels.findWhere({original: levelOriginal})
|
||||
if level.get('campaignIndex') isnt index
|
||||
level.set('campaignIndex', index)
|
||||
campaignLevel.campaignIndex = index
|
||||
index += 1
|
||||
|
||||
@campaign.set('levels', campaignLevels)
|
||||
|
||||
onClickPatches: (e) ->
|
||||
@patchesView = @insertSubView(new PatchesView(@campaign), @$el.find('.patches-view'))
|
||||
@patchesView.load()
|
||||
|
@ -160,6 +181,7 @@ module.exports = class CampaignEditorView extends RootView
|
|||
break
|
||||
|
||||
onClickSaveButton: ->
|
||||
@propagateCampaignIndexes()
|
||||
@toSave.set @toSave.filter (m) -> m.hasLocalChanges()
|
||||
@openModalView new SaveCampaignModal({}, @toSave)
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ module.exports = class CampaignView extends RootView
|
|||
return
|
||||
|
||||
@campaign = new Campaign({_id:@terrain})
|
||||
@campaign.saveBackups = @editorMode
|
||||
@campaign = @supermodel.loadModel(@campaign).model
|
||||
|
||||
# Temporary attempt to make sure all earned rewards are accounted for. Figure out a better solution...
|
||||
|
|
Loading…
Reference in a new issue