Ver Fonte

mol-plugin: tweaks, repeat once unwind

David Sehnal há 6 anos atrás
pai
commit
ca4a63371e

+ 1 - 1
src/mol-plugin/state.ts

@@ -64,7 +64,7 @@ class PluginState {
     }
 
     async setSnapshot(snapshot: PluginState.Snapshot) {
-        this.animation.stop();
+        await this.animation.stop();
 
         if (snapshot.behaviour) await this.plugin.runTask(this.behaviorState.setSnapshot(snapshot.behaviour));
         if (snapshot.data) await this.plugin.runTask(this.dataState.setSnapshot(snapshot.data));

+ 10 - 2
src/mol-plugin/state/animation/built-in.ts

@@ -90,7 +90,8 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({
     name: 'built-in.animate-assembly-unwind',
     display: { name: 'Unwind Assembly' },
     params: () => ({
-        durationInMs: PD.Numeric(3000, { min: 100, max: 10000, step: 100})
+        durationInMs: PD.Numeric(3000, { min: 100, max: 10000, step: 100}),
+        playOnce: PD.Boolean(false)
     }),
     initialState: () => ({ t: 0 }),
     async setup(_, plugin) {
@@ -133,7 +134,13 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({
         const update = state.build();
 
         const d = (t.current - t.lastApplied) / ctx.params.durationInMs;
-        const newTime = (animState.t + d) % 1;
+        let newTime = (animState.t + d), finished = false;
+        if (ctx.params.playOnce && newTime >= 1) {
+            finished = true;
+            newTime = 1;
+        } else {
+            newTime = newTime % 1;
+        }
 
         for (const m of anims) {
             update.to(m).update({ t: newTime });
@@ -141,6 +148,7 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({
 
         await PluginCommands.State.Update.dispatch(ctx.plugin, { state, tree: update, options: { doNotLogTiming: true } });
 
+        if (finished) return { kind: 'finished' };
         return { kind: 'next', state: { t: newTime } };
     }
 })

+ 1 - 1
src/mol-plugin/ui/controls.tsx

@@ -109,7 +109,7 @@ export class StateSnapshotViewportControls extends PluginUIComponent<{}, { isBus
         // TODO: this needs to be diabled when the state is updating!
         this.subscribe(this.plugin.state.snapshots.events.changed, () => this.forceUpdate());
         this.subscribe(this.plugin.behaviors.state.isUpdating, isBusy => this.setState({ isBusy }));
-        this.subscribe(this.plugin.behaviors.state.isAnimating, isAnimating => this.setState({ show: !isAnimating }));
+        this.subscribe(this.plugin.behaviors.state.isAnimating, isBusy => this.setState({ isBusy }));
     }
 
     async update(id: string) {