Skip to content

Commit

Permalink
fix: release character while removed from vstory
Browse files Browse the repository at this point in the history
  • Loading branch information
neuqzxy committed Sep 29, 2024
1 parent 93304b0 commit 2d75832
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
17 changes: 16 additions & 1 deletion packages/vstory/demo/src/demos/API.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export const API = () => {
}
});

debugger;
text.setConfig({ options: { graphic: { text: '这是普通文本' } } });
console.log(text);

Expand All @@ -136,16 +135,32 @@ export const API = () => {
// 添加character
// 更新character
story.play();
let selectedCharacter: any = null;
const edit = new Edit(story);
edit.emitter.on('startEdit', msg => {
selectedCharacter = msg.actionInfo.character;
if (msg.type === 'commonEdit' && msg.actionInfo.character) {
msg.updateCharacter({ options: { graphic: { fill: 'green' } } });
story.play();
}
});
edit.emitter.on('endEdit', msg => {
selectedCharacter = null;
});
edit.emitter.on('resize', msg => {
console.log('resize', msg);
});
// 删除character
document.addEventListener('keydown', e => {
if (e.key === 'Backspace') {
debugger;
const sc = selectedCharacter;
edit.stopEdit();
sc && story.removeCharacter(sc.id);
story.play(false);
console.log('Backspace');
}
});
// 导出DSL
console.log(story.toDSL());
// story读取DSL
Expand Down
5 changes: 4 additions & 1 deletion packages/vstory/src/story/character-tree/character-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export class CharacterTree implements ICharacterTree {
}

removeCharacter(cId: string) {
this._characters[cId] = null;
const c = this._characters[cId];
// TODO 先直接release掉,后续如果需要复用再说
c && c.release();
delete this._characters[cId];
}

addCharacter(spec: ICharacterConfig) {
Expand Down
8 changes: 3 additions & 5 deletions packages/vstory/src/story/character/chart/character.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { CommonSpecRuntime } from './runtime/common-spec';
import { ComponentSpecRuntime } from './runtime/component-spec';
import type { IChartCharacterRuntimeConstructor } from './runtime/interface';
import { cloneDeep, merge } from '@visactor/vutils';
import { VChart } from '@visactor/vchart';
import type { ICharacterConfig, IChartCharacterConfig } from '../dsl-interface';
import { VChartGraphic } from './graphic/vrender/vchart-graphic';
import { cloneDeep } from '@visactor/vutils';
import type { IChartCharacterConfig } from '../dsl-interface';
import { CharacterVisactor } from '../visactor/character';
import { SpecProcess } from './spec-process/spec-process';
import { ChartDataTempTransform } from './spec-process/data-temp-transform';
Expand All @@ -17,7 +15,7 @@ import { getLayoutFromWidget } from '../../utils/layout';
import { getChartModelWithEvent } from '../../utils/vchart-pick';
import { mergeChartOption } from '../../utils/chart';
import { Chart } from './graphic/chart';
import { StoryChartType, StoryComponentType } from '../../../constants/character';
import { StoryChartType } from '../../../constants/character';

export class CharacterChart extends CharacterVisactor {
static type = 'CharacterChart';
Expand Down
1 change: 1 addition & 0 deletions packages/vstory/src/story/character/dsl-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ICharacterConfigBase {
type: string; // 类型
position: IWidgetData; // 定位描述
zIndex: number;
extra?: any; // 带着的额外信息
}

export type IEditorTextGraphicAttribute = {
Expand Down
2 changes: 1 addition & 1 deletion packages/vstory/src/story/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class Story implements IStory {
// this._player.addAct(spec, this._characters);
// }

play(loop: boolean = true) {
play(loop: boolean = false) {
// player 开始播放
this._dsl && this.load(this._dsl);
this._player.play();
Expand Down

0 comments on commit 2d75832

Please sign in to comment.