@@ -4,18 +4,9 @@ import { webgalStore } from '@/store/store';
44import { setStage , stageActions } from '@/store/stageReducer' ;
55import cloneDeep from 'lodash/cloneDeep' ;
66import { getBooleanArgByKey , getNumberArgByKey , getStringArgByKey } from '@/Core/util/getSentenceArg' ;
7- import { baseTransform , IFreeFigure , IStageState , ITransform } from '@/store/stageInterface' ;
8- import { AnimationFrame , IUserAnimation } from '@/Core/Modules/animations' ;
9- import { generateTransformAnimationObj } from '@/Core/controller/stage/pixi/animations/generateTransformAnimationObj' ;
7+ import { baseTransform , IFreeFigure , IStageState } from '@/store/stageInterface' ;
108import { assetSetter , fileType } from '@/Core/util/gameAssetsAccess/assetSetter' ;
11- import { logger } from '@/Core/util/logger' ;
12- import {
13- createDefaultEnterExitAnimation ,
14- createEnterExitAnimation ,
15- getAnimateDuration ,
16- getEnterAnimationKey ,
17- getOldTargetKey ,
18- } from '@/Core/Modules/animationFunctions' ;
9+ import { createEnterExitAnimation , getEnterAnimationKey , getOldTargetKey } from '@/Core/Modules/animationFunctions' ;
1910import { WebGAL } from '@/Core/WebGAL' ;
2011import { STAGE_KEYS } from '../constants' ;
2112/**
@@ -48,9 +39,17 @@ export function changeFigure(sentence: ISentence): IPerform {
4839 }
4940
5041 // id 与 自由立绘
51- let key = getStringArgByKey ( sentence , 'id' ) ?? '' ;
52- const isFreeFigure = key ? true : false ;
53- const id = key ? key : `fig-${ pos } ` ;
42+ const idFromArgs = getStringArgByKey ( sentence , 'id' ) ?? '' ;
43+ const isFreeFigure = idFromArgs ? true : false ;
44+ let key = idFromArgs ;
45+ if ( ! isFreeFigure ) {
46+ const positionMap = {
47+ center : STAGE_KEYS . FIG_CENTER ,
48+ left : STAGE_KEYS . FIG_LEFT ,
49+ right : STAGE_KEYS . FIG_RIGHT ,
50+ } ;
51+ key = positionMap [ pos ] ;
52+ }
5453
5554 // live2d 或 spine 相关
5655 let motion = getStringArgByKey ( sentence , 'motion' ) ?? '' ;
@@ -66,19 +65,15 @@ export function changeFigure(sentence: ISentence): IPerform {
6665 const animationFlag = getStringArgByKey ( sentence , 'animationFlag' ) ?? '' ;
6766
6867 // 其他参数
69- const transformString = getStringArgByKey ( sentence , 'transform' ) ;
70- const ease = getStringArgByKey ( sentence , 'ease' ) ?? '' ;
7168 let duration = getNumberArgByKey ( sentence , 'duration' ) ?? 500 ;
72- const enterAnimation = getStringArgByKey ( sentence , 'enter' ) ;
73- const exitAnimation = getStringArgByKey ( sentence , 'exit' ) ;
7469 const zIndex = getNumberArgByKey ( sentence , 'zIndex' ) ?? - 1 ;
7570
7671 const dispatch = webgalStore . dispatch ;
7772
7873 const currentFigureAssociatedAnimation = webgalStore . getState ( ) . stage . figureAssociatedAnimation ;
79- const filteredFigureAssociatedAnimation = currentFigureAssociatedAnimation . filter ( ( item ) => item . targetId !== id ) ;
74+ const filteredFigureAssociatedAnimation = currentFigureAssociatedAnimation . filter ( ( item ) => item . targetId !== key ) ;
8075 const newFigureAssociatedAnimationItem = {
81- targetId : id ,
76+ targetId : key ,
8277 animationFlag : animationFlag ,
8378 mouthAnimation : {
8479 open : mouthOpen ,
@@ -97,7 +92,7 @@ export function changeFigure(sentence: ISentence): IPerform {
9792 * 如果 url 没变,不移除
9893 */
9994 let isRemoveEffects = true ;
100- if ( key !== '' ) {
95+ if ( isFreeFigure ) {
10196 const figWithKey = webgalStore . getState ( ) . stage . freeFigure . find ( ( e ) => e . key === key ) ;
10297 if ( figWithKey ) {
10398 if ( figWithKey . name === sentence . content ) {
@@ -122,16 +117,6 @@ export function changeFigure(sentence: ISentence): IPerform {
122117 }
123118 }
124119
125- // 确定 key
126- if ( ! isFreeFigure ) {
127- const positionMap = {
128- center : STAGE_KEYS . FIG_CENTER ,
129- left : STAGE_KEYS . FIG_LEFT ,
130- right : STAGE_KEYS . FIG_RIGHT ,
131- } ;
132- key = positionMap [ pos ] ;
133- }
134-
135120 // 储存一下现有的 transform 给退场动画当起始帧用, 因为马上就要清除了
136121 const currentEffect = webgalStore . getState ( ) . stage . effects . find ( ( e ) => e . target === key ) ;
137122 let currentTransform = baseTransform ;
@@ -143,13 +128,9 @@ export function changeFigure(sentence: ISentence): IPerform {
143128 * 处理 Effects
144129 */
145130 if ( isRemoveEffects ) {
146- const deleteKey = `fig-${ pos } ` ;
147- const deleteKey2 = `${ key } ` ;
148- webgalStore . dispatch ( stageActions . removeEffectByTargetId ( deleteKey ) ) ;
149- webgalStore . dispatch ( stageActions . removeEffectByTargetId ( deleteKey2 ) ) ;
131+ webgalStore . dispatch ( stageActions . removeEffectByTargetId ( key ) ) ;
150132 // 重设 figureMetaData,这里是 zIndex,实际上任何键都可以,因为整体是移除那条记录
151- dispatch ( stageActions . setFigureMetaData ( [ deleteKey , 'zIndex' , 0 , true ] ) ) ;
152- dispatch ( stageActions . setFigureMetaData ( [ deleteKey2 , 'zIndex' , 0 , true ] ) ) ;
133+ dispatch ( stageActions . setFigureMetaData ( [ key , 'zIndex' , 0 , true ] ) ) ;
153134 }
154135
155136 duration = createEnterExitAnimation ( sentence , key , duration , currentTransform ) ;
0 commit comments