1 | import {_registerNode} from "konva/lib/Global";
|
---|
2 | import MapNode from "../base/MapNode.js";
|
---|
3 | import {node} from "prop-types";
|
---|
4 | import ShapeRegistry from "../util/ShapeRegistry.js";
|
---|
5 | import ShapeQuery from "../util/ShapeQuery.js";
|
---|
6 | import Konva from "konva";
|
---|
7 |
|
---|
8 | export default class Entrance extends MapNode {
|
---|
9 |
|
---|
10 | constructor(attrs, id) {
|
---|
11 |
|
---|
12 | if (!attrs.fromLoad) {
|
---|
13 | attrs.height *= 2;
|
---|
14 | }
|
---|
15 | super(
|
---|
16 | {
|
---|
17 | x: attrs.position.x,
|
---|
18 | y: attrs.position.y,
|
---|
19 | width: attrs.width * attrs.scaleX,
|
---|
20 | height: attrs.height * attrs.scaleY,
|
---|
21 | fill: "rgb(126,238,167)",
|
---|
22 | stroke: "#252627",
|
---|
23 | strokeWidth: 1,
|
---|
24 | opacity: 0.9,
|
---|
25 | name: "mapObj",
|
---|
26 | draggable: true,
|
---|
27 | rotation: attrs.rotation,
|
---|
28 | zIndex: 1,
|
---|
29 | },
|
---|
30 | attrs.layer,
|
---|
31 | attrs.blockSize,
|
---|
32 | attrs.snap
|
---|
33 | );
|
---|
34 | this.type = "Entrance";
|
---|
35 | this.eventName = "openEntranceModalEvent";
|
---|
36 | this.floorNum = attrs.floorNum
|
---|
37 |
|
---|
38 | this.id = id;
|
---|
39 |
|
---|
40 | this._info = {
|
---|
41 | name: `Entrance${id} [${this.floorNum}F]`,
|
---|
42 | connectedRoom: "",
|
---|
43 | description: "",
|
---|
44 | isMainEntrance: false,
|
---|
45 | selectedPin: "",
|
---|
46 | selectedPins: [],
|
---|
47 | };
|
---|
48 |
|
---|
49 | this.initText();
|
---|
50 | this.moveToTop();
|
---|
51 |
|
---|
52 | console.log("room CONNECT: " + attrs.connected_room,this.info.connectedRoom + "CON")
|
---|
53 | console.log("entrance: " + this.info.name)
|
---|
54 | }
|
---|
55 |
|
---|
56 | loadInfo(attrs) {
|
---|
57 | this.info.name = attrs.obj_name ?? `Entrance${this.id} [${this.floorNum}F]`;
|
---|
58 | this.info.connectedRoom = attrs.connected_room ?? ``;
|
---|
59 | this.info.description = attrs.description ?? ``;
|
---|
60 | this.info.isMainEntrance = attrs.is_main_entrance ?? false;
|
---|
61 | this.info.selectedPins = attrs.connected_pins ?? [];
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | saveShapeDetails() {
|
---|
66 | console.info("fnum entrance",this.attrs.floorNum)
|
---|
67 | this.setAttr("connected_pins", this.info.selectedPins);
|
---|
68 | this.setAttr("obj_name", this.info.name);
|
---|
69 | this.setAttr("description", this.info.description);
|
---|
70 | this.setAttr("is_main_entrance", this.info.isMainEntrance);
|
---|
71 | this.setAttr("connected_room", this.info.connectedRoom);
|
---|
72 | this.setAttr("floor_num",this.floorNum);
|
---|
73 | }
|
---|
74 |
|
---|
75 | connect(node, draw = true) {
|
---|
76 | if(this.floorNum !== node.floorNum) return;
|
---|
77 |
|
---|
78 | super.connect(node)
|
---|
79 | }
|
---|
80 |
|
---|
81 | setInfo(infoObj) {
|
---|
82 | this.info = infoObj;
|
---|
83 | this.setHighlight();
|
---|
84 | }
|
---|
85 |
|
---|
86 | setHighlight(){
|
---|
87 | console.log("info room: " + this.info.connectedRoom)
|
---|
88 | if(this.info.connectedRoom == null || this.info.connectedRoom === "" ){
|
---|
89 | console.log("vleze if")
|
---|
90 | this.strokeWidth(2);
|
---|
91 | this.stroke("#8a000d")
|
---|
92 | }else{
|
---|
93 | this.strokeWidth(1)
|
---|
94 | this.stroke("black")
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | onPlace() {
|
---|
99 | ShapeQuery
|
---|
100 | .findAllByTypeAndFloor(this.floorNum,"Room")
|
---|
101 | .forEach(room => {
|
---|
102 | if(Konva.Util.haveIntersection(room.getClientRect(),this.getClientRect())){
|
---|
103 | this.info.connectedRoom = room.info.name;
|
---|
104 | }
|
---|
105 | })
|
---|
106 | this.setHighlight()
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | Entrance.prototype.className = "Entrance";
|
---|
111 | _registerNode(Entrance);
|
---|