{"size": 813, "ext": "js", "max_stars_repo_path": "app/models/RandomMetaShapeFactory.js", "max_stars_repo_name": "mis1/tetris", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/models/RandomMetaShapeFactory.js", "max_issues_repo_name": "mis1/tetris", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/models/RandomMetaShapeFactory.js", "max_forks_repo_name": "mis1/tetris", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.1111111111, "max_line_length": 87, "alphanum_fraction": 0.6998769988}
import MetaShape from './MetaShape';
import ShapeFactory from './ShapeFactory';

export default class RandomMetaShapeFactory{
	constructor(metaShapeDefs, shapeFactory){
		this._metaShapeDefs = metaShapeDefs;
		this._shapeFactory = shapeFactory;
		this._keys = Object.keys(metaShapeDefs);	
	}
	createMetaShape(){
		const index = Math.floor(Math.random() * this._keys.length);
		const id = this._keys[index];
		const shapes = this._createShapes(id);
		return new MetaShape(id, shapes);
	}
	_createShapes(id){
		const shapes = [];
		const metaShapeDef = this._metaShapeDefs[id];
		const shapeDefs = metaShapeDef.shapes;
		for(let i=0; i<shapeDefs.length; i++){
			shapes.push(
				this._shapeFactory.createShape(`${id}_${i}`, metaShapeDef.symbols, shapeDefs[i]));
		}
		return shapes;
	}
}
