@threekit-tools/treble 0.0.91-next-03 → 0.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Treble/Treble.d.ts +2 -2
- package/dist/Treble/Treble.js +3 -3
- package/dist/Treble/index.d.ts +1 -1
- package/dist/Treble/index.js +1 -1
- package/dist/Treble/snapshot.d.ts +1 -1
- package/dist/Treble/snapshots.d.ts +22 -0
- package/dist/Treble/snapshots.js +247 -0
- package/dist/Treble/wishlist.d.ts +1 -1
- package/dist/Treble/wishlist.js +1 -1
- package/dist/api/catalog.js +1 -1
- package/dist/api/configurations.js +1 -1
- package/dist/api/datatables.js +1 -1
- package/dist/api/orders.js +1 -1
- package/dist/api/price.js +1 -1
- package/dist/api/products.d.ts +2 -2
- package/dist/api/products.js +1 -1
- package/dist/components/BreatheAnimation/index.js +1 -1
- package/dist/components/Button/index.d.ts +2 -2
- package/dist/components/DraggableHint/draggableIndicator.styles.d.ts +1 -1
- package/dist/components/PlayerLoadingSpinner/playerLoadingSpinner.styles.d.ts +1 -1
- package/dist/components/Share/index.js +1 -1
- package/dist/components/Share/share.styles.d.ts +1 -1
- package/dist/components/ThreekitProvider/index.js +3 -2
- package/dist/components/TurntableAnimation/index.js +1 -1
- package/dist/components/Upload/index.js +1 -1
- package/dist/components/UploadArea/index.js +1 -1
- package/dist/components/Wishlist/index.js +1 -1
- package/dist/connection.d.ts +4 -1
- package/dist/connection.js +16 -53
- package/dist/hooks/useAttribute/index.d.ts +4 -4
- package/dist/hooks/useAttribute/index.js +2 -6
- package/dist/hooks/useConfigurationLoader/index.js +1 -1
- package/dist/hooks/useConfigurator/index.d.ts +3 -3
- package/dist/hooks/useDevTools/index.d.ts +1 -1
- package/dist/hooks/useNestedConfigurator/index.d.ts +2 -2
- package/dist/hooks/useNestedConfigurator/index.js +3 -2
- package/dist/hooks/usePlayer/index.d.ts +1 -1
- package/dist/hooks/usePlayerPortal/index.d.ts +1 -1
- package/dist/hooks/useProductCache/index.js +1 -1
- package/dist/hooks/useResetProduct/index.d.ts +1 -1
- package/dist/hooks/useResetProduct/index.js +1 -1
- package/dist/hooks/useRoomBuilder/RoomBuilderState.d.ts +95 -0
- package/dist/hooks/useRoomBuilder/RoomBuilderState.js +1237 -0
- package/dist/hooks/useRoomBuilder/constants.d.ts +41 -0
- package/dist/hooks/useRoomBuilder/constants.js +48 -0
- package/dist/hooks/useRoomBuilder/dataHandlers.d.ts +18 -0
- package/dist/hooks/useRoomBuilder/dataHandlers.js +187 -0
- package/dist/hooks/useRoomBuilder/draw.d.ts +55 -0
- package/dist/hooks/useRoomBuilder/draw.js +573 -0
- package/dist/hooks/useRoomBuilder/findLoops.d.ts +5 -0
- package/dist/hooks/useRoomBuilder/findLoops.js +99 -0
- package/dist/hooks/useRoomBuilder/geometry.d.ts +33 -0
- package/dist/hooks/useRoomBuilder/geometry.js +325 -0
- package/dist/hooks/useRoomBuilder/index.d.ts +40 -0
- package/dist/hooks/useRoomBuilder/index.js +303 -0
- package/dist/hooks/useRoomBuilder/messaging.d.ts +8 -0
- package/dist/hooks/useRoomBuilder/messaging.js +18 -0
- package/dist/hooks/useRoomBuilder/themes.d.ts +12 -0
- package/dist/hooks/useRoomBuilder/themes.js +273 -0
- package/dist/hooks/useRoomBuilder/types.d.ts +238 -0
- package/dist/hooks/useRoomBuilder/types.js +36 -0
- package/dist/hooks/useRoomBuilder/validators.d.ts +36 -0
- package/dist/hooks/useRoomBuilder/validators.js +362 -0
- package/dist/hooks/useShare/index.d.ts +1 -1
- package/dist/hooks/useShare/index.js +1 -1
- package/dist/hooks/useSingleAnimation/index.js +1 -1
- package/dist/hooks/useSnapshot/index.d.ts +1 -1
- package/dist/hooks/useWishlist/index.d.ts +1 -1
- package/dist/hooks/useZoom/index.d.ts +1 -1
- package/dist/http/orders.d.ts +1 -1
- package/dist/icons/Draw.js +3 -3
- package/dist/icons/Window.js +4 -4
- package/dist/icons/index.js +0 -26
- package/dist/index.d.ts +2 -16
- package/dist/index.js +5 -33
- package/dist/store/attributes.d.ts +1 -2
- package/dist/store/attributes.js +1 -1
- package/dist/store/index.d.ts +2 -9
- package/dist/store/index.js +1 -3
- package/dist/store/price.js +1 -1
- package/dist/store/product.d.ts +1 -1
- package/dist/store/product.js +8 -5
- package/dist/store/translations.js +1 -1
- package/dist/store/treble.d.ts +4 -2
- package/dist/store/treble.js +60 -43
- package/dist/store/wishlist.d.ts +1 -1
- package/dist/store/wishlist.js +1 -1
- package/dist/types.d.ts +25 -21
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,1237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.RoomBuilderState = void 0;
|
|
60
|
+
var types_1 = require("./types");
|
|
61
|
+
var types_2 = require("./types");
|
|
62
|
+
var validators_1 = require("./validators");
|
|
63
|
+
var geometry_1 = require("./geometry");
|
|
64
|
+
var draw_1 = require("./draw");
|
|
65
|
+
var dataHandlers_1 = require("./dataHandlers");
|
|
66
|
+
var __1 = require("../..");
|
|
67
|
+
var constants_1 = require("./constants");
|
|
68
|
+
var findLoops_1 = require("./findLoops");
|
|
69
|
+
var RoomBuilderState = (function () {
|
|
70
|
+
function RoomBuilderState(config) {
|
|
71
|
+
var _a;
|
|
72
|
+
var _this = this;
|
|
73
|
+
this.moveActiveVertex = function (canvas, point) {
|
|
74
|
+
var _a, _b, _c, _d;
|
|
75
|
+
if (!canvas)
|
|
76
|
+
return;
|
|
77
|
+
if (((_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type) !== types_2.IElements.VERTEX)
|
|
78
|
+
return;
|
|
79
|
+
var snapPoint = _this.getPointProximity(point);
|
|
80
|
+
if (!snapPoint && _this._angleSnappingEnabled)
|
|
81
|
+
snapPoint = _this.snapVertexToAbsoluteAngle(_this._activeElement.index, point);
|
|
82
|
+
var vertex = _this.getVertex(_this._activeElement.index);
|
|
83
|
+
if (!vertex)
|
|
84
|
+
return;
|
|
85
|
+
var validationData = {
|
|
86
|
+
vertex: vertex,
|
|
87
|
+
walls: _this.walls,
|
|
88
|
+
updatedPosition: {
|
|
89
|
+
point: point,
|
|
90
|
+
snapTo: snapPoint,
|
|
91
|
+
},
|
|
92
|
+
features: _this.features,
|
|
93
|
+
};
|
|
94
|
+
_this._errorElement = (0, validators_1.runValidators)([
|
|
95
|
+
validators_1.isVertexLandingOnFeature,
|
|
96
|
+
validators_1.areWallsTooShort,
|
|
97
|
+
validators_1.areWallsIntersecting,
|
|
98
|
+
validators_1.areWallsOrphaningFeatures,
|
|
99
|
+
validators_1.areWallsDuplicated,
|
|
100
|
+
], validationData);
|
|
101
|
+
var errorType = ((_b = _this._errorElement) === null || _b === void 0 ? void 0 : _b[0].type) || null;
|
|
102
|
+
switch (errorType) {
|
|
103
|
+
case types_1.IErrorTypes.HARD:
|
|
104
|
+
return;
|
|
105
|
+
case types_1.IErrorTypes.SOFT:
|
|
106
|
+
case types_1.IErrorTypes.WARN:
|
|
107
|
+
case null:
|
|
108
|
+
default:
|
|
109
|
+
_this._activeElement.snapPoint = snapPoint;
|
|
110
|
+
_this.repositionVertex(_this._activeElement.index, (_c = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _c !== void 0 ? _c : point);
|
|
111
|
+
_this.drawRoom(canvas);
|
|
112
|
+
(0, draw_1.drawVertex)(canvas, (_d = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _d !== void 0 ? _d : point, _this._config.config.styles.vertex, types_1.IElementStyleModes.HIGHLIGHT);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
this.finishMoveActiveVertex = function () {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
if (((_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type) !== types_2.IElements.VERTEX)
|
|
119
|
+
return;
|
|
120
|
+
if (((_b = _this._activeElement.snapPoint) === null || _b === void 0 ? void 0 : _b.type) === types_2.IElements.WALL)
|
|
121
|
+
_this.splitWall(_this._activeElement.snapPoint.index, _this._activeElement.snapPoint.point);
|
|
122
|
+
_this.pushStateToConfigurator();
|
|
123
|
+
};
|
|
124
|
+
this.moveActiveFeature = function (canvas, moveToPoint) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
if (_this._activeElement === null)
|
|
127
|
+
return;
|
|
128
|
+
var _c = _this._activeElement, type = _c.type, index = _c.index;
|
|
129
|
+
if (type !== types_2.IElements.WINDOW &&
|
|
130
|
+
type !== types_2.IElements.DOOR &&
|
|
131
|
+
type !== types_2.IElements.OPENING)
|
|
132
|
+
return;
|
|
133
|
+
var feature = _this.getFeature(type, index);
|
|
134
|
+
if (!feature)
|
|
135
|
+
return;
|
|
136
|
+
var wallIndex = (_a = _this.getWallInProximity(moveToPoint)) !== null && _a !== void 0 ? _a : feature.connectedTo[1];
|
|
137
|
+
var wall = _this.getWall(wallIndex);
|
|
138
|
+
if (!wall)
|
|
139
|
+
return;
|
|
140
|
+
var intersection = (0, geometry_1.getTangetIntersectionAndOffset)(wall.line, moveToPoint);
|
|
141
|
+
if (!intersection)
|
|
142
|
+
return;
|
|
143
|
+
var newOffset = intersection.offset - feature.length / 2;
|
|
144
|
+
var featureUpdatesToValidate = {
|
|
145
|
+
length: feature.length,
|
|
146
|
+
offset: newOffset,
|
|
147
|
+
address: { type: type, index: index },
|
|
148
|
+
};
|
|
149
|
+
_this._errorElement = (0, validators_1.runValidators)([validators_1.isFeatureOutsideWallBounds, validators_1.isFeatureCollidingWithExistingFeature], {
|
|
150
|
+
wall: wall,
|
|
151
|
+
features: _this.features,
|
|
152
|
+
updatedFeature: featureUpdatesToValidate,
|
|
153
|
+
});
|
|
154
|
+
var errorType = ((_b = _this._errorElement) === null || _b === void 0 ? void 0 : _b[0].type) || null;
|
|
155
|
+
switch (errorType) {
|
|
156
|
+
case types_1.IErrorTypes.HARD:
|
|
157
|
+
return;
|
|
158
|
+
case types_1.IErrorTypes.SOFT:
|
|
159
|
+
_this.drawRoom(canvas);
|
|
160
|
+
break;
|
|
161
|
+
case types_1.IErrorTypes.WARN:
|
|
162
|
+
case null:
|
|
163
|
+
default:
|
|
164
|
+
_this.repositionFeature([type, index], newOffset, wallIndex);
|
|
165
|
+
_this.drawRoom(canvas);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
this.finishMoveActiveFeature = function () {
|
|
170
|
+
var _a;
|
|
171
|
+
var type = (_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type;
|
|
172
|
+
if (!type)
|
|
173
|
+
return;
|
|
174
|
+
if (type !== types_2.IElements.WINDOW &&
|
|
175
|
+
type !== types_2.IElements.DOOR &&
|
|
176
|
+
type !== types_2.IElements.OPENING)
|
|
177
|
+
return;
|
|
178
|
+
_this.pushStateToConfigurator();
|
|
179
|
+
};
|
|
180
|
+
this._config = config;
|
|
181
|
+
this._newWall = null;
|
|
182
|
+
this._activeElement = null;
|
|
183
|
+
this._selectedElement = null;
|
|
184
|
+
this._highlightedElement = null;
|
|
185
|
+
this._errorElement = null;
|
|
186
|
+
this._state = (_a = {},
|
|
187
|
+
_a[types_2.IElements.WALL] = [],
|
|
188
|
+
_a[types_2.IElements.VERTEX] = {},
|
|
189
|
+
_a[types_2.IElements.FEATURE] = {},
|
|
190
|
+
_a);
|
|
191
|
+
this._showDimensions = true;
|
|
192
|
+
this._angleSnappingEnabled = true;
|
|
193
|
+
this._attributesState = null;
|
|
194
|
+
}
|
|
195
|
+
Object.defineProperty(RoomBuilderState.prototype, "walls", {
|
|
196
|
+
get: function () {
|
|
197
|
+
return this._state[types_2.IElements.WALL];
|
|
198
|
+
},
|
|
199
|
+
set: function (walls) {
|
|
200
|
+
this._state[types_2.IElements.WALL] = walls;
|
|
201
|
+
},
|
|
202
|
+
enumerable: false,
|
|
203
|
+
configurable: true
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(RoomBuilderState.prototype, "wallCount", {
|
|
206
|
+
get: function () {
|
|
207
|
+
return this.walls.length;
|
|
208
|
+
},
|
|
209
|
+
enumerable: false,
|
|
210
|
+
configurable: true
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(RoomBuilderState.prototype, "wallLines", {
|
|
213
|
+
get: function () {
|
|
214
|
+
return this.walls.map(function (_a) {
|
|
215
|
+
var line = _a.line;
|
|
216
|
+
return line;
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
enumerable: false,
|
|
220
|
+
configurable: true
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(RoomBuilderState.prototype, "vertices", {
|
|
223
|
+
get: function () {
|
|
224
|
+
return this._state[types_2.IElements.VERTEX];
|
|
225
|
+
},
|
|
226
|
+
set: function (vertices) {
|
|
227
|
+
this._state[types_2.IElements.VERTEX] = vertices;
|
|
228
|
+
},
|
|
229
|
+
enumerable: false,
|
|
230
|
+
configurable: true
|
|
231
|
+
});
|
|
232
|
+
Object.defineProperty(RoomBuilderState.prototype, "verticesList", {
|
|
233
|
+
get: function () {
|
|
234
|
+
return Object.entries(this.vertices).map(function (_a) {
|
|
235
|
+
var pointStr = _a[0], connections = _a[1];
|
|
236
|
+
return ({
|
|
237
|
+
point: JSON.parse(pointStr),
|
|
238
|
+
connections: connections,
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
enumerable: false,
|
|
243
|
+
configurable: true
|
|
244
|
+
});
|
|
245
|
+
Object.defineProperty(RoomBuilderState.prototype, "features", {
|
|
246
|
+
get: function () {
|
|
247
|
+
return this._state[types_2.IElements.FEATURE];
|
|
248
|
+
},
|
|
249
|
+
set: function (features) {
|
|
250
|
+
this._state[types_2.IElements.FEATURE] = features;
|
|
251
|
+
},
|
|
252
|
+
enumerable: false,
|
|
253
|
+
configurable: true
|
|
254
|
+
});
|
|
255
|
+
Object.defineProperty(RoomBuilderState.prototype, "getHydratedFeatures", {
|
|
256
|
+
get: function () {
|
|
257
|
+
var _this = this;
|
|
258
|
+
return Object.entries(this.features).reduce(function (output, _a) {
|
|
259
|
+
var _b;
|
|
260
|
+
var type = _a[0], featureArr = _a[1];
|
|
261
|
+
return Object.assign(output, (_b = {},
|
|
262
|
+
_b[type] = featureArr.map(function (feature) {
|
|
263
|
+
var wall = _this.getWall(feature.connectedTo[1]);
|
|
264
|
+
if (!wall)
|
|
265
|
+
return;
|
|
266
|
+
var line = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, feature.offset, feature.length);
|
|
267
|
+
return __assign(__assign({}, feature), { line: line });
|
|
268
|
+
}),
|
|
269
|
+
_b));
|
|
270
|
+
}, {});
|
|
271
|
+
},
|
|
272
|
+
enumerable: false,
|
|
273
|
+
configurable: true
|
|
274
|
+
});
|
|
275
|
+
Object.defineProperty(RoomBuilderState.prototype, "featureCount", {
|
|
276
|
+
get: function () {
|
|
277
|
+
return Object.values(this.features).flat().length;
|
|
278
|
+
},
|
|
279
|
+
enumerable: false,
|
|
280
|
+
configurable: true
|
|
281
|
+
});
|
|
282
|
+
Object.defineProperty(RoomBuilderState.prototype, "activeElement", {
|
|
283
|
+
get: function () {
|
|
284
|
+
return this._activeElement;
|
|
285
|
+
},
|
|
286
|
+
enumerable: false,
|
|
287
|
+
configurable: true
|
|
288
|
+
});
|
|
289
|
+
Object.defineProperty(RoomBuilderState.prototype, "selectedElement", {
|
|
290
|
+
get: function () {
|
|
291
|
+
return this._selectedElement;
|
|
292
|
+
},
|
|
293
|
+
set: function (element) {
|
|
294
|
+
this._selectedElement = element;
|
|
295
|
+
},
|
|
296
|
+
enumerable: false,
|
|
297
|
+
configurable: true
|
|
298
|
+
});
|
|
299
|
+
Object.defineProperty(RoomBuilderState.prototype, "showDimensions", {
|
|
300
|
+
get: function () {
|
|
301
|
+
return this._showDimensions;
|
|
302
|
+
},
|
|
303
|
+
set: function (val) {
|
|
304
|
+
this._showDimensions = val;
|
|
305
|
+
},
|
|
306
|
+
enumerable: false,
|
|
307
|
+
configurable: true
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(RoomBuilderState.prototype, "angleSnappingEnabled", {
|
|
310
|
+
get: function () {
|
|
311
|
+
return this._angleSnappingEnabled;
|
|
312
|
+
},
|
|
313
|
+
set: function (val) {
|
|
314
|
+
this._angleSnappingEnabled = val;
|
|
315
|
+
},
|
|
316
|
+
enumerable: false,
|
|
317
|
+
configurable: true
|
|
318
|
+
});
|
|
319
|
+
Object.defineProperty(RoomBuilderState.prototype, "enclosedSpaces", {
|
|
320
|
+
get: function () {
|
|
321
|
+
var _this = this;
|
|
322
|
+
var loops = (0, findLoops_1.findLoops)(this.wallLines).inner;
|
|
323
|
+
return loops.reduce(function (output, loop) {
|
|
324
|
+
var screenSpaceArea = Math.round((0, geometry_1.getPolygonArea)(loop));
|
|
325
|
+
var area = screenSpaceArea * Math.pow(_this._config.config.scale, 2);
|
|
326
|
+
var convertedArea = (0, dataHandlers_1.convertAreaUnit)(area, types_1.IUnits.METER, _this._config.config.unit);
|
|
327
|
+
var enclosedSpace = {
|
|
328
|
+
loop: loop,
|
|
329
|
+
area: (0, dataHandlers_1.prepAreaForUser)(convertedArea, _this._config.config.unit),
|
|
330
|
+
center: loop.reduce(function (centerPoint, point) {
|
|
331
|
+
centerPoint[0] += point[0] / loop.length;
|
|
332
|
+
centerPoint[1] += point[1] / loop.length;
|
|
333
|
+
return centerPoint;
|
|
334
|
+
}, [0, 0]),
|
|
335
|
+
};
|
|
336
|
+
output.push(enclosedSpace);
|
|
337
|
+
return output;
|
|
338
|
+
}, []);
|
|
339
|
+
},
|
|
340
|
+
enumerable: false,
|
|
341
|
+
configurable: true
|
|
342
|
+
});
|
|
343
|
+
RoomBuilderState.prototype.getWall = function (index) {
|
|
344
|
+
return this.walls[index];
|
|
345
|
+
};
|
|
346
|
+
RoomBuilderState.prototype.addWall = function (wall) {
|
|
347
|
+
if (!wall)
|
|
348
|
+
return;
|
|
349
|
+
var updatedWalls = this.walls;
|
|
350
|
+
updatedWalls.push(wall);
|
|
351
|
+
this.walls = updatedWalls;
|
|
352
|
+
};
|
|
353
|
+
RoomBuilderState.prototype.addWalls = function (walls) {
|
|
354
|
+
var _this = this;
|
|
355
|
+
if (!(walls === null || walls === void 0 ? void 0 : walls.length))
|
|
356
|
+
return;
|
|
357
|
+
walls.forEach(function (wall) { return _this.addWall(wall); });
|
|
358
|
+
};
|
|
359
|
+
RoomBuilderState.prototype.updateWall = function (index, wall) {
|
|
360
|
+
var currentWall = this.walls[index];
|
|
361
|
+
if (!currentWall)
|
|
362
|
+
return;
|
|
363
|
+
this._state[types_2.IElements.WALL][index] = Object.assign({}, currentWall, wall);
|
|
364
|
+
};
|
|
365
|
+
RoomBuilderState.prototype.getWallConnectionCount = function (index) {
|
|
366
|
+
var wall = this.getWall(index);
|
|
367
|
+
return (wall === null || wall === void 0 ? void 0 : wall.connections.length) || 0;
|
|
368
|
+
};
|
|
369
|
+
RoomBuilderState.prototype.getWallConnectionsHydrated = function (index) {
|
|
370
|
+
var _this = this;
|
|
371
|
+
var _a;
|
|
372
|
+
var connections = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.connections;
|
|
373
|
+
if (!connections)
|
|
374
|
+
return undefined;
|
|
375
|
+
return connections.reduce(function (output, connection) {
|
|
376
|
+
var feature = _this.getFeature.apply(_this, connection);
|
|
377
|
+
if (feature)
|
|
378
|
+
output.push(feature);
|
|
379
|
+
return output;
|
|
380
|
+
}, []);
|
|
381
|
+
};
|
|
382
|
+
RoomBuilderState.prototype.getWallDimensions = function (index) {
|
|
383
|
+
var _a;
|
|
384
|
+
var line = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.line;
|
|
385
|
+
if (!line)
|
|
386
|
+
return undefined;
|
|
387
|
+
var lineLength = (0, geometry_1.getLengthOfLineSegment)(line) * this._config.config.scale;
|
|
388
|
+
var convertedVal = (0, dataHandlers_1.convertLengthUnit)(lineLength, types_1.IUnits.METER, this._config.config.unit);
|
|
389
|
+
return {
|
|
390
|
+
line: line,
|
|
391
|
+
label: (0, dataHandlers_1.prepLengthForUser)(convertedVal, this._config.config.unit),
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
RoomBuilderState.prototype.getWallDetailedDimensions = function (index) {
|
|
395
|
+
var _this = this;
|
|
396
|
+
var _a;
|
|
397
|
+
var line = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.line;
|
|
398
|
+
var features = this.getWallConnectionsHydrated(index);
|
|
399
|
+
if (!line || !features)
|
|
400
|
+
return undefined;
|
|
401
|
+
var prepLength = function (val) { return val.toFixed(2); };
|
|
402
|
+
var lines = features
|
|
403
|
+
.sort(function (a, b) { return a.offset - b.offset; })
|
|
404
|
+
.reduce(function (output, _a, i) {
|
|
405
|
+
var offset = _a.offset, length = _a.length;
|
|
406
|
+
var featureLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(line, offset, length);
|
|
407
|
+
var featureLength = (0, geometry_1.getLengthOfLineSegment)(featureLine);
|
|
408
|
+
var unit = constants_1.UNIT_LABELS[_this._config.config.unit];
|
|
409
|
+
var scale = _this._config.config.scale;
|
|
410
|
+
if (!i) {
|
|
411
|
+
var startLine = [line[0], featureLine[0]];
|
|
412
|
+
var startLineLength = (0, geometry_1.getLengthOfLineSegment)(startLine);
|
|
413
|
+
output.push({
|
|
414
|
+
line: startLine,
|
|
415
|
+
label: "".concat(prepLength(startLineLength * scale), " ").concat(unit),
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
var previousLine = [
|
|
420
|
+
output[output.length - 1].line[1],
|
|
421
|
+
featureLine[0],
|
|
422
|
+
];
|
|
423
|
+
var previousLineLength = (0, geometry_1.getLengthOfLineSegment)(previousLine);
|
|
424
|
+
output.push({
|
|
425
|
+
line: previousLine,
|
|
426
|
+
label: "".concat(prepLength(previousLineLength * scale), " ").concat(unit),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
output.push({
|
|
430
|
+
line: featureLine,
|
|
431
|
+
label: "".concat(prepLength(featureLength * scale), " ").concat(unit),
|
|
432
|
+
});
|
|
433
|
+
if (i === features.length - 1) {
|
|
434
|
+
var endLine = [featureLine[1], line[1]];
|
|
435
|
+
var endLineLength = (0, geometry_1.getLengthOfLineSegment)(endLine);
|
|
436
|
+
output.push({
|
|
437
|
+
line: endLine,
|
|
438
|
+
label: "".concat(prepLength(endLineLength * scale), " ").concat(unit),
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
return output;
|
|
442
|
+
}, []);
|
|
443
|
+
return lines;
|
|
444
|
+
};
|
|
445
|
+
RoomBuilderState.prototype.getAllWallDimensions = function (detailedWallsIndexes) {
|
|
446
|
+
var _this = this;
|
|
447
|
+
if (detailedWallsIndexes === void 0) { detailedWallsIndexes = []; }
|
|
448
|
+
var indexes = new Set([detailedWallsIndexes].flat());
|
|
449
|
+
return this.walls.reduce(function (output, _, i) {
|
|
450
|
+
var dimensions = indexes.has(i)
|
|
451
|
+
? _this.getWallDetailedDimensions(i)
|
|
452
|
+
: _this.getWallDimensions(i);
|
|
453
|
+
if (!dimensions)
|
|
454
|
+
return output;
|
|
455
|
+
if (Array.isArray(dimensions))
|
|
456
|
+
output.push.apply(output, dimensions);
|
|
457
|
+
else
|
|
458
|
+
output.push(dimensions);
|
|
459
|
+
return output;
|
|
460
|
+
}, []);
|
|
461
|
+
};
|
|
462
|
+
RoomBuilderState.prototype.shiftAllFeaturesOnWall = function (index, shift) {
|
|
463
|
+
var _this = this;
|
|
464
|
+
var _a;
|
|
465
|
+
var connections = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.connections;
|
|
466
|
+
if (!connections)
|
|
467
|
+
return;
|
|
468
|
+
connections.forEach(function (_a) {
|
|
469
|
+
var type = _a[0], featureIndex = _a[1];
|
|
470
|
+
var feature = _this.getFeature(type, featureIndex);
|
|
471
|
+
if (!feature)
|
|
472
|
+
return;
|
|
473
|
+
_this.updateFeature(type, featureIndex, {
|
|
474
|
+
offset: feature.offset + shift,
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
RoomBuilderState.prototype.addFeatureToWall = function (index, featurePath) {
|
|
479
|
+
var _a;
|
|
480
|
+
var updatedWalls = this.walls;
|
|
481
|
+
(_a = updatedWalls[index]) === null || _a === void 0 ? void 0 : _a.connections.push(featurePath);
|
|
482
|
+
this.walls = updatedWalls;
|
|
483
|
+
};
|
|
484
|
+
RoomBuilderState.prototype.removeFeatureFromWall = function (index, featurePath) {
|
|
485
|
+
var updatedWalls = this.walls;
|
|
486
|
+
if (!updatedWalls[index])
|
|
487
|
+
return;
|
|
488
|
+
updatedWalls[index].connections = updatedWalls[index].connections.filter(function (connection) {
|
|
489
|
+
return connection[0] !== featurePath[0] || connection[1] !== featurePath[1];
|
|
490
|
+
});
|
|
491
|
+
this.walls = updatedWalls;
|
|
492
|
+
};
|
|
493
|
+
RoomBuilderState.prototype.splitWall = function (wallIndex, point) {
|
|
494
|
+
var _this = this;
|
|
495
|
+
var singleWall = this.getWall(wallIndex);
|
|
496
|
+
if (!singleWall)
|
|
497
|
+
return;
|
|
498
|
+
var offset = (0, geometry_1.getLengthOfLineSegment)([singleWall.line[0], point]);
|
|
499
|
+
var _a = (0, geometry_1.splitLineAtPoint)(singleWall.line, point), line1 = _a[0], line2 = _a[1];
|
|
500
|
+
var newWallIndex = this.wallCount;
|
|
501
|
+
var wall1 = {
|
|
502
|
+
assetId: singleWall.assetId,
|
|
503
|
+
line: line1,
|
|
504
|
+
height: singleWall.height,
|
|
505
|
+
thickness: singleWall.thickness,
|
|
506
|
+
connections: singleWall.connections,
|
|
507
|
+
};
|
|
508
|
+
var wall2 = {
|
|
509
|
+
assetId: singleWall.assetId,
|
|
510
|
+
line: line2,
|
|
511
|
+
height: singleWall.height,
|
|
512
|
+
thickness: singleWall.thickness,
|
|
513
|
+
connections: [],
|
|
514
|
+
};
|
|
515
|
+
this.updateWall(wallIndex, wall1);
|
|
516
|
+
this.addWall(wall2);
|
|
517
|
+
singleWall.connections.forEach(function (connection) {
|
|
518
|
+
var feature = _this.getFeature.apply(_this, connection);
|
|
519
|
+
if (!feature)
|
|
520
|
+
return;
|
|
521
|
+
var updatedOffset = feature.offset - offset;
|
|
522
|
+
if (updatedOffset > 0)
|
|
523
|
+
_this.repositionFeature(connection, updatedOffset, newWallIndex);
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
RoomBuilderState.prototype.deleteWall = function (index) {
|
|
527
|
+
var wall = this.getWall(index);
|
|
528
|
+
if (!wall)
|
|
529
|
+
return;
|
|
530
|
+
if (wall.connections.length) {
|
|
531
|
+
var currentFeatures_1 = this.features;
|
|
532
|
+
var deleteMap = wall.connections.reduce(function (output, _a) {
|
|
533
|
+
var type = _a[0], index = _a[1];
|
|
534
|
+
if (output[type])
|
|
535
|
+
output[type].push(index);
|
|
536
|
+
else
|
|
537
|
+
output[type] = [index];
|
|
538
|
+
return output;
|
|
539
|
+
}, {});
|
|
540
|
+
var updatedFeatures = Object.entries(deleteMap).reduce(function (output, _a) {
|
|
541
|
+
var _b;
|
|
542
|
+
var type = _a[0], deletionIndexes = _a[1];
|
|
543
|
+
output[type] = (_b = currentFeatures_1[type]) === null || _b === void 0 ? void 0 : _b.filter(function (_, i) { return !deletionIndexes.includes(i); });
|
|
544
|
+
return output;
|
|
545
|
+
}, __assign({}, currentFeatures_1));
|
|
546
|
+
this.features = updatedFeatures;
|
|
547
|
+
}
|
|
548
|
+
var updatedWalls = this.walls;
|
|
549
|
+
updatedWalls.splice(index, 1);
|
|
550
|
+
this.walls = updatedWalls;
|
|
551
|
+
var reevaluatedFeatures = Object.entries(this.features).reduce(function (output, _a) {
|
|
552
|
+
var type = _a[0], featuresArr = _a[1];
|
|
553
|
+
output[type] = featuresArr.map(function (feature) {
|
|
554
|
+
return feature.connectedTo[1] > index
|
|
555
|
+
? Object.assign({}, feature, {
|
|
556
|
+
connectedTo: [
|
|
557
|
+
feature.connectedTo[0],
|
|
558
|
+
feature.connectedTo[1] - 1,
|
|
559
|
+
],
|
|
560
|
+
})
|
|
561
|
+
: feature;
|
|
562
|
+
});
|
|
563
|
+
return output;
|
|
564
|
+
}, {});
|
|
565
|
+
this.features = reevaluatedFeatures;
|
|
566
|
+
this.reevaluateFeatureConnections();
|
|
567
|
+
this.pushStateToConfigurator();
|
|
568
|
+
};
|
|
569
|
+
RoomBuilderState.prototype.getFirstVacantLocation = function (length) {
|
|
570
|
+
var _a;
|
|
571
|
+
var walls = this.walls;
|
|
572
|
+
var offset = undefined;
|
|
573
|
+
for (var i = 0; i < walls.length; i++) {
|
|
574
|
+
var wallLength = (0, geometry_1.getLengthOfLineSegment)(walls[i].line);
|
|
575
|
+
var features = (_a = this.getWallConnectionsHydrated(i)) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.offset - b.offset; });
|
|
576
|
+
if (!(features === null || features === void 0 ? void 0 : features.length)) {
|
|
577
|
+
if (length < wallLength - 2 * constants_1.WALL_PADDING_FOR_FEATURE)
|
|
578
|
+
offset = (wallLength - 2 * constants_1.WALL_PADDING_FOR_FEATURE) / 2 - length / 2;
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
for (var j = 0; j < features.length && offset === undefined; j++) {
|
|
582
|
+
var _b = features[j], currentOffset = _b.offset, currentLength = _b.length;
|
|
583
|
+
if (!j) {
|
|
584
|
+
if (constants_1.WALL_PADDING_FOR_FEATURE + length < currentOffset) {
|
|
585
|
+
var slotStart = constants_1.WALL_PADDING_FOR_FEATURE;
|
|
586
|
+
var slotEnd = currentOffset;
|
|
587
|
+
offset = slotStart + (slotEnd - slotStart) / 2 - length / 2;
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
var _c = features[j - 1], previousOffset = _c.offset, previousLength = _c.length;
|
|
593
|
+
if (length < currentOffset - (previousOffset + previousLength)) {
|
|
594
|
+
var slotStart = previousOffset + previousLength;
|
|
595
|
+
var slotEnd = currentOffset;
|
|
596
|
+
offset = slotStart + (slotEnd - slotStart) / 2 - length / 2;
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
if (j === features.length - 1) {
|
|
601
|
+
if (length <
|
|
602
|
+
wallLength -
|
|
603
|
+
constants_1.WALL_PADDING_FOR_FEATURE -
|
|
604
|
+
(currentOffset + currentLength)) {
|
|
605
|
+
var slotStart = currentOffset + currentLength;
|
|
606
|
+
var slotEnd = wallLength - constants_1.WALL_PADDING_FOR_FEATURE;
|
|
607
|
+
offset = slotStart + (slotEnd - slotStart) / 2 - length / 2;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
if (offset !== undefined)
|
|
613
|
+
return {
|
|
614
|
+
wallIndex: i,
|
|
615
|
+
offset: offset,
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
return false;
|
|
619
|
+
};
|
|
620
|
+
RoomBuilderState.prototype.getWallUiAnchorPoint = function (index) {
|
|
621
|
+
var wall = this.getWall(index);
|
|
622
|
+
if (!wall)
|
|
623
|
+
return undefined;
|
|
624
|
+
var line = (0, geometry_1.getParallelLineSegmentAtDistance)(wall.line, constants_1.UI_ANCHOR_DISTANCE);
|
|
625
|
+
return (0, geometry_1.getMidpointOfLineSegment)(line);
|
|
626
|
+
};
|
|
627
|
+
RoomBuilderState.prototype.getVertex = function (index) {
|
|
628
|
+
return this.verticesList[index];
|
|
629
|
+
};
|
|
630
|
+
RoomBuilderState.prototype.getWallsConnectedToVertex = function (index) {
|
|
631
|
+
if (index === undefined)
|
|
632
|
+
return [];
|
|
633
|
+
var vertex = this.getVertex(index);
|
|
634
|
+
if (!vertex)
|
|
635
|
+
return [];
|
|
636
|
+
return vertex.connections.map(function (_a) {
|
|
637
|
+
var index = _a[0];
|
|
638
|
+
return index;
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
RoomBuilderState.prototype.repositionVertex = function (index, newCoordinates) {
|
|
642
|
+
var _this = this;
|
|
643
|
+
var _a;
|
|
644
|
+
var connections = (_a = this.getVertex(index)) === null || _a === void 0 ? void 0 : _a.connections;
|
|
645
|
+
if (!connections)
|
|
646
|
+
return;
|
|
647
|
+
connections.forEach(function (_a) {
|
|
648
|
+
var wallIdx = _a[0], vertexIdx = _a[1];
|
|
649
|
+
var updatedLine = JSON.parse(JSON.stringify(_this.walls[wallIdx].line));
|
|
650
|
+
var currentLine = JSON.parse(JSON.stringify(_this.walls[wallIdx].line));
|
|
651
|
+
updatedLine[vertexIdx] = newCoordinates;
|
|
652
|
+
if (_this.getWallConnectionCount(wallIdx) && vertexIdx === 0) {
|
|
653
|
+
var delta = (0, geometry_1.getLengthOfLineSegment)(updatedLine) -
|
|
654
|
+
(0, geometry_1.getLengthOfLineSegment)(currentLine);
|
|
655
|
+
_this.shiftAllFeaturesOnWall(wallIdx, delta);
|
|
656
|
+
}
|
|
657
|
+
_this.updateWall(wallIdx, {
|
|
658
|
+
line: updatedLine,
|
|
659
|
+
path: undefined,
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
RoomBuilderState.prototype.getFeatureType = function (type) {
|
|
664
|
+
return this.features[type];
|
|
665
|
+
};
|
|
666
|
+
RoomBuilderState.prototype.setFeatureType = function (type, features) {
|
|
667
|
+
var updatedFeatures = this.features;
|
|
668
|
+
updatedFeatures[type] = features;
|
|
669
|
+
this.features = updatedFeatures;
|
|
670
|
+
this.reevaluateFeatureConnections();
|
|
671
|
+
};
|
|
672
|
+
RoomBuilderState.prototype.getFeature = function (type, index) {
|
|
673
|
+
var _a;
|
|
674
|
+
return (_a = this.features[type]) === null || _a === void 0 ? void 0 : _a[index];
|
|
675
|
+
};
|
|
676
|
+
RoomBuilderState.prototype.updateFeature = function (type, index, feature) {
|
|
677
|
+
var currentFeature = this._state[types_2.IElements.FEATURE][type][index];
|
|
678
|
+
if (!currentFeature)
|
|
679
|
+
return;
|
|
680
|
+
this._state[types_2.IElements.FEATURE][type][index] = Object.assign({}, currentFeature, feature);
|
|
681
|
+
};
|
|
682
|
+
RoomBuilderState.prototype.repositionFeature = function (featurePath, offset, moveToWallIndex) {
|
|
683
|
+
var type = featurePath[0], index = featurePath[1];
|
|
684
|
+
var feature = this.getFeature(type, index);
|
|
685
|
+
if (!feature)
|
|
686
|
+
return;
|
|
687
|
+
this.updateFeature(type, index, { offset: offset, path: undefined });
|
|
688
|
+
if (moveToWallIndex === feature.connectedTo[1])
|
|
689
|
+
return;
|
|
690
|
+
this.removeFeatureFromWall(index, featurePath);
|
|
691
|
+
this.addFeatureToWall(moveToWallIndex, featurePath);
|
|
692
|
+
this.updateFeature(type, index, {
|
|
693
|
+
connectedTo: [types_2.IElements.WALL, moveToWallIndex],
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
RoomBuilderState.prototype.addFeature = function (type, feature, addToWallIndex) {
|
|
697
|
+
var offset = undefined;
|
|
698
|
+
var index = undefined;
|
|
699
|
+
if (addToWallIndex !== undefined && feature.offset !== undefined) {
|
|
700
|
+
var wall = this.getWall(addToWallIndex);
|
|
701
|
+
if (wall) {
|
|
702
|
+
var isColliding = (0, validators_1.isFeatureCollidingWithExistingFeature)({
|
|
703
|
+
wall: wall,
|
|
704
|
+
features: this.features,
|
|
705
|
+
updatedFeature: __assign(__assign({}, feature), { offset: feature.offset, address: { type: types_2.IElements.WALL, index: addToWallIndex } }),
|
|
706
|
+
});
|
|
707
|
+
if (!isColliding) {
|
|
708
|
+
offset = feature.offset;
|
|
709
|
+
index = addToWallIndex;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (offset === undefined) {
|
|
714
|
+
var availableSlot = this.getFirstVacantLocation(feature.length);
|
|
715
|
+
if (!availableSlot)
|
|
716
|
+
return;
|
|
717
|
+
offset = availableSlot.offset;
|
|
718
|
+
index = availableSlot.wallIndex;
|
|
719
|
+
}
|
|
720
|
+
if (index === undefined || offset === undefined)
|
|
721
|
+
return;
|
|
722
|
+
var newFeature = __assign(__assign({}, feature), { offset: offset, connectedTo: [types_2.IElements.WALL, index] });
|
|
723
|
+
var newFeatureIndex;
|
|
724
|
+
if (this._state[types_2.IElements.FEATURE][type]) {
|
|
725
|
+
this._state[types_2.IElements.FEATURE][type].push(newFeature);
|
|
726
|
+
newFeatureIndex = this._state[types_2.IElements.FEATURE][type].length;
|
|
727
|
+
}
|
|
728
|
+
else {
|
|
729
|
+
this._state[types_2.IElements.FEATURE][type] = [newFeature];
|
|
730
|
+
newFeatureIndex = 1;
|
|
731
|
+
}
|
|
732
|
+
this.addFeatureToWall(index, [type, newFeatureIndex]);
|
|
733
|
+
this.pushStateToConfigurator();
|
|
734
|
+
};
|
|
735
|
+
RoomBuilderState.prototype.deleteFeature = function (type, index) {
|
|
736
|
+
var features = this.getFeatureType(type);
|
|
737
|
+
if (!(features === null || features === void 0 ? void 0 : features[index]))
|
|
738
|
+
return;
|
|
739
|
+
var deletedFeature = features.splice(index, 1)[0];
|
|
740
|
+
this.setFeatureType(type, features);
|
|
741
|
+
var wallToUpdate = this.getWall(deletedFeature.connectedTo[1]);
|
|
742
|
+
if (!wallToUpdate)
|
|
743
|
+
return;
|
|
744
|
+
this.updateWall(deletedFeature.connectedTo[1], {
|
|
745
|
+
connections: wallToUpdate.connections.filter(function (connection) { return connection[0] === type && connection[1] !== index; }),
|
|
746
|
+
});
|
|
747
|
+
this.pushStateToConfigurator();
|
|
748
|
+
};
|
|
749
|
+
RoomBuilderState.prototype.getHydratedFeature = function (type, index) {
|
|
750
|
+
var feature = this.getFeature(type, index);
|
|
751
|
+
if (!feature)
|
|
752
|
+
return;
|
|
753
|
+
var wall = this.getWall(feature.connectedTo[1]);
|
|
754
|
+
if (!wall)
|
|
755
|
+
return;
|
|
756
|
+
var line = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, feature.offset, feature.length);
|
|
757
|
+
return __assign(__assign({}, feature), { line: line });
|
|
758
|
+
};
|
|
759
|
+
RoomBuilderState.prototype.getFeatureUiAnchorPoint = function (type, index) {
|
|
760
|
+
var feature = this.getHydratedFeature(type, index);
|
|
761
|
+
if (!feature)
|
|
762
|
+
return;
|
|
763
|
+
var line = (0, geometry_1.getParallelLineSegmentAtDistance)(feature.line, constants_1.UI_ANCHOR_DISTANCE);
|
|
764
|
+
return (0, geometry_1.getMidpointOfLineSegment)(line);
|
|
765
|
+
};
|
|
766
|
+
RoomBuilderState.prototype.deleteElement = function (type, index) {
|
|
767
|
+
if (type === types_2.IElements.VERTEX)
|
|
768
|
+
return;
|
|
769
|
+
if (type === types_2.IElements.WALL)
|
|
770
|
+
this.deleteWall(index);
|
|
771
|
+
else
|
|
772
|
+
this.deleteFeature(type, index);
|
|
773
|
+
};
|
|
774
|
+
RoomBuilderState.prototype.getVertexInProximity = function (point) {
|
|
775
|
+
var _this = this;
|
|
776
|
+
if (!point)
|
|
777
|
+
return undefined;
|
|
778
|
+
var index = this.verticesList.findIndex(function (vertex) {
|
|
779
|
+
return (0, geometry_1.arePointsWithinProximity)(vertex.point, point, _this._config.config.snapProximity);
|
|
780
|
+
});
|
|
781
|
+
if (index === -1)
|
|
782
|
+
return undefined;
|
|
783
|
+
return index;
|
|
784
|
+
};
|
|
785
|
+
RoomBuilderState.prototype.getWallInProximity = function (point) {
|
|
786
|
+
var _this = this;
|
|
787
|
+
var index = this.walls.findIndex(function (wall) {
|
|
788
|
+
var path = (0, geometry_1.addThicknessToLine)(wall.line, _this._config.config.styles.wall.thickness + constants_1.WALL_SNAP_DISTANCE);
|
|
789
|
+
return (0, geometry_1.isPointInQuadrilateral)(path, point);
|
|
790
|
+
});
|
|
791
|
+
if (index === -1)
|
|
792
|
+
return undefined;
|
|
793
|
+
return index;
|
|
794
|
+
};
|
|
795
|
+
RoomBuilderState.prototype.snapPointToVertex = function (point) {
|
|
796
|
+
var _a, _b;
|
|
797
|
+
if (!point)
|
|
798
|
+
return undefined;
|
|
799
|
+
var index = this.getVertexInProximity(point);
|
|
800
|
+
if (index === undefined)
|
|
801
|
+
return undefined;
|
|
802
|
+
if (((_a = this._activeElement) === null || _a === void 0 ? void 0 : _a.type) === types_2.IElements.VERTEX &&
|
|
803
|
+
((_b = this._activeElement) === null || _b === void 0 ? void 0 : _b.index) === index)
|
|
804
|
+
return undefined;
|
|
805
|
+
var vertex = this.getVertex(index);
|
|
806
|
+
if (!vertex)
|
|
807
|
+
return undefined;
|
|
808
|
+
return {
|
|
809
|
+
type: types_2.IElements.VERTEX,
|
|
810
|
+
index: index,
|
|
811
|
+
point: vertex.point,
|
|
812
|
+
};
|
|
813
|
+
};
|
|
814
|
+
RoomBuilderState.prototype.snapPointToWall = function (point) {
|
|
815
|
+
var index = this.getWallInProximity(point);
|
|
816
|
+
if (index === undefined)
|
|
817
|
+
return undefined;
|
|
818
|
+
if (this._activeElement) {
|
|
819
|
+
if (this._activeElement.type === types_2.IElements.WALL &&
|
|
820
|
+
this._activeElement.index === index)
|
|
821
|
+
return undefined;
|
|
822
|
+
if (this._activeElement.type === types_2.IElements.VERTEX) {
|
|
823
|
+
var vertex = this.getVertex(this._activeElement.index);
|
|
824
|
+
if (vertex)
|
|
825
|
+
for (var i = 0; i < vertex.connections.length; i++) {
|
|
826
|
+
if (vertex.connections[i][0] === index)
|
|
827
|
+
return undefined;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
var intersection = (0, geometry_1.getTangetIntersectionAndOffset)(this.getWall(index).line, point);
|
|
832
|
+
if (!intersection)
|
|
833
|
+
return undefined;
|
|
834
|
+
return __assign({ type: types_2.IElements.WALL, index: index }, intersection);
|
|
835
|
+
};
|
|
836
|
+
RoomBuilderState.prototype.snapPointToAbsoluteAngle = function (point, anchorPoint, angle) {
|
|
837
|
+
if (angle === void 0) { angle = 15; }
|
|
838
|
+
var snapProximity = this._config.config.snapProximity;
|
|
839
|
+
if (Math.abs(point[0] - anchorPoint[0]) < snapProximity) {
|
|
840
|
+
return {
|
|
841
|
+
type: 'Angle',
|
|
842
|
+
point: [anchorPoint[0], point[1]],
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
else if (Math.abs(point[1] - anchorPoint[1]) < snapProximity) {
|
|
846
|
+
return {
|
|
847
|
+
type: 'Angle',
|
|
848
|
+
point: [point[0], anchorPoint[1]],
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
for (var degrees = 0; degrees < 360; degrees += angle) {
|
|
852
|
+
if (degrees === 0 || degrees % 90 === 0)
|
|
853
|
+
continue;
|
|
854
|
+
var radians = degrees * (Math.PI / 180);
|
|
855
|
+
if ((0, geometry_1.getDistanceToLine)(anchorPoint, radians, point) < snapProximity)
|
|
856
|
+
return {
|
|
857
|
+
type: 'Angle',
|
|
858
|
+
point: (0, geometry_1.closestPointOnLine)(anchorPoint, radians, point),
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
return undefined;
|
|
862
|
+
};
|
|
863
|
+
RoomBuilderState.prototype.snapVertexToAbsoluteAngle = function (vertexIndex, updatedPoint) {
|
|
864
|
+
var _this = this;
|
|
865
|
+
var vertex = this.getVertex(vertexIndex);
|
|
866
|
+
if (!vertex)
|
|
867
|
+
return undefined;
|
|
868
|
+
var point = vertex.connections.reduce(function (output, connection) {
|
|
869
|
+
var _a;
|
|
870
|
+
var line = (_a = _this.getWall(connection[0])) === null || _a === void 0 ? void 0 : _a.line;
|
|
871
|
+
if (!line)
|
|
872
|
+
return output;
|
|
873
|
+
var _b = output || updatedPoint, x = _b[0], y = _b[1];
|
|
874
|
+
var _c = line[connection[1] === 0 ? 1 : 0], xAnchor = _c[0], yAnchor = _c[1];
|
|
875
|
+
if (Math.abs(x - xAnchor) < _this._config.config.snapProximity)
|
|
876
|
+
return [xAnchor, y];
|
|
877
|
+
else if (Math.abs(y - yAnchor) < _this._config.config.snapProximity)
|
|
878
|
+
return [x, yAnchor];
|
|
879
|
+
return output;
|
|
880
|
+
}, undefined);
|
|
881
|
+
if (!point)
|
|
882
|
+
return point;
|
|
883
|
+
return {
|
|
884
|
+
type: 'Angle',
|
|
885
|
+
point: point,
|
|
886
|
+
};
|
|
887
|
+
};
|
|
888
|
+
RoomBuilderState.prototype.getFeatureAtPoint = function (point) {
|
|
889
|
+
var _this = this;
|
|
890
|
+
if (!point)
|
|
891
|
+
return undefined;
|
|
892
|
+
if (!this.featureCount)
|
|
893
|
+
return undefined;
|
|
894
|
+
var featuresMap = Object.entries(this.features);
|
|
895
|
+
for (var i = 0; i < featuresMap.length; i++) {
|
|
896
|
+
var _a = featuresMap[i], name_1 = _a[0], feature = _a[1];
|
|
897
|
+
var index = feature.findIndex(function (feature) {
|
|
898
|
+
var path = feature.path;
|
|
899
|
+
if (!path) {
|
|
900
|
+
var wallIndex = feature.connectedTo[1];
|
|
901
|
+
var featureLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(_this.getWall(wallIndex).line, feature.offset, feature.length);
|
|
902
|
+
path = (0, geometry_1.addThicknessToLine)(featureLine, _this._config.config.styles.feature.thickness);
|
|
903
|
+
}
|
|
904
|
+
return (0, geometry_1.isPointInQuadrilateral)(path, point);
|
|
905
|
+
});
|
|
906
|
+
if (index !== -1)
|
|
907
|
+
return {
|
|
908
|
+
type: name_1,
|
|
909
|
+
index: index,
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
return undefined;
|
|
913
|
+
};
|
|
914
|
+
RoomBuilderState.prototype.getElementAtPoint = function (point) {
|
|
915
|
+
if (!point)
|
|
916
|
+
return undefined;
|
|
917
|
+
var snapToVertex = this.snapPointToVertex(point);
|
|
918
|
+
if (snapToVertex !== undefined)
|
|
919
|
+
return snapToVertex;
|
|
920
|
+
if (this.featureCount) {
|
|
921
|
+
var featureInProximity = this.getFeatureAtPoint(point);
|
|
922
|
+
if (featureInProximity)
|
|
923
|
+
return featureInProximity;
|
|
924
|
+
}
|
|
925
|
+
var wallInProximity = this.getWallInProximity(point);
|
|
926
|
+
if (wallInProximity !== undefined)
|
|
927
|
+
return { type: types_2.IElements.WALL, index: wallInProximity };
|
|
928
|
+
return undefined;
|
|
929
|
+
};
|
|
930
|
+
RoomBuilderState.prototype.getClickedElement = function (point) {
|
|
931
|
+
var element = this.getElementAtPoint(point);
|
|
932
|
+
if (!element)
|
|
933
|
+
return;
|
|
934
|
+
var uiAnchor;
|
|
935
|
+
if (element.type === types_2.IElements.VERTEX)
|
|
936
|
+
return;
|
|
937
|
+
if (element.type === types_2.IElements.WALL)
|
|
938
|
+
uiAnchor = this.getWallUiAnchorPoint(element.index);
|
|
939
|
+
else
|
|
940
|
+
uiAnchor = this.getFeatureUiAnchorPoint(element.type, element.index);
|
|
941
|
+
if (!uiAnchor)
|
|
942
|
+
return undefined;
|
|
943
|
+
return {
|
|
944
|
+
path: [element.type, element.index],
|
|
945
|
+
uiAnchor: uiAnchor,
|
|
946
|
+
};
|
|
947
|
+
};
|
|
948
|
+
RoomBuilderState.prototype.getPointProximity = function (point) {
|
|
949
|
+
var feature = this.getFeatureAtPoint(point);
|
|
950
|
+
if (feature)
|
|
951
|
+
return __assign(__assign({}, feature), { point: point });
|
|
952
|
+
var snapToVertex = this.snapPointToVertex(point);
|
|
953
|
+
if (snapToVertex)
|
|
954
|
+
return snapToVertex;
|
|
955
|
+
var snapToWall = this.snapPointToWall(point);
|
|
956
|
+
if (snapToWall)
|
|
957
|
+
return snapToWall;
|
|
958
|
+
return undefined;
|
|
959
|
+
};
|
|
960
|
+
RoomBuilderState.prototype.reevaluateFeatureConnections = function () {
|
|
961
|
+
var _this = this;
|
|
962
|
+
this.walls.forEach(function (_, i) { return _this.updateWall(i, { connections: [] }); });
|
|
963
|
+
Object.entries(this.features).forEach(function (_a) {
|
|
964
|
+
var type = _a[0], featuresArr = _a[1];
|
|
965
|
+
return featuresArr.forEach(function (feature, i) {
|
|
966
|
+
return _this.addFeatureToWall(feature.connectedTo[1], [type, i]);
|
|
967
|
+
});
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
RoomBuilderState.prototype.pushStateToConfigurator = function () {
|
|
971
|
+
var configuration = (0, dataHandlers_1.prepAttributesOutgoing)(this.walls, this.features, this._config);
|
|
972
|
+
window.threekit.configurator.setConfiguration(configuration);
|
|
973
|
+
};
|
|
974
|
+
RoomBuilderState.prototype.setAttributesToState = function (attributes) {
|
|
975
|
+
if (!attributes)
|
|
976
|
+
return;
|
|
977
|
+
if (!attributes[this._config.attributes[types_2.IElements.WALL]])
|
|
978
|
+
return;
|
|
979
|
+
this._attributesState = attributes;
|
|
980
|
+
var data = (0, dataHandlers_1.prepAttributesIncoming)(attributes, this._config);
|
|
981
|
+
this.walls = data[types_2.IElements.WALL];
|
|
982
|
+
this.vertices = data[types_2.IElements.VERTEX];
|
|
983
|
+
this.features = data[types_2.IElements.FEATURE];
|
|
984
|
+
this.reevaluateFeatureConnections();
|
|
985
|
+
};
|
|
986
|
+
RoomBuilderState.prototype.deleteAll = function () {
|
|
987
|
+
this.walls = [];
|
|
988
|
+
this.vertices = {};
|
|
989
|
+
this.features = Object.keys(this.features).reduce(function (output, type) {
|
|
990
|
+
var _a;
|
|
991
|
+
return Object.assign(output, (_a = {}, _a[type] = [], _a));
|
|
992
|
+
}, {});
|
|
993
|
+
this.pushStateToConfigurator();
|
|
994
|
+
};
|
|
995
|
+
RoomBuilderState.prototype.resetInternalState = function () {
|
|
996
|
+
if (this._attributesState)
|
|
997
|
+
this.setAttributesToState(this._attributesState);
|
|
998
|
+
};
|
|
999
|
+
RoomBuilderState.prototype.highlightElementIfInProximity = function (canvas, point) {
|
|
1000
|
+
var _a, _b;
|
|
1001
|
+
var elementAtPoint = this.getElementAtPoint(point);
|
|
1002
|
+
if ((!elementAtPoint && !this._highlightedElement) ||
|
|
1003
|
+
Array.isArray(this._highlightedElement))
|
|
1004
|
+
return;
|
|
1005
|
+
if (elementAtPoint) {
|
|
1006
|
+
var type = elementAtPoint.type, index = elementAtPoint.index;
|
|
1007
|
+
if (((_a = this._highlightedElement) === null || _a === void 0 ? void 0 : _a.type) === type &&
|
|
1008
|
+
((_b = this._highlightedElement) === null || _b === void 0 ? void 0 : _b.index) === index)
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
this._highlightedElement = elementAtPoint !== null && elementAtPoint !== void 0 ? elementAtPoint : null;
|
|
1012
|
+
this.drawRoom(canvas);
|
|
1013
|
+
};
|
|
1014
|
+
RoomBuilderState.prototype.startDrawNewWall = function (startPoint) {
|
|
1015
|
+
var _a;
|
|
1016
|
+
var snapPoint = this.getPointProximity(startPoint);
|
|
1017
|
+
if ((snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.type) === types_2.IElements.WINDOW ||
|
|
1018
|
+
(snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.type) === types_2.IElements.OPENING ||
|
|
1019
|
+
(snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.type) === types_2.IElements.DOOR)
|
|
1020
|
+
return;
|
|
1021
|
+
this._newWall = {
|
|
1022
|
+
start: (_a = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _a !== void 0 ? _a : startPoint,
|
|
1023
|
+
snapStartTo: snapPoint,
|
|
1024
|
+
};
|
|
1025
|
+
};
|
|
1026
|
+
RoomBuilderState.prototype.drawNewWall = function (canvas, endPoint) {
|
|
1027
|
+
var _a, _b, _c, _d, _e;
|
|
1028
|
+
if (!this._newWall)
|
|
1029
|
+
return;
|
|
1030
|
+
var snapPoint = this.getPointProximity(endPoint);
|
|
1031
|
+
if (!snapPoint && this._angleSnappingEnabled)
|
|
1032
|
+
snapPoint = this.snapPointToAbsoluteAngle(endPoint, (_b = (_a = this._newWall.snapStartTo) === null || _a === void 0 ? void 0 : _a.point) !== null && _b !== void 0 ? _b : this._newWall.start);
|
|
1033
|
+
var wallLine = [
|
|
1034
|
+
this._newWall.start,
|
|
1035
|
+
(_c = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _c !== void 0 ? _c : endPoint,
|
|
1036
|
+
];
|
|
1037
|
+
var validationData = {
|
|
1038
|
+
walls: this.walls,
|
|
1039
|
+
features: this.features,
|
|
1040
|
+
newWall: {
|
|
1041
|
+
line: wallLine,
|
|
1042
|
+
snapStartTo: this._newWall.snapStartTo,
|
|
1043
|
+
snapEndTo: snapPoint,
|
|
1044
|
+
},
|
|
1045
|
+
};
|
|
1046
|
+
this._errorElement = (0, validators_1.runValidators)([
|
|
1047
|
+
validators_1.isWallEndingOnFeature,
|
|
1048
|
+
validators_1.isWallTooShort,
|
|
1049
|
+
validators_1.isWallOverlappingExisitingWalls,
|
|
1050
|
+
validators_1.isWallIntersectingFeature,
|
|
1051
|
+
], validationData);
|
|
1052
|
+
var errorType = ((_d = this._errorElement) === null || _d === void 0 ? void 0 : _d[0].type) || null;
|
|
1053
|
+
switch (errorType) {
|
|
1054
|
+
case types_1.IErrorTypes.HARD:
|
|
1055
|
+
return;
|
|
1056
|
+
case types_1.IErrorTypes.SOFT:
|
|
1057
|
+
case types_1.IErrorTypes.WARN:
|
|
1058
|
+
case null:
|
|
1059
|
+
default:
|
|
1060
|
+
this._newWall.end = (_e = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _e !== void 0 ? _e : endPoint;
|
|
1061
|
+
this._newWall.snapEndTo = snapPoint;
|
|
1062
|
+
this.drawRoom(canvas);
|
|
1063
|
+
break;
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
RoomBuilderState.prototype.cancelDrawNewWall = function (canvas) {
|
|
1067
|
+
this._newWall = null;
|
|
1068
|
+
this._errorElement = null;
|
|
1069
|
+
this._highlightedElement = null;
|
|
1070
|
+
this.drawRoom(canvas);
|
|
1071
|
+
};
|
|
1072
|
+
RoomBuilderState.prototype.finishDrawNewWall = function (canvas, assetId) {
|
|
1073
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1074
|
+
var _a, start, end, snapStartTo, snapEndTo, wallsToExclude, filteredWalls, intersections, newWallLines;
|
|
1075
|
+
var _this = this;
|
|
1076
|
+
return __generator(this, function (_b) {
|
|
1077
|
+
if (this._errorElement) {
|
|
1078
|
+
if ([this._errorElement].flat()[0].message)
|
|
1079
|
+
__1.message.info([this._errorElement].flat()[0].message);
|
|
1080
|
+
this._newWall = null;
|
|
1081
|
+
this._errorElement = null;
|
|
1082
|
+
this._highlightedElement = null;
|
|
1083
|
+
this.drawRoom(canvas);
|
|
1084
|
+
return [2];
|
|
1085
|
+
}
|
|
1086
|
+
_a = this._newWall || {}, start = _a.start, end = _a.end, snapStartTo = _a.snapStartTo, snapEndTo = _a.snapEndTo;
|
|
1087
|
+
if (!start || !end) {
|
|
1088
|
+
this._newWall = null;
|
|
1089
|
+
this._errorElement = null;
|
|
1090
|
+
this._highlightedElement = null;
|
|
1091
|
+
return [2];
|
|
1092
|
+
}
|
|
1093
|
+
wallsToExclude = new Set([]);
|
|
1094
|
+
if ((snapStartTo === null || snapStartTo === void 0 ? void 0 : snapStartTo.type) === types_2.IElements.WALL) {
|
|
1095
|
+
this.splitWall(snapStartTo.index, start);
|
|
1096
|
+
wallsToExclude.add(snapStartTo.index);
|
|
1097
|
+
}
|
|
1098
|
+
if ((snapEndTo === null || snapEndTo === void 0 ? void 0 : snapEndTo.type) === types_2.IElements.WALL) {
|
|
1099
|
+
this.splitWall(snapEndTo.index, end);
|
|
1100
|
+
wallsToExclude.add(snapEndTo.index);
|
|
1101
|
+
}
|
|
1102
|
+
if (wallsToExclude.size === 1)
|
|
1103
|
+
wallsToExclude.add(this.wallCount - 1);
|
|
1104
|
+
else if (wallsToExclude.size === 2)
|
|
1105
|
+
wallsToExclude.add(this.wallCount - 1).add(this.wallCount - 2);
|
|
1106
|
+
filteredWalls = this.walls.map(function (wall, i) {
|
|
1107
|
+
return wallsToExclude.has(i) ? null : wall.line;
|
|
1108
|
+
});
|
|
1109
|
+
intersections = (0, geometry_1.getAllLineIntersections)([start, end], filteredWalls);
|
|
1110
|
+
intersections.forEach(function (_a) {
|
|
1111
|
+
var index = _a.index, point = _a.point;
|
|
1112
|
+
return _this.splitWall(index, point);
|
|
1113
|
+
});
|
|
1114
|
+
newWallLines = (0, geometry_1.splitLineAtPoints)([start, end], intersections.map(function (_a) {
|
|
1115
|
+
var point = _a.point;
|
|
1116
|
+
return point;
|
|
1117
|
+
}));
|
|
1118
|
+
this.addWalls(newWallLines.map(function (line) { return ({
|
|
1119
|
+
assetId: assetId,
|
|
1120
|
+
line: line,
|
|
1121
|
+
height: 1,
|
|
1122
|
+
thickness: 0.6,
|
|
1123
|
+
connections: [],
|
|
1124
|
+
}); }));
|
|
1125
|
+
this._newWall = null;
|
|
1126
|
+
this._errorElement = null;
|
|
1127
|
+
this._highlightedElement = null;
|
|
1128
|
+
this.pushStateToConfigurator();
|
|
1129
|
+
return [2];
|
|
1130
|
+
});
|
|
1131
|
+
});
|
|
1132
|
+
};
|
|
1133
|
+
RoomBuilderState.prototype.selectElementIfInProximity = function (canvas, point) {
|
|
1134
|
+
var elementAtPoint = this.getElementAtPoint(point);
|
|
1135
|
+
if (!elementAtPoint || elementAtPoint.type === types_2.IElements.WALL)
|
|
1136
|
+
return;
|
|
1137
|
+
this._activeElement = elementAtPoint;
|
|
1138
|
+
if (elementAtPoint.type === types_2.IElements.VERTEX) {
|
|
1139
|
+
var wallIndexes = this.getWallsConnectedToVertex(elementAtPoint.index);
|
|
1140
|
+
this._highlightedElement = wallIndexes.map(function (index) { return ({
|
|
1141
|
+
type: types_2.IElements.WALL,
|
|
1142
|
+
index: index,
|
|
1143
|
+
}); });
|
|
1144
|
+
}
|
|
1145
|
+
this.drawRoom(canvas);
|
|
1146
|
+
};
|
|
1147
|
+
RoomBuilderState.prototype.moveActiveElement = function (canvas, moveToPoint) {
|
|
1148
|
+
if (!canvas)
|
|
1149
|
+
return;
|
|
1150
|
+
if (!this._activeElement)
|
|
1151
|
+
return;
|
|
1152
|
+
var type = this._activeElement.type;
|
|
1153
|
+
if (type === types_2.IElements.VERTEX)
|
|
1154
|
+
this.moveActiveVertex(canvas, moveToPoint);
|
|
1155
|
+
else if (type === types_2.IElements.WINDOW ||
|
|
1156
|
+
type === types_2.IElements.DOOR ||
|
|
1157
|
+
type === types_2.IElements.OPENING)
|
|
1158
|
+
this.moveActiveFeature(canvas, moveToPoint);
|
|
1159
|
+
};
|
|
1160
|
+
RoomBuilderState.prototype.finishMoveActiveElement = function (canvas) {
|
|
1161
|
+
if (!this._activeElement)
|
|
1162
|
+
return;
|
|
1163
|
+
if (this._errorElement) {
|
|
1164
|
+
if ([this._errorElement].flat()[0].message)
|
|
1165
|
+
__1.message.info([this._errorElement].flat()[0].message);
|
|
1166
|
+
this._activeElement = null;
|
|
1167
|
+
this._errorElement = null;
|
|
1168
|
+
this._highlightedElement = null;
|
|
1169
|
+
this.resetInternalState();
|
|
1170
|
+
this.drawRoom(canvas);
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
var type = this._activeElement.type;
|
|
1174
|
+
if (type === types_2.IElements.VERTEX)
|
|
1175
|
+
this.finishMoveActiveVertex();
|
|
1176
|
+
else if (type === types_2.IElements.WINDOW ||
|
|
1177
|
+
type === types_2.IElements.DOOR ||
|
|
1178
|
+
type === types_2.IElements.OPENING)
|
|
1179
|
+
this.finishMoveActiveFeature();
|
|
1180
|
+
this._activeElement = null;
|
|
1181
|
+
this._errorElement = null;
|
|
1182
|
+
this._highlightedElement = null;
|
|
1183
|
+
this.drawRoom(canvas);
|
|
1184
|
+
};
|
|
1185
|
+
RoomBuilderState.prototype.cancelMoveActiveElement = function (canvas) {
|
|
1186
|
+
this._activeElement = null;
|
|
1187
|
+
this._errorElement = null;
|
|
1188
|
+
this._highlightedElement = null;
|
|
1189
|
+
this.resetInternalState();
|
|
1190
|
+
this.drawRoom(canvas);
|
|
1191
|
+
};
|
|
1192
|
+
RoomBuilderState.prototype.drawRoom = function (canvas) {
|
|
1193
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1194
|
+
if (!canvas)
|
|
1195
|
+
return;
|
|
1196
|
+
var highlighted = this._highlightedElement
|
|
1197
|
+
? [this._highlightedElement].flat()
|
|
1198
|
+
: [];
|
|
1199
|
+
var active = this._activeElement && this._activeElement.type !== types_2.IElements.VERTEX
|
|
1200
|
+
? [this._activeElement]
|
|
1201
|
+
: [];
|
|
1202
|
+
var error = this._errorElement
|
|
1203
|
+
? [this._errorElement]
|
|
1204
|
+
.flat()
|
|
1205
|
+
.reduce(function (output, _a) {
|
|
1206
|
+
var address = _a.address;
|
|
1207
|
+
return (address ? __spreadArray(__spreadArray([], output, true), [address], false) : output);
|
|
1208
|
+
}, [])
|
|
1209
|
+
: [];
|
|
1210
|
+
var hidden = ((_a = this._activeElement) === null || _a === void 0 ? void 0 : _a.type) === types_2.IElements.VERTEX
|
|
1211
|
+
? [this._activeElement]
|
|
1212
|
+
: [];
|
|
1213
|
+
if (this.selectedElement)
|
|
1214
|
+
highlighted.push(this.selectedElement);
|
|
1215
|
+
var selection = {
|
|
1216
|
+
highlighted: highlighted,
|
|
1217
|
+
active: active,
|
|
1218
|
+
error: error,
|
|
1219
|
+
hidden: hidden,
|
|
1220
|
+
};
|
|
1221
|
+
var activeWallIndex;
|
|
1222
|
+
if (this._showDimensions &&
|
|
1223
|
+
(((_b = this._activeElement) === null || _b === void 0 ? void 0 : _b.type) === types_2.IElements.WINDOW ||
|
|
1224
|
+
((_c = this._activeElement) === null || _c === void 0 ? void 0 : _c.type) === types_2.IElements.DOOR ||
|
|
1225
|
+
((_d = this._activeElement) === null || _d === void 0 ? void 0 : _d.type) === types_2.IElements.OPENING))
|
|
1226
|
+
activeWallIndex = (_e = this.getFeature(this._activeElement.type, this._activeElement.index)) === null || _e === void 0 ? void 0 : _e.connectedTo[1];
|
|
1227
|
+
(0, draw_1.drawRoom)(canvas, this.enclosedSpaces, this.walls, this.verticesList, this.features, this._showDimensions
|
|
1228
|
+
? this.getAllWallDimensions(activeWallIndex)
|
|
1229
|
+
: undefined, selection, this._config.config);
|
|
1230
|
+
if (((_f = this._newWall) === null || _f === void 0 ? void 0 : _f.start) && ((_g = this._newWall) === null || _g === void 0 ? void 0 : _g.end)) {
|
|
1231
|
+
(0, draw_1.drawNewWall)(canvas, [this._newWall.start, this._newWall.end], this._config.config.styles, this._errorElement ? types_1.IElementStyleModes.ERROR : undefined);
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
return RoomBuilderState;
|
|
1235
|
+
}());
|
|
1236
|
+
exports.RoomBuilderState = RoomBuilderState;
|
|
1237
|
+
exports.default = RoomBuilderState;
|