codecombat/app/schemas/models/level_system.coffee

84 lines
3.1 KiB
CoffeeScript
Raw Normal View History

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
"""
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', 'code']
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
configSchema: {}
2014-04-12 04:35:56 -04:00
}
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
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
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'
c.extendPermissionsProperties LevelSystemSchema
c.extendPatchableProperties LevelSystemSchema
2014-04-12 04:35:56 -04:00
module.exports = LevelSystemSchema