var Scenery = new function(){ var base = this; base.list = {} base.nextMedia = null base.mouse = new mouse ({ use_offset: false }) base.init = function(){ base.resize.init() } base.add = function(opt){ var scene_media switch (opt.media.type) { case 'image': scene_media = new Scenery.types.image (opt) break case 'video': case 'youtube': case 'vimeo': scene_media = new Scenery.types.video (opt) break } base.list[scene_media.id] = scene_media return scene_media } base.addNextToWall = function(opt){ opt.media = base.nextMedia opt.index = opt.index || 0 var scene_media = base.add(opt) // test if scenery was placed here if (! scene_media.bounds) { base.remove( scene_media.id ) return null } else { base.nextMedia = null return scene_media } } base.find = function(id){ return base.list[id] || null } base.remove = function(id){ var scene_media = base.list[id] delete base.list[id] scene_media && scene_media.destroy() } base.removeAll = function(){ base.forEach(function(scene_media){ base.remove(scene_media.id) }) } base.uid = new UidGenerator(base.list) base.forEach = function(f){ return base.values().forEach(f) } base.map = function(f){ return base.values().map(f) } base.values = function(){ return _.values(base.list) } base.serialize = function(){ var scenery = base.map(function(media){ return media.serialize() }) return scenery } base.deserialize = function(scenery_data){ scenery_data.forEach(function(data){ var wall = Rooms.walls[data.wall_id] var scene_media = base.add({ data: data, wall: wall, media: data.media, id: data.id }) }) } return base } Scenery.types = {}