@@ -9,10 +9,10 @@ import { AnimationFrame, IUserAnimation } from '@/Core/Modules/animations';
99import { generateTransformAnimationObj } from '@/Core/controller/stage/pixi/animations/generateTransformAnimationObj' ;
1010import { assetSetter , fileType } from '@/Core/util/gameAssetsAccess/assetSetter' ;
1111import { logger } from '@/Core/util/logger' ;
12- import { getAnimateDuration } from '@/Core/Modules/animationFunctions' ;
12+ import { getAnimateDuration , getAnimationPerformName } from '@/Core/Modules/animationFunctions' ;
1313import { WebGAL } from '@/Core/WebGAL' ;
1414import { baseBlinkParam , baseFocusParam , BlinkParam , FocusParam } from '@/Core/live2DCore' ;
15- import { WEBGAL_NONE } from '../constants' ;
15+ import { STAGE_KEYS , WEBGAL_NONE } from '../constants' ;
1616/**
1717 * 更改立绘
1818 * @param sentence 语句
@@ -46,9 +46,24 @@ export function changeFigure(sentence: ISentence): IPerform {
4646 }
4747
4848 // id 与 自由立绘
49- let key = getStringArgByKey ( sentence , 'id' ) ?? '' ;
50- const isFreeFigure = key ? true : false ;
51- const id = key ? key : `fig-${ pos } ` ;
49+ let idFromArgs = getStringArgByKey ( sentence , 'id' ) ?? '' ;
50+ const isFreeFigure = idFromArgs ? true : false ;
51+ let key = '' ;
52+ if ( isFreeFigure ) {
53+ key = idFromArgs ;
54+ } else {
55+ switch ( pos ) {
56+ case 'center' :
57+ key = STAGE_KEYS . FIG_C ;
58+ break ;
59+ case 'left' :
60+ key = STAGE_KEYS . FIG_L ;
61+ break ;
62+ case 'right' :
63+ key = STAGE_KEYS . FIG_R ;
64+ break ;
65+ }
66+ }
5267
5368 // live2d 或 spine 相关
5469 let motion = getStringArgByKey ( sentence , 'motion' ) ?? '' ;
@@ -95,9 +110,9 @@ export function changeFigure(sentence: ISentence): IPerform {
95110 const dispatch = webgalStore . dispatch ;
96111
97112 const currentFigureAssociatedAnimation = webgalStore . getState ( ) . stage . figureAssociatedAnimation ;
98- const filteredFigureAssociatedAnimation = currentFigureAssociatedAnimation . filter ( ( item ) => item . targetId !== id ) ;
113+ const filteredFigureAssociatedAnimation = currentFigureAssociatedAnimation . filter ( ( item ) => item . targetId !== key ) ;
99114 const newFigureAssociatedAnimationItem = {
100- targetId : id ,
115+ targetId : key ,
101116 animationFlag : animationFlag ,
102117 mouthAnimation : {
103118 open : mouthOpen ,
@@ -112,9 +127,7 @@ export function changeFigure(sentence: ISentence): IPerform {
112127 filteredFigureAssociatedAnimation . push ( newFigureAssociatedAnimationItem ) ;
113128 dispatch ( setStage ( { key : 'figureAssociatedAnimation' , value : filteredFigureAssociatedAnimation } ) ) ;
114129
115- /**
116- * 如果 url 没变,不移除
117- */
130+ // 检测 url 是否变化
118131 let isUrlChanged = true ;
119132 if ( key !== '' ) {
120133 const figWithKey = webgalStore . getState ( ) . stage . freeFigure . find ( ( e ) => e . key === key ) ;
@@ -140,16 +153,19 @@ export function changeFigure(sentence: ISentence): IPerform {
140153 }
141154 }
142155 }
143- /**
144- * 处理 Effects
145- */
156+
146157 if ( isUrlChanged ) {
147- webgalStore . dispatch ( stageActions . removeEffectByTargetId ( id ) ) ;
148- const oldStageObject = WebGAL . gameplay . pixiStage ?. getStageObjByKey ( id ) ;
158+ // 移除旧的 effect
159+ webgalStore . dispatch ( stageActions . removeEffectByTargetId ( key ) ) ;
160+ // 清除动画演出
161+ WebGAL . gameplay . performController . unmountPerform ( getAnimationPerformName ( key ) , true ) ;
162+ // 标记旧的立绘为退出中,防止旧立绘继承新参数
163+ const oldStageObject = WebGAL . gameplay . pixiStage ?. getStageObjByKey ( key ) ;
149164 if ( oldStageObject ) {
150165 oldStageObject . isExiting = true ;
151166 }
152167 }
168+
153169 const setAnimationNames = ( key : string , sentence : ISentence ) => {
154170 // 处理 transform 和 默认 transform
155171 let animationObj : AnimationFrame [ ] ;
@@ -242,18 +258,12 @@ export function changeFigure(sentence: ISentence): IPerform {
242258 /**
243259 * 下面的代码是设置与位置关联的立绘的
244260 */
245- const positionMap = {
246- center : 'fig-center' ,
247- left : 'fig-left' ,
248- right : 'fig-right' ,
249- } ;
250261 const dispatchMap : Record < string , keyof IStageState > = {
251262 center : 'figName' ,
252263 left : 'figNameLeft' ,
253264 right : 'figNameRight' ,
254265 } ;
255266
256- key = positionMap [ pos ] ;
257267 setAnimationNames ( key , sentence ) ;
258268 setFigureData ( ) ;
259269 dispatch ( setStage ( { key : dispatchMap [ pos ] , value : content } ) ) ;
0 commit comments