Skip to content
Snippets Groups Projects
Select Git revision
  • d6077d9a9acad1e2f3357aac7dd9bc0656722ced
  • master default protected
  • devel
  • hruska-feature-clients-api
  • malostik-#5066-deduplicate-idea-ids
  • warden-postgresql-port
  • hruska-feature-#6799-filter-keys
  • hruska-feature-5066-duplicateIdeaID
  • warden-client-3.0-beta3
  • warden-server-3.0-beta3
  • warden-client-2.2-final
  • warden-server-2.2-final
  • warden-client-3.0-beta2
  • warden-server-3.0-beta2
  • warden-client-2.2
  • warden-server-2.2-patch3
  • warden-client-3.0-beta1
  • warden-server-3.0-beta1
  • warden-server-2.2-patch1
  • warden-client-3.0-beta0
  • warden-server-3.0-beta0
  • warden-server-2.2
  • warden-server-2.1-patch1
  • warden-client-2.1
  • warden-server-2.1
  • warden-server-2.1-beta6
  • warden-server-2.1-beta5
  • warden-server-2.1-beta4
28 results

install.sh

Blame
  • state.ts 3.18 KiB
    /**
     * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { State } from 'mol-state';
    import { PluginStateObject as SO } from './state/objects';
    import { Camera } from 'mol-canvas3d/camera';
    import { PluginBehavior } from './behavior';
    import { CameraSnapshotManager } from './state/camera';
    import { PluginStateSnapshotManager } from './state/snapshots';
    import { RxEventHelper } from 'mol-util/rx-event-helper';
    export { PluginState }
    
    class PluginState {
        private ev = RxEventHelper.create();
    
        readonly dataState: State;
        readonly behaviorState: State;
        readonly cameraSnapshots = new CameraSnapshotManager();
    
        readonly snapshots = new PluginStateSnapshotManager();
    
        readonly behavior = {
            kind: this.ev.behavior<PluginState.Kind>('data'),
            currentObject: this.ev.behavior<State.ObjectEvent>({} as any)
        }
    
        setKind(kind: PluginState.Kind) {
            const current = this.behavior.kind.value;
            if (kind !== current) {
                this.behavior.kind.next(kind);
                this.behavior.currentObject.next(kind === 'data'
                    ? this.dataState.behaviors.currentObject.value
                    : this.behaviorState.behaviors.currentObject.value)
            }
        }
    
        getSnapshot(): PluginState.Snapshot {
            return {
                data: this.dataState.getSnapshot(),
                behaviour: this.behaviorState.getSnapshot(),
                cameraSnapshots: this.cameraSnapshots.getStateSnapshot(),
                canvas3d: {
                    camera: this.plugin.canvas3d.camera.getSnapshot()
                }
            };
        }
    
        async setSnapshot(snapshot: PluginState.Snapshot) {
            // await this.plugin.runTask(this.behaviorState.setSnapshot(snapshot.behaviour));
            await this.plugin.runTask(this.dataState.setSnapshot(snapshot.data));
            this.cameraSnapshots.setStateSnapshot(snapshot.cameraSnapshots);
            this.plugin.canvas3d.camera.setState(snapshot.canvas3d.camera);
            this.plugin.canvas3d.requestDraw(true);
        }
    
        dispose() {
            this.ev.dispose();
            this.dataState.dispose();
            this.behaviorState.dispose();
            this.cameraSnapshots.dispose();
        }
    
        constructor(private plugin: import('./context').PluginContext) {
            this.dataState = State.create(new SO.Root({ }), { globalContext: plugin });
            this.behaviorState = State.create(new PluginBehavior.Root({ }), { globalContext: plugin });
    
            this.dataState.behaviors.currentObject.subscribe(o => {
                if (this.behavior.kind.value === 'data') this.behavior.currentObject.next(o);
            });
            this.behaviorState.behaviors.currentObject.subscribe(o => {
                if (this.behavior.kind.value === 'behavior') this.behavior.currentObject.next(o);
            });
    
            this.behavior.currentObject.next(this.dataState.behaviors.currentObject.value);
        }
    }
    
    namespace PluginState {
        export type Kind = 'data' | 'behavior'
    
        export interface Snapshot {
            data: State.Snapshot,
            behaviour: State.Snapshot,
            cameraSnapshots: CameraSnapshotManager.StateSnapshot,
            canvas3d: {
                camera: Camera.Snapshot
            }
        }
    }