From 4a65c6e91ce345740c8beb189b916d97a2f4f41d Mon Sep 17 00:00:00 2001 From: cory-glooh <85269391+cory-glooh@users.noreply.github.com> Date: Tue, 2 Nov 2021 13:50:08 +0000 Subject: [PATCH] All prop sequencing (#48) --- packages/playground/src/shared/dom/Scene.tsx | 59 +++++++++---- .../store/types/SheetState_Historic.ts | 2 +- theatre/core/src/propTypes/index.ts | 87 ++++++++++++++++--- .../core/src/sequences/trackValueAtTime.ts | 31 ++++--- theatre/core/src/sheetObjects/SheetObject.ts | 33 ++++++- .../src/sheetObjects/SheetObjectTemplate.ts | 24 ++++- theatre/globals.d.ts | 8 +- theatre/studio/src/StudioStore/StudioStore.ts | 8 ++ .../propEditors/DeterminePropEditor.tsx | 4 +- .../utils/useEditingToolsForPrimitiveProp.tsx | 4 +- .../DopeSheet/Left/PrimitivePropRow.tsx | 7 +- .../DopeSheet/Right/PrimitivePropRow.tsx | 9 +- .../BasicKeyframedTrack.tsx | 9 +- .../KeyframeEditor/Curve.tsx | 13 +-- .../KeyframeEditor/CurveHandle.tsx | 13 ++- .../KeyframeEditor/Dot.tsx | 45 ++++++---- .../KeyframeEditor/KeyframeEditor.tsx | 2 +- .../GraphEditor/PrimitivePropGraph.tsx | 7 +- theatre/studio/src/store/stateEditors.ts | 12 ++- 19 files changed, 280 insertions(+), 97 deletions(-) diff --git a/packages/playground/src/shared/dom/Scene.tsx b/packages/playground/src/shared/dom/Scene.tsx index 0809b8a..428ed52 100644 --- a/packages/playground/src/shared/dom/Scene.tsx +++ b/packages/playground/src/shared/dom/Scene.tsx @@ -3,14 +3,27 @@ import type {UseDragOpts} from './useDrag' import useDrag from './useDrag' import React, {useLayoutEffect, useMemo, useState} from 'react' import type {IProject, ISheet} from '@theatre/core' -import {onChange} from '@theatre/core' +import {onChange, types} from '@theatre/core' import type {IScrub, IStudio} from '@theatre/studio' -studio.initialize() +studio.initialize({usePersistentStorage: false}) + +const textInterpolate = (left: string, right: string, progression: number) => { + if (!left || right.startsWith(left)) { + const length = Math.floor( + Math.max(0, (right.length - left.length) * progression), + ) + return left + right.slice(left.length, left.length + length) + } + return left +} const boxObjectConfig = { - x: 0, - y: 0, + test: types.string('Hello?', {interpolate: textInterpolate}), + testLiteral: types.stringLiteral('a', {a: 'Option A', b: 'Option B'}), + bool: types.boolean(false), + x: types.number(200), + y: types.number(200), } const Box: React.FC<{ @@ -23,11 +36,17 @@ const Box: React.FC<{ const isSelected = selection.includes(obj) - const [pos, setPos] = useState<{x: number; y: number}>({x: 0, y: 0}) + const [state, setState] = useState<{ + x: number + y: number + test: string + testLiteral: string + bool: boolean + }>(obj.value) useLayoutEffect(() => { const unsubscribeFromChanges = onChange(obj.props, (newValues) => { - setPos(newValues) + setState(newValues) }) return unsubscribeFromChanges }, [id]) @@ -50,7 +69,13 @@ const Box: React.FC<{ firstOnDragCalled = true } scrub!.capture(({set}) => { - set(obj.props, {x: x + initial.x, y: y + initial.y}) + set(obj.props, { + x: x + initial.x, + y: y + initial.y, + test: initial.test, + testLiteral: initial.testLiteral, + bool: initial.bool, + }) }) }, onDragEnd(dragHappened) { @@ -73,16 +98,20 @@ const Box: React.FC<{ }} ref={setDivRef} style={{ - width: 100, - height: 100, - background: 'gray', + width: 300, + height: 300, + color: 'white', position: 'absolute', - left: pos.x + 'px', - top: pos.y + 'px', + left: state.x + 'px', + top: state.y + 'px', boxSizing: 'border-box', - border: isSelected ? '1px solid #5a92fa' : '1px solid transparent', + border: isSelected ? '1px solid #5a92fa' : '1px solid white', }} - > + > +
+        {JSON.stringify(state, null, 4)}
+      
+ ) } @@ -109,7 +138,7 @@ export const Scene: React.FC<{project: IProject}> = ({project}) => { right: '0', top: 0, bottom: '0', - background: 'black', + background: '#333', }} >