Don't require CocoModel instantiation before schemas are included. Reload neutral spells on reload. Fix for adding Components to Thangs. Surface background: darkness, no parents.

This commit is contained in:
Nick Winter 2014-04-22 11:11:08 -07:00
parent 1e50ef36ce
commit 675db1b76f
16 changed files with 32 additions and 22 deletions

View file

@ -2,5 +2,6 @@ CocoModel = require('./CocoModel')
module.exports = class Article extends CocoModel module.exports = class Article extends CocoModel
@className: "Article" @className: "Article"
@schema: require 'schemas/models/article'
urlRoot: "/db/article" urlRoot: "/db/article"
saveBackups: true saveBackups: true

View file

@ -11,7 +11,6 @@ class CocoModel extends Backbone.Model
initialize: -> initialize: ->
super() super()
@constructor.schema ?= require "schemas/models/#{@urlRoot[4..].replace '.', '_'}"
if not @constructor.className if not @constructor.className
console.error("#{@} needs a className set.") console.error("#{@} needs a className set.")
@markToRevert() @markToRevert()
@ -223,7 +222,7 @@ class CocoModel extends Backbone.Model
watch: (doWatch=true) -> watch: (doWatch=true) ->
$.ajax("#{@urlRoot}/#{@id}/watch", {type:'PUT', data:{on:doWatch}}) $.ajax("#{@urlRoot}/#{@id}/watch", {type:'PUT', data:{on:doWatch}})
@watching = -> doWatch @watching = -> doWatch
watching: -> watching: ->
return me.id in (@get('watchers') or []) return me.id in (@get('watchers') or [])

View file

@ -2,4 +2,5 @@ CocoModel = require('./CocoModel')
module.exports = class File extends CocoModel module.exports = class File extends CocoModel
@className: "File" @className: "File"
urlRoot: "/db/file" @schema: require 'schemas/models/file'
urlRoot: "/db/file"

View file

@ -5,6 +5,7 @@ ThangType = require './ThangType'
module.exports = class Level extends CocoModel module.exports = class Level extends CocoModel
@className: "Level" @className: "Level"
@schema: require 'schemas/models/level'
urlRoot: "/db/level" urlRoot: "/db/level"
serialize: (supermodel) -> serialize: (supermodel) ->

View file

@ -2,6 +2,7 @@ CocoModel = require('./CocoModel')
module.exports = class LevelComponent extends CocoModel module.exports = class LevelComponent extends CocoModel
@className: "LevelComponent" @className: "LevelComponent"
@schema: require 'schemas/models/level_component'
urlRoot: "/db/level.component" urlRoot: "/db/level.component"
set: (key, val, options) -> set: (key, val, options) ->

View file

@ -2,4 +2,5 @@ CocoModel = require('./CocoModel')
module.exports = class LevelFeedback extends CocoModel module.exports = class LevelFeedback extends CocoModel
@className: "LevelFeedback" @className: "LevelFeedback"
@schema: require 'schemas/models/level_feedback'
urlRoot: "/db/level.feedback" urlRoot: "/db/level.feedback"

View file

@ -2,6 +2,7 @@ CocoModel = require('./CocoModel')
module.exports = class LevelSession extends CocoModel module.exports = class LevelSession extends CocoModel
@className: "LevelSession" @className: "LevelSession"
@schema: require 'schemas/models/level_session'
urlRoot: "/db/level.session" urlRoot: "/db/level.session"
initialize: -> initialize: ->
@ -10,7 +11,7 @@ module.exports = class LevelSession extends CocoModel
state = @get('state') or {} state = @get('state') or {}
state.scripts ?= {} state.scripts ?= {}
@set('state', state) @set('state', state)
updatePermissions: -> updatePermissions: ->
permissions = @get 'permissions' permissions = @get 'permissions'
permissions = (p for p in permissions when p.target isnt 'public') permissions = (p for p in permissions when p.target isnt 'public')

View file

@ -3,6 +3,7 @@ SystemNameLoader = require('lib/SystemNameLoader')
module.exports = class LevelSystem extends CocoModel module.exports = class LevelSystem extends CocoModel
@className: "LevelSystem" @className: "LevelSystem"
@schema: require 'schemas/models/level_system'
urlRoot: "/db/level.system" urlRoot: "/db/level.system"
set: (key, val, options) -> set: (key, val, options) ->

View file

