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);
diagramManager.onDiagramEventObservable.add((evt) => {
worker.postMessage(evt);
worker.postMessage({entity: evt});
}, 2);
config.onConfigChangedObservable.add((config) => {
worker.postMessage({config: config});
}, 2);
worker.onmessage = (evt) => {
if (evt.data.entity) {

View File

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

View File

@ -41,57 +41,24 @@ export function diagramEventHandler(event: DiagramEvent,
break;
case DiagramEventType.DROP:
if (mesh.metadata.template.indexOf('#') > -1) {
//@TODO refactor
// persistenceManager.modify(entity);
TextLabel.updateTextNode(mesh, entity.text);
}
break;
case DiagramEventType.ADD:
//@TODO refactor
//persistenceManager.add(event.entity);
if (!mesh.actionManager) {
mesh.actionManager = actionManager;
}
if (physicsEnabled) {
applyPhysics(sounds, mesh, scene);
}
break;
case DiagramEventType.MODIFY:
//@TODO refactor
//persistenceManager.modify(mesh);
if (physicsEnabled) {
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;
case DiagramEventType.REMOVE:
if (mesh) {
//@TODO refactor
//persistenceManager.remove(mesh.id)
mesh?.physicsBody?.dispose();
mesh.dispose();
sounds.exit.play();

View File

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

View File

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

View File

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

View File

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

View File

@ -19,18 +19,27 @@ ctx.onmessage = (event) => {
console.log('initialized');
});
} else {
const data = (event.data as DiagramEvent);
switch (data.type) {
case DiagramEventType.ADD:
persistenceManager.add(data.entity);
break;
case DiagramEventType.MODIFY:
persistenceManager.modify(data.entity);
break;
case DiagramEventType.REMOVE:
persistenceManager.remove(data.entity.id);
break;
if (event.data.entity) {
const data = (event.data.entity as DiagramEvent);
console.log(data);
switch (data.type) {
case DiagramEventType.ADD:
persistenceManager.add(data.entity);
break;
case DiagramEventType.DROP:
case DiagramEventType.MODIFY:
persistenceManager.modify(data.entity);
break;
case DiagramEventType.REMOVE:
persistenceManager.remove(data.entity.id);
break;
}
}
if (event.data.config) {
persistenceManager.setConfig(event.data.config);
}
}
};