source: imaps-frontend/src/scripts/util/Factory.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[d565449]1import Entrance from "../shapes/Entrance";
2import Wall from "../shapes/Wall";
3import Room from "../shapes/Room";
4import InfoPin from "../shapes/InfoPin";
5import RenderedRoom from "../rendered_shapes/RenderedRoom";
6import RenderedEntrance from "../rendered_shapes/RenderedEntrance";
7import RenderedWall from "../rendered_shapes/RenderedWall.js";
8export 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}
Note: See TracBrowser for help on using the repository browser.