[d565449] | 1 | import Entrance from "../shapes/Entrance";
|
---|
| 2 | import Wall from "../shapes/Wall";
|
---|
| 3 | import Room from "../shapes/Room";
|
---|
| 4 | import InfoPin from "../shapes/InfoPin";
|
---|
| 5 | import RenderedRoom from "../rendered_shapes/RenderedRoom";
|
---|
| 6 | import RenderedEntrance from "../rendered_shapes/RenderedEntrance";
|
---|
| 7 | import RenderedWall from "../rendered_shapes/RenderedWall.js";
|
---|
| 8 | export default class Factory {
|
---|
| 9 |
|
---|
| 10 | static infoPinCount = 0;
|
---|
| 11 | static wallCount = 0;
|
---|
| 12 | static entranceCount = 0;
|
---|
| 13 | static roomCount = 0;
|
---|
| 14 |
|
---|
| 15 | static createShape(shapeType, position, blockSize, layer, rotation,scaleX = 1, scaleY = 1, increment = false) {
|
---|
| 16 | switch (shapeType) {
|
---|
| 17 | case "Entrance":
|
---|
| 18 | if(increment) this.entranceCount++;
|
---|
| 19 | return new Entrance(position, blockSize, layer, rotation,true,this.entranceCount,scaleX,scaleY);
|
---|
| 20 | case "Room":
|
---|
| 21 | if(increment) this.roomCount++;
|
---|
| 22 | return new Room(position, blockSize, layer, rotation,true, this.roomCount,scaleX,scaleY);
|
---|
| 23 | case "Wall":
|
---|
| 24 | return new Wall(position, blockSize, layer, rotation,true,scaleX,scaleY);
|
---|
| 25 | case "InfoPin":
|
---|
| 26 | if(increment) this.infoPinCount++;
|
---|
| 27 | return new InfoPin(position, blockSize, layer, false,this.infoPinCount);
|
---|
| 28 | default:
|
---|
| 29 | throw new Error("Invalid shape type: " + shapeType);
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | static createRenderedShape(shapeType,attrs){
|
---|
| 34 | let scaleX = (attrs.scaleX ? parseFloat(attrs.scaleX) : 1);
|
---|
| 35 | let scaleY = (attrs.scaleY ? parseFloat(attrs.scaleY) : 1);
|
---|
| 36 | switch (shapeType) {
|
---|
| 37 | case "Entrance":
|
---|
| 38 | return new RenderedEntrance(attrs,scaleX,scaleY);
|
---|
| 39 | case "Room":
|
---|
| 40 | return new RenderedRoom(attrs,scaleX,scaleY);
|
---|
| 41 | case "Wall":
|
---|
| 42 | return new RenderedWall(attrs,scaleX,scaleY);
|
---|
| 43 | default:
|
---|
| 44 | throw new Error("Invalid shape type." + shapeType);
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | }
|
---|