@@ -3,7 +3,7 @@ import type { ServiceDefinition } from "../../../modularity/serviceDefinition";
3
3
import type { ISceneContext } from "../../sceneContext" ;
4
4
import type { ISceneExplorerService } from "./sceneExplorerService" ;
5
5
6
- import { LayerDiagonalPersonRegular , PersonSquareRegular } from "@fluentui/react-icons" ;
6
+ import { LayerDiagonalPersonRegular , PersonSquareRegular , PlayFilled , StopFilled } from "@fluentui/react-icons" ;
7
7
8
8
import { Observable } from "core/Misc" ;
9
9
import { InterceptProperty } from "../../../instrumentation/propertyInstrumentation" ;
@@ -12,6 +12,7 @@ import { DefaultSectionsOrder } from "./defaultSectionsMetadata";
12
12
import { SceneExplorerServiceIdentity } from "./sceneExplorerService" ;
13
13
14
14
import "core/Sprites/spriteSceneComponent" ;
15
+ import { InterceptFunction } from "../../../instrumentation/functionInstrumentation" ;
15
16
16
17
function IsSpriteManager ( entity : unknown ) : entity is ISpriteManager {
17
18
return ( entity as ISpriteManager ) . sprites !== undefined ;
@@ -60,9 +61,42 @@ export const SpriteManagerExplorerServiceDefinition: ServiceDefinition<[], [ISce
60
61
getEntityRemovedObservables : ( ) => [ scene . onSpriteManagerRemovedObservable ] ,
61
62
} ) ;
62
63
64
+ const spritePlayStopCommandRegistration = sceneExplorerService . addCommand ( {
65
+ predicate : ( entity : unknown ) => IsSprite ( entity ) ,
66
+ getCommand : ( sprite ) => {
67
+ const onChangeObservable = new Observable < void > ( ) ;
68
+ const playHook = InterceptFunction ( sprite , "playAnimation" , {
69
+ afterCall : ( ) => onChangeObservable . notifyObservers ( ) ,
70
+ } ) ;
71
+ const stopHook = InterceptFunction ( sprite , "stopAnimation" , {
72
+ afterCall : ( ) => onChangeObservable . notifyObservers ( ) ,
73
+ } ) ;
74
+ const animateHook = InterceptFunction ( sprite , "_animate" , {
75
+ afterCall : ( ) => onChangeObservable . notifyObservers ( ) ,
76
+ } ) ;
77
+
78
+ return {
79
+ type : "action" ,
80
+ get displayName ( ) {
81
+ return `${ sprite . animationStarted ? "Stop" : "Play" } Animation` ;
82
+ } ,
83
+ icon : ( ) => ( sprite . animationStarted ? < StopFilled /> : < PlayFilled /> ) ,
84
+ execute : ( ) => ( sprite . animationStarted ? sprite . stopAnimation ( ) : sprite . playAnimation ( sprite . fromIndex , sprite . toIndex , sprite . loopAnimation , sprite . delay ) ) ,
85
+ onChange : onChangeObservable ,
86
+ dispose : ( ) => {
87
+ playHook . dispose ( ) ;
88
+ stopHook . dispose ( ) ;
89
+ animateHook . dispose ( ) ;
90
+ onChangeObservable . clear ( ) ;
91
+ } ,
92
+ } ;
93
+ } ,
94
+ } ) ;
95
+
63
96
return {
64
97
dispose : ( ) => {
65
98
sectionRegistration . dispose ( ) ;
99
+ spritePlayStopCommandRegistration . dispose ( ) ;
66
100
} ,
67
101
} ;
68
102
} ,
0 commit comments