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:
Scott Erickson 2016-05-31 15:08:09 -07:00
parent d36908f8c1
commit d4c5d418ff
4 changed files with 23 additions and 3 deletions

View file

@ -8,7 +8,6 @@ module.exports = class Campaign extends CocoModel
@className: 'Campaign' @className: 'Campaign'
@schema: schema @schema: schema
urlRoot: '/db/campaign' urlRoot: '/db/campaign'
saveBackups: true
@denormalizedLevelProperties: _.keys(_.omit(schema.properties.levels.additionalProperties.properties, ['unlocks', 'position', 'rewards'])) @denormalizedLevelProperties: _.keys(_.omit(schema.properties.levels.additionalProperties.properties, ['unlocks', 'position', 'rewards']))
@denormalizedCampaignProperties: ['name', 'i18n', 'slug'] @denormalizedCampaignProperties: ['name', 'i18n', 'slug']

View file

@ -60,6 +60,14 @@ module.exports = class CampaignEditorView extends RootView
@listenToOnce @levels, 'sync', @onFundamentalLoaded @listenToOnce @levels, 'sync', @onFundamentalLoaded
@listenToOnce @achievements, '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: -> loadThangTypeNames: ->
# Load the names of the ThangTypes that this level's Treema nodes might want to display. # Load the names of the ThangTypes that this level's Treema nodes might want to display.
originals = [] originals = []
@ -143,6 +151,19 @@ module.exports = class CampaignEditorView extends RootView
@updateRewardsForLevel model, level.rewards @updateRewardsForLevel model, level.rewards
super() 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) -> onClickPatches: (e) ->
@patchesView = @insertSubView(new PatchesView(@campaign), @$el.find('.patches-view')) @patchesView = @insertSubView(new PatchesView(@campaign), @$el.find('.patches-view'))
@ -160,6 +181,7 @@ module.exports = class CampaignEditorView extends RootView
break break
onClickSaveButton: -> onClickSaveButton: ->
@propagateCampaignIndexes()
@toSave.set @toSave.filter (m) -> m.hasLocalChanges() @toSave.set @toSave.filter (m) -> m.hasLocalChanges()
@openModalView new SaveCampaignModal({}, @toSave) @openModalView new SaveCampaignModal({}, @toSave)

View file

@ -80,7 +80,6 @@ module.exports = class CampaignView extends RootView
return return
@campaign = new Campaign({_id:@terrain}) @campaign = new Campaign({_id:@terrain})
@campaign.saveBackups = @editorMode
@campaign = @supermodel.loadModel(@campaign).model @campaign = @supermodel.loadModel(@campaign).model
# Temporary attempt to make sure all earned rewards are accounted for. Figure out a better solution... # Temporary attempt to make sure all earned rewards are accounted for. Figure out a better solution...

View file

@ -79,4 +79,4 @@ module.exports =
for original, level of campaign.levels for original, level of campaign.levels
campaign.levels[original] = _.pick level, ['locked', 'disabled', 'original', 'rewards', 'slug'] campaign.levels[original] = _.pick level, ['locked', 'disabled', 'original', 'rewards', 'slug']
return campaign return campaign
res.status(200).send((formatCampaign(campaign) for campaign in campaigns)) res.status(200).send((formatCampaign(campaign) for campaign in campaigns))