2014-01-22 17:57:41 -05:00
c = require ' ../../commons/schemas '
metaschema = require ' ../../commons/metaschema '
2014-01-03 13:32:13 -05:00
attackSelfCode = """
class AttacksSelf extends Component
@className: " AttacksSelf "
chooseAction: ->
@ attack @
"""
2014-01-08 14:27:13 -05:00
systems = [
2014-01-29 15:28:57 -05:00
' action ' , ' ai ' , ' alliance ' , ' collision ' , ' combat ' , ' display ' , ' event ' , ' existence ' , ' hearing '
2014-02-05 14:03:32 -05:00
' inventory ' , ' movement ' , ' programming ' , ' targeting ' , ' ui ' , ' vision ' , ' misc ' , ' physics ' , ' effect ' ,
' magic '
2014-01-08 14:27:13 -05:00
]
2014-01-03 13:32:13 -05:00
PropertyDocumentationSchema = c . object {
title: " Property Documentation "
2014-01-08 14:27:13 -05:00
description: " Documentation entry for a property this Component will add to its Thang which other Components might
want to also use . "
2014-01-03 13:32:13 -05:00
" default " :
name: " foo "
type: " object "
2014-02-13 19:09:32 -05:00
description: ' The `foo` property can satisfy all the # {spriteName} \' s foobar needs. Use it wisely. '
2014-01-03 13:32:13 -05:00
required: [ ' name ' , ' type ' , ' description ' ]
} ,
2014-02-12 21:54:45 -05:00
name: { type: ' string ' , title: " Name " , description: " Name of the property. " }
2014-01-08 14:27:13 -05:00
# not actual JS types, just whatever they describe...
type: c . shortString ( title: " Type " , description: " Intended type of the property. " )
2014-02-12 21:54:45 -05:00
description: { title: " Description " , type: ' string ' , description: " Description of the property. " , format: ' markdown ' , maxLength: 1000 }
2014-01-03 13:32:13 -05:00
args: c . array { title: " Arguments " , description: " If this property has type ' function ' , then provide documentation for any function arguments. " } , c . FunctionArgumentSchema
2014-02-12 19:42:09 -05:00
owner: { title: " Owner " , type: ' string ' , description: ' Owner of the property, like " this " or " Math " . ' }
2014-02-12 21:54:45 -05:00
example: { title: " Example " , type: ' string ' , description: ' An optional example code block. ' , format: ' javascript ' }
2014-02-20 14:57:04 -05:00
returns: c . object {
title: " Return Value "
description: ' Optional documentation of any return value. '
required: [ ' type ' ]
default: { type: ' null ' }
} ,
type: c . shortString ( title: " Type " , description: " Type of the return value " )
example: c . shortString ( title: " Example " , description: " Example return value " )
description: { title: " Description " , type: ' string ' , description: " Description of the return value. " , maxLength: 1000 }
2014-01-03 13:32:13 -05:00
DependencySchema = c . object {
title: " Component Dependency "
description: " A Component upon which this Component depends. "
" default " :
#original: ?
majorVersion: 0
required: [ " original " , " majorVersion " ]
format: ' latest-version-reference '
links: [ { rel: " db " , href: " /db/level.component/{(original)}/version/{(majorVersion)} " } ]
} ,
original: c . objectId ( title: " Original " , description: " A reference to another Component upon which this Component depends. " )
2014-01-08 14:27:13 -05:00
majorVersion:
title: " Major Version "
description: " Which major version of the Component this Component needs. "
type: ' integer '
minimum: 0
2014-01-03 13:32:13 -05:00
LevelComponentSchema = c . object {
title: " Component "
description: " A Component which can affect Thang behavior. "
required: [ " system " , " name " , " description " , " code " , " dependencies " , " propertyDocumentation " , " language " ]
" default " :
system: " ai "
name: " AttacksSelf "
description: " This Component makes the Thang attack itself. "
code: attackSelfCode
language: " coffeescript "
dependencies: [ ] # TODO: should depend on something by default
propertyDocumentation: [ ]
}
c . extendNamedProperties LevelComponentSchema # let's have the name be the first property
LevelComponentSchema.properties.name.pattern = c . classNamePattern
_ . extend LevelComponentSchema . properties ,
2014-01-08 14:27:13 -05:00
system:
title: " System "
description: " The short name of the System this Component belongs to, like \" ai \" . "
type: " string "
" enum " : systems
" default " : " ai "
description:
title: " Description "
description: " A short explanation of what this Component does. "
type: " string "
maxLength: 2000
" default " : " This Component makes the Thang attack itself. "
language:
type: " string "
title: " Language "
description: " Which programming language this Component is written in. "
" enum " : [ " coffeescript " ]
code:
title: " Code "
description: " The code for this Component, as a CoffeeScript class. TODO: add link to documentation for
how to write these . "
" default " : attackSelfCode
type: " string "
format: " coffee "
js:
title: " JavaScript "
description: " The transpiled JavaScript code for this Component "
type: " string "
format: " hidden "
2014-01-03 13:32:13 -05:00
dependencies: c . array { title: " Dependencies " , description: " An array of Components upon which this Component depends. " , " default " : [ ] , 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. " , " default " : [ ] } , PropertyDocumentationSchema
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 ' , additionalProperties: false } }
2014-01-08 14:27:13 -05:00
official:
type: " boolean "
title: " Official "
description: " Whether this is an official CodeCombat Component. "
" default " : false
2014-01-03 13:32:13 -05:00
c . extendBasicProperties LevelComponentSchema , ' level.component '
c . extendSearchableProperties LevelComponentSchema
c . extendVersionedProperties LevelComponentSchema , ' level.component '
c . extendPermissionsProperties LevelComponentSchema , ' level.component '
module.exports = LevelComponentSchema