codecombat/app/schemas/models/achievement.coffee

97 lines
3.3 KiB
CoffeeScript
Raw Normal View History

c = require './../schemas'
# TODO add these: http://docs.mongodb.org/manual/reference/operator/query/
MongoQueryOperatorSchema =
title: 'Query Operator'
type: 'object'
properties:
'$gt': type: 'number'
'$gte': type: 'number'
'$in': type: 'array'
'$lt': type: 'number'
'$lte': type: 'number'
2014-06-30 22:16:26 -04:00
'$ne': type: ['number', 'string']
'$nin': type: 'array'
'$exists': type: 'boolean'
additionalProperties: false
MongoFindQuerySchema =
title: 'Query'
type: 'object'
patternProperties:
'^[-a-zA-Z0-9.]*$':
anyOf: [
{$ref: '#/definitions/mongoQueryOperator'},
{type: 'string'}
2014-06-30 22:16:26 -04:00
{type: 'object'}
{type: 'boolean'}
]
additionalProperties: false
definitions: {}
AchievementSchema = c.object()
c.extendNamedProperties AchievementSchema
c.extendBasicProperties AchievementSchema, 'achievement'
c.extendSearchableProperties AchievementSchema
2014-08-23 18:51:59 -04:00
AchievementSchema.default =
worth: 10
description: 'Probably the coolest you\'ll ever get.'
difficulty: 1
recalculable: true
function: {}
2014-07-28 08:13:38 -04:00
_.extend AchievementSchema.properties,
query:
#type:'object'
$ref: '#/definitions/mongoFindQuery'
worth: c.float()
2014-06-30 22:16:26 -04:00
collection: {type: 'string'}
2014-08-23 18:51:59 -04:00
description: c.shortString()
userField: c.shortString()
related: c.objectId(description: 'Related entity')
icon: {type: 'string', format: 'image-file', title: 'Icon', description: 'Image should be a 100x100 transparent png.'}
2014-07-28 08:13:38 -04:00
category:
enum: ['level', 'ladder', 'contributor']
description: 'For categorizing and display purposes'
2014-07-28 08:13:38 -04:00
difficulty: c.int
description: 'The higher the more difficult'
proportionalTo:
type: 'string'
description: 'For repeatables only. Denotes the field a repeatable achievement needs for its calculations'
recalculable:
type: 'boolean'
description: 'Deprecated: all achievements must be recalculable now. Used to need to be set to true before it is eligible for recalculation.'
function:
type: 'object'
2014-07-28 08:13:38 -04:00
description: 'Function that gives total experience for X amount achieved'
properties:
kind: {enum: ['linear', 'logarithmic', 'quadratic', 'pow'] }
parameters:
type: 'object'
2014-08-29 19:28:07 -04:00
default: { a: 1, b: 0, c: 0 }
properties:
2014-08-23 18:51:59 -04:00
a: {type: 'number' }
b: {type: 'number' }
c: {type: 'number' }
additionalProperties: true
2014-08-23 18:51:59 -04:00
default: {kind: 'linear', parameters: {}}
required: ['kind', 'parameters']
additionalProperties: false
i18n: {type: 'object', format: 'i18n', props: ['name', 'description'], description: 'Help translate this achievement'}
rewards: c.RewardSchema 'awarded by this achievement'
2014-07-28 08:13:38 -04:00
_.extend AchievementSchema, # Let's have these on the bottom
# TODO We really need some required properties in my opinion but this makes creating new achievements impossible as it is now
#required: ['name', 'description', 'query', 'worth', 'collection', 'userField', 'category', 'difficulty']
2014-07-28 08:13:38 -04:00
additionalProperties: false
AchievementSchema.definitions = {}
AchievementSchema.definitions['mongoQueryOperator'] = MongoQueryOperatorSchema
AchievementSchema.definitions['mongoFindQuery'] = MongoFindQuerySchema
c.extendTranslationCoverageProperties AchievementSchema
c.extendPatchableProperties AchievementSchema
module.exports = AchievementSchema