diff --git a/app/styles/play/level/modal/hero-victory-modal.sass b/app/styles/play/level/modal/hero-victory-modal.sass new file mode 100644 index 000000000..d8c58f1e5 --- /dev/null +++ b/app/styles/play/level/modal/hero-victory-modal.sass @@ -0,0 +1,2 @@ +#hero-victory-modal + color: red \ No newline at end of file diff --git a/app/templates/play/level/modal/hero-victory-modal.jade b/app/templates/play/level/modal/hero-victory-modal.jade new file mode 100644 index 000000000..e9ed7109e --- /dev/null +++ b/app/templates/play/level/modal/hero-victory-modal.jade @@ -0,0 +1,34 @@ +extends /templates/modal/modal_base +block modal-header-content + h3 + span(data-i18n="play_level.victory_title_prefix") + span= levelName + span(data-i18n="play_level.victory_title_suffix") Complete + +block modal-body-content + h4 Achievements Unlocked + + for achievement in achievements + .panel + img(src=achievement.getImageURL()) + h5= achievement.get('name') + p= achievement.get('description') + if achievement.completed + strong Completed + else + strong Incomplete + p Earned #{achievement.get('worth')} xp. + - var rewards = achievement.get('rewards') || {}; + if rewards.gems + p Earned #{achievement.get('rewards').gems} gems. + if rewards.heroes + for hero in rewards.heroes + - var hero = thangTypes[hero]; + img(src=hero.getPortraitURL()) + if rewards.items + for item in rewards.items + - var item = thangTypes[item]; + img(src=item.getPortraitURL()) + +block modal-footer-content + | footer \ No newline at end of file diff --git a/app/views/play/level/PlayLevelView.coffee b/app/views/play/level/PlayLevelView.coffee index e5e1380af..003f374fe 100644 --- a/app/views/play/level/PlayLevelView.coffee +++ b/app/views/play/level/PlayLevelView.coffee @@ -32,6 +32,7 @@ GoalsView = require './LevelGoalsView' LevelFlagsView = require './LevelFlagsView' GoldView = require './LevelGoldView' VictoryModal = require './modal/VictoryModal' +HeroVictoryModal = require './modal/HeroVictoryModal' InfiniteLoopModal = require './modal/InfiniteLoopModal' GameMenuModal = require 'views/game-menu/GameMenuModal' @@ -196,6 +197,11 @@ module.exports = class PlayLevelView extends RootView @insertSubviews() @initVolume() @listenTo(@session, 'change:multiplayer', @onMultiplayerChanged) + + # testing +# modal = new HeroVictoryModal({session: @session, level: @level}) +# @openModalView(modal) + @originalSessionState = $.extend(true, {}, @session.get('state')) @register() @controlBar.setBus(@bus) @@ -450,8 +456,10 @@ module.exports = class PlayLevelView extends RootView showVictory: -> options = {level: @level, supermodel: @supermodel, session: @session} - docs = new VictoryModal(options) - @openModalView(docs) +# ModalClass = if @level.get('type', true) is 'hero' then HeroVictoryModal else VictoryModal +# victoryModal = new ModalClass(options) + victoryModal = new VictoryModal(options) + @openModalView(victoryModal) if me.get('anonymous') window.nextLevelURL = @getNextLevelURL() # Signup will go here on completion instead of reloading. diff --git a/app/views/play/level/modal/HeroVictoryModal.coffee b/app/views/play/level/modal/HeroVictoryModal.coffee new file mode 100644 index 000000000..3d7672447 --- /dev/null +++ b/app/views/play/level/modal/HeroVictoryModal.coffee @@ -0,0 +1,47 @@ +ModalView = require 'views/kinds/ModalView' +template = require 'templates/play/level/modal/hero-victory-modal' +Achievement = require 'models/Achievement' +CocoCollection = require 'collections/CocoCollection' +LocalMongo = require 'lib/LocalMongo' +utils = require 'lib/utils' +ThangType = require 'models/ThangType' + +module.exports = class UnnamedView extends ModalView + id: 'hero-victory-modal' + template: template + + constructor: (options) -> + super(options) + @session = options.session + @level = options.level + achievements = new CocoCollection([], { + url: "/db/achievement?related=#{@session.get('level').original}" + model: Achievement + }) + @thangTypes = {} + @achievements = @supermodel.loadCollection(achievements, 'achievements').model + @listenToOnce @achievements, 'sync', @onAchievementsLoaded + + onAchievementsLoaded: -> + thangTypeOriginals = [] + for achievement in @achievements.models + rewards = achievement.get('rewards') + console.log 'rewards', rewards + thangTypeOriginals.push rewards.heroes or [] + thangTypeOriginals.push rewards.items or [] + thangTypeOriginals = _.uniq _.flatten thangTypeOriginals + console.log 'thang type originals?', thangTypeOriginals + for thangTypeOriginal in thangTypeOriginals + thangType = new ThangType() + thangType.url = "/db/thang.type/#{thangTypeOriginal}/version" + thangType.project = ['original', 'rasterIcon'] + @thangTypes[thangTypeOriginal] = @supermodel.loadModel(thangType, 'thang').model + + getRenderData: -> + c = super() + c.levelName = utils.i18n @level.attributes, 'name' + for achievement in @achievements.models + achievement.completed = LocalMongo.matchesQuery(@session.attributes, achievement.get('query')) + c.achievements = @achievements.models + c.thangTypes = @thangTypes + return c \ No newline at end of file