2014-04-12 13:51:02 -04:00
c = require ' ./../schemas '
metaschema = require ' ./../metaschema '
2014-04-12 04:35:56 -04:00
jitterSystemCode = """
class Jitter extends System
constructor: (world, config) ->
super world , config
@idlers = @ addRegistry (thang) -> thang . exists and thang . acts and thang . moves and thang . action is ' idle '
update: ->
# We return a simple numeric hash that will combine to a frame hash
# help us determine whether this frame has changed in resimulations.
hash = 0
for thang in @ idlers
hash += thang . pos . x += 0.5 - Math . random ( )
hash += thang . pos . y += 0.5 - Math . random ( )
thang.hasMoved = true
return hash
"""
PropertyDocumentationSchema = c . object {
2014-06-30 22:16:26 -04:00
title: ' Property Documentation '
description: ' Documentation entry for a property this System will add to its Thang which other Systems 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 '
description: ' This System provides a " foo " property to satisfy all one \' s foobar needs. Use it wisely. '
2014-04-12 04:35:56 -04:00
required: [ ' name ' , ' type ' , ' description ' ]
} ,
2014-06-30 22:16:26 -04:00
name: { type: ' string ' , pattern: c . identifierPattern , title: ' Name ' , description: ' Name of the property. ' }
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: { type: ' string ' , description: ' Description of the property. ' , maxLength: 1000 }
args: c . array { title: ' Arguments ' , description: ' If this property has type " function " , then provide documentation for any function arguments. ' } , c . FunctionArgumentSchema
2014-04-12 04:35:56 -04:00
DependencySchema = c . object {
2014-06-30 22:16:26 -04:00
title: ' System Dependency '
description: ' A System upon which this System 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.system/{(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 System upon which this System 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 System this System needs. '
2014-04-12 04:35:56 -04:00
type: ' integer '
minimum: 0
LevelSystemSchema = c . object {
2014-06-30 22:16:26 -04:00
title: ' System '
description: ' A System which can affect Level behavior. '
required: [ ' name ' , ' description ' , ' code ' , ' dependencies ' , ' propertyDocumentation ' , ' codeLanguage ' ]
2014-08-23 19:06:41 -04:00
default:
2014-06-30 22:16:26 -04:00
name: ' JitterSystem '
description: ' This System makes all idle, movable Thangs jitter around. '
2014-04-12 04:35:56 -04:00
code: jitterSystemCode
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: [ ]
}
c . extendNamedProperties LevelSystemSchema # let's have the name be the first property
LevelSystemSchema.properties.name.pattern = c . classNamePattern
_ . extend LevelSystemSchema . properties ,
description:
2014-06-30 22:16:26 -04:00
title: ' Description '
description: ' A short explanation of what this System does. '
type: ' string '
2014-04-12 04:35:56 -04:00
maxLength: 2000
2014-06-10 16:20:14 -04:00
codeLanguage:
2014-06-30 22:16:26 -04:00
type: ' string '
title: ' Language '
description: ' Which programming language this System 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 System, 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 System '
type: ' string '
format: ' hidden '
2014-08-23 19:06:41 -04:00
dependencies: c . array { title: ' Dependencies ' , description: ' An array of Systems upon which this System depends. ' , uniqueItems: true } , DependencySchema
propertyDocumentation: c . array { title: ' Property Documentation ' , description: ' An array of documentation entries for each notable property this System will add to its Level which other Systems might want to also use. ' } , PropertyDocumentationSchema
2014-06-30 22:16:26 -04:00
configSchema: _ . extend metaschema , { title: ' Configuration Schema ' , description: ' A schema for validating the arguments that can be passed to this System as configuration. ' , default: { type: ' object ' , additionalProperties: false } }
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 System. '
2014-04-12 04:35:56 -04:00
c . extendBasicProperties LevelSystemSchema , ' level.system '
c . extendSearchableProperties LevelSystemSchema
c . extendVersionedProperties LevelSystemSchema , ' level.system '
2014-04-12 04:46:41 -04:00
c . extendPermissionsProperties LevelSystemSchema
c . extendPatchableProperties LevelSystemSchema
2014-04-12 04:35:56 -04:00
module.exports = LevelSystemSchema