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

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.3 KB
Line 
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";
8import Stairs from "../shapes/Stairs.js";
9import RenderedStairs from "../rendered_shapes/RenderedStairs.js";
10import {updateShapeCount, getShapeCount} from "./ShapeCount.js";
11export default class Factory {
12 // BUG KO KE NAPRES REFRESH SA RESETVAT COUNTS!
13
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;
23
24 switch (shapeType) {
25 case "Entrance":
26 if(attrs.increment) updateShapeCount("entrance")
27 return new Entrance(attrs,getShapeCount("entrance"));
28 case "Room":
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"))
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
48 attrs.width *= scaleX;
49 attrs.height *= scaleY
50
51 console.log("SCALEX " + scaleX)
52 console.log("SCALEY " + scaleY)
53 switch (shapeType) {
54 case "Entrance":
55 return new RenderedEntrance(attrs,scaleX,scaleY);
56 case "Room":
57 return new RenderedRoom(attrs,scaleX,scaleY);
58 case "Wall":
59 return new RenderedWall(attrs,scaleX,scaleY);
60 case "Stairs":
61 return new RenderedStairs(attrs,scaleX,scaleY)
62 default:
63 throw new Error("Invalid shape type." + shapeType);
64 }
65 }
66}
Note: See TracBrowser for help on using the repository browser.