dataarts / dat.gui

Lightweight controller library for JavaScript.
Apache License 2.0
7.46k stars 1.08k forks source link

Slider and its text field get unlinked #200

Open Nodragem opened 5 years ago

Nodragem commented 5 years ago

After I try to change the target object that the slider is controlling, the text field of the slider and the slider does not change together. See below: dat-gui-bugreport

The property of the target object is changing when I move the slider, but not when I input a new value in the text field.

Here is how I change my target object:

        var gui = new dat.GUI();
        gui.domElement.style.marginTop = "100px";
        gui.domElement.id = "datGUI";

        gui.add(game.player, 'swapCameraView').name("Swap Camera");
        let e1 = gui.add(game.player.mvtManager, 'movementDuration', 0, 4).name("Movement duration (s)");
        let e2 = gui.add(game.player.mvtManager, 'rotationDuration', 0, 4).name("Rotation duration (s)");
        let e3 = gui.add(game.player.mvtManager.getTargetBall(), 'isVisible').name("Show target ball:");

        let options = {Movement:game.player.mvtManager.name};
        let e4 = gui.add(options, 'Movement', ['Preset 1', 'Preset 2', 'Preset 3'] ).onChange(
            (value) => {
                game.player.changeMvtManager(value)
                e1.object = game.player.mvtManager;
                e1.setValue(game.player.mvtManager.movementDuration);
                e1.updateDisplay();
                e2.object = game.player.mvtManager;
                e2.setValue(game.player.mvtManager.rotationDuration);
                e2.updateDisplay();
                e3.object = game.player.mvtManager.getTargetBall();
                e3.setValue(game.player.mvtManager.getTargetBall().isVisible);
            }
        );
        e4.name('Movement scheme: ')

Here the content of changeMvtManager(value):

public changeMvtManager(name:string){
        console.log("change Movement Scheme to: " + name);
        this.mvtManager.dispose();
        switch(name){
            case "Preset 1":
                this.root.position = new BABYLON.Vector3(0, 0.7, 0);
                this.mvtManager = new GridMovement1(this.scene, this.maze, this.root);
                break;
                case "Preset 2":
                this.root.position = new BABYLON.Vector3(0, 0.7, 0);
                this.mvtManager = new GridMovement2(this.scene, this.maze, this.root);
                break;
                case "Preset 3":
                this.root.position = new BABYLON.Vector3(0, 0.7, 0);
                this.mvtManager = new GridMovement3(this.scene, this.maze, this.root);
            break;
        }
    }
donmccurdy commented 5 years ago

I don't think the controller's .object property is meant to be modified. Are you able to reproduce this issue without doing that?