mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Was confused about achievement collections and categories.
This commit is contained in:
parent
6cdd6fbc44
commit
578ec6d7d0
2 changed files with 10 additions and 16 deletions
|
@ -8,6 +8,7 @@ do (setupLodash = this) ->
|
|||
GLOBAL._ = require 'lodash'
|
||||
_.str = require 'underscore.string'
|
||||
_.mixin _.str.exports()
|
||||
GLOBAL.tv4 = require('tv4').tv4
|
||||
|
||||
database.connect()
|
||||
|
||||
|
@ -20,13 +21,6 @@ Achievement.loadAchievements (achievementCategories) ->
|
|||
userAchievements = achievementCategories.users
|
||||
console.log 'There are', userAchievements.length, 'user achievements.'
|
||||
|
||||
# 0. Stream all the non-anonymous users.
|
||||
# 1. Adapt this logic below to fetch the earned achievement to see if it exists.
|
||||
# 2. If it doesn't exist, make it and add to total.
|
||||
# 3. Keep other totals, too, for interesting stats.
|
||||
# 4. Print out how long it's going to take.
|
||||
# 5. process.exit()
|
||||
|
||||
t0 = new Date().getTime()
|
||||
total = 100000
|
||||
#testUsers = ['livelily+test31@gmail.com', 'livelily+test37@gmail.com']
|
||||
|
|
|
@ -47,7 +47,7 @@ AchievementSchema.methods.getExpFunction = ->
|
|||
return utils.functionCreators[func.kind](func.parameters) if func.kind of utils.functionCreators
|
||||
|
||||
AchievementSchema.statics.jsonschema = jsonschema
|
||||
AchievementSchema.statics.achievementCategories = {}
|
||||
AchievementSchema.statics.achievementCollections = {}
|
||||
|
||||
# Reloads all achievements into memory.
|
||||
# TODO might want to tweak this to only load new achievements
|
||||
|
@ -57,21 +57,21 @@ AchievementSchema.statics.loadAchievements = (done) ->
|
|||
query = Achievement.find({collection: {$ne: 'level.sessions'}})
|
||||
query.exec (err, docs) ->
|
||||
_.each docs, (achievement) ->
|
||||
category = achievement.get 'collection'
|
||||
AchievementSchema.statics.achievementCategories[category] ?= []
|
||||
if _.find AchievementSchema.statics.achievementCategories[category], ((a) -> a.get('_id').toHexString() is achievement.get('_id').toHexString())
|
||||
log.warn "Uh oh, we tried to add another copy of the same achievement #{achievement.get('_id')} #{achievement.get('name')} to the #{category} achievement list..."
|
||||
collection = achievement.get 'collection'
|
||||
AchievementSchema.statics.achievementCollections[collection] ?= []
|
||||
if _.find AchievementSchema.statics.achievementCollections[collection], ((a) -> a.get('_id').toHexString() is achievement.get('_id').toHexString())
|
||||
log.warn "Uh oh, we tried to add another copy of the same achievement #{achievement.get('_id')} #{achievement.get('name')} to the #{collection} achievement list..."
|
||||
else
|
||||
AchievementSchema.statics.achievementCategories[category].push achievement
|
||||
AchievementSchema.statics.achievementCollections[collection].push achievement
|
||||
unless achievement.get('query')
|
||||
log.error "Uh oh, there is an achievement with an empty query: #{achievement}"
|
||||
done?(AchievementSchema.statics.achievementCategories)
|
||||
done?(AchievementSchema.statics.achievementCollections)
|
||||
|
||||
AchievementSchema.statics.getLoadedAchievements = ->
|
||||
AchievementSchema.statics.achievementCategories
|
||||
AchievementSchema.statics.achievementCollections
|
||||
|
||||
AchievementSchema.statics.resetAchievements = ->
|
||||
delete AchievementSchema.statics.achievementCategories[category] for category of AchievementSchema.statics.achievementCategories
|
||||
delete AchievementSchema.statics.achievementCollections[collection] for collection of AchievementSchema.statics.achievementCollections
|
||||
|
||||
# Queries are stored as JSON strings, objectify them upon loading
|
||||
AchievementSchema.post 'init', (doc) -> doc.objectifyQuery()
|
||||
|
|
Loading…
Reference in a new issue