Skip to content

Commit

Permalink
feat(core): add export-import features to config
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Nov 6, 2024
1 parent 006b4a1 commit e1b84e6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thatopen/components",
"description": "Collection of core functionalities to author BIM apps.",
"version": "2.4.0-alpha.28",
"version": "2.4.0-alpha.30",
"author": "That Open Company",
"contributors": [
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
Expand Down
44 changes: 44 additions & 0 deletions packages/core/src/core/ConfigManager/src/configurator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as THREE from "three";
import {
ControlsSchema,
ControlEntry,
Expand Down Expand Up @@ -57,6 +58,49 @@ export abstract class Configurator<
}
}

export() {
const serializedData: any = {};
for (const id in this._config) {
const control = this._config[id];

if (control.type === "Color") {
const { r, g, b } = control.value;
serializedData[id] = { ...control, value: { r, g, b } };
} else if (control.type === "Vector3") {
const { x, y, z } = control.value;
serializedData[id] = { ...control, value: { x, y, z } };
} else if (control.type === "Select" || control.type === "TextSet") {
const value = Array.from(control.value);
serializedData[id] = { ...control, value };
} else {
serializedData[id] = { ...control };
}
}

return serializedData;
}

import(serializedData: any) {
const imported: any = {};

for (const id in serializedData) {
const control = serializedData[id];
if (control.type === "Color") {
const { r, g, b } = control.value;
imported[id] = { ...control, value: new THREE.Color(r, g, b) };
} else if (control.type === "Vector3") {
const { x, y, z } = control.value;
imported[id] = { ...control, value: new THREE.Vector3(x, y, z) };
} else if (control.type === "Select" || control.type === "TextSet") {
imported[id] = { ...control, value: new Set(control.value) };
} else {
imported[id] = { ...control };
}
}

this.set(imported);
}

copyEntry(controlEntry: ControlEntry): ControlEntry {
if (controlEntry.type === "Boolean") {
const entry = controlEntry as BooleanSettingsControl;
Expand Down
4 changes: 2 additions & 2 deletions packages/front/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thatopen/components-front",
"description": "Collection of frontend tools to author BIM apps.",
"version": "2.4.0-alpha.29",
"version": "2.4.0-alpha.30",
"author": "That Open Company",
"contributors": [
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
Expand Down Expand Up @@ -47,7 +47,7 @@
"web-ifc": "0.0.61"
},
"dependencies": {
"@thatopen/components": ">=2.4.0-alpha.28",
"@thatopen/components": ">=2.4.0-alpha.30",
"camera-controls": "2.7.3",
"dexie": "^4.0.4",
"earcut": "^2.2.4",
Expand Down

0 comments on commit e1b84e6

Please sign in to comment.