codecombat/app/models/LevelSession.coffee

27 lines
743 B
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
CocoModel = require('./CocoModel')
module.exports = class LevelSession extends CocoModel
@className: "LevelSession"
@schema: require 'schemas/models/level_session'
2014-01-03 13:32:13 -05:00
urlRoot: "/db/level.session"
initialize: ->
super()
@on 'sync', (e) =>
state = @get('state') or {}
state.scripts ?= {}
@set('state', state)
2014-01-03 13:32:13 -05:00
updatePermissions: ->
permissions = @get 'permissions'
permissions = (p for p in permissions when p.target isnt 'public')
if @get('multiplayer')
permissions.push {target:'public', access:'write'}
@set 'permissions', permissions
getSourceFor: (spellKey) ->
# spellKey ex: 'tharin/plan'
code = @get('code')
parts = spellKey.split '/'
code?[parts[0]]?[parts[1]]