Skip to content
Snippets Groups Projects
Commit 5533e7e3 authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: snapshot duration

parent c9a07888
No related branches found
No related tags found
No related merge requests found
...@@ -128,7 +128,7 @@ export function Snapshots(ctx: PluginContext) { ...@@ -128,7 +128,7 @@ export function Snapshots(ctx: PluginContext) {
}); });
PluginCommands.State.Snapshots.Add.subscribe(ctx, ({ name, description, params }) => { PluginCommands.State.Snapshots.Add.subscribe(ctx, ({ name, description, params }) => {
const entry = PluginStateSnapshotManager.Entry(ctx.state.getSnapshot(params), name, description); const entry = PluginStateSnapshotManager.Entry(ctx.state.getSnapshot(params), { name, description });
ctx.state.snapshots.add(entry); ctx.state.snapshots.add(entry);
}); });
......
...@@ -56,7 +56,8 @@ class PluginState { ...@@ -56,7 +56,8 @@ class PluginState {
cameraSnapshots: p.cameraSnapshots ? this.cameraSnapshots.getStateSnapshot() : void 0, cameraSnapshots: p.cameraSnapshots ? this.cameraSnapshots.getStateSnapshot() : void 0,
canvas3d: p.canvas3d ? { canvas3d: p.canvas3d ? {
props: this.plugin.canvas3d.props props: this.plugin.canvas3d.props
} : void 0 } : void 0,
durationInMs: params && params.durationInMs
}; };
} }
...@@ -111,6 +112,7 @@ namespace PluginState { ...@@ -111,6 +112,7 @@ namespace PluginState {
export type CameraTransitionStyle = 'instant' | 'animate' export type CameraTransitionStyle = 'instant' | 'animate'
export const GetSnapshotParams = { export const GetSnapshotParams = {
durationInMs: PD.Numeric(1500, { min: 100, max: 15000, step: 100 }, { label: 'Duration in MS' }),
data: PD.Boolean(true), data: PD.Boolean(true),
behavior: PD.Boolean(false), behavior: PD.Boolean(false),
animation: PD.Boolean(true), animation: PD.Boolean(true),
...@@ -120,7 +122,7 @@ namespace PluginState { ...@@ -120,7 +122,7 @@ namespace PluginState {
cameraSnapshots: PD.Boolean(false), cameraSnapshots: PD.Boolean(false),
cameraTranstionStyle: PD.Select<CameraTransitionStyle>('animate', [['animate', 'Animate'], ['instant', 'Instant']]) cameraTranstionStyle: PD.Select<CameraTransitionStyle>('animate', [['animate', 'Animate'], ['instant', 'Instant']])
}; };
export type GetSnapshotParams = Partial<PD.Value<typeof GetSnapshotParams>> export type GetSnapshotParams = Partial<PD.Values<typeof GetSnapshotParams>>
export const DefaultGetSnapshotParams = PD.getDefaultValues(GetSnapshotParams); export const DefaultGetSnapshotParams = PD.getDefaultValues(GetSnapshotParams);
export interface Snapshot { export interface Snapshot {
...@@ -135,6 +137,7 @@ namespace PluginState { ...@@ -135,6 +137,7 @@ namespace PluginState {
cameraSnapshots?: CameraSnapshotManager.StateSnapshot, cameraSnapshots?: CameraSnapshotManager.StateSnapshot,
canvas3d?: { canvas3d?: {
props?: Canvas3DProps props?: Canvas3DProps
} },
durationInMs?: number
} }
} }
...@@ -61,7 +61,10 @@ class PluginStateSnapshotManager extends PluginComponent<{ ...@@ -61,7 +61,10 @@ class PluginStateSnapshotManager extends PluginComponent<{
const idx = this.getIndex(old); const idx = this.getIndex(old);
// The id changes here! // The id changes here!
const e = PluginStateSnapshotManager.Entry(snapshot, old.name, old.description); const e = PluginStateSnapshotManager.Entry(snapshot, {
name: old.name,
description: old.description
});
this.entryMap.set(snapshot.id, e); this.entryMap.set(snapshot.id, e);
this.updateState({ current: e.snapshot.id, entries: this.state.entries.set(idx, e) }); this.updateState({ current: e.snapshot.id, entries: this.state.entries.set(idx, e) });
this.events.changed.next(); this.events.changed.next();
...@@ -174,7 +177,8 @@ class PluginStateSnapshotManager extends PluginComponent<{ ...@@ -174,7 +177,8 @@ class PluginStateSnapshotManager extends PluginComponent<{
} }
const snapshot = this.setCurrent(next)!; const snapshot = this.setCurrent(next)!;
await this.plugin.state.setSnapshot(snapshot); await this.plugin.state.setSnapshot(snapshot);
this.timeoutHandle = setTimeout(this.next, this.state.nextSnapshotDelayInMs); const delay = typeof snapshot.durationInMs !== 'undefined' ? snapshot.durationInMs : this.state.nextSnapshotDelayInMs;
this.timeoutHandle = setTimeout(this.next, delay);
}; };
play() { play() {
...@@ -213,8 +217,8 @@ namespace PluginStateSnapshotManager { ...@@ -213,8 +217,8 @@ namespace PluginStateSnapshotManager {
snapshot: PluginState.Snapshot snapshot: PluginState.Snapshot
} }
export function Entry(snapshot: PluginState.Snapshot, name?: string, description?: string): Entry { export function Entry(snapshot: PluginState.Snapshot, params: {name?: string, description?: string }): Entry {
return { timestamp: +new Date(), name, snapshot, description }; return { timestamp: +new Date(), snapshot, ...params };
} }
export interface RemoteSnapshot { export interface RemoteSnapshot {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment