@@ -6,14 +6,17 @@ import { addFrameToFFmpeg, loadffmpeg, outputMP4, removePNG } from "./FFmpeg";
66import { recourse } from "./Recourse" ;
77import { interval , Timer } from "d3" ;
88import { eachLimit , eachSeries } from "async" ;
9- import { createFFmpeg , FFmpeg } from "@ffmpeg/ffmpeg" ;
9+ import { createFFmpeg } from "@ffmpeg/ffmpeg" ;
10+ import { Controller } from "./Controller" ;
1011
1112// Enable Path2D
1213require ( "canvas-5-polyfill" ) ;
1314
1415export class Stage {
1516 compRoot : Component = new Component ( ) ;
1617 renderer : Renderer ;
18+
19+ ctl : Controller ;
1720 options = { sec : 5 , fps : 30 } ;
1821 outputOptions = {
1922 fileName : "output" ,
@@ -68,6 +71,7 @@ export class Stage {
6871 this . renderer . setCanvas ( canvas ) ;
6972 }
7073 this . sec = 0 ;
74+ this . ctl = new Controller ( this ) ;
7175 }
7276
7377 addChild ( child : Ani | Component ) {
@@ -78,11 +82,21 @@ export class Stage {
7882 if ( sec ) {
7983 this . sec = sec ;
8084 }
85+ if ( ! this . alreadySetup ) {
86+ this . loadRecourse ( ) . then ( ( ) => {
87+ this . compRoot . setup ( this ) ;
88+ this . alreadySetup = true ;
89+ this . doRender ( ) ;
90+ } ) ;
91+ } else {
92+ this . doRender ( ) ;
93+ }
94+ }
95+ private doRender ( ) {
8196 this . renderer . clean ( ) ;
8297 this . renderer . render ( this . compRoot , this . compRoot . offsetSec ) ;
8398 }
84-
85- loadRecourse ( ) {
99+ async loadRecourse ( ) {
86100 return recourse . setup ( ) ;
87101 }
88102
@@ -173,7 +187,12 @@ export class Stage {
173187 }
174188
175189 setup ( ) {
176- this . compRoot . setup ( this ) ;
177- this . alreadySetup = true ;
190+ this . loadRecourse ( ) . then ( ( ) => {
191+ this . compRoot . setup ( this ) ;
192+ this . alreadySetup = true ;
193+ } ) ;
194+ }
195+ renderController ( ) {
196+ this . ctl . render ( ) ;
178197 }
179198}
0 commit comments