@gedit/editor-2d 0.1.93 → 0.1.99
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-contribution.js +6 -6
- package/lib/browser/editor2d-contribution.js.map +1 -1
- 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 +22 -3
- 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.d.ts +9 -0
- package/lib/browser/model/editor2d.d.ts.map +1 -1
- package/lib/browser/model/editor2d.js +35 -3
- 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 +6 -1
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +50 -0
- 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-contribution.ts +2 -2
- package/src/browser/editor2d-frontend-module.ts +1 -0
- package/src/browser/editor2d-service.ts +33 -11
- package/src/browser/model/editor2d-document.ts +25 -4
- package/src/browser/model/editor2d-selection.ts +10 -0
- package/src/browser/model/editor2d.ts +31 -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 +44 -1
- 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
|
@@ -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
|
}
|