Merge branch 'master' into production

This commit is contained in:
Nick Winter 2015-11-19 14:52:04 -08:00
commit c867b1f5b4
8 changed files with 99 additions and 9 deletions

View file

@ -10,6 +10,7 @@ CocoClass = require 'core/CocoClass'
AudioPlayer = require 'lib/AudioPlayer'
app = require 'core/application'
World = require 'lib/world/world'
utils = require 'core/utils'
# This is an initial stab at unifying loading and setup into a single place which can
# monitor everything and keep a LoadingScreen visible overall progress.
@ -105,6 +106,8 @@ module.exports = class LevelLoader extends CocoClass
loadDependenciesForSession: (session) ->
if me.id isnt session.get 'creator'
session.patch = session.save = -> console.error "Not saving session, since we didn't create it."
else if codeLanguage = utils.getQueryVariable 'codeLanguage'
session.set 'codeLanguage', codeLanguage
@loadCodeLanguagesForSession session
if session is @session
@addSessionBrowserInfo session

View file

@ -247,7 +247,7 @@
victory_title_suffix: " Complete"
victory_sign_up: "Sign Up to Save Progress"
victory_sign_up_poke: "Want to save your code? Create a free account!"
victory_rate_the_level: "Rate the level: " # Only in old-style levels.
victory_rate_the_level: "How fun was this level?" # {change}
victory_return_to_ladder: "Return to Ladder"
victory_play_continue: "Continue"
victory_saving_progress: "Saving Progress"

View file

@ -196,7 +196,7 @@ module.exports = class ClanDetailsView extends RootView
if level.concepts?
for concept in level.concepts
@conceptsProgression.push concept unless concept in @conceptsProgression
if level.type is 'hero-ladder'
if level.type is 'hero-ladder' and level.slug not in ['capture-their-flag']
@arenas.push level
@campaignLevelProgressions.push campaignLevelProgression
@render?()

View file