@ -2,10 +2,11 @@ CocoModel = require('./CocoModel')
module.exports = class PatchModel extends CocoModel module.exports = class PatchModel extends CocoModel
@className: "Patch" @className: "Patch"
urlRoot: "/db/patch" @schema: require 'schemas/models/patch'
urlRoot: "/db/patch"
setStatus: (status) -> setStatus: (status) ->
PatchModel.setStatus @id, status PatchModel.setStatus @id, status
@setStatus: (id, status) -> @setStatus: (id, status) ->
$.ajax("/db/patch/#{id}/status", {type:"PUT", data: {status:status}}) $.ajax("/db/patch/#{id}/status", {type:"PUT", data: {status:status}})

View file

@ -5,6 +5,7 @@ buildQueue = []
module.exports = class ThangType extends CocoModel module.exports = class ThangType extends CocoModel
@className: "ThangType" @className: "ThangType"
@schema: require 'schemas/models/thang_type'
urlRoot: "/db/thang.type" urlRoot: "/db/thang.type"
building: {} building: {}

View file

@ -4,6 +4,7 @@ CocoModel = require('./CocoModel')
module.exports = class User extends CocoModel module.exports = class User extends CocoModel
@className: "User" @className: "User"
@schema: require 'schemas/models/user'
urlRoot: "/db/user" urlRoot: "/db/user"
initialize: -> initialize: ->

View file

@ -1,5 +1,5 @@
c = require './../schemas' c = require './../schemas'
ThangComponentSchema = require './../models/thang_component' ThangComponentSchema = require './thang_component'
SpecificArticleSchema = c.object() SpecificArticleSchema = c.object()
c.extendNamedProperties SpecificArticleSchema # name first c.extendNamedProperties SpecificArticleSchema # name first

View file

@ -18,7 +18,7 @@ body.is-playing
position: relative position: relative
canvas#surface canvas#surface
background-color: #ddd background-color: #333
width: 100% width: 100%
display: block display: block
z-index: 1 z-index: 1

View file

@ -156,17 +156,18 @@ module.exports = class ThangComponentEditView extends CocoView
@reportChanges() @reportChanges()
onAddComponentEnterPressed: (node) => onAddComponentEnterPressed: (node) =>
extantSystems = if extantSystems
(@supermodel.getModelByOriginalAndMajorVersion LevelSystem, sn.original, sn.majorVersion).attributes.name.toLowerCase() for idx, sn of @level.get('systems') extantSystems =
requireSystem = node.data.system.toLowerCase() (@supermodel.getModelByOriginalAndMajorVersion LevelSystem, sn.original, sn.majorVersion).attributes.name.toLowerCase() for idx, sn of @level.get('systems')
requireSystem = node.data.system.toLowerCase()
if requireSystem not in extantSystems if requireSystem not in extantSystems
warn_element = 'Component <b>' + node.data.name + '</b> requires system <b>' + requireSystem + '</b> which is currently not specified in this level.' warn_element = 'Component <b>' + node.data.name + '</b> requires system <b>' + requireSystem + '</b> which is currently not specified in this level.'
noty({ noty({
text: warn_element, text: warn_element,
layout: 'bottomLeft', layout: 'bottomLeft',
type: 'warning' type: 'warning'
}) })
currentSelection = @addComponentsTreema?.getLastSelectedTreema()?.data._id currentSelection = @addComponentsTreema?.getLastSelectedTreema()?.data._id

View file

@ -112,7 +112,7 @@ module.exports = class PlaybackView extends View
@$el.find('.toggle-fullscreen').hide() @$el.find('.toggle-fullscreen').hide()
updatePopupContent: -> updatePopupContent: ->
@timePopup.updateContent "<h2>#{@timeToString @newTime}</h2>#{@formatTime(@current, @currentTime)}<br/>#{@formatTime(@total, @totalTime)}" @timePopup?.updateContent "<h2>#{@timeToString @newTime}</h2>#{@formatTime(@current, @currentTime)}<br/>#{@formatTime(@total, @totalTime)}"
# These functions could go to some helper class # These functions could go to some helper class

View file

@ -222,7 +222,7 @@ module.exports = class TomeView extends View
@spellPaletteView.toggleControls {}, spell.view.controlsEnabled # TODO: know when palette should have been disabled but didn't exist @spellPaletteView.toggleControls {}, spell.view.controlsEnabled # TODO: know when palette should have been disabled but didn't exist
reloadAllCode: -> reloadAllCode: ->
spell.view.reloadCode false for spellKey, spell of @spells when spell.team is me.team spell.view.reloadCode false for spellKey, spell of @spells when spell.team is me.team or (spell.team in ["common", "neutral", null])
Backbone.Mediator.publish 'tome:cast-spells', spells: @spells Backbone.Mediator.publish 'tome:cast-spells', spells: @spells
updateLanguageForAllSpells: -> updateLanguageForAllSpells: ->