@@ -4,35 +4,26 @@ import { useRef } from 'react';
44import { FC } from 'react' ;
55import { ArrayBar } from 'data-structure' ;
66import { Schema } from 'schema' ;
7+ import { useDsv } from './model' ;
78VStory . registerAll ( ) ;
89
9- interface ChartProps {
10- schema : Schema ;
11- }
12- export const Chart : FC < ChartProps > = ( props ) => {
13- const { schema } = props ;
10+ export const Chart : FC = ( ) => {
11+ const schema = useDsv ( ( state ) => state . schema ) ;
1412
1513 const ref = useRef < HTMLDivElement > ( null ) ;
1614
1715 useEffect ( ( ) => {
1816 if ( ! ref . current ) {
1917 return ;
2018 }
21-
22- const interval = 1000 ;
19+ if ( schema . actions . length === 0 || schema . structures . length === 0 ) {
20+ return ;
21+ }
2322 const arrayBar = new ArrayBar < number > ( [ ...schema . structures [ 0 ] . array ] , {
2423 id : schema . structures [ 0 ] . id ,
25- interval : interval ,
26- structure : {
27- position : {
28- top : 10 ,
29- left : 10 ,
30- width : 580 ,
31- height : 300 ,
32- } ,
33- } ,
24+ interval : 300 ,
25+ structure : { } ,
3426 } ) ;
35-
3627 schema . actions . forEach ( ( action ) => {
3728 if ( action . structureId === arrayBar . id ) {
3829 if ( action . type === 'set' ) {
@@ -41,6 +32,9 @@ export const Chart: FC<ChartProps> = (props) => {
4132 if ( action . type === 'swap' ) {
4233 arrayBar . swap ( action . args [ 0 ] , action . args [ 1 ] ) ;
4334 }
35+ if ( action . type === 'appear' ) {
36+ arrayBar . appear ( ) ;
37+ }
4438 }
4539 } ) ;
4640
@@ -53,37 +47,16 @@ export const Chart: FC<ChartProps> = (props) => {
5347 {
5448 id : 'default-chapter' ,
5549 scenes : [
56- // 场景数组,可以包含多个场景,场景与场景是有先后顺序的串联结构
57- {
58- id : 'scene0' ,
59- // 场景中包含的动作数组,动作中描述了一个或多个character的具体行为,一个场景中可以包含多个动作,动作之间是并行执行的
60- actions : [
61- {
62- characterId : 'array-f5c481' ,
63- characterActions : [
64- {
65- action : 'appear' ,
66- startTime : 0 ,
67- payload : {
68- animation : {
69- duration : interval ,
70- } ,
71- } ,
72- } ,
73- ] ,
74- } ,
75- ] ,
76- } ,
7750 {
78- id : 'scene1 ' ,
51+ id : 'scene ' ,
7952 actions : arrayBar . actions ,
8053 } ,
8154 ] ,
8255 } ,
8356 ] ,
8457 } ;
8558
86- console . log ( dsl ) ;
59+ console . log ( 'debug dsl' , dsl ) ;
8760
8861 const story = new VStory . Story ( dsl , {
8962 dom : ref . current ,
@@ -97,11 +70,10 @@ export const Chart: FC<ChartProps> = (props) => {
9770 return ( ) => {
9871 story ?. release ( ) ;
9972 } ;
100- } , [ ] ) ;
73+ } , [ schema ] ) ;
10174
10275 return (
10376 < >
104- < div > test</ div >
10577 < div style = { { width : '600px' , height : '600px' } } ref = { ref } > </ div >
10678 </ >
10779 ) ;
0 commit comments