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

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 2.2 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";
[0c6b92a]8import Stairs from "../shapes/Stairs.js";
9import RenderedStairs from "../rendered_shapes/RenderedStairs.js";
10import {updateShapeCount, getShapeCount} from "./ShapeCount.js";
[d565449]11export default class Factory {
[0c6b92a]12 // BUG KO KE NAPRES REFRESH SA RESETVAT COUNTS!
[d565449]13
[0c6b92a]14 static createShape(shapeType,attrs) {
15 console.log(attrs,"attrs in factory")
16 console.log("position in factory: " + attrs.position.x)
17
18 let scaleX = (attrs.scaleX ? parseFloat(attrs.scaleX) : 1);
19 let scaleY = (attrs.scaleY ? parseFloat(attrs.scaleY) : 1);
20
21 attrs.scaleX = scaleX;
22 attrs.scaleY = scaleY;
[d565449]23
24 switch (shapeType) {
25 case "Entrance":
[0c6b92a]26 if(attrs.increment) updateShapeCount("entrance")
27 return new Entrance(attrs,getShapeCount("entrance"));
[d565449]28 case "Room":
[0c6b92a]29 if(attrs.increment) updateShapeCount("room");
30 return new Room(attrs,getShapeCount("room"));
31 case "Wall":
32 return new Wall(attrs);
33 case "InfoPin":
34 if(attrs.increment) updateShapeCount("infoPin")
35 return new InfoPin(attrs,getShapeCount("infoPin"));
36 case "Stairs":
37 if(attrs.increment) updateShapeCount("stairs")
38 return new Stairs(attrs,getShapeCount("stairs"))
[d565449]39 default:
40 throw new Error("Invalid shape type: " + shapeType);
41 }
42 }
43
44 static createRenderedShape(shapeType,attrs){
45 let scaleX = (attrs.scaleX ? parseFloat(attrs.scaleX) : 1);
46 let scaleY = (attrs.scaleY ? parseFloat(attrs.scaleY) : 1);
47 switch (shapeType) {
48 case "Entrance":
49 return new RenderedEntrance(attrs,scaleX,scaleY);
50 case "Room":
51 return new RenderedRoom(attrs,scaleX,scaleY);
52 case "Wall":
53 return new RenderedWall(attrs,scaleX,scaleY);
[0c6b92a]54 case "Stairs":
55 return new RenderedStairs(attrs,scaleX,scaleY)
[d565449]56 default:
57 throw new Error("Invalid shape type." + shapeType);
58 }
59 }
60}
Note: See TracBrowser for help on using the repository browser.