'use strict';

// Convenience instance. Instance of Scene with create method simplified.
angular.module('tabletop').factory('scene', ['Scene', 'stateMachine', 'grid',
function(Scene, stateMachine, grid) {

	var scene = new Scene();

	scene._init = function(svg) {
		this.create(svg);

		var gridLayer = this.layer('grid', true);
		this.layer('selection', true);
		this.layer('avatar');

		var defs = this.defs;

		grid.watch(function() {
			defs.append(grid.pattern);
			gridLayer.append(grid.overlay);
		});
	};

	scene.onScene = function(eventName, listener) {
		this.scene.on(eventName+'.scene', function() {
			listener(d3.mouse(scene.isoGroup.node()));
		});
	};
	
	return scene;
}]);