@gedit/editor-2d 0.1.92 → 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-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/index.d.ts +1 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +6 -1
- package/lib/browser/index.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 +17 -2
- 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 +1 -0
- package/lib/browser/model/editor2d.d.ts.map +1 -1
- package/lib/browser/model/editor2d.js +3 -2
- package/lib/browser/model/editor2d.js.map +1 -1
- package/lib/browser/model/index.js +5 -1
- package/lib/browser/model/index.js.map +1 -1
- package/lib/browser/model/utils/anim.utils.d.ts.map +1 -1
- package/lib/browser/model/utils/anim.utils.js +6 -2
- package/lib/browser/model/utils/anim.utils.js.map +1 -1
- package/lib/browser/model/utils/index.js +5 -1
- package/lib/browser/model/utils/index.js.map +1 -1
- package/lib/browser/playground/canvas-draw.d.ts +2 -7
- package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
- package/lib/browser/playground/canvas-draw.js +1 -8
- package/lib/browser/playground/canvas-draw.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/entities/index.js +5 -1
- package/lib/browser/playground/entities/index.js.map +1 -1
- package/lib/browser/playground/index.js +5 -1
- package/lib/browser/playground/index.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 +18 -0
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/lib/browser/utils/snapshot.d.ts +61 -0
- package/lib/browser/utils/snapshot.d.ts.map +1 -0
- package/lib/browser/utils/snapshot.js +257 -0
- package/lib/browser/utils/snapshot.js.map +1 -0
- 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/index.ts +1 -0
- package/src/browser/model/editor2d-document.ts +13 -2
- package/src/browser/model/editor2d-selection.ts +10 -0
- package/src/browser/model/editor2d.ts +3 -2
- package/src/browser/model/utils/anim.utils.ts +7 -2
- package/src/browser/playground/canvas-draw.ts +3 -16
- 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 +17 -0
- package/src/browser/style/canvas-draw-layer.less +1 -1
- package/src/browser/style/index.less +0 -1
- package/src/browser/utils/snapshot.ts +203 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CanvasDraw, CanvasDrawOpts } from '../playground/canvas-draw';
|
|
2
|
+
import { Disposable, DisposableImpl, Emitter, PromiseDeferred, SizeSchema } from '@gedit/utils';
|
|
3
|
+
import type { Editor2dModel } from '../model/editor2d-model';
|
|
4
|
+
import { Editor2dNode } from '../model';
|
|
5
|
+
import { GameConfig } from '@gedit/render-engine/lib/common';
|
|
6
|
+
export interface SnapshotOpts extends Omit<CanvasDrawOpts, 'host'> {
|
|
7
|
+
imageType?: string;
|
|
8
|
+
quility?: number;
|
|
9
|
+
limitSize?: SizeSchema;
|
|
10
|
+
appConfig: GameConfig | (() => GameConfig);
|
|
11
|
+
engineName: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const SnapshotOptsDefault: {
|
|
14
|
+
quility: number;
|
|
15
|
+
imageType: string;
|
|
16
|
+
};
|
|
17
|
+
export interface Snapshot {
|
|
18
|
+
uri: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
version?: string | number;
|
|
21
|
+
imageData: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SnapshotInput {
|
|
24
|
+
uri: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
version?: string | number;
|
|
27
|
+
content: Editor2dNode;
|
|
28
|
+
}
|
|
29
|
+
export declare function createSnapshots(opts: SnapshotOpts, sceneDatas: SnapshotInput[]): Promise<Snapshot[]>;
|
|
30
|
+
export declare class SnapshotCreator extends DisposableImpl {
|
|
31
|
+
protected readonly opts: SnapshotOpts;
|
|
32
|
+
protected drawer: CanvasDraw;
|
|
33
|
+
protected processing?: PromiseDeferred<void>;
|
|
34
|
+
protected result: {
|
|
35
|
+
[key: string]: Snapshot;
|
|
36
|
+
};
|
|
37
|
+
protected processingData: SnapshotInput[];
|
|
38
|
+
protected onUpdateEmitter: Emitter<void>;
|
|
39
|
+
readonly onUpdate: import("@gedit/utils").Event<void>;
|
|
40
|
+
protected current?: SnapshotInput;
|
|
41
|
+
constructor(opts: SnapshotOpts);
|
|
42
|
+
/**
|
|
43
|
+
* 清楚缓存数据
|
|
44
|
+
*/
|
|
45
|
+
clearResultCache(includeUris: string[]): void;
|
|
46
|
+
getResultFromCache(): Snapshot[];
|
|
47
|
+
updateResultCache(data: Snapshot): void;
|
|
48
|
+
getSnapshot(uri: string): Snapshot | undefined;
|
|
49
|
+
draw(scenes: SnapshotInput[]): Promise<Snapshot[]>;
|
|
50
|
+
protected process(): Promise<void>;
|
|
51
|
+
protected next(end: () => void): void;
|
|
52
|
+
/**
|
|
53
|
+
* 监听变化,并自动刷新缩略图缓存
|
|
54
|
+
* @param model
|
|
55
|
+
* @param fn
|
|
56
|
+
* @param quility 缩略图质量
|
|
57
|
+
* @param delay 延迟生成
|
|
58
|
+
*/
|
|
59
|
+
listenModelChanged(model: Editor2dModel, fn: (imageData: string) => void, quility?: number, delay?: number): Disposable;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/browser/utils/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EACL,UAAU,EAEV,cAAc,EAEd,OAAO,EACP,eAAe,EACf,UAAU,EAEX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,UAAU,GAAG,CAAC,MAAM,UAAU,CAAC,CAAC;IAC3C,UAAU,EAAE,M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IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAUxD,SAAS,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2ClC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,IAAI,GAAG,IAAI;IAwBrC;;;;;;OAMG;IACH,kBAAkB,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,EAAE,OAAO,SAAM,EAAE,KAAK,SAAO,GAAG,UAAU;CAUnH"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
+
function step(op) {
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (_) try {
|
|
44
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.SnapshotCreator = exports.createSnapshots = exports.SnapshotOptsDefault = void 0;
|
|
66
|
+
var canvas_draw_1 = require("../playground/canvas-draw");
|
|
67
|
+
var utils_1 = require("@gedit/utils");
|
|
68
|
+
var model_1 = require("../model");
|
|
69
|
+
exports.SnapshotOptsDefault = {
|
|
70
|
+
quility: 0.8,
|
|
71
|
+
imageType: 'image/webp',
|
|
72
|
+
};
|
|
73
|
+
function fixDrawerScale(drawer, limitSize) {
|
|
74
|
+
// const appConfig = drawer.getData()?.appConfig;
|
|
75
|
+
// if (!appConfig) return;
|
|
76
|
+
var currentSize = drawer.getSceneSize();
|
|
77
|
+
var scale = utils_1.SizeSchema.fixSize(currentSize, {
|
|
78
|
+
width: limitSize.width,
|
|
79
|
+
height: limitSize.height,
|
|
80
|
+
});
|
|
81
|
+
drawer.refreshScale(false, scale);
|
|
82
|
+
}
|
|
83
|
+
function createSnapshots(opts, sceneDatas) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
var creator, result;
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
creator = new SnapshotCreator(opts);
|
|
90
|
+
return [4 /*yield*/, creator.draw(sceneDatas)];
|
|
91
|
+
case 1:
|
|
92
|
+
result = _a.sent();
|
|
93
|
+
creator.dispose();
|
|
94
|
+
return [2 /*return*/, result];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
exports.createSnapshots = createSnapshots;
|
|
100
|
+
var host;
|
|
101
|
+
var SnapshotCreator = /** @class */ (function (_super) {
|
|
102
|
+
__extends(SnapshotCreator, _super);
|
|
103
|
+
function SnapshotCreator(opts) {
|
|
104
|
+
var _this = _super.call(this) || this;
|
|
105
|
+
_this.opts = opts;
|
|
106
|
+
_this.result = {};
|
|
107
|
+
_this.processingData = [];
|
|
108
|
+
_this.onUpdateEmitter = new utils_1.Emitter();
|
|
109
|
+
_this.onUpdate = _this.onUpdateEmitter.event;
|
|
110
|
+
if (!host) {
|
|
111
|
+
host = document.createElement('div');
|
|
112
|
+
host.className = 'gedit-editor-snapshots';
|
|
113
|
+
host.style.display = 'none';
|
|
114
|
+
document.body.appendChild(host);
|
|
115
|
+
}
|
|
116
|
+
_this.drawer = new canvas_draw_1.CanvasDraw(__assign({ host: host }, opts));
|
|
117
|
+
_this.toDispose.pushAll([
|
|
118
|
+
_this.drawer,
|
|
119
|
+
_this.onUpdateEmitter,
|
|
120
|
+
]);
|
|
121
|
+
return _this;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 清楚缓存数据
|
|
125
|
+
*/
|
|
126
|
+
SnapshotCreator.prototype.clearResultCache = function (includeUris) {
|
|
127
|
+
var _this = this;
|
|
128
|
+
Object.keys(this.result).forEach(function (key) {
|
|
129
|
+
if (!includeUris.includes(key)) {
|
|
130
|
+
delete _this.result[key];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
SnapshotCreator.prototype.getResultFromCache = function () {
|
|
135
|
+
var _this = this;
|
|
136
|
+
return Object.keys(this.result).map(function (k) { return _this.result[k]; });
|
|
137
|
+
};
|
|
138
|
+
SnapshotCreator.prototype.updateResultCache = function (data) {
|
|
139
|
+
this.result[data.uri] = data;
|
|
140
|
+
};
|
|
141
|
+
SnapshotCreator.prototype.getSnapshot = function (uri) {
|
|
142
|
+
return this.result[uri];
|
|
143
|
+
};
|
|
144
|
+
SnapshotCreator.prototype.draw = function (scenes) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var _this = this;
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
switch (_a.label) {
|
|
149
|
+
case 0:
|
|
150
|
+
this.processingData = scenes.filter(function (s) {
|
|
151
|
+
var result = _this.result[s.uri];
|
|
152
|
+
if (result && s.version === result.version)
|
|
153
|
+
return false;
|
|
154
|
+
if (_this.current && _this.current.version === s.version)
|
|
155
|
+
return false;
|
|
156
|
+
return true;
|
|
157
|
+
});
|
|
158
|
+
return [4 /*yield*/, this.process()];
|
|
159
|
+
case 1:
|
|
160
|
+
_a.sent();
|
|
161
|
+
return [2 /*return*/, scenes.map(function (s) { return _this.result[s.uri]; })];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
SnapshotCreator.prototype.process = function () {
|
|
167
|
+
var _this = this;
|
|
168
|
+
if (this.processing) {
|
|
169
|
+
return this.processing.promise;
|
|
170
|
+
}
|
|
171
|
+
var deferred = this.processing = new utils_1.PromiseDeferred();
|
|
172
|
+
var drawer = this.drawer;
|
|
173
|
+
var dispose = new utils_1.DisposableCollection();
|
|
174
|
+
dispose.push(utils_1.Disposable.create(function () {
|
|
175
|
+
deferred.resolve();
|
|
176
|
+
_this.current = undefined;
|
|
177
|
+
_this.processing = undefined;
|
|
178
|
+
}));
|
|
179
|
+
dispose.push(drawer.onLoading(function (e) {
|
|
180
|
+
var loaded = e.loaded, allCount = e.allCount, currentCount = e.currentCount;
|
|
181
|
+
if (loaded || allCount <= currentCount) {
|
|
182
|
+
var widget = drawer.renderWidget;
|
|
183
|
+
if (_this.opts.limitSize) {
|
|
184
|
+
fixDrawerScale(drawer, _this.opts.limitSize);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
drawer.refreshScale(false, 1);
|
|
188
|
+
}
|
|
189
|
+
widget.createSnapShot(_this.opts.imageType || exports.SnapshotOptsDefault.imageType, _this.opts.quility || exports.SnapshotOptsDefault.quility).then(function (imageData) {
|
|
190
|
+
var current = _this.current;
|
|
191
|
+
if (current) {
|
|
192
|
+
_this.result[current.uri] = {
|
|
193
|
+
uri: current.uri,
|
|
194
|
+
version: current.version,
|
|
195
|
+
name: current.name,
|
|
196
|
+
imageData: imageData
|
|
197
|
+
};
|
|
198
|
+
_this.onUpdateEmitter.fire();
|
|
199
|
+
}
|
|
200
|
+
_this.next(function () { return dispose.dispose(); });
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}));
|
|
204
|
+
this.next(function () { return dispose.dispose(); });
|
|
205
|
+
return deferred.promise;
|
|
206
|
+
};
|
|
207
|
+
SnapshotCreator.prototype.next = function (end) {
|
|
208
|
+
var _a, _b;
|
|
209
|
+
var next = this.processingData.shift();
|
|
210
|
+
if (next) {
|
|
211
|
+
this.current = next;
|
|
212
|
+
(_b = (_a = this.drawer.renderWidget) === null || _a === void 0 ? void 0 : _a.currentScene) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
213
|
+
var appConfig = typeof this.opts.appConfig === 'function' ? this.opts.appConfig() : this.opts.appConfig;
|
|
214
|
+
var content = next.content;
|
|
215
|
+
// Empty
|
|
216
|
+
if (!content || !content.children || Object.keys(content).length === 0) {
|
|
217
|
+
content = model_1.Editor2dNode.createRootNode(new utils_1.URI(next.uri));
|
|
218
|
+
var attrs = this.opts.renderEngine.getDisplayDefaultData(this.opts.engineName, content.displayType);
|
|
219
|
+
Object.assign(content, __assign({}, attrs));
|
|
220
|
+
}
|
|
221
|
+
this.drawer.update({
|
|
222
|
+
visible: true,
|
|
223
|
+
uri: next.uri,
|
|
224
|
+
engineName: this.opts.engineName,
|
|
225
|
+
appConfig: appConfig,
|
|
226
|
+
content: content,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
end();
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* 监听变化,并自动刷新缩略图缓存
|
|
235
|
+
* @param model
|
|
236
|
+
* @param fn
|
|
237
|
+
* @param quility 缩略图质量
|
|
238
|
+
* @param delay 延迟生成
|
|
239
|
+
*/
|
|
240
|
+
SnapshotCreator.prototype.listenModelChanged = function (model, fn, quility, delay) {
|
|
241
|
+
var _this = this;
|
|
242
|
+
if (quility === void 0) { quility = 0.1; }
|
|
243
|
+
if (delay === void 0) { delay = 1000; }
|
|
244
|
+
return model.playground.context.onCanvasDataChanged((0, utils_1.debounce)(function (drawer) {
|
|
245
|
+
var _a = drawer.getData() || {}, content = _a.content, visible = _a.visible;
|
|
246
|
+
if (!content || drawer.loading)
|
|
247
|
+
return;
|
|
248
|
+
if (visible) {
|
|
249
|
+
var widget = drawer.renderWidget;
|
|
250
|
+
widget.createSnapShot(_this.opts.imageType, quility).then(function (base64) { return fn(base64); });
|
|
251
|
+
}
|
|
252
|
+
}, delay));
|
|
253
|
+
};
|
|
254
|
+
return SnapshotCreator;
|
|
255
|
+
}(utils_1.DisposableImpl));
|
|
256
|
+
exports.SnapshotCreator = SnapshotCreator;
|
|
257
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../src/browser/utils/snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAuE;AACvE,sCASsB;AAEtB,kCAAwC;AAW3B,QAAA,mBAAmB,GAAG;IACjC,OAAO,EAAE,GAAG;IACZ,SAAS,EAAE,YAAY;CACxB,CAAC;AAgBF,SAAS,cAAc,CAAC,MAAkB,EAAE,SAAqB;IAC/D,iDAAiD;I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Aa,CAAC;gBACpC,MAAM,CAAC,cAAc,CAAC,KAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,UAAC,MAAc,IAAK,OAAA,EAAE,CAAC,MAAM,CAAC,EAAV,CAAU,CAAC,CAAC;aAC1F;QACH,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACb,CAAC;IACH,sBAAC;AAAD,CAAC,AA5ID,CAAqC,sBAAc,GA4IlD;AA5IY,0CAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gedit/editor-2d",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.98",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/browser/index",
|
|
6
6
|
"typings": "lib/browser/index.d.ts",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"src"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@gedit/app-config": "^0.1.
|
|
13
|
-
"@gedit/editor": "^0.1.
|
|
14
|
-
"@gedit/playground": "^0.1.
|
|
15
|
-
"@gedit/render-engine-ide": "^0.1.
|
|
16
|
-
"@gedit/workspace-2d": "^0.1.
|
|
12
|
+
"@gedit/app-config": "^0.1.92",
|
|
13
|
+
"@gedit/editor": "^0.1.74",
|
|
14
|
+
"@gedit/playground": "^0.1.82",
|
|
15
|
+
"@gedit/render-engine-ide": "^0.1.98",
|
|
16
|
+
"@gedit/workspace-2d": "^0.1.78",
|
|
17
17
|
"json-stringify-pretty-compact": "^2.0.0"
|
|
18
18
|
},
|
|
19
19
|
"geditExtensions": [
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"nyc": {
|
|
35
35
|
"extends": "../../configs/nyc.json"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "b63ded2ca7a5d825937e4c58fb0b17d471bfb315"
|
|
38
38
|
}
|
|
@@ -118,12 +118,12 @@ export class Editor2dContribution implements FrontendApplicationContribution, Co
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
registerToolbarItems(toolbars: TabBarToolbarRegistry): void {
|
|
121
|
-
toolbars.registerItem({
|
|
121
|
+
/* toolbars.registerItem({
|
|
122
122
|
id: Editor2dCommands.FULLSCREEN.id,
|
|
123
123
|
command: Editor2dCommands.FULLSCREEN.id,
|
|
124
124
|
tooltip: Editor2dCommands.FULLSCREEN.label,
|
|
125
125
|
priority: 0,
|
|
126
|
-
});
|
|
126
|
+
}); */
|
|
127
127
|
/*
|
|
128
128
|
toolbars.registerItem({
|
|
129
129
|
id: Editor2dCommands.ZOOM_IN.id,
|
|
@@ -25,6 +25,7 @@ export default new ContainerModule(bind => {
|
|
|
25
25
|
Editor2dRefProviderContribution,
|
|
26
26
|
Editor2dContextKeyService,
|
|
27
27
|
]);
|
|
28
|
+
bind(Editor2dService.Provider).toFactory(ctx => () => ctx.container.get(Editor2dService));
|
|
28
29
|
bindContributions(bind, Editor2dContribution, [
|
|
29
30
|
FrontendApplicationContribution,
|
|
30
31
|
CommandContribution,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
SelectionService,
|
|
6
6
|
} from '@gedit/application-common';
|
|
7
7
|
import { Editor2dModel } from './model/editor2d-model';
|
|
8
|
-
import { EditorAccess, EditorManager, EditorWidget } from '@gedit/editor';
|
|
8
|
+
import { EditorAccess, EditorDocumentChangeEvent, EditorManager, EditorWidget } from '@gedit/editor';
|
|
9
9
|
import { Editor2dNode } from './model/editor2d';
|
|
10
10
|
import { Editor2dDocument } from './model/editor2d-document';
|
|
11
11
|
import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
|
|
@@ -17,6 +17,10 @@ export interface Editor2dSelectedNodesChangedEvent {
|
|
|
17
17
|
document: Editor2dDocument | undefined; // 如果为空,代表当前没有在编辑文档
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export interface Editor2dModelContentChangedEvent extends Editor2dSelectedNodesChangedEvent {
|
|
21
|
+
event: EditorDocumentChangeEvent<Editor2dDocument>
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
@injectable()
|
|
21
25
|
export class Editor2dService {
|
|
22
26
|
@inject(SelectionService) protected readonly selectionService: SelectionService;
|
|
@@ -59,7 +63,21 @@ export class Editor2dService {
|
|
|
59
63
|
fn(this.getCurrentModel());
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
|
-
onDeleteNode(fn: (e:
|
|
66
|
+
onDeleteNode(fn: (e: Editor2dModelContentChangedEvent & { deleteNodes: Editor2dNode[] }) => void): Disposable {
|
|
67
|
+
return this.onCurrentModelContentChanged(e => {
|
|
68
|
+
if (e.event.type === 'delete') {
|
|
69
|
+
return fn({
|
|
70
|
+
...e,
|
|
71
|
+
deleteNodes: (e.event.nodes as Editor2dNode[]) || [],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 内容修改触发
|
|
78
|
+
* @param fn
|
|
79
|
+
*/
|
|
80
|
+
onCurrentModelContentChanged(fn: (e: Editor2dModelContentChangedEvent) => void): Disposable {
|
|
63
81
|
const self = this;
|
|
64
82
|
let model: Editor2dModel | undefined;
|
|
65
83
|
const toDispose = new DisposableCollection();
|
|
@@ -71,15 +89,13 @@ export class Editor2dService {
|
|
|
71
89
|
preDispose.dispose();
|
|
72
90
|
preDispose = new DisposableCollection();
|
|
73
91
|
if (model) {
|
|
74
|
-
preDispose.push(model.onDocumentContentChanged(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
}
|
|
92
|
+
preDispose.push(model.onDocumentContentChanged(event => {
|
|
93
|
+
fn({
|
|
94
|
+
selectedNodes: model?.selection.selectedNodes || [],
|
|
95
|
+
document: model?.document,
|
|
96
|
+
model,
|
|
97
|
+
event
|
|
98
|
+
});
|
|
83
99
|
}));
|
|
84
100
|
}
|
|
85
101
|
toDispose.push(preDispose);
|
|
@@ -153,3 +169,9 @@ export class Editor2dService {
|
|
|
153
169
|
return toDispose;
|
|
154
170
|
}
|
|
155
171
|
}
|
|
172
|
+
|
|
173
|
+
export namespace Editor2dService {
|
|
174
|
+
// 动态获取, 用于循环依赖情况, 可以在AppShell加载之后使用
|
|
175
|
+
export type Provider = () => Editor2dService;
|
|
176
|
+
export const Provider = Symbol('Editor2dService.Provider');
|
|
177
|
+
}
|
package/src/browser/index.ts
CHANGED
|
@@ -36,7 +36,8 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
36
36
|
readonly onSaved = this.onSavedEmitter.event;
|
|
37
37
|
public animationStarted: boolean = false;
|
|
38
38
|
protected animationIds: string[] = []; // 当前正在录制的动画节点
|
|
39
|
-
private _localVersion: number =
|
|
39
|
+
private _localVersion: number = 0;
|
|
40
|
+
private _saveVersion: number = 0;
|
|
40
41
|
protected errors: ResourceRefError[] = [];
|
|
41
42
|
protected componentContents: { [key: string]: Editor2dNode } = {};
|
|
42
43
|
protected _snaplines: any[] = [];
|
|
@@ -61,7 +62,8 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
61
62
|
super();
|
|
62
63
|
this.toDispose.push(this.onContentChangedEmitter);
|
|
63
64
|
this.toDispose.push(this.onSavedEmitter);
|
|
64
|
-
this.toDispose.
|
|
65
|
+
// this.toDispose.
|
|
66
|
+
// this.toDispose.push(this.resourceAutoSaveService);
|
|
65
67
|
this.toDispose.push(this.resourceAutoSaveService.onSyncContent(content => this.reloadContent(content || '')));
|
|
66
68
|
this.toDispose.push(this.onSaved(event => this.resourceAutoSaveService.fireDidChangeContent(event)));
|
|
67
69
|
this.toDispose.push(this.resourceService.onRefsChange(async () => {
|
|
@@ -264,6 +266,8 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
264
266
|
}
|
|
265
267
|
if (data.content) {
|
|
266
268
|
this._localVersion = data.content.version;
|
|
269
|
+
(data.content as any).visible = false;
|
|
270
|
+
this._saveVersion = data.version || 0;
|
|
267
271
|
this.root = data.content;
|
|
268
272
|
} else {
|
|
269
273
|
this.root = this.createRootNode();
|
|
@@ -296,6 +300,10 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
296
300
|
this.onContentChangedEmitter.fire({ document: this, contentChanges: contents, nodes, type });
|
|
297
301
|
}
|
|
298
302
|
if (!this.loading && !noSave) {
|
|
303
|
+
this._saveVersion++;
|
|
304
|
+
if (this._saveVersion === Number.MAX_VALUE) {
|
|
305
|
+
this._saveVersion = 0;
|
|
306
|
+
}
|
|
299
307
|
this.onSavedEmitter.fire({ document: this, contentChanges: contents, nodes, type });
|
|
300
308
|
}
|
|
301
309
|
};
|
|
@@ -756,4 +764,7 @@ export class Editor2dDocument extends TreeImpl<Editor2dNode, Editor2dContainerNo
|
|
|
756
764
|
this.fireContentChanged([], 'update');
|
|
757
765
|
}
|
|
758
766
|
}
|
|
767
|
+
get saveVersion(): number {
|
|
768
|
+
return this._saveVersion;
|
|
769
|
+
}
|
|
759
770
|
}
|
|
@@ -2,10 +2,20 @@ import { injectable } from 'inversify';
|
|
|
2
2
|
import { EditorDocumentSelection } from '@gedit/editor';
|
|
3
3
|
import { TreeSelectionServiceImpl } from '@gedit/tree/lib/browser/tree-selection-impl';
|
|
4
4
|
import { Editor2dNode } from './editor2d';
|
|
5
|
+
import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
|
|
6
|
+
import SelectionType = TreeSelection.SelectionType;
|
|
5
7
|
|
|
6
8
|
@injectable()
|
|
7
9
|
export class Editor2dSelection extends TreeSelectionServiceImpl implements EditorDocumentSelection {
|
|
8
10
|
get selectedNodes(): Editor2dNode[] {
|
|
9
11
|
return this.state.selection() as Editor2dNode[];
|
|
10
12
|
}
|
|
13
|
+
clearSelection(): void {
|
|
14
|
+
this.selectedNodes.forEach(node =>
|
|
15
|
+
this.addSelection({
|
|
16
|
+
node: node as Readonly<SelectableTreeNode>,
|
|
17
|
+
type: SelectionType.TOGGLE
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
}
|
|
11
21
|
}
|
|
@@ -86,6 +86,7 @@ export interface Editor2dContainerNode extends Editor2dNode, ExpandableTreeNode
|
|
|
86
86
|
|
|
87
87
|
export namespace Editor2dNode {
|
|
88
88
|
export const ROOT_NODE_ID = 'root';
|
|
89
|
+
export const GLOBAL_ADD_EVENT = 'global_add_event'; // 全局添加标记事件
|
|
89
90
|
export function createNodeId(): string {
|
|
90
91
|
return generateUuid();
|
|
91
92
|
}
|
|
@@ -188,7 +189,7 @@ export namespace Editor2dNode {
|
|
|
188
189
|
parent: undefined,
|
|
189
190
|
name: uri.displayName,
|
|
190
191
|
children: [],
|
|
191
|
-
visible:
|
|
192
|
+
visible: false,
|
|
192
193
|
expanded: true,
|
|
193
194
|
selected: false,
|
|
194
195
|
locked: false,
|
|
@@ -247,7 +248,7 @@ export async function getEditor2dModelOpts(resource: Resource, resourceService:
|
|
|
247
248
|
const options: ResourceAutoSaveOptions = {
|
|
248
249
|
encoding,
|
|
249
250
|
resource,
|
|
250
|
-
saveAsString: e => Editor2dContent.parseToString({version: e.document.
|
|
251
|
+
saveAsString: e => Editor2dContent.parseToString({version: e.document.saveVersion, content: e.document.root, snaplines: e.document.snaplines})
|
|
251
252
|
};
|
|
252
253
|
const autoSaveService = await resourceService.createAutoSaveResource(options);
|
|
253
254
|
return {
|
|
@@ -10,7 +10,7 @@ interface KeysValue {
|
|
|
10
10
|
name: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const supportKeys: SchemaType[] = ['integer', 'float'];
|
|
13
|
+
const supportKeys: SchemaType[] = ['integer', 'float', 'color'];
|
|
14
14
|
function readAnimationKeys(
|
|
15
15
|
deco: SchemaDecoration,
|
|
16
16
|
keyList: { key: string; name: string }[],
|
|
@@ -32,7 +32,12 @@ function readAnimationKeys(
|
|
|
32
32
|
currentKey
|
|
33
33
|
);
|
|
34
34
|
});
|
|
35
|
-
} else if (
|
|
35
|
+
} else if (
|
|
36
|
+
currentLabel &&
|
|
37
|
+
currentKey &&
|
|
38
|
+
supportKeys.includes(deco.type) &&
|
|
39
|
+
!currentKey.match(/^(origin)/) // 干掉原点
|
|
40
|
+
) {
|
|
36
41
|
keyList.push({
|
|
37
42
|
key: currentKey,
|
|
38
43
|
name: currentLabel.toUpperCase(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GameConfig, GameObject,
|
|
1
|
+
import { GameConfig, GameObject, GameObjectData, GameObjectError } from '@gedit/render-engine';
|
|
2
2
|
import { Editor2dNode } from '../model/editor2d';
|
|
3
3
|
import { GameSceneIDE, GameWidgetIDE, RenderEngineIDEService } from '@gedit/render-engine-ide';
|
|
4
4
|
import { AppConfigData } from '@gedit/app-config/lib/common';
|
|
@@ -11,11 +11,6 @@ interface GameObjectState {
|
|
|
11
11
|
adsorbable: boolean,
|
|
12
12
|
isInside: boolean
|
|
13
13
|
}
|
|
14
|
-
interface GameSceneSizeConfig {
|
|
15
|
-
width?: number // 场景宽
|
|
16
|
-
height?: number // 场景高
|
|
17
|
-
autoSize?: boolean
|
|
18
|
-
}
|
|
19
14
|
|
|
20
15
|
export interface CanvasDrawOpts {
|
|
21
16
|
host: HTMLElement,
|
|
@@ -87,7 +82,7 @@ function toNodeData(node: Editor2dNode, config: AppConfigData): GameObjectData {
|
|
|
87
82
|
* 画布绘制逻辑
|
|
88
83
|
*/
|
|
89
84
|
export class CanvasDraw extends DisposableImpl {
|
|
90
|
-
protected onDrawEmitter = new Emitter<
|
|
85
|
+
protected onDrawEmitter = new Emitter<GameConfig.SceneSizeConfig>();
|
|
91
86
|
protected onLoadingEmitter = new Emitter<CanvasDrawLoadingState>();
|
|
92
87
|
protected onGameObjectChangeEmitter = new Emitter<GameObjectChangeEvent>();
|
|
93
88
|
protected data?: CanvasDrawData;
|
|
@@ -353,14 +348,7 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
353
348
|
if (!this.data) return undefined;
|
|
354
349
|
const { content, appConfig } = this.data;
|
|
355
350
|
if (!appConfig || !content) return undefined;
|
|
356
|
-
|
|
357
|
-
const sizeConfig = (content as any)[GameObjectBaseType.SCENE] as GameSceneSizeConfig | undefined;
|
|
358
|
-
const config = GameConfig.toAutoSize(appConfig);
|
|
359
|
-
const isAuto = sizeConfig?.autoSize;
|
|
360
|
-
return {
|
|
361
|
-
width: isAuto ? config.width : sizeConfig?.width || config.width,
|
|
362
|
-
height: isAuto ? config.height : sizeConfig?.height || config.height
|
|
363
|
-
};
|
|
351
|
+
return GameConfig.getSceneSize(appConfig, content);
|
|
364
352
|
}
|
|
365
353
|
protected draw(): void {
|
|
366
354
|
if (!this.data) return;
|
|
@@ -395,4 +383,3 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
395
383
|
this.onDrawEmitter.fire(size);
|
|
396
384
|
}
|
|
397
385
|
}
|
|
398
|
-
|
|
@@ -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 {
|