@eva/plugin-renderer-img 2.0.2 → 2.1.0-beta.1
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/dist/EVA.plugin.renderer.img.js +201 -48
- package/dist/EVA.plugin.renderer.img.min.js +1 -1
- package/dist/plugin-renderer-img.cjs.js +123 -32
- package/dist/plugin-renderer-img.cjs.prod.js +1 -1
- package/dist/plugin-renderer-img.d.ts +35 -2
- package/dist/plugin-renderer-img.esm.js +123 -32
- package/package.json +5 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
1
2
|
globalThis.EVA = globalThis.EVA || {};
|
|
2
3
|
globalThis.EVA.plugin = globalThis.EVA.plugin || {};
|
|
3
4
|
globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
|
|
@@ -10,6 +11,9 @@ var _EVA_IIFE_img = function (exports, eva_js, pluginRenderer, rendererAdapter,
|
|
|
10
11
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11
12
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
13
|
}
|
|
14
|
+
function __metadata(metadataKey, metadataValue) {
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
16
|
+
}
|
|
13
17
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
14
18
|
function adopt(value) {
|
|
15
19
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -37,36 +41,158 @@ var _EVA_IIFE_img = function (exports, eva_js, pluginRenderer, rendererAdapter,
|
|
|
37
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
function __rest(s, e) {
|
|
45
|
+
var t = {};
|
|
46
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
47
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
48
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
49
|
+
}
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
53
|
+
var e = new Error(message);
|
|
54
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
55
|
+
};
|
|
56
|
+
class SymbolKeysNotSupportedError extends Error {
|
|
57
|
+
constructor() {
|
|
58
|
+
super('Symbol keys are not supported yet!');
|
|
59
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
|
|
63
|
+
function transformBasicType(type) {
|
|
64
|
+
if (type === String) {
|
|
65
|
+
return 'string';
|
|
66
|
+
}
|
|
67
|
+
if (type === Number) {
|
|
68
|
+
return 'number';
|
|
43
69
|
}
|
|
44
|
-
if (
|
|
45
|
-
|
|
70
|
+
if (type === Boolean) {
|
|
71
|
+
return 'boolean';
|
|
46
72
|
}
|
|
47
|
-
|
|
48
|
-
|
|
73
|
+
return 'unknown';
|
|
74
|
+
}
|
|
75
|
+
function defineLegacyIDEProp(target, propertyKey, patch) {
|
|
76
|
+
const constructor = target.constructor;
|
|
77
|
+
const current = constructor.IDEProps || {};
|
|
78
|
+
current[propertyKey] = _extends(_extends({
|
|
79
|
+
key: propertyKey
|
|
80
|
+
}, current[propertyKey]), patch);
|
|
81
|
+
constructor.IDEProps = current;
|
|
82
|
+
}
|
|
83
|
+
function defineTypes(target, key, options, returnTypeFunction) {
|
|
84
|
+
let type = Reflect.getMetadata('design:type', target, key);
|
|
85
|
+
let isArray = type === Array;
|
|
86
|
+
const str = transformBasicType(type);
|
|
87
|
+
if (str !== 'unknown') {
|
|
88
|
+
type = str;
|
|
89
|
+
}
|
|
90
|
+
if (returnTypeFunction) {
|
|
91
|
+
const returnType = returnTypeFunction();
|
|
92
|
+
if (Array.isArray(returnType)) {
|
|
93
|
+
isArray = true;
|
|
94
|
+
type = returnType[0];
|
|
95
|
+
} else {
|
|
96
|
+
type = returnType;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
|
|
100
|
+
const current = properties[key] || {};
|
|
101
|
+
const property = _extends(_extends(_extends({}, current), {
|
|
102
|
+
type,
|
|
103
|
+
isArray: isArray
|
|
104
|
+
}), options);
|
|
105
|
+
properties[key] = property;
|
|
106
|
+
Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
|
|
107
|
+
const legacyProperty = __rest(property, ["isArray"]);
|
|
108
|
+
defineLegacyIDEProp(target, key, legacyProperty);
|
|
49
109
|
}
|
|
50
110
|
function type(type) {
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
111
|
+
return Field({
|
|
112
|
+
type
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
|
|
116
|
+
if (typeof returnTypeFuncOrOptions === 'function') {
|
|
117
|
+
return {
|
|
118
|
+
returnTypeFunc: returnTypeFuncOrOptions,
|
|
119
|
+
options: maybeOptions || {}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
options: returnTypeFuncOrOptions || {}
|
|
55
124
|
};
|
|
56
125
|
}
|
|
126
|
+
function Field(returnTypeFunction, maybeOptions) {
|
|
127
|
+
return (target, propertyKey) => {
|
|
128
|
+
if (typeof propertyKey === 'symbol') {
|
|
129
|
+
throw new SymbolKeysNotSupportedError();
|
|
130
|
+
}
|
|
131
|
+
const {
|
|
132
|
+
options,
|
|
133
|
+
returnTypeFunc
|
|
134
|
+
} = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
|
|
135
|
+
defineTypes(target, propertyKey, options, returnTypeFunc);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
var ExecuteMode;
|
|
139
|
+
(function (ExecuteMode) {
|
|
140
|
+
ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
|
|
141
|
+
ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
|
|
142
|
+
ExecuteMode[ExecuteMode["All"] = 6] = "All";
|
|
143
|
+
})(ExecuteMode || (ExecuteMode = {}));
|
|
57
144
|
class Img$2 extends eva_js.Component {
|
|
58
|
-
constructor() {
|
|
59
|
-
super(
|
|
145
|
+
constructor(params) {
|
|
146
|
+
super(params);
|
|
60
147
|
this.resource = '';
|
|
148
|
+
this.anchor = {
|
|
149
|
+
x: 0,
|
|
150
|
+
y: 0
|
|
151
|
+
};
|
|
152
|
+
this.init(params);
|
|
61
153
|
}
|
|
62
154
|
init(obj) {
|
|
155
|
+
var _a, _b;
|
|
63
156
|
if (obj && obj.resource) {
|
|
64
157
|
this.resource = obj.resource;
|
|
65
158
|
}
|
|
159
|
+
if (obj && obj.anchor) {
|
|
160
|
+
this.anchor = {
|
|
161
|
+
x: (_a = obj.anchor.x) !== null && _a !== void 0 ? _a : this.anchor.x,
|
|
162
|
+
y: (_b = obj.anchor.y) !== null && _b !== void 0 ? _b : this.anchor.y
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (obj && typeof obj.width === 'number') {
|
|
166
|
+
this.width = obj.width;
|
|
167
|
+
}
|
|
168
|
+
if (obj && typeof obj.height === 'number') {
|
|
169
|
+
this.height = obj.height;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
load(resource) {
|
|
173
|
+
if (resource) {
|
|
174
|
+
this.resource = resource;
|
|
175
|
+
}
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
setAnchor(x, y = x) {
|
|
179
|
+
this.anchor.x = x;
|
|
180
|
+
this.anchor.y = y;
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
setSize(width, height) {
|
|
184
|
+
this.width = width;
|
|
185
|
+
this.height = height;
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
destroy() {
|
|
189
|
+
return this;
|
|
66
190
|
}
|
|
67
191
|
}
|
|
68
192
|
Img$2.componentName = 'Img';
|
|
69
|
-
__decorate([type('string')], Img$2.prototype, "resource", void 0);
|
|
193
|
+
__decorate([type('string'), __metadata("design:type", String)], Img$2.prototype, "resource", void 0);
|
|
194
|
+
__decorate([type('number'), __metadata("design:type", Number)], Img$2.prototype, "width", void 0);
|
|
195
|
+
__decorate([type('number'), __metadata("design:type", Number)], Img$2.prototype, "height", void 0);
|
|
70
196
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.IMAGE, ({
|
|
71
197
|
data = {}
|
|
72
198
|
}) => {
|
|
@@ -92,64 +218,91 @@ var _EVA_IIFE_img = function (exports, eva_js, pluginRenderer, rendererAdapter,
|
|
|
92
218
|
let Img = class Img extends pluginRenderer.Renderer {
|
|
93
219
|
constructor() {
|
|
94
220
|
super(...arguments);
|
|
95
|
-
this.name = '
|
|
221
|
+
this.name = 'ImgSystem';
|
|
96
222
|
this.imgs = {};
|
|
97
223
|
}
|
|
98
|
-
init() {
|
|
99
|
-
|
|
224
|
+
init(_params) {
|
|
225
|
+
var _a, _b;
|
|
226
|
+
const renderSystem = (_b = (_a = this.game) === null || _a === void 0 ? void 0 : _a.getSystem) === null || _b === void 0 ? void 0 : _b.call(_a, pluginRenderer.RendererSystem);
|
|
227
|
+
if (!(renderSystem === null || renderSystem === void 0 ? void 0 : renderSystem.rendererManager)) return;
|
|
228
|
+
this.renderSystem = renderSystem;
|
|
100
229
|
this.renderSystem.rendererManager.register(this);
|
|
101
230
|
}
|
|
231
|
+
update(_frame) {
|
|
232
|
+
super.update(_frame);
|
|
233
|
+
}
|
|
102
234
|
rendererUpdate(gameObject) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
height
|
|
106
|
-
} = gameObject.transform.size;
|
|
107
|
-
if (this.imgs[gameObject.id]) {
|
|
108
|
-
this.imgs[gameObject.id].sprite.width = width;
|
|
109
|
-
this.imgs[gameObject.id].sprite.height = height;
|
|
110
|
-
}
|
|
235
|
+
const component = gameObject.getComponent('Img');
|
|
236
|
+
this.applySpriteLayout(gameObject, component);
|
|
111
237
|
}
|
|
112
238
|
componentChanged(changed) {
|
|
113
|
-
var _a, _b;
|
|
239
|
+
var _a, _b, _c, _d, _e, _f;
|
|
114
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
241
|
if (changed.componentName === 'Img') {
|
|
242
|
+
const gameObjectId = changed.gameObject.id;
|
|
116
243
|
const component = changed.component;
|
|
117
244
|
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
118
245
|
const sprite = new rendererAdapter.Sprite(null);
|
|
119
|
-
this.imgs[
|
|
120
|
-
this.containerManager.getContainer(
|
|
121
|
-
|
|
246
|
+
this.imgs[gameObjectId] = sprite;
|
|
247
|
+
(_b = (_a = this.containerManager) === null || _a === void 0 ? void 0 : _a.getContainer(gameObjectId)) === null || _b === void 0 ? void 0 : _b.addChildAt(sprite.sprite, 0);
|
|
248
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
249
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
122
250
|
const {
|
|
123
251
|
instance
|
|
124
252
|
} = yield eva_js.resource.getResource(component.resource);
|
|
125
|
-
if (!this.validateAsyncId(
|
|
253
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
126
254
|
if (!instance) {
|
|
127
255
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
256
|
+
return;
|
|
128
257
|
}
|
|
129
|
-
|
|
258
|
+
sprite.image = instance;
|
|
259
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
130
260
|
} else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
261
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
262
|
+
if ((_d = (_c = changed.prop) === null || _c === void 0 ? void 0 : _c.prop) === null || _d === void 0 ? void 0 : _d.includes('resource')) {
|
|
263
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
264
|
+
const {
|
|
265
|
+
instance
|
|
266
|
+
} = yield eva_js.resource.getResource(component.resource);
|
|
267
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
268
|
+
if (!instance) {
|
|
269
|
+
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
this.imgs[gameObjectId].image = instance;
|
|
273
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
138
274
|
}
|
|
139
|
-
this.imgs[changed.gameObject.id].image = instance;
|
|
140
275
|
} else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
141
|
-
this.increaseAsyncId(
|
|
142
|
-
const sprite = this.imgs[
|
|
276
|
+
this.increaseAsyncId(gameObjectId);
|
|
277
|
+
const sprite = this.imgs[gameObjectId];
|
|
143
278
|
if (!sprite) return;
|
|
144
|
-
(
|
|
279
|
+
(_f = (_e = this.containerManager) === null || _e === void 0 ? void 0 : _e.getContainer(gameObjectId)) === null || _f === void 0 ? void 0 : _f.removeChild(sprite.sprite);
|
|
145
280
|
sprite.sprite.destroy({
|
|
146
281
|
children: true
|
|
147
282
|
});
|
|
148
|
-
delete this.imgs[
|
|
283
|
+
delete this.imgs[gameObjectId];
|
|
149
284
|
}
|
|
150
285
|
}
|
|
151
286
|
});
|
|
152
287
|
}
|
|
288
|
+
applySpriteLayout(gameObject, component) {
|
|
289
|
+
var _a, _b, _c, _d, _e;
|
|
290
|
+
const sprite = this.imgs[gameObject.id];
|
|
291
|
+
if (!sprite) return;
|
|
292
|
+
const size = (_a = gameObject.transform) === null || _a === void 0 ? void 0 : _a.size;
|
|
293
|
+
const width = (_b = component === null || component === void 0 ? void 0 : component.width) !== null && _b !== void 0 ? _b : size === null || size === void 0 ? void 0 : size.width;
|
|
294
|
+
const height = (_c = component === null || component === void 0 ? void 0 : component.height) !== null && _c !== void 0 ? _c : size === null || size === void 0 ? void 0 : size.height;
|
|
295
|
+
if (typeof width === 'number') {
|
|
296
|
+
sprite.sprite.width = width;
|
|
297
|
+
}
|
|
298
|
+
if (typeof height === 'number') {
|
|
299
|
+
sprite.sprite.height = height;
|
|
300
|
+
}
|
|
301
|
+
const anchor = component === null || component === void 0 ? void 0 : component.anchor;
|
|
302
|
+
if (anchor) {
|
|
303
|
+
(_e = (_d = sprite.sprite.anchor) === null || _d === void 0 ? void 0 : _d.set) === null || _e === void 0 ? void 0 : _e.call(_d, anchor.x, anchor.y);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
153
306
|
destroy() {
|
|
154
307
|
var _a, _b;
|
|
155
308
|
for (const key in this.imgs) {
|
|
@@ -162,12 +315,12 @@ var _EVA_IIFE_img = function (exports, eva_js, pluginRenderer, rendererAdapter,
|
|
|
162
315
|
}
|
|
163
316
|
}
|
|
164
317
|
};
|
|
165
|
-
Img.systemName = '
|
|
318
|
+
Img.systemName = 'ImgSystem';
|
|
166
319
|
Img = __decorate([eva_js.decorators.componentObserver({
|
|
167
|
-
Img: [{
|
|
168
|
-
prop:
|
|
169
|
-
deep:
|
|
170
|
-
}]
|
|
320
|
+
Img: ['resource', {
|
|
321
|
+
prop: 'anchor',
|
|
322
|
+
deep: true
|
|
323
|
+
}, 'width', 'height']
|
|
171
324
|
})], Img);
|
|
172
325
|
var Img$1 = Img;
|
|
173
326
|
exports.Img = Img$2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_img=function(e,t,r,
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_img=function(e,t,r,n,o){"use strict";function i(e,t,r,n){var o,i=arguments.length,s=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(s=(i<3?o(s):i>3?o(t,r,s):o(t,r))||s);return i>3&&s&&Object.defineProperty(t,r,s),s}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t,r,n){return new(r||(r=Promise))(function(o,i){function s(e){try{a(n.next(e))}catch(e){i(e)}}function c(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,c)}a((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class a extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const l="IDE_PROPERTY_METADATA";function u(e,t,r,n){let o=Reflect.getMetadata("design:type",e,t),i=o===Array;const s=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),n){const e=n();Array.isArray(e)?(i=!0,o=e[0]):o=e}const c=Reflect.getMetadata(l,e.constructor)||{},a=_extends(_extends(_extends({},c[t]||{}),{type:o,isArray:i}),r);c[t]=a,Reflect.defineMetadata(l,c,e.constructor);!function(e,t,r){const n=e.constructor,o=n.IDEProps||{};o[t]=_extends(_extends({key:t},o[t]),r),n.IDEProps=o}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(a,["isArray"]))}function d(e){return t={type:e},(e,n)=>{if("symbol"==typeof n)throw new a;const{options:o,returnTypeFunc:i}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,r);u(e,n,o,i)};var t,r}var p;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(p||(p={}));class h extends t.Component{constructor(e){super(e),this.resource="",this.anchor={x:0,y:0},this.init(e)}init(e){var t,r;e&&e.resource&&(this.resource=e.resource),e&&e.anchor&&(this.anchor={x:null!==(t=e.anchor.x)&&void 0!==t?t:this.anchor.x,y:null!==(r=e.anchor.y)&&void 0!==r?r:this.anchor.y}),e&&"number"==typeof e.width&&(this.width=e.width),e&&"number"==typeof e.height&&(this.height=e.height)}load(e){return e&&(this.resource=e),this}setAnchor(e,t=e){return this.anchor.x=e,this.anchor.y=t,this}setSize(e,t){return this.width=e,this.height=t,this}destroy(){return this}}h.componentName="Img",i([d("string"),s("design:type",String)],h.prototype,"resource",void 0),i([d("number"),s("design:type",Number)],h.prototype,"width",void 0),i([d("number"),s("design:type",Number)],h.prototype,"height",void 0),t.resource.registerInstance(t.RESOURCE_TYPE.IMAGE,({data:e={}})=>{const{image:t}=e;if(t){if(t instanceof o.Texture)return t;return o.Texture.from(t)}return e}),t.resource.registerDestroy(t.RESOURCE_TYPE.IMAGE,({instance:e})=>{e&&e.destroy(!0)});let g=class extends r.Renderer{constructor(){super(...arguments),this.name="ImgSystem",this.imgs={}}init(e){var t,n;const o=null===(n=null===(t=this.game)||void 0===t?void 0:t.getSystem)||void 0===n?void 0:n.call(t,r.RendererSystem);(null==o?void 0:o.rendererManager)&&(this.renderSystem=o,this.renderSystem.rendererManager.register(this))}update(e){super.update(e)}rendererUpdate(e){const t=e.getComponent("Img");this.applySpriteLayout(e,t)}componentChanged(e){var r,o,i,s,a,l;return c(this,void 0,void 0,function*(){if("Img"===e.componentName){const c=e.gameObject.id,u=e.component;if(e.type===t.OBSERVER_TYPE.ADD){const i=new n.Sprite(null);this.imgs[c]=i,null===(o=null===(r=this.containerManager)||void 0===r?void 0:r.getContainer(c))||void 0===o||o.addChildAt(i.sprite,0),this.applySpriteLayout(e.gameObject,u);const s=this.increaseAsyncId(c),{instance:a}=yield t.resource.getResource(u.resource);if(!this.validateAsyncId(c,s))return;if(!a)return void console.error(`GameObject:${e.gameObject.name}'s Img resource load error`);i.image=a,this.applySpriteLayout(e.gameObject,u)}else if(e.type===t.OBSERVER_TYPE.CHANGE){if(this.applySpriteLayout(e.gameObject,u),null===(s=null===(i=e.prop)||void 0===i?void 0:i.prop)||void 0===s?void 0:s.includes("resource")){const r=this.increaseAsyncId(c),{instance:n}=yield t.resource.getResource(u.resource);if(!this.validateAsyncId(c,r))return;if(!n)return void console.error(`GameObject:${e.gameObject.name}'s Img resource load error`);this.imgs[c].image=n,this.applySpriteLayout(e.gameObject,u)}}else if(e.type===t.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(c);const e=this.imgs[c];if(!e)return;null===(l=null===(a=this.containerManager)||void 0===a?void 0:a.getContainer(c))||void 0===l||l.removeChild(e.sprite),e.sprite.destroy({children:!0}),delete this.imgs[c]}}})}applySpriteLayout(e,t){var r,n,o,i,s;const c=this.imgs[e.id];if(!c)return;const a=null===(r=e.transform)||void 0===r?void 0:r.size,l=null!==(n=null==t?void 0:t.width)&&void 0!==n?n:null==a?void 0:a.width,u=null!==(o=null==t?void 0:t.height)&&void 0!==o?o:null==a?void 0:a.height;"number"==typeof l&&(c.sprite.width=l),"number"==typeof u&&(c.sprite.height=u);const d=null==t?void 0:t.anchor;d&&(null===(s=null===(i=c.sprite.anchor)||void 0===i?void 0:i.set)||void 0===s||s.call(i,d.x,d.y))}destroy(){var e,t;for(const r in this.imgs){const n=this.imgs[r];null===(t=null===(e=this.containerManager)||void 0===e?void 0:e.getContainer(parseInt(r)))||void 0===t||t.removeChild(n.sprite),n.sprite.destroy({children:!0}),delete this.imgs[r]}}};g.systemName="ImgSystem",g=i([t.decorators.componentObserver({Img:["resource",{prop:"anchor",deep:!0},"width","height"]})],g);var y=g;return e.Img=h,e.ImgSystem=y,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);globalThis.EVA.plugin.renderer.img=globalThis.EVA.plugin.renderer.img||_EVA_IIFE_img;
|
|
@@ -30,6 +30,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
30
30
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function __metadata(metadataKey, metadataValue) {
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
34
38
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
35
39
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -61,27 +65,82 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
61
65
|
* ```
|
|
62
66
|
*/
|
|
63
67
|
class Img$2 extends eva_js.Component {
|
|
64
|
-
constructor() {
|
|
65
|
-
super(
|
|
68
|
+
constructor(params) {
|
|
69
|
+
super(params);
|
|
66
70
|
/** 图片资源名称 */
|
|
67
71
|
this.resource = '';
|
|
72
|
+
/** 图片锚点 */
|
|
73
|
+
this.anchor = { x: 0, y: 0 };
|
|
74
|
+
this.init(params);
|
|
68
75
|
}
|
|
69
76
|
/**
|
|
70
77
|
* 初始化组件
|
|
71
78
|
* @param obj - 初始化参数
|
|
72
|
-
*
|
|
79
|
+
*
|
|
80
|
+
* 配置项包括 resource、anchor、width 和 height。
|
|
73
81
|
*/
|
|
74
82
|
init(obj) {
|
|
83
|
+
var _a, _b;
|
|
75
84
|
if (obj && obj.resource) {
|
|
76
85
|
this.resource = obj.resource;
|
|
77
86
|
}
|
|
87
|
+
if (obj && obj.anchor) {
|
|
88
|
+
this.anchor = {
|
|
89
|
+
x: (_a = obj.anchor.x) !== null && _a !== void 0 ? _a : this.anchor.x,
|
|
90
|
+
y: (_b = obj.anchor.y) !== null && _b !== void 0 ? _b : this.anchor.y,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (obj && typeof obj.width === 'number') {
|
|
94
|
+
this.width = obj.width;
|
|
95
|
+
}
|
|
96
|
+
if (obj && typeof obj.height === 'number') {
|
|
97
|
+
this.height = obj.height;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 切换当前图片资源。
|
|
102
|
+
*
|
|
103
|
+
* ImgSystem 会监听 resource 变化并刷新渲染纹理。
|
|
104
|
+
*
|
|
105
|
+
* @param resource - 图片资源名称
|
|
106
|
+
*/
|
|
107
|
+
load(resource) {
|
|
108
|
+
if (resource) {
|
|
109
|
+
this.resource = resource;
|
|
110
|
+
}
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/** 设置图片锚点。 */
|
|
114
|
+
setAnchor(x, y = x) {
|
|
115
|
+
this.anchor.x = x;
|
|
116
|
+
this.anchor.y = y;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
/** 设置显式渲染尺寸。 */
|
|
120
|
+
setSize(width, height) {
|
|
121
|
+
this.width = width;
|
|
122
|
+
this.height = height;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/** 释放组件持有的可编辑状态。渲染资源由 ImgSystem 统一管理。 */
|
|
126
|
+
destroy() {
|
|
127
|
+
return this;
|
|
78
128
|
}
|
|
79
129
|
}
|
|
80
130
|
/** 组件名称 */
|
|
81
131
|
Img$2.componentName = 'Img';
|
|
82
132
|
__decorate([
|
|
83
|
-
inspectorDecorator.type('string')
|
|
84
|
-
|
|
133
|
+
inspectorDecorator.type('string'),
|
|
134
|
+
__metadata("design:type", String)
|
|
135
|
+
], Img$2.prototype, "resource", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
inspectorDecorator.type('number'),
|
|
138
|
+
__metadata("design:type", Number)
|
|
139
|
+
], Img$2.prototype, "width", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
inspectorDecorator.type('number'),
|
|
142
|
+
__metadata("design:type", Number)
|
|
143
|
+
], Img$2.prototype, "height", void 0);
|
|
85
144
|
|
|
86
145
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.IMAGE, ({ data = {} }) => {
|
|
87
146
|
const { image } = data;
|
|
@@ -102,60 +161,92 @@ eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.IMAGE, ({ instance }) => {
|
|
|
102
161
|
let Img = class Img extends pluginRenderer.Renderer {
|
|
103
162
|
constructor() {
|
|
104
163
|
super(...arguments);
|
|
105
|
-
this.name = '
|
|
164
|
+
this.name = 'ImgSystem';
|
|
106
165
|
this.imgs = {};
|
|
107
166
|
}
|
|
108
|
-
init() {
|
|
109
|
-
|
|
167
|
+
init(_params) {
|
|
168
|
+
var _a, _b;
|
|
169
|
+
const renderSystem = (_b = (_a = this.game) === null || _a === void 0 ? void 0 : _a.getSystem) === null || _b === void 0 ? void 0 : _b.call(_a, pluginRenderer.RendererSystem);
|
|
170
|
+
if (!(renderSystem === null || renderSystem === void 0 ? void 0 : renderSystem.rendererManager))
|
|
171
|
+
return;
|
|
172
|
+
this.renderSystem = renderSystem;
|
|
110
173
|
this.renderSystem.rendererManager.register(this);
|
|
111
174
|
}
|
|
175
|
+
update(_frame) {
|
|
176
|
+
super.update(_frame);
|
|
177
|
+
}
|
|
112
178
|
rendererUpdate(gameObject) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
this.imgs[gameObject.id].sprite.width = width;
|
|
116
|
-
this.imgs[gameObject.id].sprite.height = height;
|
|
117
|
-
}
|
|
179
|
+
const component = gameObject.getComponent('Img');
|
|
180
|
+
this.applySpriteLayout(gameObject, component);
|
|
118
181
|
}
|
|
119
182
|
componentChanged(changed) {
|
|
120
|
-
var _a, _b;
|
|
183
|
+
var _a, _b, _c, _d, _e, _f;
|
|
121
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
185
|
if (changed.componentName === 'Img') {
|
|
186
|
+
const gameObjectId = changed.gameObject.id;
|
|
123
187
|
const component = changed.component;
|
|
124
188
|
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
125
189
|
const sprite = new rendererAdapter.Sprite(null);
|
|
126
|
-
this.imgs[
|
|
127
|
-
this.containerManager.getContainer(
|
|
128
|
-
|
|
190
|
+
this.imgs[gameObjectId] = sprite;
|
|
191
|
+
(_b = (_a = this.containerManager) === null || _a === void 0 ? void 0 : _a.getContainer(gameObjectId)) === null || _b === void 0 ? void 0 : _b.addChildAt(sprite.sprite, 0);
|
|
192
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
193
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
129
194
|
const { instance } = yield eva_js.resource.getResource(component.resource);
|
|
130
|
-
if (!this.validateAsyncId(
|
|
195
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
131
196
|
return;
|
|
132
197
|
if (!instance) {
|
|
133
198
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
199
|
+
return;
|
|
134
200
|
}
|
|
135
|
-
|
|
201
|
+
sprite.image = instance;
|
|
202
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
136
203
|
}
|
|
137
204
|
else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
205
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
206
|
+
if ((_d = (_c = changed.prop) === null || _c === void 0 ? void 0 : _c.prop) === null || _d === void 0 ? void 0 : _d.includes('resource')) {
|
|
207
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
208
|
+
const { instance } = yield eva_js.resource.getResource(component.resource);
|
|
209
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
210
|
+
return;
|
|
211
|
+
if (!instance) {
|
|
212
|
+
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.imgs[gameObjectId].image = instance;
|
|
216
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
144
217
|
}
|
|
145
|
-
this.imgs[changed.gameObject.id].image = instance;
|
|
146
218
|
}
|
|
147
219
|
else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
148
|
-
this.increaseAsyncId(
|
|
149
|
-
const sprite = this.imgs[
|
|
220
|
+
this.increaseAsyncId(gameObjectId);
|
|
221
|
+
const sprite = this.imgs[gameObjectId];
|
|
150
222
|
if (!sprite)
|
|
151
223
|
return;
|
|
152
|
-
(
|
|
224
|
+
(_f = (_e = this.containerManager) === null || _e === void 0 ? void 0 : _e.getContainer(gameObjectId)) === null || _f === void 0 ? void 0 : _f.removeChild(sprite.sprite);
|
|
153
225
|
sprite.sprite.destroy({ children: true });
|
|
154
|
-
delete this.imgs[
|
|
226
|
+
delete this.imgs[gameObjectId];
|
|
155
227
|
}
|
|
156
228
|
}
|
|
157
229
|
});
|
|
158
230
|
}
|
|
231
|
+
applySpriteLayout(gameObject, component) {
|
|
232
|
+
var _a, _b, _c, _d, _e;
|
|
233
|
+
const sprite = this.imgs[gameObject.id];
|
|
234
|
+
if (!sprite)
|
|
235
|
+
return;
|
|
236
|
+
const size = (_a = gameObject.transform) === null || _a === void 0 ? void 0 : _a.size;
|
|
237
|
+
const width = (_b = component === null || component === void 0 ? void 0 : component.width) !== null && _b !== void 0 ? _b : size === null || size === void 0 ? void 0 : size.width;
|
|
238
|
+
const height = (_c = component === null || component === void 0 ? void 0 : component.height) !== null && _c !== void 0 ? _c : size === null || size === void 0 ? void 0 : size.height;
|
|
239
|
+
if (typeof width === 'number') {
|
|
240
|
+
sprite.sprite.width = width;
|
|
241
|
+
}
|
|
242
|
+
if (typeof height === 'number') {
|
|
243
|
+
sprite.sprite.height = height;
|
|
244
|
+
}
|
|
245
|
+
const anchor = component === null || component === void 0 ? void 0 : component.anchor;
|
|
246
|
+
if (anchor) {
|
|
247
|
+
(_e = (_d = sprite.sprite.anchor) === null || _d === void 0 ? void 0 : _d.set) === null || _e === void 0 ? void 0 : _e.call(_d, anchor.x, anchor.y);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
159
250
|
destroy() {
|
|
160
251
|
var _a, _b;
|
|
161
252
|
for (const key in this.imgs) {
|
|
@@ -166,10 +257,10 @@ let Img = class Img extends pluginRenderer.Renderer {
|
|
|
166
257
|
}
|
|
167
258
|
}
|
|
168
259
|
};
|
|
169
|
-
Img.systemName = '
|
|
260
|
+
Img.systemName = 'ImgSystem';
|
|
170
261
|
Img = __decorate([
|
|
171
262
|
eva_js.decorators.componentObserver({
|
|
172
|
-
Img: [{ prop:
|
|
263
|
+
Img: ['resource', { prop: 'anchor', deep: true }, 'width', 'height'],
|
|
173
264
|
})
|
|
174
265
|
], Img);
|
|
175
266
|
var Img$1 = Img;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/inspector-decorator"),t=require("@eva/eva.js"),r=require("@eva/plugin-renderer"),i=require("@eva/renderer-adapter"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/inspector-decorator"),t=require("@eva/eva.js"),r=require("@eva/plugin-renderer"),i=require("@eva/renderer-adapter"),n=require("pixi.js");function o(e,t,r,i){var n,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,i);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(s=(o<3?n(s):o>3?n(t,r,s):n(t,r))||s);return o>3&&s&&Object.defineProperty(t,r,s),s}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t,r,i){return new(r||(r=Promise))(function(n,o){function s(e){try{a(i.next(e))}catch(e){o(e)}}function c(e){try{a(i.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,c)}a((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class a extends t.Component{constructor(e){super(e),this.resource="",this.anchor={x:0,y:0},this.init(e)}init(e){var t,r;e&&e.resource&&(this.resource=e.resource),e&&e.anchor&&(this.anchor={x:null!==(t=e.anchor.x)&&void 0!==t?t:this.anchor.x,y:null!==(r=e.anchor.y)&&void 0!==r?r:this.anchor.y}),e&&"number"==typeof e.width&&(this.width=e.width),e&&"number"==typeof e.height&&(this.height=e.height)}load(e){return e&&(this.resource=e),this}setAnchor(e,t=e){return this.anchor.x=e,this.anchor.y=t,this}setSize(e,t){return this.width=e,this.height=t,this}destroy(){return this}}a.componentName="Img",o([e.type("string"),s("design:type",String)],a.prototype,"resource",void 0),o([e.type("number"),s("design:type",Number)],a.prototype,"width",void 0),o([e.type("number"),s("design:type",Number)],a.prototype,"height",void 0),t.resource.registerInstance(t.RESOURCE_TYPE.IMAGE,({data:e={}})=>{const{image:t}=e;if(t){if(t instanceof n.Texture)return t;return n.Texture.from(t)}return e}),t.resource.registerDestroy(t.RESOURCE_TYPE.IMAGE,({instance:e})=>{e&&e.destroy(!0)});let d=class extends r.Renderer{constructor(){super(...arguments),this.name="ImgSystem",this.imgs={}}init(e){var t,i;const n=null===(i=null===(t=this.game)||void 0===t?void 0:t.getSystem)||void 0===i?void 0:i.call(t,r.RendererSystem);(null==n?void 0:n.rendererManager)&&(this.renderSystem=n,this.renderSystem.rendererManager.register(this))}update(e){super.update(e)}rendererUpdate(e){const t=e.getComponent("Img");this.applySpriteLayout(e,t)}componentChanged(e){var r,n,o,s,a,d;return c(this,void 0,void 0,function*(){if("Img"===e.componentName){const c=e.gameObject.id,u=e.component;if(e.type===t.OBSERVER_TYPE.ADD){const o=new i.Sprite(null);this.imgs[c]=o,null===(n=null===(r=this.containerManager)||void 0===r?void 0:r.getContainer(c))||void 0===n||n.addChildAt(o.sprite,0),this.applySpriteLayout(e.gameObject,u);const s=this.increaseAsyncId(c),{instance:a}=yield t.resource.getResource(u.resource);if(!this.validateAsyncId(c,s))return;if(!a)return void console.error(`GameObject:${e.gameObject.name}'s Img resource load error`);o.image=a,this.applySpriteLayout(e.gameObject,u)}else if(e.type===t.OBSERVER_TYPE.CHANGE){if(this.applySpriteLayout(e.gameObject,u),null===(s=null===(o=e.prop)||void 0===o?void 0:o.prop)||void 0===s?void 0:s.includes("resource")){const r=this.increaseAsyncId(c),{instance:i}=yield t.resource.getResource(u.resource);if(!this.validateAsyncId(c,r))return;if(!i)return void console.error(`GameObject:${e.gameObject.name}'s Img resource load error`);this.imgs[c].image=i,this.applySpriteLayout(e.gameObject,u)}}else if(e.type===t.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(c);const e=this.imgs[c];if(!e)return;null===(d=null===(a=this.containerManager)||void 0===a?void 0:a.getContainer(c))||void 0===d||d.removeChild(e.sprite),e.sprite.destroy({children:!0}),delete this.imgs[c]}}})}applySpriteLayout(e,t){var r,i,n,o,s;const c=this.imgs[e.id];if(!c)return;const a=null===(r=e.transform)||void 0===r?void 0:r.size,d=null!==(i=null==t?void 0:t.width)&&void 0!==i?i:null==a?void 0:a.width,u=null!==(n=null==t?void 0:t.height)&&void 0!==n?n:null==a?void 0:a.height;"number"==typeof d&&(c.sprite.width=d),"number"==typeof u&&(c.sprite.height=u);const h=null==t?void 0:t.anchor;h&&(null===(s=null===(o=c.sprite.anchor)||void 0===o?void 0:o.set)||void 0===s||s.call(o,h.x,h.y))}destroy(){var e,t;for(const r in this.imgs){const i=this.imgs[r];null===(t=null===(e=this.containerManager)||void 0===e?void 0:e.getContainer(parseInt(r)))||void 0===t||t.removeChild(i.sprite),i.sprite.destroy({children:!0}),delete this.imgs[r]}}};d.systemName="ImgSystem",d=o([t.decorators.componentObserver({Img:["resource",{prop:"anchor",deep:!0},"width","height"]})],d);var u=d;exports.Img=a,exports.ImgSystem=u;
|
|
@@ -27,16 +27,47 @@ export declare class Img extends Component<ImgParams> {
|
|
|
27
27
|
static componentName: string;
|
|
28
28
|
/** 图片资源名称 */
|
|
29
29
|
resource: string;
|
|
30
|
+
/** 图片锚点 */
|
|
31
|
+
anchor: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
};
|
|
35
|
+
/** 显式渲染宽度 */
|
|
36
|
+
width?: number;
|
|
37
|
+
/** 显式渲染高度 */
|
|
38
|
+
height?: number;
|
|
39
|
+
constructor(params?: ImgParams);
|
|
30
40
|
/**
|
|
31
41
|
* 初始化组件
|
|
32
42
|
* @param obj - 初始化参数
|
|
33
|
-
*
|
|
43
|
+
*
|
|
44
|
+
* 配置项包括 resource、anchor、width 和 height。
|
|
34
45
|
*/
|
|
35
46
|
init(obj?: ImgParams): void;
|
|
47
|
+
/**
|
|
48
|
+
* 切换当前图片资源。
|
|
49
|
+
*
|
|
50
|
+
* ImgSystem 会监听 resource 变化并刷新渲染纹理。
|
|
51
|
+
*
|
|
52
|
+
* @param resource - 图片资源名称
|
|
53
|
+
*/
|
|
54
|
+
load(resource?: string): this;
|
|
55
|
+
/** 设置图片锚点。 */
|
|
56
|
+
setAnchor(x: number, y?: number): this;
|
|
57
|
+
/** 设置显式渲染尺寸。 */
|
|
58
|
+
setSize(width?: number, height?: number): this;
|
|
59
|
+
/** 释放组件持有的可编辑状态。渲染资源由 ImgSystem 统一管理。 */
|
|
60
|
+
destroy(): this;
|
|
36
61
|
}
|
|
37
62
|
|
|
38
63
|
export declare interface ImgParams {
|
|
39
64
|
resource: string;
|
|
65
|
+
anchor?: {
|
|
66
|
+
x?: number;
|
|
67
|
+
y?: number;
|
|
68
|
+
};
|
|
69
|
+
width?: number;
|
|
70
|
+
height?: number;
|
|
40
71
|
}
|
|
41
72
|
|
|
42
73
|
export declare class ImgSystem extends Renderer {
|
|
@@ -48,9 +79,11 @@ export declare class ImgSystem extends Renderer {
|
|
|
48
79
|
renderSystem: RendererSystem;
|
|
49
80
|
rendererManager: RendererManager;
|
|
50
81
|
containerManager: ContainerManager;
|
|
51
|
-
init(): void;
|
|
82
|
+
init(_params?: unknown): void;
|
|
83
|
+
update(_frame?: unknown): void;
|
|
52
84
|
rendererUpdate(gameObject: GameObject): void;
|
|
53
85
|
componentChanged(changed: ComponentChanged): Promise<void>;
|
|
86
|
+
private applySpriteLayout;
|
|
54
87
|
destroy(): void;
|
|
55
88
|
}
|
|
56
89
|
|
|
@@ -26,6 +26,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
26
26
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function __metadata(metadataKey, metadataValue) {
|
|
30
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
30
34
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
35
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -57,27 +61,82 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
57
61
|
* ```
|
|
58
62
|
*/
|
|
59
63
|
class Img$2 extends Component {
|
|
60
|
-
constructor() {
|
|
61
|
-
super(
|
|
64
|
+
constructor(params) {
|
|
65
|
+
super(params);
|
|
62
66
|
/** 图片资源名称 */
|
|
63
67
|
this.resource = '';
|
|
68
|
+
/** 图片锚点 */
|
|
69
|
+
this.anchor = { x: 0, y: 0 };
|
|
70
|
+
this.init(params);
|
|
64
71
|
}
|
|
65
72
|
/**
|
|
66
73
|
* 初始化组件
|
|
67
74
|
* @param obj - 初始化参数
|
|
68
|
-
*
|
|
75
|
+
*
|
|
76
|
+
* 配置项包括 resource、anchor、width 和 height。
|
|
69
77
|
*/
|
|
70
78
|
init(obj) {
|
|
79
|
+
var _a, _b;
|
|
71
80
|
if (obj && obj.resource) {
|
|
72
81
|
this.resource = obj.resource;
|
|
73
82
|
}
|
|
83
|
+
if (obj && obj.anchor) {
|
|
84
|
+
this.anchor = {
|
|
85
|
+
x: (_a = obj.anchor.x) !== null && _a !== void 0 ? _a : this.anchor.x,
|
|
86
|
+
y: (_b = obj.anchor.y) !== null && _b !== void 0 ? _b : this.anchor.y,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (obj && typeof obj.width === 'number') {
|
|
90
|
+
this.width = obj.width;
|
|
91
|
+
}
|
|
92
|
+
if (obj && typeof obj.height === 'number') {
|
|
93
|
+
this.height = obj.height;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 切换当前图片资源。
|
|
98
|
+
*
|
|
99
|
+
* ImgSystem 会监听 resource 变化并刷新渲染纹理。
|
|
100
|
+
*
|
|
101
|
+
* @param resource - 图片资源名称
|
|
102
|
+
*/
|
|
103
|
+
load(resource) {
|
|
104
|
+
if (resource) {
|
|
105
|
+
this.resource = resource;
|
|
106
|
+
}
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/** 设置图片锚点。 */
|
|
110
|
+
setAnchor(x, y = x) {
|
|
111
|
+
this.anchor.x = x;
|
|
112
|
+
this.anchor.y = y;
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
/** 设置显式渲染尺寸。 */
|
|
116
|
+
setSize(width, height) {
|
|
117
|
+
this.width = width;
|
|
118
|
+
this.height = height;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
/** 释放组件持有的可编辑状态。渲染资源由 ImgSystem 统一管理。 */
|
|
122
|
+
destroy() {
|
|
123
|
+
return this;
|
|
74
124
|
}
|
|
75
125
|
}
|
|
76
126
|
/** 组件名称 */
|
|
77
127
|
Img$2.componentName = 'Img';
|
|
78
128
|
__decorate([
|
|
79
|
-
type('string')
|
|
80
|
-
|
|
129
|
+
type('string'),
|
|
130
|
+
__metadata("design:type", String)
|
|
131
|
+
], Img$2.prototype, "resource", void 0);
|
|
132
|
+
__decorate([
|
|
133
|
+
type('number'),
|
|
134
|
+
__metadata("design:type", Number)
|
|
135
|
+
], Img$2.prototype, "width", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
type('number'),
|
|
138
|
+
__metadata("design:type", Number)
|
|
139
|
+
], Img$2.prototype, "height", void 0);
|
|
81
140
|
|
|
82
141
|
resource.registerInstance(RESOURCE_TYPE.IMAGE, ({ data = {} }) => {
|
|
83
142
|
const { image } = data;
|
|
@@ -98,60 +157,92 @@ resource.registerDestroy(RESOURCE_TYPE.IMAGE, ({ instance }) => {
|
|
|
98
157
|
let Img = class Img extends Renderer {
|
|
99
158
|
constructor() {
|
|
100
159
|
super(...arguments);
|
|
101
|
-
this.name = '
|
|
160
|
+
this.name = 'ImgSystem';
|
|
102
161
|
this.imgs = {};
|
|
103
162
|
}
|
|
104
|
-
init() {
|
|
105
|
-
|
|
163
|
+
init(_params) {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
const renderSystem = (_b = (_a = this.game) === null || _a === void 0 ? void 0 : _a.getSystem) === null || _b === void 0 ? void 0 : _b.call(_a, RendererSystem);
|
|
166
|
+
if (!(renderSystem === null || renderSystem === void 0 ? void 0 : renderSystem.rendererManager))
|
|
167
|
+
return;
|
|
168
|
+
this.renderSystem = renderSystem;
|
|
106
169
|
this.renderSystem.rendererManager.register(this);
|
|
107
170
|
}
|
|
171
|
+
update(_frame) {
|
|
172
|
+
super.update(_frame);
|
|
173
|
+
}
|
|
108
174
|
rendererUpdate(gameObject) {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
this.imgs[gameObject.id].sprite.width = width;
|
|
112
|
-
this.imgs[gameObject.id].sprite.height = height;
|
|
113
|
-
}
|
|
175
|
+
const component = gameObject.getComponent('Img');
|
|
176
|
+
this.applySpriteLayout(gameObject, component);
|
|
114
177
|
}
|
|
115
178
|
componentChanged(changed) {
|
|
116
|
-
var _a, _b;
|
|
179
|
+
var _a, _b, _c, _d, _e, _f;
|
|
117
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
181
|
if (changed.componentName === 'Img') {
|
|
182
|
+
const gameObjectId = changed.gameObject.id;
|
|
119
183
|
const component = changed.component;
|
|
120
184
|
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
121
185
|
const sprite = new Sprite(null);
|
|
122
|
-
this.imgs[
|
|
123
|
-
this.containerManager.getContainer(
|
|
124
|
-
|
|
186
|
+
this.imgs[gameObjectId] = sprite;
|
|
187
|
+
(_b = (_a = this.containerManager) === null || _a === void 0 ? void 0 : _a.getContainer(gameObjectId)) === null || _b === void 0 ? void 0 : _b.addChildAt(sprite.sprite, 0);
|
|
188
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
189
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
125
190
|
const { instance } = yield resource.getResource(component.resource);
|
|
126
|
-
if (!this.validateAsyncId(
|
|
191
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
127
192
|
return;
|
|
128
193
|
if (!instance) {
|
|
129
194
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
195
|
+
return;
|
|
130
196
|
}
|
|
131
|
-
|
|
197
|
+
sprite.image = instance;
|
|
198
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
132
199
|
}
|
|
133
200
|
else if (changed.type === OBSERVER_TYPE.CHANGE) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
201
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
202
|
+
if ((_d = (_c = changed.prop) === null || _c === void 0 ? void 0 : _c.prop) === null || _d === void 0 ? void 0 : _d.includes('resource')) {
|
|
203
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
204
|
+
const { instance } = yield resource.getResource(component.resource);
|
|
205
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
206
|
+
return;
|
|
207
|
+
if (!instance) {
|
|
208
|
+
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this.imgs[gameObjectId].image = instance;
|
|
212
|
+
this.applySpriteLayout(changed.gameObject, component);
|
|
140
213
|
}
|
|
141
|
-
this.imgs[changed.gameObject.id].image = instance;
|
|
142
214
|
}
|
|
143
215
|
else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
144
|
-
this.increaseAsyncId(
|
|
145
|
-
const sprite = this.imgs[
|
|
216
|
+
this.increaseAsyncId(gameObjectId);
|
|
217
|
+
const sprite = this.imgs[gameObjectId];
|
|
146
218
|
if (!sprite)
|
|
147
219
|
return;
|
|
148
|
-
(
|
|
220
|
+
(_f = (_e = this.containerManager) === null || _e === void 0 ? void 0 : _e.getContainer(gameObjectId)) === null || _f === void 0 ? void 0 : _f.removeChild(sprite.sprite);
|
|
149
221
|
sprite.sprite.destroy({ children: true });
|
|
150
|
-
delete this.imgs[
|
|
222
|
+
delete this.imgs[gameObjectId];
|
|
151
223
|
}
|
|
152
224
|
}
|
|
153
225
|
});
|
|
154
226
|
}
|
|
227
|
+
applySpriteLayout(gameObject, component) {
|
|
228
|
+
var _a, _b, _c, _d, _e;
|
|
229
|
+
const sprite = this.imgs[gameObject.id];
|
|
230
|
+
if (!sprite)
|
|
231
|
+
return;
|
|
232
|
+
const size = (_a = gameObject.transform) === null || _a === void 0 ? void 0 : _a.size;
|
|
233
|
+
const width = (_b = component === null || component === void 0 ? void 0 : component.width) !== null && _b !== void 0 ? _b : size === null || size === void 0 ? void 0 : size.width;
|
|
234
|
+
const height = (_c = component === null || component === void 0 ? void 0 : component.height) !== null && _c !== void 0 ? _c : size === null || size === void 0 ? void 0 : size.height;
|
|
235
|
+
if (typeof width === 'number') {
|
|
236
|
+
sprite.sprite.width = width;
|
|
237
|
+
}
|
|
238
|
+
if (typeof height === 'number') {
|
|
239
|
+
sprite.sprite.height = height;
|
|
240
|
+
}
|
|
241
|
+
const anchor = component === null || component === void 0 ? void 0 : component.anchor;
|
|
242
|
+
if (anchor) {
|
|
243
|
+
(_e = (_d = sprite.sprite.anchor) === null || _d === void 0 ? void 0 : _d.set) === null || _e === void 0 ? void 0 : _e.call(_d, anchor.x, anchor.y);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
155
246
|
destroy() {
|
|
156
247
|
var _a, _b;
|
|
157
248
|
for (const key in this.imgs) {
|
|
@@ -162,10 +253,10 @@ let Img = class Img extends Renderer {
|
|
|
162
253
|
}
|
|
163
254
|
}
|
|
164
255
|
};
|
|
165
|
-
Img.systemName = '
|
|
256
|
+
Img.systemName = 'ImgSystem';
|
|
166
257
|
Img = __decorate([
|
|
167
258
|
decorators.componentObserver({
|
|
168
|
-
Img: [{ prop:
|
|
259
|
+
Img: ['resource', { prop: 'anchor', deep: true }, 'width', 'height'],
|
|
169
260
|
})
|
|
170
261
|
], Img);
|
|
171
262
|
var Img$1 = Img;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-img",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-beta.1",
|
|
4
4
|
"description": "@eva/plugin-renderer-img",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-img.esm.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/inspector-decorator": "^0.0.
|
|
22
|
-
"@eva/plugin-renderer": "2.0.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.
|
|
24
|
-
"@eva/eva.js": "2.0.
|
|
21
|
+
"@eva/inspector-decorator": "^2.0.0-beta.0",
|
|
22
|
+
"@eva/plugin-renderer": "2.1.0-beta.1",
|
|
23
|
+
"@eva/renderer-adapter": "2.1.0-beta.1",
|
|
24
|
+
"@eva/eva.js": "2.1.0-beta.1",
|
|
25
25
|
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|