2014-06-30 22:16:26 -04:00
|
|
|
CocoModel = require './CocoModel'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
module.exports = class LevelComponent extends CocoModel
|
2014-06-30 22:16:26 -04:00
|
|
|
@className: 'LevelComponent'
|
2014-04-22 14:11:08 -04:00
|
|
|
@schema: require 'schemas/models/level_component'
|
2014-09-02 14:29:24 -04:00
|
|
|
|
2014-08-07 21:27:47 -04:00
|
|
|
@EquipsID: '53e217d253457600003e3ebb'
|
2014-08-13 20:21:37 -04:00
|
|
|
@ItemID: '53e12043b82921000051cdf9'
|
|
|
|
@AttacksID: '524b7ba57fc0f6d519000016'
|
2014-09-02 14:29:24 -04:00
|
|
|
@PhysicalID: '524b75ad7fc0f6d519000001'
|
|
|
|
@ExistsID: '524b4150ff92f1f4f8000024'
|
|
|
|
@LandID: '524b7aff7fc0f6d519000006'
|
|
|
|
@CollidesID: '524b7b857fc0f6d519000012'
|
2014-09-15 16:15:18 -04:00
|
|
|
@PlansID: '524b7b517fc0f6d51900000d'
|
2014-10-29 00:15:41 -04:00
|
|
|
@ProgrammableID: '524b7b5a7fc0f6d51900000e'
|
2014-11-05 16:28:54 -05:00
|
|
|
@MovesID: '524b7b8c7fc0f6d519000013'
|
2015-01-01 16:47:42 -05:00
|
|
|
@MissileID: '524cc2593ea855e0ab000142'
|
2015-02-22 14:07:46 -05:00
|
|
|
@FindsPathsID: '52872b0ead92b98561000002'
|
2014-06-30 22:16:26 -04:00
|
|
|
urlRoot: '/db/level.component'
|
2015-02-25 21:41:39 -05:00
|
|
|
editableByArtisans: true
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
set: (key, val, options) ->
|
|
|
|
if _.isObject key
|
|
|
|
[attrs, options] = [key, val]
|
|
|
|
else
|
|
|
|
(attrs = {})[key] = val
|
|
|
|
if 'code' of attrs and not ('js' of attrs)
|
|
|
|
attrs.js = @compile attrs.code
|
|
|
|
super attrs, options
|
|
|
|
|
2014-02-11 18:47:59 -05:00
|
|
|
onLoaded: ->
|
2014-01-03 13:32:13 -05:00
|
|
|
super()
|
|
|
|
@set 'js', @compile(@get 'code') unless @get 'js'
|
|
|
|
|
|
|
|
compile: (code) ->
|
2014-06-10 16:20:14 -04:00
|
|
|
if @get('codeLanguage') and @get('codeLanguage') isnt 'coffeescript'
|
2014-06-30 22:16:26 -04:00
|
|
|
return console.error('Can\'t compile', @get('codeLanguage'), '-- only CoffeeScript.', @)
|
2014-01-03 13:32:13 -05:00
|
|
|
try
|
|
|
|
js = CoffeeScript.compile(code, bare: true)
|
|
|
|
catch e
|
2014-06-30 22:16:26 -04:00
|
|
|
#console.log 'couldn\'t compile', code, 'for', @get('name'), 'because', e
|
2014-01-03 13:32:13 -05:00
|
|
|
js = @get 'js'
|
|
|
|
js
|
|
|
|
|
|
|
|
getDependencies: (allComponents) ->
|
|
|
|
results = []
|
|
|
|
for dep in @get('dependencies') or []
|
|
|
|
comp = _.find allComponents, (c) ->
|
|
|
|
c.get('original') is dep.original and c.get('version').major is dep.majorVersion
|
|
|
|
for result in comp.getDependencies(allComponents).concat [comp]
|
|
|
|
results.push result unless result in results
|
|
|
|
results
|