codecombat/app/schemas/models/achievement.coffee

86 lines
2.8 KiB
CoffeeScript
Raw Normal View History

c = require './../schemas'
# TODO add these: http://docs.mongodb.org/manual/reference/operator/query/
MongoQueryOperatorSchema =
title: 'MongoDB Query operator'
id: 'mongoQueryOperator'
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'
additionalProperties: true # TODO set to false when the schema's done
MongoFindQuerySchema =
title: 'MongoDB Query'
id: 'mongoFindQuery'
type: 'object'
patternProperties:
#'^[-a-zA-Z0-9_]*$':
'^[-a-zA-Z0-9\.]*$':
oneOf: [
2014-06-30 22:16:26 -04:00
#{$ref: '#/definitions/' + MongoQueryOperatorSchema.id},
{type: 'string'}
2014-06-30 22:16:26 -04:00
{type: 'object'}
{type: 'boolean'}
]
additionalProperties: true # TODO make Treema accept new pattern matched keys
definitions: {}
MongoFindQuerySchema.definitions[MongoQueryOperatorSchema.id] = MongoQueryOperatorSchema
AchievementSchema = c.object()
c.extendNamedProperties AchievementSchema
2014-07-28 08:13:38 -04:00
c.extendBasicProperties AchievementSchema, 'achievement' # TODO What's this about?
c.extendSearchableProperties AchievementSchema
2014-07-28 08:13:38 -04:00
_.extend AchievementSchema.properties,
query:
#type:'object'
$ref: '#/definitions/' + MongoFindQuerySchema.id
2014-06-30 22:16:26 -04:00
worth: {type: 'number'}
collection: {type: 'string'}
description: {type: 'string'}
userField: {type: 'string'}
related: c.objectId(description: 'Related entity')
2014-06-30 22:16:26 -04:00
icon: {type: 'string', format: 'image-file', title: 'Icon'}
2014-07-28 08:13:38 -04:00
category:
type: 'string'
description: "E.g. 'level', 'ladder', 'contributor'..." # TODO might make this enum?
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: 'Needs to be set to true before it is elligible 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'], default: 'linear'}
parameters:
type: 'object'
properties:
a: {type: 'number', default: 1}
b: {type: 'number', default: 1}
c: {type: 'number', default: 1}
additionalProperties: true
default: {kind: 'linear', parameters: a: 1}
required: ['kind', 'parameters']
additionalProperties: false
2014-07-28 08:13:38 -04:00
_.extend AchievementSchema, # Let's have these on the bottom
required: ['name', 'description', 'query', 'worth', 'collection', 'userField', 'category', 'difficulty']
2014-07-28 08:13:38 -04:00
additionalProperties: false
AchievementSchema.definitions = {}
AchievementSchema.definitions[MongoFindQuerySchema.id] = MongoFindQuerySchema
module.exports = AchievementSchema