updated config and some looping observables.

This commit is contained in:
Michael Mainguy 2023-08-24 15:51:05 -05:00
parent 50c972eb97
commit 559108281f
8 changed files with 48 additions and 72 deletions

View File

@ -52,7 +52,10 @@ export class App {
const diagramManager = new DiagramManager(scene, controllers, toolbox, config); const diagramManager = new DiagramManager(scene, controllers, toolbox, config);
diagramManager.onDiagramEventObservable.add((evt) => { diagramManager.onDiagramEventObservable.add((evt) => {
worker.postMessage(evt); worker.postMessage({entity: evt});
}, 2);
config.onConfigChangedObservable.add((config) => {
worker.postMessage({config: config});
}, 2); }, 2);
worker.onmessage = (evt) => { worker.onmessage = (evt) => {
if (evt.data.entity) { if (evt.data.entity) {

View File

@ -157,7 +157,7 @@ export class Base {
type: DiagramEventType.ADD, type: DiagramEventType.ADD,
entity: toDiagramEntity(newMesh) entity: toDiagramEntity(newMesh)
} }
this.diagramManager.onDiagramEventObservable.notifyObservers(event, 2); this.diagramManager.onDiagramEventObservable.notifyObservers(event, -1);
} }
} }
@ -202,7 +202,7 @@ export class Base {
entity: entity entity: entity
} }
this.diagramManager.onDiagramEventObservable.notifyObservers(event, 2);
const body = mesh?.physicsBody; const body = mesh?.physicsBody;
if (body) { if (body) {
body.setMotionType(PhysicsMotionType.DYNAMIC); body.setMotionType(PhysicsMotionType.DYNAMIC);
@ -214,6 +214,7 @@ export class Base {
this.logger.debug(this.lastPosition.subtract(body.transformNode.absolutePosition).scale(20)); this.logger.debug(this.lastPosition.subtract(body.transformNode.absolutePosition).scale(20));
} }
} }
this.diagramManager.onDiagramEventObservable.notifyObservers(event, -1);
} }
private initGrip(grip: WebXRControllerComponent) { private initGrip(grip: WebXRControllerComponent) {

View File

@ -41,57 +41,24 @@ export function diagramEventHandler(event: DiagramEvent,
break; break;
case DiagramEventType.DROP: case DiagramEventType.DROP:
if (mesh.metadata.template.indexOf('#') > -1) { if (mesh.metadata.template.indexOf('#') > -1) {
//@TODO refactor
// persistenceManager.modify(entity);
TextLabel.updateTextNode(mesh, entity.text); TextLabel.updateTextNode(mesh, entity.text);
} }
break; break;
case DiagramEventType.ADD: case DiagramEventType.ADD:
//@TODO refactor
//persistenceManager.add(event.entity);
if (!mesh.actionManager) { if (!mesh.actionManager) {
mesh.actionManager = actionManager; mesh.actionManager = actionManager;
} }
if (physicsEnabled) { if (physicsEnabled) {
applyPhysics(sounds, mesh, scene); applyPhysics(sounds, mesh, scene);
} }
break; break;
case DiagramEventType.MODIFY: case DiagramEventType.MODIFY:
//@TODO refactor
//persistenceManager.modify(mesh);
if (physicsEnabled) { if (physicsEnabled) {
applyPhysics(sounds, mesh, scene); applyPhysics(sounds, mesh, scene);
} }
break;
case DiagramEventType.CHANGECOLOR:
if (!event.oldColor) {
if (!event.newColor) {
//@TODO refactor
//persistenceManager.changeColor(null, Color3.FromHexString(event.entity.color));
this.logger.info("Received color change event, sending entity color as new color");
} else {
this.logger.info("Received color change event, no old color, sending new color");
//@TODO refactor
//persistenceManager.changeColor(null, event.newColor);
}
} else {
if (event.newColor) {
this.logger.info("changing color from " + event.oldColor + " to " + event.newColor);
//@TODO refactor
//persistenceManager.changeColor(event.oldColor, event.newColor);
} else {
this.logger.error("changing color from " + event.oldColor + ", but no new color found");
}
}
break; break;
case DiagramEventType.REMOVE: case DiagramEventType.REMOVE:
if (mesh) { if (mesh) {
//@TODO refactor
//persistenceManager.remove(mesh.id)
mesh?.physicsBody?.dispose(); mesh?.physicsBody?.dispose();
mesh.dispose(); mesh.dispose();
sounds.exit.play(); sounds.exit.play();

View File

@ -23,12 +23,12 @@ export class DiagramManager {
private readonly controllers: Controllers; private readonly controllers: Controllers;
private readonly diagramEntityActionManager: DiagramEntityActionManager private readonly diagramEntityActionManager: DiagramEntityActionManager
private presentationManager: PresentationManager; private presentationManager: PresentationManager;
private _config: AppConfig; public readonly config: AppConfig;
constructor(scene: Scene, controllers: Controllers, toolbox: Toolbox, config: AppConfig) { constructor(scene: Scene, controllers: Controllers, toolbox: Toolbox, config: AppConfig) {
this.sounds = new DiaSounds(scene); this.sounds = new DiaSounds(scene);
this.scene = scene; this.scene = scene;
this._config = config; this.config = config;
this.toolbox = toolbox; this.toolbox = toolbox;
this.controllers = controllers; this.controllers = controllers;
this.presentationManager = new PresentationManager(this.scene); this.presentationManager = new PresentationManager(this.scene);
@ -63,10 +63,6 @@ export class DiagramManager {
}); });
} }
public get config(): AppConfig {
return this._config;
}
//@TODO Refactor //@TODO Refactor
/*public setPersistenceManager(persistenceManager: IPersistenceManager) { /*public setPersistenceManager(persistenceManager: IPersistenceManager) {
this.persistenceManager = persistenceManager; this.persistenceManager = persistenceManager;

View File

@ -96,9 +96,12 @@ export class ConfigMenu extends AbstractMenu {
private buildGridSizeControl(selectionPanel: SelectionPanel): RadioGroup { private buildGridSizeControl(selectionPanel: SelectionPanel): RadioGroup {
const radio = new RadioGroup("Grid Snap"); const radio = new RadioGroup("Grid Snap");
selectionPanel.addGroup(radio); selectionPanel.addGroup(radio);
for (const [index, snap] of this.gridSnaps.entries()) { for (const [index, snap] of this.gridSnaps.entries()) {
const selected = this.config.current.gridSnap == snap.value; const selected = this.config.current.gridSnap == snap.value;
radio.addRadio(snap.label, this.gridVal.bind(this), selected); radio.addRadio(snap.label, this.gridVal.bind(this), selected);
} }
return radio; return radio;
@ -116,19 +119,26 @@ export class ConfigMenu extends AbstractMenu {
private createVal(value) { private createVal(value) {
const config = this.config.current; const config = this.config.current;
if (config.createSnap != this.gridSnaps[value].value) {
config.createSnap = this.gridSnaps[value].value; config.createSnap = this.gridSnaps[value].value;
this.config.current = config; this.config.current = config;
log.debug("configMenu", "create Snap", value); log.debug("configMenu", "create Snap", value);
} }
}
private rotateVal(value) { private rotateVal(value) {
const config = this.config.current; const config = this.config.current;
if (config.rotateSnap != this.rotationSnaps[value].value) {
config.rotateSnap = this.rotationSnaps[value].value; config.rotateSnap = this.rotationSnaps[value].value;
this.config.current = config; this.config.current = config;
log.debug("configMenu", "rotate Snap", value); log.debug("configMenu", "rotate Snap", value);
} }
}
private turnVal(value) { private turnVal(value) {
const config = this.config.current; const config = this.config.current;
config.turnSnap = this.rotationSnaps[value].value; config.turnSnap = this.rotationSnaps[value].value;

View File

@ -186,7 +186,7 @@ export class EditMenu extends AbstractMenu {
this.diagramManager.onDiagramEventObservable.notifyObservers({ this.diagramManager.onDiagramEventObservable.notifyObservers({
type: DiagramEventType.MODIFY, type: DiagramEventType.MODIFY,
entity: toDiagramEntity(newMesh) entity: toDiagramEntity(newMesh)
}, 2); }, -1);
} else { } else {
this.logger.error("no paint color selectced"); this.logger.error("no paint color selectced");

View File

@ -1,21 +1,15 @@
import {Observable} from "@babylonjs/core"; import {Observable} from "@babylonjs/core";
//import {IPersistenceManager} from "../integration/iPersistenceManager";
import {AppConfigType} from "./appConfigType"; import {AppConfigType} from "./appConfigType";
export class AppConfig { export class AppConfig {
public readonly onConfigChangedObservable = new Observable<AppConfigType>(); public readonly onConfigChangedObservable = new Observable<AppConfigType>();
private _currentConfig: AppConfigType; private _currentConfig: AppConfigType;
// private persistenceManager: IPersistenceManager;
constructor() { constructor() {
this.onConfigChangedObservable.add((config, state) => { this.onConfigChangedObservable.add((config, state) => {
console.log(state); console.log(state);
this._currentConfig = config; this._currentConfig = config;
}, 2); }, -1);
//this.persistenceManager = persistenceManager;
//this.persistenceManager.configObserver.add(this.load, -1, false, this, false);
} }
public get current(): AppConfigType { public get current(): AppConfigType {
@ -38,12 +32,8 @@ export class AppConfig {
} }
public set current(config: AppConfigType) { public set current(config: AppConfigType) {
this._currentConfig = config;
this.onConfigChangedObservable.notifyObservers(config, 2); this.onConfigChangedObservable.notifyObservers(config, 2);
this.save();
}
public save() {
//this.persistenceManager.setConfig(this._currentConfig);
} }
public load(config: AppConfigType) { public load(config: AppConfigType) {

View File

@ -19,11 +19,14 @@ ctx.onmessage = (event) => {
console.log('initialized'); console.log('initialized');
}); });
} else { } else {
const data = (event.data as DiagramEvent); if (event.data.entity) {
const data = (event.data.entity as DiagramEvent);
console.log(data);
switch (data.type) { switch (data.type) {
case DiagramEventType.ADD: case DiagramEventType.ADD:
persistenceManager.add(data.entity); persistenceManager.add(data.entity);
break; break;
case DiagramEventType.DROP:
case DiagramEventType.MODIFY: case DiagramEventType.MODIFY:
persistenceManager.modify(data.entity); persistenceManager.modify(data.entity);
break; break;
@ -33,4 +36,10 @@ ctx.onmessage = (event) => {
} }
} }
if (event.data.config) {
persistenceManager.setConfig(event.data.config);
}
}
}; };