Ignore:
Timestamp:
01/21/25 03:08:24 (3 days ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
0c6b92a
Message:

F4 Finalna Verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/src/scripts/main/MapBuilder.js

    r0c6b92a r79a0317  
    2121
    2222        // TODO AKO DRAGNIT NEKOJ OD POCETOK NA STAGE POZICIIVE KE SA ZEZNAT
    23         // TODO jwt vo cookie
    2423        // TODO placed shape i mouseMoveHandler da ne callback ( da ne vrakjat funkcija)
    2524        // TODO text na top layer sekogas
     
    3534        this.textLayer = new Konva.Layer();
    3635        this.gridLayer.listening(false);
     36
     37        this.isDrawEventBound = false;
    3738
    3839
     
    9697    setupEventListeners() {
    9798        document.getElementById("shapeOptions").addEventListener("click", this.selectShape.bind(this));
    98         window.addEventListener("keydown", this.handleExitSelection.bind(this));
    99         window.addEventListener("keydown", this.handleDelete.bind(this));
    100         window.addEventListener("keydown", this.rotateShapesBy90Deg.bind(this));
    101         window.addEventListener("keydown", this.toggleEfficientDrawingMode.bind(this));
     99        // window.addEventListener("keydown", this.handleExitSelection.bind(this));
     100        // window.addEventListener("keydown", this.handleDelete.bind(this));
     101        // window.addEventListener("keydown", this.rotateShapesBy90Deg.bind(this));
     102        // window.addEventListener("keydown", this.toggleEfficientDrawingMode.bind(this));
    102103        window.addEventListener("resize", this.handleResize.bind(this));
    103104
     
    107108        this.boundEfficientDrawingModeEventListener = this.toggleEfficientDrawingMode.bind(this);
    108109
    109         //this.attachKeyPressEventListeners();
     110        this.attachKeyPressEventListeners();
    110111
    111112        this.stage.on("mousedown touchstart", this.handleMouseDown.bind(this));
     
    119120
    120121    detachKeyPressEventListeners() {
     122        console.log("DETACH")
    121123        window.removeEventListener("keydown", this.boundEscapeEventListener);
    122124        window.removeEventListener("keydown", this.boundDeleteEventListener);
     
    126128
    127129    attachKeyPressEventListeners() {
     130        console.log("ATTACH")
    128131        window.addEventListener("keydown", this.boundEscapeEventListener);
    129132        window.addEventListener("keydown", this.boundDeleteEventListener);
     
    269272        let infoPin = Factory.createShape("InfoPin", attrs);
    270273        addEventHandling(infoPin, this, "dblclick");
    271         //this.shapes.push(infoPin);
    272274        ShapeRegistry.add(infoPin)
    273275        this.mainLayer.add(infoPin);
     
    307309
    308310        const placedObj = Factory.createShape(this.hoverObj.type, attrs);
     311
    309312        if (!placedObj) return;
    310313
     
    312315
    313316        this.mainLayer.add(placedObj);
    314         //this.shapes.push(placedObj);
    315         console.log("VO PLACED SHAEPS WALL ZITI SE: " + placedObj.className);
    316317        ShapeRegistry.add(placedObj);
    317318        addEventHandling(placedObj, this, "dblclick");
    318319        this.mainLayer.draw();
    319 
    320320        // site ovie func da se vo edna funkcija vo shape.
    321321
    322322        placedObj.displayName(this.textLayer);
    323323        placedObj.snapToGrid();
     324        placedObj.onPlace();
    324325
    325326        triggerMapSave();
     
    328329            this.stopDrawing();
    329330        }
     331        this.mainTransformer.nodes([])
    330332    }
    331333
    332334    stopDrawing() {
    333         this.mainTransformer.nodes([]);
    334         if (this.hoverObj != null) this.hoverObj.remove();
    335         this.dragLayer.removeChildren();
    336         this.stage.off("mousemove", this.boundMouseMoveHandler);
    337         this.stage.off("click", this.boundPlaceShapeHandler);
     335        if(this.isDrawEventBound){
     336            this.mainTransformer.nodes([]);
     337            if (this.hoverObj != null) this.hoverObj.remove();
     338            this.dragLayer.removeChildren();
     339            this.stage.off("mousemove", this.boundMouseMoveHandler);
     340            this.stage.off("click", this.boundPlaceShapeHandler);
     341            this.isDrawEventBound = false;
     342        }
     343
    338344    }
    339345
     
    365371        this.dragLayer.add(this.hoverObj);
    366372        this.dragLayer.moveToTop();
     373
     374
    367375        this.boundMouseMoveHandler = this.mouseMoveHandler.bind(this);
    368376        this.boundPlaceShapeHandler = this.placeShape.bind(this);
     377        this.isDrawEventBound = true;
    369378
    370379        this.stage.on("mousemove", this.boundMouseMoveHandler);
     
    374383    selectShape(e) {
    375384        if (e.target.tagName === "LI") {
     385          this.stopDrawing()
    376386            const shapeType = e.target.getAttribute("data-info");
    377387            this.startDrawing(shapeType);
    378             this.mainTransformer.nodes([]);
     388            this.mainTransformer.nodes([])
    379389        }
    380390    }
     
    464474
    465475    saveShapeDetails() {
    466         // this.shapes.forEach(shape => {
    467         //     shape.saveShapeDetails();
    468         //     console.log(shape.info);
    469         // });
    470476        ShapeRegistry.saveDetails();
    471477        console.log("thisflornum",this.floorNum)
     
    478484    }
    479485
    480     getPayload(){
    481         this.saveShapeDetails();
    482         return {
    483             shapes: ShapeRegistry.getShapes(this.floorNum),
    484             roomTypes: JSON.stringify(this.roomTypes),
    485             mapName: this.mapName,
    486             floorNum: this.floorNum
    487         }
    488     }
    489486
    490487
    491488    handleStageClick(e) {
    492489        if (this.selectionRectangle.visible()) {
     490            console.log("STAGECLICK1")
    493491            return;
    494492        }
    495493
    496494        if (e.target === this.stage) {
     495            console.log("STAGECLICK2")
    497496            this.mainTransformer.nodes([]);
    498497            return;
     
    500499
    501500        if (!e.target.hasName("mapObj")) {
     501            console.log("STAGECLICK3")
    502502            return;
    503503        }
     
    505505        const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
    506506        const isSelected = this.mainTransformer.nodes().indexOf(e.target) >= 0;
     507
    507508
    508509        if (!metaPressed && !isSelected) {
     
    527528    }
    528529
    529     getRoomTypes() {
    530         return this.roomTypes;
    531     }
    532 
    533     getRooms() {
    534         return this.getShapeInfoByType("Room");
    535     }
    536 
    537     getPins() {
    538         return this.getShapeInfoByType("InfoPin");
    539     }
    540 
    541     getEntrances() {
    542         return this.getShapeInfoByType("Entrance");
    543     }
    544 
    545 
    546 
    547     getShapeInfoByType(type) {
    548         return ShapeRegistry.getShapes(this.floorNum).filter((shape) => shape.className === type).map((shape) => shape.info);
    549     }
    550 
    551530
    552531    drawConnection(node1Name, node2Name) {
    553532
    554533        ShapeRegistry.drawConnection(node1Name,node2Name);
    555     }
    556 
    557     getNodeByName(name) {
    558         return ShapeRegistry.getShapes(this.floorNum).filter(shape => shape instanceof MapNode && shape.info.name === name)[0];
    559534    }
    560535
     
    571546    }
    572547
    573     isMainEntranceSelected() {
    574         console.log(this.getEntrances().forEach((en) => console.log(en.isMainEntrance, "asdsad")));
    575 
    576         let hasMainEntrance = false;
    577 
    578         this.getEntrances().forEach((entrance) => {
    579             if (entrance.isMainEntrance === true) hasMainEntrance = true;
    580         });
    581 
    582         return hasMainEntrance;
    583 
    584     }
    585548
    586549    clearMap() {
     
    653616        this.mainLayer.add(this.selectionRectangle);
    654617
    655         ShapeRegistry.getShapes(this.floorNum).forEach((shape) => shape.displayName(this.textLayer));
     618        ShapeRegistry.getShapes(this.floorNum).forEach((shape) => {
     619            shape.displayName(this.textLayer);
     620            if(shape.className === "Entrance"){
     621                shape.setHighlight();
     622            }
     623        });
    656624    }
    657625
Note: See TracChangeset for help on using the changeset viewer.