@ -221,9 +221,9 @@ module.exports = class CourseDetailsView extends RootView
levelID = $(e.target).data('level-id')
level = @campaign.get('levels')[levelID]
if level.type is 'course-ladder'
Backbone.Mediator.publish 'router:navigate', {
route: '/play/ladder/' + levelSlug + '/course/' + @courseInstance.id
}
route = '/play/ladder/' + levelSlug
route += '/course'/ + @courseInstance.id if @courseInstance.get('members').length > 1 # No league for solo courses
Backbone.Mediator.publish 'router:navigate', route: route
else
Backbone.Mediator.publish 'router:navigate', {
route: @getLevelURL levelSlug

View file

@ -11,10 +11,14 @@ module.exports.teamDataFromLevel = (level) ->
color = teamConfigs[team].color
bgColor = hslToHex([color.hue, color.saturation, color.lightness + (1 - color.lightness) * 0.5])
primaryColor = hslToHex([color.hue, 0.5, 0.5])
if level.get('slug') in ['wakka-maul']
displayName = _.string.titleize(team)
else
displayName = $.i18n.t("ladder.#{team}") # Use Red/Blue instead of Humans/Ogres
teams.push({
id: team
name: _.string.titleize(team)
displayName: $.i18n.t("ladder.#{team}") # Use Red/Blue instead of Humans/Ogres
displayName: displayName
otherTeam: otherTeam
otherTeamDisplayName: $.i18n.t("ladder.#{otherTeam}")
bgColor: bgColor

View file

@ -33,9 +33,9 @@ class LevelSessionsCollection extends CocoCollection
@url = "/db/user/#{me.id}/level.sessions?project=state.complete,levelID,state.difficulty,playtime"
class CampaignsCollection extends CocoCollection
url: '/db/campaign/-/overworld'
# We don't send all of levels, just the parts needed in countLevels
url: '/db/campaign/-/overworld?project=slug,adjacentCampaigns,name,fullName,description,i18n,color,levels'
model: Campaign
project: ['name', 'fullName', 'description', 'i18n']
module.exports = class CampaignView extends RootView
id: 'campaign-view'

View file

@ -0,0 +1,78 @@
// Add user.courseInstances properties and then add those to session leagues
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
addCourseInstancesToUsers();
function uniq(array) {
var u = {}, a = [];
for(var i = 0, l = array.length; i < l; ++i){
if(u.hasOwnProperty(array[i])) {
continue;
}
a.push(array[i]);
u[array[i]] = 1;
}
return a;
}
function addCourseInstancesToUsers() {
print("Adding courseInstances to users...");
var cursor = db.course.instances.find({$where: "this.members && this.members.length > 1"}, {members: 1});
print("CourseInstances with users found: " + cursor.count());
var courseInstances = cursor.toArray();
var userIDList = [];
courseInstances.forEach(function (courseInstance, courseInstanceIndex) {
userIDList = userIDList.concat(courseInstance.members);
var conditions = {_id: {$in: courseInstance.members}};
var operations = {$addToSet: {courseInstances: courseInstance._id}};
//print('Fetching', JSON.stringify(conditions), 'with operations', JSON.stringify(operations));
//print("... Have this many:", db.users.count(conditions));
var result = db.users.update(conditions, operations, {multi: true});
if (courseInstanceIndex % 100 === 0)
print("Done", courseInstanceIndex, "\tof", courseInstances.length, "course instances.");
});
print("Done adding course instances to users; now going to add them to sessions for leagues.");
addCourseInstancesToSessions(userIDList);
}
function addCourseInstancesToSessions(userIDList) {
userIDList = uniq(userIDList);
print("Adding courseInstance leagues to sessions for", userIDList.length, "users...");
var cursor = db.users.find({_id: {$in: userIDList}, courseInstances: {$exists: true}}, {courseInstances: 1, name: 1, leagues: 1});
print("Users with courseInstances found: " + cursor.count(), '-- supposed to have:', userIDList.length);
var users = cursor.toArray();
var arenas = [
"5442ba0e1e835500007eb1c7",
"550363b4ec31df9c691ab629",
"5469643c37600b40e0e09c5b",
"54b83c2629843994803c838e",
"544437e0645c0c0000c3291d",
"5630eab0c0fcbd86057cc2f8",
"55de80407a57948705777e89"
];
users.forEach(function (user, userIndex) {
var sessions = db.level.sessions.find({creator: user._id + '', 'level.original': {$in: arenas}, submitted: true}).toArray();
//print("Found sessions", sessions, "for user", user._id, user.name, 'who has courseInstances', user.courseInstances.join(', '));
sessions.forEach(function(session, sessionIndex) {
var leagues = session.leagues || [];
for (var i = 0; i < user.courseInstances.length; ++i) {
var alreadyHave = false;
for (var j = 0; j < leagues.length; ++j)
if (leagues[j].leagueID == user.courseInstances[i])
alreadyHave = true;
if (!alreadyHave)
leagues.push({leagueID: user.courseInstances[i] + '', stats: {standardDeviation: 25 / 3, numberOfWinsAndTies: 0, numberOfLosses: 0, totalScore: 10, meanStrength: 25}});
}
//print(" Setting leagues to...");
//printjson(leagues);
session.leagues = leagues;
db.level.sessions.save(session);
});
if (userIndex % 100 === 0)
print("Done", userIndex, "\tof", users.length, "users.");
});
print("Done.");
}

View file

@ -54,12 +54,17 @@ CampaignHandler = class CampaignHandler extends Handler
getOverworld: (req, res) ->
return @sendForbiddenError(res) if not @hasAccess(req)
q = @modelClass.find {}, slug: 1, adjacentCampaigns: 1, fullName: 1, description: 1, color: 1
projection = {}
if req.query.project
projection[field] = 1 for field in req.query.project.split(',')
q = @modelClass.find {}, projection
q.exec (err, documents) =>
return @sendDatabaseError(res, err) if err
formatCampaign = (doc) =>
obj = @formatEntity(req, doc)
obj.adjacentCampaigns = _.mapValues(obj.adjacentCampaigns, (a) -> _.pick(a, ['showIfUnlocked', 'color', 'name', 'description' ]))
for original, level of obj.levels
obj.levels[original] = _.pick level, ['locked', 'disabled', 'original', 'rewards']
obj
documents = (formatCampaign(doc) for doc in documents)
@sendSuccess(res, documents)