UNPKG

1.68 kBJavaScriptView Raw
1import { Runner } from '@pixi/runner';
2
3class Resource {
4 constructor(width = 0, height = 0) {
5 this._width = width;
6 this._height = height;
7 this.destroyed = false;
8 this.internal = false;
9 this.onResize = new Runner("setRealSize");
10 this.onUpdate = new Runner("update");
11 this.onError = new Runner("onError");
12 }
13 bind(baseTexture) {
14 this.onResize.add(baseTexture);
15 this.onUpdate.add(baseTexture);
16 this.onError.add(baseTexture);
17 if (this._width || this._height) {
18 this.onResize.emit(this._width, this._height);
19 }
20 }
21 unbind(baseTexture) {
22 this.onResize.remove(baseTexture);
23 this.onUpdate.remove(baseTexture);
24 this.onError.remove(baseTexture);
25 }
26 resize(width, height) {
27 if (width !== this._width || height !== this._height) {
28 this._width = width;
29 this._height = height;
30 this.onResize.emit(width, height);
31 }
32 }
33 get valid() {
34 return !!this._width && !!this._height;
35 }
36 update() {
37 if (!this.destroyed) {
38 this.onUpdate.emit();
39 }
40 }
41 load() {
42 return Promise.resolve(this);
43 }
44 get width() {
45 return this._width;
46 }
47 get height() {
48 return this._height;
49 }
50 style(_renderer, _baseTexture, _glTexture) {
51 return false;
52 }
53 dispose() {
54 }
55 destroy() {
56 if (!this.destroyed) {
57 this.destroyed = true;
58 this.dispose();
59 this.onError.removeAll();
60 this.onError = null;
61 this.onResize.removeAll();
62 this.onResize = null;
63 this.onUpdate.removeAll();
64 this.onUpdate = null;
65 }
66 }
67 static test(_source, _extension) {
68 return false;
69 }
70}
71
72export { Resource };
73//# sourceMappingURL=Resource.mjs.map