@@ -26,6 +26,7 @@ type FaceViewBaseParams = CommonViewParams
2626type DieRegion = PiuContainer & { set : ( x : number , y : number , w : number , h : number ) => DieRegion ; cut : ( ) => void }
2727type FaceContainerBehavior = {
2828 onFaceUpdate ?: ( container : PiuContainer , face : FaceContext ) => void
29+ rehydrate ?: ( container : PiuContainer , face : Readonly < FaceContext > , palette ?: FaceSkinPalette | null ) => void
2930 getBaseCoordinates ?: ( container : PiuContainer ) => { left : number ; top : number }
3031}
3132
@@ -69,14 +70,14 @@ class FaceViewBehavior extends CommonViewBehavior {
6970 }
7071
7172 onFaceUpdate ( _container : PiuContainer , faceContext : Readonly < FaceContext > ) {
72- const palette = updateFaceSkinPalette ( this . lastPalette , faceContext )
73- if ( palette !== this . lastPalette ) {
74- this . onFaceSkin ( _container , palette )
75- }
7673 if ( this . lastFaceContext === null ) {
7774 this . lastFaceContext = createFaceContext ( )
7875 }
7976 copyFaceContext ( faceContext , this . lastFaceContext )
77+ const palette = updateFaceSkinPalette ( this . lastPalette , faceContext )
78+ if ( palette !== this . lastPalette ) {
79+ this . onFaceSkin ( _container , palette )
80+ }
8081 const face = this . face
8182 const behavior = face ?. behavior as FaceContainerBehavior | undefined
8283 behavior ?. onFaceUpdate ?.( face as PiuContainer , faceContext as FaceContext )
@@ -89,6 +90,9 @@ class FaceViewBehavior extends CommonViewBehavior {
8990 this . main . skin = palette . secondary
9091 }
9192 this . face ?. distribute ?.( 'onFaceSkin' , palette )
93+ if ( this . face ) {
94+ this . rehydrateFace ( this . face , this . lastFaceContext ?? defaultFaceContext , palette )
95+ }
9296 this . effects ?. distribute ( 'onFaceSkin' , palette )
9397 this . overlay ?. distribute ( 'onFaceSkin' , palette )
9498 this . appBar ?. distribute ?.( 'onFaceSkin' , palette )
@@ -139,16 +143,22 @@ class FaceViewBehavior extends CommonViewBehavior {
139143 }
140144 }
141145
146+ rehydrateFace ( face : PiuContainer , faceContext : Readonly < FaceContext > , palette = this . lastPalette ) : void {
147+ const behavior = face . behavior as FaceContainerBehavior | undefined
148+ if ( behavior ?. rehydrate ) {
149+ behavior . rehydrate ( face , faceContext , palette )
150+ return
151+ }
152+ behavior ?. onFaceUpdate ?.( face , faceContext as FaceContext )
153+ }
154+
142155 applyFaceState ( face : PiuContainer ) : void {
156+ const faceContext = this . lastFaceContext ?? defaultFaceContext
143157 if ( this . lastPalette ) {
144158 face . distribute ?.( 'onFaceSkin' , this . lastPalette )
145159 }
146- if ( ! this . lastFaceContext ) {
147- return
148- }
149- const behavior = face . behavior as FaceContainerBehavior | undefined
150- behavior ?. onFaceUpdate ?.( face , this . lastFaceContext )
151- face . distribute ?.( 'onFaceContext' , this . lastFaceContext )
160+ face . distribute ?.( 'onFaceContext' , faceContext )
161+ this . rehydrateFace ( face , faceContext , this . lastPalette )
152162 }
153163
154164 setFace ( face : PiuContainer ) : void {
0 commit comments