1 | import { Runner } from "@pixi/runner";
|
2 | class Resource {
|
3 | /**
|
4 | * @param width - Width of the resource
|
5 | * @param height - Height of the resource
|
6 | */
|
7 | constructor(width = 0, height = 0) {
|
8 | this._width = width, this._height = height, this.destroyed = !1, this.internal = !1, this.onResize = new Runner("setRealSize"), this.onUpdate = new Runner("update"), this.onError = new Runner("onError");
|
9 | }
|
10 | /**
|
11 | * Bind to a parent BaseTexture
|
12 | * @param baseTexture - Parent texture
|
13 | */
|
14 | bind(baseTexture) {
|
15 | this.onResize.add(baseTexture), this.onUpdate.add(baseTexture), this.onError.add(baseTexture), (this._width || this._height) && this.onResize.emit(this._width, this._height);
|
16 | }
|
17 | /**
|
18 | * Unbind to a parent BaseTexture
|
19 | * @param baseTexture - Parent texture
|
20 | */
|
21 | unbind(baseTexture) {
|
22 | this.onResize.remove(baseTexture), this.onUpdate.remove(baseTexture), this.onError.remove(baseTexture);
|
23 | }
|
24 | /**
|
25 | * Trigger a resize event
|
26 | * @param width - X dimension
|
27 | * @param height - Y dimension
|
28 | */
|
29 | resize(width, height) {
|
30 | (width !== this._width || height !== this._height) && (this._width = width, this._height = height, this.onResize.emit(width, height));
|
31 | }
|
32 | /**
|
33 | * Has been validated
|
34 | * @readonly
|
35 | */
|
36 | get valid() {
|
37 | return !!this._width && !!this._height;
|
38 | }
|
39 | /** Has been updated trigger event. */
|
40 | update() {
|
41 | this.destroyed || this.onUpdate.emit();
|
42 | }
|
43 | /**
|
44 | * This can be overridden to start preloading a resource
|
45 | * or do any other prepare step.
|
46 | * @protected
|
47 | * @returns Handle the validate event
|
48 | */
|
49 | load() {
|
50 | return Promise.resolve(this);
|
51 | }
|
52 | /**
|
53 | * The width of the resource.
|
54 | * @readonly
|
55 | */
|
56 | get width() {
|
57 | return this._width;
|
58 | }
|
59 | /**
|
60 | * The height of the resource.
|
61 | * @readonly
|
62 | */
|
63 | get height() {
|
64 | return this._height;
|
65 | }
|
66 | /**
|
67 | * Set the style, optional to override
|
68 | * @param _renderer - yeah, renderer!
|
69 | * @param _baseTexture - the texture
|
70 | * @param _glTexture - texture instance for this webgl context
|
71 | * @returns - `true` is success
|
72 | */
|
73 | style(_renderer, _baseTexture, _glTexture) {
|
74 | return !1;
|
75 | }
|
76 | /** Clean up anything, this happens when destroying is ready. */
|
77 | dispose() {
|
78 | }
|
79 | /**
|
80 | * Call when destroying resource, unbind any BaseTexture object
|
81 | * before calling this method, as reference counts are maintained
|
82 | * internally.
|
83 | */
|
84 | destroy() {
|
85 | this.destroyed || (this.destroyed = !0, this.dispose(), this.onError.removeAll(), this.onError = null, this.onResize.removeAll(), this.onResize = null, this.onUpdate.removeAll(), this.onUpdate = null);
|
86 | }
|
87 | /**
|
88 | * Abstract, used to auto-detect resource type.
|
89 | * @param {*} _source - The source object
|
90 | * @param {string} _extension - The extension of source, if set
|
91 | */
|
92 | static test(_source, _extension) {
|
93 | return !1;
|
94 | }
|
95 | }
|
96 | export {
|
97 | Resource
|
98 | };
|
99 | //# sourceMappingURL=Resource.mjs.map
|