1
1
import React from "react" ;
2
2
import { Stage , Text , Sprite } from '@inlet/react-pixi' ;
3
3
import { utils } from 'pixi.js' ;
4
- import { subGoal , stepInfo , allStages , steps , stepSubgoalMap , vfg } from './dataUtils' ;
4
+ import { subGoal , stepInfo , allStages , steps , stepSubgoalMap , vfg , textContent } from './dataUtils' ;
5
5
import Button from '@material-ui/core/Button' ;
6
6
import IconButton from '@material-ui/core/IconButton' ;
7
7
import PlayCircleFilledIcon from '@material-ui/icons/PlayCircleFilled' ;
@@ -15,7 +15,7 @@ import styles from './index.less';
15
15
import * as PIXI from 'pixi.js'
16
16
17
17
const canvasWidth_Middle = 800
18
- const canvasHeight_Middle = 480
18
+ const canvasHeight_Middle = 470
19
19
20
20
const useStyles = makeStyles ( {
21
21
root : {
@@ -268,15 +268,19 @@ class PageFour extends React.Component {
268
268
if ( this . handlerPlay ) {
269
269
clearTimeout ( this . handlerPlay ) ;
270
270
}
271
+ this . setState ( {
272
+ playButtonColor : 'primary' ,
273
+ pauseButtonColor : 'default' }
274
+ )
271
275
} else {
272
276
// setInterval effect
273
277
// detect change of playSpeed
274
- const handlerPlay = setTimeout ( run , 3000 / this . state . playSpeed ) ;
278
+ const handlerPlay = setTimeout ( run , 1000 / this . state . playSpeed ) ;
275
279
this . handlerPlay = handlerPlay ;
276
280
}
277
281
} ;
278
282
279
- const handlerPlay = setTimeout ( run , 3000 / this . state . playSpeed ) ;
283
+ const handlerPlay = setTimeout ( run , 1000 / this . state . playSpeed ) ;
280
284
this . handlerPlay = handlerPlay ;
281
285
}
282
286
}
@@ -327,6 +331,30 @@ class PageFour extends React.Component {
327
331
this . stepItem [ index ] . current . scrollIntoView ( ) ;
328
332
}
329
333
334
+ handleExportClick ( ) {
335
+ const data = textContent
336
+ let blob = new Blob ( [ data ] ) ;
337
+ let filename = "download.vfg" ;
338
+
339
+ if ( typeof window . navigator . msSaveBlob !== "undefined" ) {
340
+ window . navigator . msSaveBlob ( blob , filename ) ;
341
+ } else {
342
+ var blobURL = window . URL . createObjectURL ( blob ) ;
343
+ // create a hidden <a> tag for download
344
+ var tempLink = document . createElement ( "a" ) ;
345
+ tempLink . style . display = "none" ;
346
+ tempLink . href = blobURL ;
347
+ tempLink . setAttribute ( "download" , filename ) ;
348
+ if ( typeof tempLink . download === "undefined" ) {
349
+ tempLink . setAttribute ( "target" , "_blank" ) ;
350
+ }
351
+ document . body . appendChild ( tempLink ) ;
352
+ tempLink . click ( ) ;
353
+ document . body . removeChild ( tempLink ) ;
354
+ window . URL . revokeObjectURL ( blobURL ) ;
355
+ }
356
+ }
357
+
330
358
handleSpeedScroll ( value ) {
331
359
// console.info(value);
332
360
this . setState ( {
@@ -337,7 +365,6 @@ class PageFour extends React.Component {
337
365
338
366
render ( ) {
339
367
// Get all sprites
340
- if ( ! vfg . visualStages ) return null ;
341
368
var sprites = vfg . visualStages [ this . state . stepInfoIndex ] . visualSprites ;
342
369
// Sort sprites by their depth
343
370
sprites . sort ( ( itemA , itemB ) => itemA . depth - itemB . depth )
@@ -374,10 +401,8 @@ class PageFour extends React.Component {
374
401
{
375
402
376
403
sprites . map ( ( sprite , i ) => {
377
- // Get the texture from base64 image storing in the vfg file
404
+ // Get the texture name
378
405
var textureName = sprite . prefabimage
379
- var base = new PIXI . BaseTexture ( "data:image/png;base64," + vfg . imageTable . m_values [ vfg . imageTable . m_keys . indexOf ( textureName ) ] ) ;
380
- var texture = new PIXI . Texture ( base ) ;
381
406
// Get the color of the sprite
382
407
var color = utils . rgb2hex ( [ sprite . color . r , sprite . color . g , sprite . color . b ] )
383
408
// Initialize the rotation of the sprite
@@ -400,7 +425,8 @@ class PageFour extends React.Component {
400
425
return (
401
426
< >
402
427
< Sprite
403
- texture = { texture }
428
+ // the image texture of the sprite
429
+ image = { "data:image/png;base64," + vfg . imageTable . m_values [ vfg . imageTable . m_keys . indexOf ( textureName ) ] }
404
430
name = { sprite . name }
405
431
anchor = { anchor }
406
432
rotation = { rotation }
@@ -426,7 +452,7 @@ class PageFour extends React.Component {
426
452
return (
427
453
< >
428
454
< Sprite
429
- texture = { texture }
455
+ image = { "data:image/png;base64," + vfg . imageTable . m_values [ vfg . imageTable . m_keys . indexOf ( textureName ) ] }
430
456
name = { sprite . name }
431
457
anchor = { anchor }
432
458
rotation = { rotation }
@@ -479,6 +505,10 @@ class PageFour extends React.Component {
479
505
< Button variant = "contained" color = "primary" size = "small" onClick = { ( ) => { this . handleShowGoalClick ( ) } } >
480
506
Show the Goal
481
507
</ Button >
508
+
509
+ < Button variant = "contained" color = "primary" size = "small" onClick = { ( ) => { this . handleExportClick ( ) } } >
510
+ Export
511
+ </ Button >
482
512
</ div >
483
513
< div className = { styles . sub_title } >
484
514
< div className = { styles . sub_title_key } > Subgoal</ div >
@@ -487,19 +517,19 @@ class PageFour extends React.Component {
487
517
< div className = { styles . sub_list } >
488
518
{
489
519
[ ...subGoal . keys ( ) ] . map ( key => {
490
- return < div className = { styles . sub_item + ' ' + ( this . state . selectedSubGoals [ key ] ? styles . highlight_item : '' ) }
520
+ return < div className = { styles . sub_item + ' ' + ( this . state . selectedSubGoals [ key ] ? styles . highlight_item : ' ' ) }
491
521
key = { key } onClick = { ( ) => { this . handleSubItemClick ( key ) } } >
492
- { key }
493
- < div className = { styles . sub_item_menu }
494
- style = { { display : this . state . showKey === key ? 'block' : 'none' } } >
495
- { subGoal . get ( key ) . map ( value => {
496
- return < div className = { styles . sub_item_menu_item }
497
- onClick = { ( ) => this . handleStepClick ( value ) }
498
- key = { key + value }
499
- > Step { value } </ div >
500
- } ) }
501
- </ div >
502
- </ div > ;
522
+ { key }
523
+ < div className = { styles . sub_item_menu }
524
+ style = { { display : this . state . showKey === key ? 'block' : 'none' } } >
525
+ { subGoal . get ( key ) . map ( value => {
526
+ return < div className = { styles . sub_item_menu_item }
527
+ onClick = { ( ) => this . handleStepClick ( value ) }
528
+ key = { key + value }
529
+ > Step { value } </ div >
530
+ } ) }
531
+ </ div >
532
+ </ div > ;
503
533
} )
504
534
}
505
535
</ div >
0 commit comments