24 lines
532 B
JavaScript
24 lines
532 B
JavaScript
import {PolygonShape} from './polygon';
|
|
import {CircleShape} from './circle';
|
|
import {RectangleShape} from './rectangle';
|
|
import {ShapeList} from './list';
|
|
|
|
export function shapeFromJSON(json) {
|
|
let shape;
|
|
switch (json.type) {
|
|
case 'circle':
|
|
shape = new CircleShape();
|
|
break;
|
|
case 'list':
|
|
shape = new ShapeList();
|
|
break;
|
|
case 'polygon':
|
|
shape = new PolygonShape();
|
|
break;
|
|
case 'rectangle':
|
|
shape = new RectangleShape();
|
|
break;
|
|
}
|
|
return shape.fromJSON(json);
|
|
}
|