From eba4d5ae47e0999a169edf60e3fe6db9cc883261 Mon Sep 17 00:00:00 2001 From: zhouxinyu Date: Fri, 16 Aug 2024 15:26:18 +0800 Subject: [PATCH] feat: character id support array --- .../vstory/demo/src/demos/BaseComponent.tsx | 35 +++++++++++++++++++ packages/vstory/src/player/scheduler.ts | 21 ++++++----- .../src/story/interface/dsl-interface.ts | 2 +- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/packages/vstory/demo/src/demos/BaseComponent.tsx b/packages/vstory/demo/src/demos/BaseComponent.tsx index 6b8d528f..c1ddc1e6 100644 --- a/packages/vstory/demo/src/demos/BaseComponent.tsx +++ b/packages/vstory/demo/src/demos/BaseComponent.tsx @@ -152,6 +152,41 @@ export const BaseComponent = () => { { id: 'default-chapter', scenes: [ + { + id: 'scene1', + actions: [ + { + characterId: [ + ...new Array(3).fill(0).map((_, i) => 'rect' + (i % 3)), + ...new Array(3).fill(0).map((_, i) => 'line' + (i % 3)), + ...new Array(3).fill(0).map((_, i) => 'shape' + (i % 3)), + ...new Array(3).fill(0).map((_, i) => 'image' + (i % 3)), + ...new Array(4).fill(0).map((_, i) => 'text' + (i % 4)), + ...new Array(4).fill(0).map((_, i) => 'timeline' + (i % 4)) + ], + characterActions: [ + { + startTime: 0, + action: 'appear', + payload: { + animation: { + duration: 1600 + } + } + }, + { + startTime: 2000, + action: 'disappear', + payload: { + animation: { + duration: 1600 + } + } + } + ] + } + ] + }, { id: 'scene0', actions: [ diff --git a/packages/vstory/src/player/scheduler.ts b/packages/vstory/src/player/scheduler.ts index ebd13175..6d92a6cf 100644 --- a/packages/vstory/src/player/scheduler.ts +++ b/packages/vstory/src/player/scheduler.ts @@ -1,4 +1,4 @@ -import { isNumber } from '@visactor/vutils'; +import { isNumber, isString } from '@visactor/vutils'; import type { IActionSpec, IActSpec, ISceneSpec } from '../story/interface'; import { IStory } from '../story/interface'; import type { IActionProcessor } from './processor/interface/action-processor'; @@ -153,15 +153,18 @@ export class Scheduler implements IScheduler { let character_st = Infinity; let character_et = -Infinity; action.characterActions.forEach(ca => { - const info = this._actionProcessor.getActInfo(action.characterId, ca); - if (!info) { - return; - } - const item = new ActionItem(info.startTime, info.duration, ca, action.characterId); + const characterIdList = isString(action.characterId) ? [action.characterId] : action.characterId; + characterIdList.forEach(characterId => { + const info = this._actionProcessor.getActInfo(characterId, ca); + if (!info) { + return; + } + const item = new ActionItem(info.startTime, info.duration, ca, characterId); - character_st = Math.max(Math.min(item.startTime, character_st), 0); - character_et = Math.max(item.startTime + item.duration, character_et); - actionList.push(item); + character_st = Math.max(Math.min(item.startTime, character_st), 0); + character_et = Math.max(item.startTime + item.duration, character_et); + actionList.push(item); + }); }); scene_st = !actIdx ? character_st : Math.max(Math.min(character_st, scene_st), 0); diff --git a/packages/vstory/src/story/interface/dsl-interface.ts b/packages/vstory/src/story/interface/dsl-interface.ts index acf251b4..47e95f81 100644 --- a/packages/vstory/src/story/interface/dsl-interface.ts +++ b/packages/vstory/src/story/interface/dsl-interface.ts @@ -28,7 +28,7 @@ export interface IStorySpec { } export interface IActionsLink { - characterId: string; + characterId: string[]; characterActions: IActionSpec[]; }