@@ -373,7 +373,7 @@ namespace pxt {
373373 return this . state . animations . add ( newAnimation ) ;
374374 }
375375
376- public createNewAnimationFromData ( frames : pxt . sprite . BitmapData [ ] , interval = 500 ) {
376+ public createNewAnimationFromData ( frames : pxt . sprite . BitmapData [ ] , interval = 500 , displayName ?: string ) {
377377 const id = this . generateNewID ( AssetType . Animation , pxt . sprite . ANIMATION_PREFIX , pxt . sprite . ANIMATION_NAMESPACE ) ;
378378
379379 const newAnimation : Animation = {
@@ -382,7 +382,7 @@ namespace pxt {
382382 type : AssetType . Animation ,
383383 frames,
384384 interval,
385- meta : { } ,
385+ meta : { displayName } ,
386386 } ;
387387 return this . state . animations . add ( newAnimation ) ;
388388 }
@@ -891,27 +891,21 @@ namespace pxt {
891891 public duplicateAsset ( asset : Asset ) : Asset ;
892892 public duplicateAsset ( asset : Asset ) {
893893 this . onChange ( ) ;
894- const newAsset = cloneAsset ( asset ) ;
895- newAsset . internalID = this . getNewInternalId ( ) ;
896- const id = newAsset . id . substr ( newAsset . id . lastIndexOf ( "." ) + 1 ) . replace ( / \d * $ / , "" ) ;
897- if ( ! newAsset . meta ?. displayName ) {
898- if ( ! newAsset . meta ) newAsset . meta = { } ;
899- newAsset . meta . displayName = id ;
900- }
894+ const clone = cloneAsset ( asset ) ;
895+ const displayName = clone . meta ?. displayName ;
901896
902- switch ( newAsset . type ) {
897+ let newAsset : pxt . Asset ;
898+ switch ( asset . type ) {
903899 case AssetType . Image :
904- newAsset . id = this . generateNewID ( AssetType . Image , id , pxt . sprite . IMAGES_NAMESPACE ) ;
905- this . state . images . add ( newAsset ) ; break ;
900+ newAsset = this . createNewProjectImage ( ( clone as pxt . ProjectImage ) . bitmap , displayName ) ; break ;
906901 case AssetType . Tile :
907- newAsset . id = this . generateNewID ( AssetType . Tile , id , pxt . sprite . TILE_NAMESPACE ) ;
908- this . state . tiles . add ( newAsset ) ; break ;
902+ newAsset = this . createNewTile ( ( clone as pxt . Tile ) . bitmap , null , displayName ) ; break ;
909903 case AssetType . Tilemap :
910- newAsset . id = this . generateNewID ( AssetType . Tilemap , id ) ;
911- this . state . tilemaps . add ( newAsset ) ; break ;
904+ const [ id , tilemap ] = this . createNewTilemapFromData ( ( clone as pxt . ProjectTilemap ) . data , displayName ) ;
905+ newAsset = this . getTilemap ( id ) ;
906+ break ;
912907 case AssetType . Animation :
913- newAsset . id = this . generateNewID ( AssetType . Animation , id ) ;
914- this . state . animations . add ( newAsset ) ; break ;
908+ newAsset = this . createNewAnimationFromData ( ( clone as pxt . Animation ) . frames , ( clone as pxt . Animation ) . interval , displayName )
915909 }
916910 return newAsset ;
917911 }
0 commit comments