codecombat/app/schemas/models/level_component.coffee

163 lines
7.1 KiB
CoffeeScript
Raw Normal View History

c = require './../schemas'
metaschema = require './../metaschema'
2014-04-12 04:35:56 -04:00
attackSelfCode = """
class AttacksSelf extends Component
2014-06-30 22:16:26 -04:00
@className: 'AttacksSelf'
2014-04-12 04:35:56 -04:00
chooseAction: ->
@attack @
"""
systems = [
2014-06-30 22:16:26 -04:00
'action', 'ai', 'alliance', 'collision', 'combat', 'display', 'event', 'existence', 'hearing',
2014-04-12 04:35:56 -04:00
'inventory', 'movement', 'programming', 'targeting', 'ui', 'vision', 'misc', 'physics', 'effect',
'magic'
]
PropertyDocumentationSchema = c.object {
2014-06-30 22:16:26 -04:00
title: 'Property Documentation'
description: 'Documentation entry for a property this Component will add to its Thang which other Components might want to also use.'
2014-08-23 19:06:41 -04:00
default:
2014-06-30 22:16:26 -04:00
name: 'foo'
type: 'object'
2014-04-12 04:35:56 -04:00
description: 'The `foo` property can satisfy all the #{spriteName}\'s foobar needs. Use it wisely.'
required: ['name', 'type', 'description']
},
2014-06-30 22:16:26 -04:00
name: {type: 'string', title: 'Name', description: 'Name of the property.'}
codeLanguages: c.array {title: 'Specific Code Languages', description: 'If present, then only the languages specified will show this documentation. Leave unset for language-independent documentation.', format: 'code-languages-array'}, c.shortString(title: 'Code Language', description: 'A specific code language to show this documentation for.', format: 'code-language')
2014-04-12 04:35:56 -04:00
# not actual JS types, just whatever they describe...
2014-06-30 22:16:26 -04:00
type: c.shortString(title: 'Type', description: 'Intended type of the property.')
description:
oneOf: [
{
type: 'object',
2014-06-30 22:16:26 -04:00
title: 'Language Descriptions',
description: 'Property descriptions by code language.',
additionalProperties: {type: 'string', description: 'Description of the property.', maxLength: 1000, format: 'markdown'}
format: 'code-languages-object'
default: {javascript: ''}
}
{title: 'Description', type: 'string', description: 'Description of the property.', maxLength: 1000, format: 'markdown'}
]
2014-06-30 22:16:26 -04:00
args: c.array {title: 'Arguments', description: 'If this property has type "function", then provide documentation for any function arguments.'}, c.FunctionArgumentSchema
owner: {title: 'Owner', type: 'string', description: 'Owner of the property, like "this" or "Math".'}
example:
oneOf: [
{
type: 'object',
2014-06-30 22:16:26 -04:00
title: 'Language Examples',
description: 'Examples by code language.',
additionalProperties: {type: 'string', description: 'An example code block.', format: 'code'}
format: 'code-languages-object'
default: {javascript: ''}
}
{title: 'Example', type: 'string', description: 'An optional example code block.', format: 'javascript'}
]
snippets: {type: 'object', title: 'Snippets', description: 'List of snippets for the respective programming languages', additionalProperties: c.codeSnippet, format: 'code-languages-object'}
2014-04-12 04:35:56 -04:00
returns: c.object {
2014-06-30 22:16:26 -04:00
title: 'Return Value'
2014-04-12 04:35:56 -04:00
description: 'Optional documentation of any return value.'
required: ['type']
default: {type: 'null'}
},
2014-06-30 22:16:26 -04:00
type: c.shortString(title: 'Type', description: 'Type of the return value')
example:
oneOf: [
{
type: 'object',
2014-06-30 22:16:26 -04:00
title: 'Language Examples',
description: 'Example return values by code language.',
additionalProperties: c.shortString(description: 'Example return value.', format: 'code')
format: 'code-languages-object'
default: {javascript: ''}
}
c.shortString(title: 'Example', description: 'Example return value')
]
description:
oneOf: [
{
type: 'object',
2014-06-30 22:16:26 -04:00
title: 'Language Descriptions',
description: 'Example return values by code language.',
additionalProperties: {type: 'string', description: 'Description of the return value.', maxLength: 1000}
format: 'code-languages-object'
default: {javascript: ''}
}
{title: 'Description', type: 'string', description: 'Description of the return value.', maxLength: 1000}
]
2014-04-12 04:35:56 -04:00
DependencySchema = c.object {
2014-06-30 22:16:26 -04:00
title: 'Component Dependency'
description: 'A Component upon which this Component depends.'
required: ['original', 'majorVersion']
2014-04-12 04:35:56 -04:00
format: 'latest-version-reference'
2014-06-30 22:16:26 -04:00
links: [{rel: 'db', href: '/db/level.component/{(original)}/version/{(majorVersion)}'}]
2014-04-12 04:35:56 -04:00
},
2014-06-30 22:16:26 -04:00
original: c.objectId(title: 'Original', description: 'A reference to another Component upon which this Component depends.')
2014-04-12 04:35:56 -04:00
majorVersion:
2014-06-30 22:16:26 -04:00
title: 'Major Version'
description: 'Which major version of the Component this Component needs.'
2014-04-12 04:35:56 -04:00
type: 'integer'
minimum: 0
LevelComponentSchema = c.object {
2014-06-30 22:16:26 -04:00
title: 'Component'
description: 'A Component which can affect Thang behavior.'
required: ['system', 'name', 'description', 'code', 'dependencies', 'propertyDocumentation', 'codeLanguage']
default:
2014-06-30 22:16:26 -04:00
system: 'ai'
name: 'AttacksSelf'
description: 'This Component makes the Thang attack itself.'
2014-04-12 04:35:56 -04:00
code: attackSelfCode
2014-06-30 22:16:26 -04:00
codeLanguage: 'coffeescript'
2014-04-12 04:35:56 -04:00
dependencies: [] # TODO: should depend on something by default
propertyDocumentation: []
2014-08-23 19:06:41 -04:00
configSchema: {}
2014-04-12 04:35:56 -04:00
}
c.extendNamedProperties LevelComponentSchema # let's have the name be the first property
LevelComponentSchema.properties.name.pattern = c.classNamePattern
_.extend LevelComponentSchema.properties,
system:
2014-06-30 22:16:26 -04:00
title: 'System'
description: 'The short name of the System this Component belongs to, like \"ai\".'
type: 'string'
'enum': systems
2014-04-12 04:35:56 -04:00
description:
2014-06-30 22:16:26 -04:00
title: 'Description'
description: 'A short explanation of what this Component does.'
type: 'string'
2014-04-12 04:35:56 -04:00
maxLength: 2000
codeLanguage:
2014-06-30 22:16:26 -04:00
type: 'string'
title: 'Language'
description: 'Which programming language this Component is written in.'
'enum': ['coffeescript']
2014-04-12 04:35:56 -04:00
code:
2014-06-30 22:16:26 -04:00
title: 'Code'
description: 'The code for this Component, as a CoffeeScript class. TODO: add link to documentation for how to write these.'
type: 'string'
format: 'coffee'
2014-04-12 04:35:56 -04:00
js:
2014-06-30 22:16:26 -04:00
title: 'JavaScript'
description: 'The transpiled JavaScript code for this Component'
type: 'string'
format: 'hidden'
2014-08-23 19:06:41 -04:00
dependencies: c.array {title: 'Dependencies', description: 'An array of Components upon which this Component depends.', uniqueItems: true}, DependencySchema
propertyDocumentation: c.array {title: 'Property Documentation', description: 'An array of documentation entries for each notable property this Component will add to its Thang which other Components might want to also use.'}, PropertyDocumentationSchema
2014-09-01 16:51:30 -04:00
configSchema: _.extend metaschema, {title: 'Configuration Schema', description: 'A schema for validating the arguments that can be passed to this Component as configuration.', default: {type: 'object'}}
2014-04-12 04:35:56 -04:00
official:
2014-06-30 22:16:26 -04:00
type: 'boolean'
title: 'Official'
description: 'Whether this is an official CodeCombat Component.'
searchStrings: {
type: 'array'
items: { type: 'string' }
}
2014-04-12 04:35:56 -04:00
c.extendBasicProperties LevelComponentSchema, 'level.component'
c.extendSearchableProperties LevelComponentSchema
c.extendVersionedProperties LevelComponentSchema, 'level.component'
c.extendPermissionsProperties LevelComponentSchema, 'level.component'
c.extendPatchableProperties LevelComponentSchema
2014-04-12 04:35:56 -04:00
module.exports = LevelComponentSchema