Skip to content

Commit

Permalink
feat: character id support array
Browse files Browse the repository at this point in the history
  • Loading branch information
neuqzxy committed Aug 16, 2024
1 parent 43af15f commit eba4d5a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
35 changes: 35 additions & 0 deletions packages/vstory/demo/src/demos/BaseComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
21 changes: 12 additions & 9 deletions packages/vstory/src/player/scheduler.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/vstory/src/story/interface/dsl-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface IStorySpec {
}

export interface IActionsLink {
characterId: string;
characterId: string[];
characterActions: IActionSpec[];
}

Expand Down

0 comments on commit eba4d5a

Please sign in to comment.