@gedit/editor-2d 0.1.97 → 0.1.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/editor2d-frontend-module.d.ts.map +1 -1
- package/lib/browser/editor2d-frontend-module.js +1 -0
- package/lib/browser/editor2d-frontend-module.js.map +1 -1
- package/lib/browser/editor2d-service.d.ts +14 -2
- package/lib/browser/editor2d-service.d.ts.map +1 -1
- package/lib/browser/editor2d-service.js +33 -9
- package/lib/browser/editor2d-service.js.map +1 -1
- package/lib/browser/model/editor2d-document.d.ts +2 -0
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +16 -1
- package/lib/browser/model/editor2d-document.js.map +1 -1
- package/lib/browser/model/editor2d-selection.d.ts +1 -0
- package/lib/browser/model/editor2d-selection.d.ts.map +1 -1
- package/lib/browser/model/editor2d-selection.js +11 -0
- package/lib/browser/model/editor2d-selection.js.map +1 -1
- package/lib/browser/model/editor2d.js +2 -2
- package/lib/browser/model/editor2d.js.map +1 -1
- package/lib/browser/playground/canvas-layer.js +1 -1
- package/lib/browser/playground/canvas-layer.js.map +1 -1
- package/lib/browser/playground/playground-context.d.ts +7 -3
- package/lib/browser/playground/playground-context.d.ts.map +1 -1
- package/lib/browser/playground/playground-context.js +9 -6
- package/lib/browser/playground/playground-context.js.map +1 -1
- package/lib/browser/playground/playground-contribution.d.ts +3 -2
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +10 -5
- package/lib/browser/playground/playground-contribution.js.map +1 -1
- package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
- package/lib/browser/playground/selection-entity-manager.js +19 -17
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/lib/browser/utils/snapshot.d.ts +16 -2
- package/lib/browser/utils/snapshot.d.ts.map +1 -1
- package/lib/browser/utils/snapshot.js +85 -47
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/editor2d-frontend-module.ts +1 -0
- package/src/browser/editor2d-service.ts +33 -11
- package/src/browser/model/editor2d-document.ts +12 -1
- package/src/browser/model/editor2d-selection.ts +10 -0
- package/src/browser/model/editor2d.ts +2 -2
- package/src/browser/playground/canvas-layer.ts +1 -1
- package/src/browser/playground/playground-context.ts +10 -8
- package/src/browser/playground/playground-contribution.ts +8 -3
- package/src/browser/playground/selection-entity-manager.tsx +18 -16
- package/src/browser/style/canvas-draw-layer.less +1 -1
- package/src/browser/style/index.less +0 -1
- package/src/browser/utils/snapshot.ts +53 -7
|
@@ -189,7 +189,7 @@ export namespace Editor2dNode {
|
|
|
189
189
|
parent: undefined,
|
|
190
190
|
name: uri.displayName,
|
|
191
191
|
children: [],
|
|
192
|
-
visible:
|
|
192
|
+
visible: false,
|
|
193
193
|
expanded: true,
|
|
194
194
|
selected: false,
|
|
195
195
|
locked: false,
|
|
@@ -248,7 +248,7 @@ export async function getEditor2dModelOpts(resource: Resource, resourceService:
|
|
|
248
248
|
const options: ResourceAutoSaveOptions = {
|
|
249
249
|
encoding,
|
|
250
250
|
resource,
|
|
251
|
-
saveAsString: e => Editor2dContent.parseToString({version: e.document.
|
|
251
|
+
saveAsString: e => Editor2dContent.parseToString({version: e.document.saveVersion, content: e.document.root, snaplines: e.document.snaplines})
|
|
252
252
|
};
|
|
253
253
|
const autoSaveService = await resourceService.createAutoSaveResource(options);
|
|
254
254
|
return {
|
|
@@ -61,7 +61,7 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
|
|
|
61
61
|
this.document?.updateNode(e.node, {error: e.error});
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
64
|
-
this.context.
|
|
64
|
+
this.context.onCanvasDataChangedEmitter.fire(this.canvasDrawer!);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
getAssetsURI(): string {
|
|
@@ -2,7 +2,7 @@ import { inject, injectable } from 'inversify';
|
|
|
2
2
|
import { RenderEngineIDEService } from '@gedit/render-engine-ide';
|
|
3
3
|
import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
|
|
4
4
|
import { AppConfigService } from '@gedit/app-config';
|
|
5
|
-
import { debounce, URI } from '@gedit/utils';
|
|
5
|
+
import { debounce, Emitter, URI } from '@gedit/utils';
|
|
6
6
|
import { Editor2dEntity } from './entities/editor2d-entity';
|
|
7
7
|
import type { SelectionEntityManager } from './selection-entity-manager';
|
|
8
8
|
import { Playground, Selectable } from '@gedit/playground';
|
|
@@ -16,10 +16,15 @@ import type { CanvasDraw } from './canvas-draw';
|
|
|
16
16
|
|
|
17
17
|
export const Editor2dPlayGround = Symbol('Editor2dPlayGround');
|
|
18
18
|
|
|
19
|
-
export type Editor2dPlayGround = Playground
|
|
19
|
+
export type Editor2dPlayGround = Playground<PlaygroundContext2d>;
|
|
20
20
|
|
|
21
21
|
@injectable()
|
|
22
22
|
export class PlaygroundContext2d {
|
|
23
|
+
readonly onCanvasDataChangedEmitter = new Emitter<CanvasDraw>();
|
|
24
|
+
/**
|
|
25
|
+
* 监听画布变化,可用于生成缩略图
|
|
26
|
+
*/
|
|
27
|
+
readonly onCanvasDataChanged = this.onCanvasDataChangedEmitter.event;
|
|
23
28
|
constructor(
|
|
24
29
|
@inject(RenderEngineIDEService) readonly renderEngine: RenderEngineIDEService,
|
|
25
30
|
@inject(Editor2dDocument) readonly document: Editor2dDocument,
|
|
@@ -29,12 +34,9 @@ export class PlaygroundContext2d {
|
|
|
29
34
|
@inject(Editor2dModelOptions) readonly options: Editor2dModelOptions,
|
|
30
35
|
@inject(Editor2dContextKeyService) readonly contextKeyService: Editor2dContextKeyService
|
|
31
36
|
) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
onCanvasDataChanged(drawer: CanvasDraw): void {
|
|
36
|
-
if (this.options.onCanvasDataChanged) {
|
|
37
|
-
this.options.onCanvasDataChanged(drawer);
|
|
37
|
+
this.document.toDispose.push(this.onCanvasDataChangedEmitter);
|
|
38
|
+
if (options.onCanvasDataChanged) {
|
|
39
|
+
this.onCanvasDataChanged(drawer => options.onCanvasDataChanged!(drawer));
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
@@ -15,15 +15,17 @@ import { CanvasDrawLayer } from './canvas-draw-layer';
|
|
|
15
15
|
import { AppConfigData, AppConfigService } from '@gedit/app-config';
|
|
16
16
|
import { HistoryService } from '@gedit/history';
|
|
17
17
|
import { Editor2dModelOptions, Editor2dNode } from '../model/editor2d';
|
|
18
|
-
import {
|
|
18
|
+
import { ContextMenuRenderer } from '@gedit/layout';
|
|
19
|
+
import { CommandService } from '@gedit/command';
|
|
20
|
+
import { CommonCommands } from '@gedit/application-common/lib/browser';
|
|
19
21
|
|
|
20
22
|
@injectable()
|
|
21
23
|
export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
22
24
|
@inject(AppConfigService) readonly appConfig: AppConfigService;
|
|
23
25
|
@inject(Editor2dModelOptions) readonly modelOpts: Editor2dModelOptions;
|
|
24
26
|
@inject(HistoryService) readonly historyService: HistoryService;
|
|
25
|
-
@inject(ApplicationShell) readonly appShell: ApplicationShell;
|
|
26
27
|
@inject(PlaygroundConfig) readonly config: PlaygroundConfig;
|
|
28
|
+
@inject(CommandService) readonly commandService: CommandService;
|
|
27
29
|
@inject(ContextMenuRenderer) readonly menuRender: ContextMenuRenderer;
|
|
28
30
|
registerPlayground(registry: PlaygroundRegistry): void {
|
|
29
31
|
registry.registerLayer(CanvasLayer);
|
|
@@ -56,7 +58,10 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
56
58
|
priority: 6,
|
|
57
59
|
cancelMode: 'once',
|
|
58
60
|
handle: () => {
|
|
59
|
-
this.
|
|
61
|
+
this.commandService.executeCommand(CommonCommands.TOGGLE_MAXIMIZED.id);
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
playground.config.scrollPageBoundsToCenter();
|
|
64
|
+
}, 10);
|
|
60
65
|
}
|
|
61
66
|
});
|
|
62
67
|
stateEntity.registerState({
|
|
@@ -12,6 +12,22 @@ import type { PlaygroundContext2d } from './playground-context';
|
|
|
12
12
|
import { Rectangle } from '@gedit/math';
|
|
13
13
|
import { GameObject } from '@gedit/render-engine';
|
|
14
14
|
|
|
15
|
+
const numberToFixed4 = (data: {[key: string]: any}) => {
|
|
16
|
+
const d: any = {};
|
|
17
|
+
Object.keys(data).forEach(key => {
|
|
18
|
+
const value = data[key];
|
|
19
|
+
// 旋转不能四舍五入,不然属性面板旋转角度误差很大
|
|
20
|
+
if (typeof value === 'number' && key !== 'rotation') {
|
|
21
|
+
d[key] = parseFloat(value.toFixed(6));
|
|
22
|
+
} else if (typeof value === 'object') {
|
|
23
|
+
d[key] = numberToFixed4(value);
|
|
24
|
+
} else {
|
|
25
|
+
d[key] = value;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return d;
|
|
29
|
+
};
|
|
30
|
+
|
|
15
31
|
/**
|
|
16
32
|
* 选择器实体相关逻辑
|
|
17
33
|
*/
|
|
@@ -95,23 +111,9 @@ export class SelectionEntityManager {
|
|
|
95
111
|
lastTransform = newTransform;
|
|
96
112
|
return;
|
|
97
113
|
}; */
|
|
114
|
+
newTransform = numberToFixed4(newTransform);
|
|
98
115
|
// const delta = TransformSchema.getDelta(lastTransform, newTransform);
|
|
99
|
-
|
|
100
|
-
const d: any = {};
|
|
101
|
-
Object.keys(data).forEach(key => {
|
|
102
|
-
const value = data[key];
|
|
103
|
-
if (typeof value === 'number') {
|
|
104
|
-
d[key] = parseFloat(value.toFixed(6));
|
|
105
|
-
} else if (typeof value === 'object') {
|
|
106
|
-
d[key] = numberToFixed4(value);
|
|
107
|
-
} else {
|
|
108
|
-
d[key] = key;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
return d;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
document.updateNode(entity.nodeId, numberToFixed4(newTransform), true);
|
|
116
|
+
document.updateNode(entity.nodeId, newTransform, true);
|
|
115
117
|
// lastTransform = newTransform;
|
|
116
118
|
});
|
|
117
119
|
// 设置控制key
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { CanvasDraw, CanvasDrawOpts } from '../playground/canvas-draw';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Disposable,
|
|
4
|
+
DisposableCollection,
|
|
5
|
+
DisposableImpl,
|
|
6
|
+
URI,
|
|
7
|
+
Emitter,
|
|
8
|
+
PromiseDeferred,
|
|
9
|
+
SizeSchema,
|
|
10
|
+
debounce
|
|
11
|
+
} from '@gedit/utils';
|
|
12
|
+
import type { Editor2dModel } from '../model/editor2d-model';
|
|
3
13
|
import { Editor2dNode } from '../model';
|
|
4
14
|
import { GameConfig } from '@gedit/render-engine/lib/common';
|
|
5
15
|
|
|
@@ -77,7 +87,22 @@ export class SnapshotCreator extends DisposableImpl {
|
|
|
77
87
|
this.onUpdateEmitter,
|
|
78
88
|
]);
|
|
79
89
|
}
|
|
80
|
-
|
|
90
|
+
/**
|
|
91
|
+
* 清楚缓存数据
|
|
92
|
+
*/
|
|
93
|
+
clearResultCache(includeUris: string[]): void {
|
|
94
|
+
Object.keys(this.result).forEach(key => {
|
|
95
|
+
if (!includeUris.includes(key)) {
|
|
96
|
+
delete this.result[key];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getResultFromCache(): Snapshot[] {
|
|
101
|
+
return Object.keys(this.result).map(k => this.result[k]);
|
|
102
|
+
}
|
|
103
|
+
updateResultCache(data: Snapshot): void {
|
|
104
|
+
this.result[data.uri] = data;
|
|
105
|
+
}
|
|
81
106
|
getSnapshot(uri: string): Snapshot | undefined {
|
|
82
107
|
return this.result[uri];
|
|
83
108
|
}
|
|
@@ -91,10 +116,7 @@ export class SnapshotCreator extends DisposableImpl {
|
|
|
91
116
|
await this.process();
|
|
92
117
|
return scenes.map(s => this.result[s.uri]!);
|
|
93
118
|
}
|
|
94
|
-
|
|
95
|
-
return Object.keys(this.result).map(k => this.result[k]);
|
|
96
|
-
}
|
|
97
|
-
protected async process(): Promise<void> {
|
|
119
|
+
protected process(): Promise<void> {
|
|
98
120
|
if (this.processing) {
|
|
99
121
|
return this.processing.promise;
|
|
100
122
|
}
|
|
@@ -143,15 +165,39 @@ export class SnapshotCreator extends DisposableImpl {
|
|
|
143
165
|
this.current = next;
|
|
144
166
|
this.drawer.renderWidget?.currentScene?.dispose();
|
|
145
167
|
const appConfig = typeof this.opts.appConfig === 'function' ? this.opts.appConfig() : this.opts.appConfig;
|
|
168
|
+
let content: Editor2dNode = next.content;
|
|
169
|
+
// Empty
|
|
170
|
+
if (!content || !content.children || Object.keys(content).length === 0) {
|
|
171
|
+
content = Editor2dNode.createRootNode(new URI(next.uri));
|
|
172
|
+
const attrs = this.opts.renderEngine.getDisplayDefaultData(this.opts.engineName, content.displayType);
|
|
173
|
+
Object.assign(content, { ...attrs });
|
|
174
|
+
}
|
|
146
175
|
this.drawer.update({
|
|
147
176
|
visible: true,
|
|
148
177
|
uri: next.uri,
|
|
149
178
|
engineName: this.opts.engineName,
|
|
150
179
|
appConfig,
|
|
151
|
-
content
|
|
180
|
+
content,
|
|
152
181
|
});
|
|
153
182
|
} else {
|
|
154
183
|
end();
|
|
155
184
|
}
|
|
156
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* 监听变化,并自动刷新缩略图缓存
|
|
188
|
+
* @param model
|
|
189
|
+
* @param fn
|
|
190
|
+
* @param quility 缩略图质量
|
|
191
|
+
* @param delay 延迟生成
|
|
192
|
+
*/
|
|
193
|
+
listenModelChanged(model: Editor2dModel, fn: (imageData: string) => void, quility = 0.1, delay = 1000): Disposable {
|
|
194
|
+
return model.playground.context.onCanvasDataChanged(debounce(drawer => {
|
|
195
|
+
const {content, visible} = drawer.getData() || {};
|
|
196
|
+
if (!content || drawer.loading) return;
|
|
197
|
+
if (visible) {
|
|
198
|
+
const widget = drawer.renderWidget!;
|
|
199
|
+
widget.createSnapShot(this.opts.imageType, quility).then((base64: string) => fn(base64));
|
|
200
|
+
}
|
|
201
|
+
}, delay));
|
|
202
|
+
}
|
|
157
203
|
}
|