Skip to content

Commit

Permalink
feat(core): clean up config manager
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Aug 31, 2024
1 parent a523c01 commit 468d425
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 49 deletions.
93 changes: 82 additions & 11 deletions packages/core/src/core/Types/src/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@ export interface NumberSettingControl {

export interface SelectSettingControl {
type: "Select";
multiple: boolean;
options: Set<string>;
value: string;
}

export interface MultiSelectSettingControl {
type: "MultiSelect";
options: Set<string>;
value: Set<string>;
}

export interface Vector3SettingControl {
type: "Vector";
type: "Vector3";
value: THREE.Vector3;
}

Expand All @@ -46,6 +41,11 @@ export interface TextSetSettingControl {
value: Set<string>;
}

export interface NoControl {
type: "None";
value: any;
}

type ControlEntry =
| BooleanSettingsControl
| ColorSettingsControl
Expand All @@ -54,22 +54,93 @@ type ControlEntry =
| SelectSettingControl
| Vector3SettingControl
| TextSetSettingControl
| MultiSelectSettingControl;
| NoControl;

interface ControlsSchema {
[name: string]: ControlEntry | ControlsSchema;
}

export abstract class ConfigManager<T, U extends ControlsSchema> {
protected abstract _list: U;
protected abstract _config: U;

protected _component: T;

get controls() {
return JSON.parse(JSON.stringify(this._list));
get controls(): U {
const copy: any = {};
for (const name in this._config) {
const entry = this._config[name] as ControlEntry;
copy[name] = this.copyEntry(entry);
}
return copy as U;
}

constructor(component: T) {
this._component = component;
}

copyEntry(controlEntry: ControlEntry): ControlEntry {
if (controlEntry.type === "Boolean") {
const entry = controlEntry as BooleanSettingsControl;
return {
type: entry.type,
value: entry.value,
};
}
if (controlEntry.type === "Color") {
const entry = controlEntry as ColorSettingsControl;
return {
type: entry.type,
opacity: entry.opacity,
value: entry.value.clone(),
};
}
if (controlEntry.type === "Text") {
const entry = controlEntry as TextSettingsControl;
return {
type: entry.type,
value: entry.value,
};
}
if (controlEntry.type === "Number") {
const entry = controlEntry as NumberSettingControl;
return {
type: entry.type,
value: entry.value,
min: entry.min,
max: entry.max,
interpolable: entry.interpolable,
};
}
if (controlEntry.type === "Select") {
const entry = controlEntry as SelectSettingControl;
return {
type: entry.type,
value: entry.value,
multiple: entry.multiple,
options: new Set(entry.options),
};
}
if (controlEntry.type === "Vector3") {
const entry = controlEntry as Vector3SettingControl;
return {
type: entry.type,
value: entry.value.clone(),
};
}
if (controlEntry.type === "TextSet") {
const entry = controlEntry as TextSetSettingControl;
return {
type: entry.type,
value: new Set(entry.value),
};
}
if (controlEntry.type === "None") {
const entry = controlEntry as NoControl;
return {
type: entry.type,
value: entry.value,
};
}
throw new Error("Invalid entry!");
}
}
6 changes: 3 additions & 3 deletions packages/core/src/core/Viewpoints/src/viewpoints-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ViewpointsConfigManger extends ConfigManager<
Viewpoints,
ViewpointsConfigType
> {
protected _list = {
protected _config = {
overwriteColors: {
value: false,
opacity: 1,
Expand All @@ -30,10 +30,10 @@ export class ViewpointsConfigManger extends ConfigManager<
};

get overwriteColors() {
return this._list.overwriteColors.value;
return this._config.overwriteColors.value;
}

set overwriteColors(value: boolean) {
this._list.overwriteColors.value = value;
this._config.overwriteColors.value = value;
}
}
12 changes: 6 additions & 6 deletions packages/core/src/core/Worlds/src/simple-scene-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class SimpleSceneConfigManager extends ConfigManager<
SimpleScene,
SimpleSceneConfigType
> {
protected _list = {
protected _config = {
backgroundColor: {
value: new THREE.Color() as THREE.Color,
opacity: 1,
Expand Down Expand Up @@ -146,22 +146,22 @@ export class SimpleSceneConfigManager extends ConfigManager<
value: 2,
},
position: {
type: "Vector" as const,
type: "Vector3" as const,
value: new THREE.Vector3(),
},
},
};

ambientLight = new AmbientLightConfig(this._list, this._component);
ambientLight = new AmbientLightConfig(this._config, this._component);

directionalLight = new DirectionalLightConfig(this._list, this._component);
directionalLight = new DirectionalLightConfig(this._config, this._component);

get backgroundColor() {
return this._list.backgroundColor.value;
return this._config.backgroundColor.value;
}

set backgroundColor(value: THREE.Color) {
this._list.backgroundColor.value = value;
this._config.backgroundColor.value = value;
this._component.three.background = value;
}
}
60 changes: 31 additions & 29 deletions packages/core/src/openbim/BCFTopics/src/bcf-topics-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ export class BCFTopicsConfigManager extends ConfigManager<
BCFTopics,
BCFTopicsConfigType
> {
protected _list = {
protected _config = {
version: {
type: "Select" as const,
options: new Set<string>(),
multiple: false,
value: "",
},
author: {
Expand Down Expand Up @@ -166,6 +167,7 @@ export class BCFTopicsConfigManager extends ConfigManager<
},
fallbackVersionOnImport: {
type: "Select" as const,
multiple: false,
options: new Set<string>(),
value: "",
},
Expand All @@ -176,113 +178,113 @@ export class BCFTopicsConfigManager extends ConfigManager<
};

get version() {
return this._list.version.value;
return this._config.version.value;
}
set version(value) {
this._list.version.value = value;
this._config.version.value = value;
}

get author() {
return this._list.author.value;
return this._config.author.value;
}

set author(value) {
this._list.author.value = value;
this._config.author.value = value;
}

get types() {
return this._list.types.value;
return this._config.types.value;
}

set types(value) {
this._list.types.value = value;
this._config.types.value = value;
}

get statuses() {
return this._list.statuses.value;
return this._config.statuses.value;
}

set statuses(value) {
this._list.statuses.value = value;
this._config.statuses.value = value;
}

get priorities() {
return this._list.priorities.value;
return this._config.priorities.value;
}

set priorities(value) {
this._list.priorities.value = value;
this._config.priorities.value = value;
}

get labels() {
return this._list.labels.value;
return this._config.labels.value;
}

set labels(value) {
this._list.labels.value = value;
this._config.labels.value = value;
}

get stages() {
return this._list.stages.value;
return this._config.stages.value;
}

set stages(value) {
this._list.stages.value = value;
this._config.stages.value = value;
}

get users() {
return this._list.users.value;
return this._config.users.value;
}

set users(value) {
this._list.users.value = value;
this._config.users.value = value;
}

get includeSelectionTag() {
return this._list.includeSelectionTag.value;
return this._config.includeSelectionTag.value;
}

set includeSelectionTag(value) {
this._list.includeSelectionTag.value = value;
this._config.includeSelectionTag.value = value;
}

get updateExtensionsOnImport() {
return this._list.updateExtensionsOnImport.value;
return this._config.updateExtensionsOnImport.value;
}

set updateExtensionsOnImport(value) {
this._list.updateExtensionsOnImport.value = value;
this._config.updateExtensionsOnImport.value = value;
}

get strict() {
return this._list.strict.value;
return this._config.strict.value;
}

set strict(value) {
this._list.strict.value = value;
this._config.strict.value = value;
}

get includeAllExtensionsOnExport() {
return this._list.includeAllExtensionsOnExport.value;
return this._config.includeAllExtensionsOnExport.value;
}

set includeAllExtensionsOnExport(value) {
this._list.includeAllExtensionsOnExport.value = value;
this._config.includeAllExtensionsOnExport.value = value;
}

get fallbackVersionOnImport() {
return this._list.fallbackVersionOnImport.value;
return this._config.fallbackVersionOnImport.value;
}

set fallbackVersionOnImport(value) {
this._list.fallbackVersionOnImport.value = value;
this._config.fallbackVersionOnImport.value = value;
}

get ignoreIncompleteTopicsOnImport() {
return this._list.ignoreIncompleteTopicsOnImport.value;
return this._config.ignoreIncompleteTopicsOnImport.value;
}

set ignoreIncompleteTopicsOnImport(value) {
this._list.ignoreIncompleteTopicsOnImport.value = value;
this._config.ignoreIncompleteTopicsOnImport.value = value;
}
}

0 comments on commit 468d425

Please sign in to comment.