diff --git a/app/models/Campaign.coffee b/app/models/Campaign.coffee index 495ca7ac5..2e5cb9db1 100644 --- a/app/models/Campaign.coffee +++ b/app/models/Campaign.coffee @@ -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'] diff --git a/app/views/editor/campaign/CampaignEditorView.coffee b/app/views/editor/campaign/CampaignEditorView.coffee index 245d330b9..7a0920023 100644 --- a/app/views/editor/campaign/CampaignEditorView.coffee +++ b/app/views/editor/campaign/CampaignEditorView.coffee @@ -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 = [] @@ -143,6 +151,19 @@ module.exports = class CampaignEditorView extends RootView @updateRewardsForLevel model, level.rewards 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')) @@ -160,6 +181,7 @@ module.exports = class CampaignEditorView extends RootView break onClickSaveButton: -> + @propagateCampaignIndexes() @toSave.set @toSave.filter (m) -> m.hasLocalChanges() @openModalView new SaveCampaignModal({}, @toSave) diff --git a/app/views/play/CampaignView.coffee b/app/views/play/CampaignView.coffee index 8c87b2dd8..5852514fd 100644 --- a/app/views/play/CampaignView.coffee +++ b/app/views/play/CampaignView.coffee @@ -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... diff --git a/server/middleware/campaigns.coffee b/server/middleware/campaigns.coffee index 2be34e9db..66c1cbba7 100644 --- a/server/middleware/campaigns.coffee +++ b/server/middleware/campaigns.coffee @@ -79,4 +79,4 @@ module.exports = for original, level of campaign.levels campaign.levels[original] = _.pick level, ['locked', 'disabled', 'original', 'rewards', 'slug'] return campaign - res.status(200).send((formatCampaign(campaign) for campaign in campaigns)) \ No newline at end of file + res.status(200).send((formatCampaign(campaign) for campaign in campaigns))