@eva/plugin-renderer-text 2.0.1-beta.18 → 2.0.1-beta.19
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.text.js +31 -27
- package/dist/EVA.plugin.renderer.text.min.js +1 -1
- package/dist/plugin-renderer-text.cjs.js +31 -28
- package/dist/plugin-renderer-text.cjs.prod.js +2 -2
- package/dist/plugin-renderer-text.d.ts +1 -3
- package/dist/plugin-renderer-text.esm.js +32 -29
- package/package.json +4 -4
|
@@ -86,7 +86,6 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
86
86
|
super(...arguments);
|
|
87
87
|
this.name = 'Text';
|
|
88
88
|
this.texts = {};
|
|
89
|
-
this._lastFontFamily = undefined;
|
|
90
89
|
}
|
|
91
90
|
init() {
|
|
92
91
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
@@ -97,13 +96,19 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
97
96
|
if (changed.componentName !== 'Text') return;
|
|
98
97
|
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
99
98
|
const component = changed.component;
|
|
100
|
-
const
|
|
99
|
+
const styleWithoutFont = _extends({}, component.style);
|
|
100
|
+
const fontFamily = styleWithoutFont.fontFamily;
|
|
101
|
+
delete styleWithoutFont.fontFamily;
|
|
102
|
+
const text = new rendererAdapter.Text(component.text, styleWithoutFont);
|
|
101
103
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
|
|
102
104
|
this.texts[changed.gameObject.id] = {
|
|
103
105
|
text,
|
|
104
106
|
component: changed.component
|
|
105
107
|
};
|
|
106
108
|
this.setSize(changed);
|
|
109
|
+
if (fontFamily) {
|
|
110
|
+
yield this.waitForFontResource(text, changed, fontFamily);
|
|
111
|
+
}
|
|
107
112
|
} else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
108
113
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
|
|
109
114
|
this.texts[changed.gameObject.id].text.destroy({
|
|
@@ -113,6 +118,30 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
113
118
|
} else {
|
|
114
119
|
this.change(changed);
|
|
115
120
|
this.setSize(changed);
|
|
121
|
+
const component = changed.component;
|
|
122
|
+
if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
|
|
123
|
+
const {
|
|
124
|
+
text
|
|
125
|
+
} = this.texts[changed.gameObject.id];
|
|
126
|
+
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
waitForFontResource(text, changed, fontFamily) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
if (!fontFamily) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
138
|
+
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
139
|
+
yield eva_js.resource.getResource(fontName);
|
|
140
|
+
if (!this.validateAsyncId(changed.gameObject.id, asyncId)) return;
|
|
141
|
+
text.style.fontFamily = fontFamily;
|
|
142
|
+
this.setSize(changed);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
116
145
|
}
|
|
117
146
|
});
|
|
118
147
|
}
|
|
@@ -126,31 +155,6 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
126
155
|
} else if (changed.prop.prop[0] === 'style') {
|
|
127
156
|
_extends(text.style, changed.component.style);
|
|
128
157
|
}
|
|
129
|
-
if (text.style.fontFamily && text.style.fontFamily !== this._lastFontFamily) {
|
|
130
|
-
this._lastFontFamily = text.style.fontFamily;
|
|
131
|
-
this.asyncChangeTextStyle(text, text.style);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
asyncChangeTextStyle(text, textStyle) {
|
|
135
|
-
if (textStyle.fontFamily) {
|
|
136
|
-
const fontFamily = textStyle.fontFamily;
|
|
137
|
-
textStyle.fontFamily = '';
|
|
138
|
-
this.asyncUpdateFontFamily(text, fontFamily);
|
|
139
|
-
}
|
|
140
|
-
_extends(text.style, textStyle);
|
|
141
|
-
}
|
|
142
|
-
asyncUpdateFontFamily(text, fontFamily) {
|
|
143
|
-
if (fontFamily) {
|
|
144
|
-
if (Array.isArray(fontFamily)) {
|
|
145
|
-
Promise.all(fontFamily.map(font => eva_js.resource.getResource(font))).finally(() => {
|
|
146
|
-
text.style.fontFamily = fontFamily;
|
|
147
|
-
});
|
|
148
|
-
} else {
|
|
149
|
-
eva_js.resource.getResource(fontFamily).finally(() => {
|
|
150
|
-
text.style.fontFamily = fontFamily;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
158
|
}
|
|
155
159
|
setSize(changed) {
|
|
156
160
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}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_text=function(e,t,n,r,s){"use strict";function i(e,t,n,r){var s,i=arguments.length,o=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(o=(i<3?s(o):i>3?s(t,n,o):s(t,n))||o);return i>3&&o&&Object.defineProperty(t,n,o),o}function o(e,t,n,r){return new(n||(n=Promise))((function(s,i){function o(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}a((r=r.apply(e,t||[])).next())}))}class c extends n.Component{constructor(){super(...arguments),this.text="",this.style={}}init(e){const n=new t.TextStyle({fontSize:20}),r={};for(const e in n)0===e.indexOf("_")&&(r[e.substring(1)]=n[e]);delete r.styleKey,this.style=r,e&&(this.text=e.text,_extends(this.style,e.style))}}c.componentName="Text",i([function(e){return function(t,n){var r=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,n);r.key=n,r.type=e}}("string")],c.prototype,"text",void 0);let a=class extends r.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return o(this,void 0,void 0,(function*(){if("Text"===e.componentName)if(e.type===n.OBSERVER_TYPE.ADD){const t=e.component,n=_extends({},t.style),r=n.fontFamily;delete n.fontFamily;const i=new s.Text(t.text,n);this.containerManager.getContainer(e.gameObject.id).addChildAt(i,0),this.texts[e.gameObject.id]={text:i,component:e.component},this.setSize(e),r&&(yield this.waitForFontResource(i,e,r))}else if(e.type===n.OBSERVER_TYPE.REMOVE)this.containerManager.getContainer(e.gameObject.id).removeChild(this.texts[e.gameObject.id].text),this.texts[e.gameObject.id].text.destroy({children:!0}),delete this.texts[e.gameObject.id];else{this.change(e),this.setSize(e);const t=e.component;if("style"===e.prop.prop[0]&&t.style&&t.style.fontFamily){const{text:n}=this.texts[e.gameObject.id];yield this.waitForFontResource(n,e,t.style.fontFamily)}}}))}waitForFontResource(e,t,r){return o(this,void 0,void 0,(function*(){if(r)try{const s=Array.isArray(r)?r[0]:r,i=this.increaseAsyncId(t.gameObject.id);if(yield n.resource.getResource(s),!this.validateAsyncId(t.gameObject.id,i))return;e.style.fontFamily=r,this.setSize(t)}catch(e){console.warn(`字体资源 ${r} 加载失败:`,e)}}))}change(e){const{text:t,component:n}=this.texts[e.gameObject.id];"text"===e.prop.prop[0]?t.text=n.text:"style"===e.prop.prop[0]&&_extends(t.style,e.component.style)}setSize(e){const{transform:t}=e.gameObject;t&&(t.size.width=this.texts[e.gameObject.id].text.width,t.size.height=this.texts[e.gameObject.id].text.height)}};a.systemName="Text",a=i([n.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],a);var l=a;return e.Text=c,e.TextSystem=l,Object.defineProperty(e,"__esModule",{value:!0}),e}({},PIXI,EVA,EVA.plugin.renderer,EVA.rendererAdapter);globalThis.EVA.plugin.renderer.text=globalThis.EVA.plugin.renderer.text||_EVA_IIFE_text;
|
|
@@ -73,7 +73,6 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
73
73
|
super(...arguments);
|
|
74
74
|
this.name = 'Text';
|
|
75
75
|
this.texts = {};
|
|
76
|
-
this._lastFontFamily = undefined;
|
|
77
76
|
}
|
|
78
77
|
init() {
|
|
79
78
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
@@ -85,13 +84,19 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
85
84
|
return;
|
|
86
85
|
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
87
86
|
const component = changed.component;
|
|
88
|
-
const
|
|
87
|
+
const styleWithoutFont = Object.assign({}, component.style);
|
|
88
|
+
const fontFamily = styleWithoutFont.fontFamily;
|
|
89
|
+
delete styleWithoutFont.fontFamily;
|
|
90
|
+
const text = new rendererAdapter.Text(component.text, styleWithoutFont);
|
|
89
91
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
|
|
90
92
|
this.texts[changed.gameObject.id] = {
|
|
91
93
|
text,
|
|
92
94
|
component: changed.component,
|
|
93
95
|
};
|
|
94
96
|
this.setSize(changed);
|
|
97
|
+
if (fontFamily) {
|
|
98
|
+
yield this.waitForFontResource(text, changed, fontFamily);
|
|
99
|
+
}
|
|
95
100
|
}
|
|
96
101
|
else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
97
102
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
|
|
@@ -101,6 +106,30 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
101
106
|
else {
|
|
102
107
|
this.change(changed);
|
|
103
108
|
this.setSize(changed);
|
|
109
|
+
const component = changed.component;
|
|
110
|
+
if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
|
|
111
|
+
const { text } = this.texts[changed.gameObject.id];
|
|
112
|
+
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
waitForFontResource(text, changed, fontFamily) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
if (!fontFamily) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
124
|
+
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
125
|
+
yield eva_js.resource.getResource(fontName);
|
|
126
|
+
if (!this.validateAsyncId(changed.gameObject.id, asyncId))
|
|
127
|
+
return;
|
|
128
|
+
text.style.fontFamily = fontFamily;
|
|
129
|
+
this.setSize(changed);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
104
133
|
}
|
|
105
134
|
});
|
|
106
135
|
}
|
|
@@ -112,32 +141,6 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
112
141
|
else if (changed.prop.prop[0] === 'style') {
|
|
113
142
|
Object.assign(text.style, changed.component.style);
|
|
114
143
|
}
|
|
115
|
-
if (text.style.fontFamily && text.style.fontFamily !== this._lastFontFamily) {
|
|
116
|
-
this._lastFontFamily = text.style.fontFamily;
|
|
117
|
-
this.asyncChangeTextStyle(text, text.style);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
asyncChangeTextStyle(text, textStyle) {
|
|
121
|
-
if (textStyle.fontFamily) {
|
|
122
|
-
const fontFamily = textStyle.fontFamily;
|
|
123
|
-
textStyle.fontFamily = '';
|
|
124
|
-
this.asyncUpdateFontFamily(text, fontFamily);
|
|
125
|
-
}
|
|
126
|
-
Object.assign(text.style, textStyle);
|
|
127
|
-
}
|
|
128
|
-
asyncUpdateFontFamily(text, fontFamily) {
|
|
129
|
-
if (fontFamily) {
|
|
130
|
-
if (Array.isArray(fontFamily)) {
|
|
131
|
-
Promise.all(fontFamily.map(font => eva_js.resource.getResource(font))).finally(() => {
|
|
132
|
-
text.style.fontFamily = fontFamily;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
eva_js.resource.getResource(fontFamily).finally(() => {
|
|
137
|
-
text.style.fontFamily = fontFamily;
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
144
|
}
|
|
142
145
|
setSize(changed) {
|
|
143
146
|
const { transform } = changed.gameObject;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("pixi.js"),t=require("@eva/eva.js"),s=require("@eva/inspector-decorator"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("pixi.js"),t=require("@eva/eva.js"),s=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),n=require("@eva/renderer-adapter");
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -13,4 +13,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
15
|
***************************************************************************** */
|
|
16
|
-
function r(e,t,s,
|
|
16
|
+
function r(e,t,s,i){var n,r=arguments.length,o=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,s,i);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(o=(r<3?n(o):r>3?n(t,s,o):n(t,s))||o);return r>3&&o&&Object.defineProperty(t,s,o),o}function o(e,t,s,i){return new(s||(s=Promise))((function(n,r){function o(e){try{a(i.next(e))}catch(e){r(e)}}function c(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){e.done?n(e.value):new s((function(t){t(e.value)})).then(o,c)}a((i=i.apply(e,t||[])).next())}))}class c extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const s=new e.TextStyle({fontSize:20}),i={};for(const e in s)0===e.indexOf("_")&&(i[e.substring(1)]=s[e]);delete i.styleKey,this.style=i,t&&(this.text=t.text,Object.assign(this.style,t.style))}}c.componentName="Text",r([s.type("string")],c.prototype,"text",void 0);let a=class extends i.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return o(this,void 0,void 0,(function*(){if("Text"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD){const t=e.component,s=Object.assign({},t.style),i=s.fontFamily;delete s.fontFamily;const r=new n.Text(t.text,s);this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:e.component},this.setSize(e),i&&(yield this.waitForFontResource(r,e,i))}else if(e.type===t.OBSERVER_TYPE.REMOVE)this.containerManager.getContainer(e.gameObject.id).removeChild(this.texts[e.gameObject.id].text),this.texts[e.gameObject.id].text.destroy({children:!0}),delete this.texts[e.gameObject.id];else{this.change(e),this.setSize(e);const t=e.component;if("style"===e.prop.prop[0]&&t.style&&t.style.fontFamily){const{text:s}=this.texts[e.gameObject.id];yield this.waitForFontResource(s,e,t.style.fontFamily)}}}))}waitForFontResource(e,s,i){return o(this,void 0,void 0,(function*(){if(i)try{const n=Array.isArray(i)?i[0]:i,r=this.increaseAsyncId(s.gameObject.id);if(yield t.resource.getResource(n),!this.validateAsyncId(s.gameObject.id,r))return;e.style.fontFamily=i,this.setSize(s)}catch(e){console.warn(`字体资源 ${i} 加载失败:`,e)}}))}change(e){const{text:t,component:s}=this.texts[e.gameObject.id];"text"===e.prop.prop[0]?t.text=s.text:"style"===e.prop.prop[0]&&Object.assign(t.style,e.component.style)}setSize(e){const{transform:t}=e.gameObject;t&&(t.size.width=this.texts[e.gameObject.id].text.width,t.size.height=this.texts[e.gameObject.id].text.height)}};a.systemName="Text",a=r([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],a);var d=a;exports.Text=c,exports.TextSystem=d;
|
|
@@ -67,12 +67,10 @@ export declare class TextSystem extends Renderer {
|
|
|
67
67
|
renderSystem: RendererSystem;
|
|
68
68
|
rendererManager: RendererManager;
|
|
69
69
|
containerManager: ContainerManager;
|
|
70
|
-
_lastFontFamily: string | string[] | undefined;
|
|
71
70
|
init(): void;
|
|
72
71
|
componentChanged(changed: ComponentChanged): Promise<void>;
|
|
72
|
+
private waitForFontResource;
|
|
73
73
|
change(changed: ComponentChanged): void;
|
|
74
|
-
asyncChangeTextStyle(text: Text_3, textStyle: TextParams['style']): void;
|
|
75
|
-
asyncUpdateFontFamily(text: Text_3, fontFamily: string | string[] | undefined): void;
|
|
76
74
|
setSize(changed: ComponentChanged): void;
|
|
77
75
|
}
|
|
78
76
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TextStyle } from 'pixi.js';
|
|
2
|
-
import { Component,
|
|
2
|
+
import { Component, decorators, OBSERVER_TYPE, resource } from '@eva/eva.js';
|
|
3
3
|
import { type } from '@eva/inspector-decorator';
|
|
4
4
|
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
5
5
|
import { Text as Text$3 } from '@eva/renderer-adapter';
|
|
@@ -69,7 +69,6 @@ let Text = class Text extends Renderer {
|
|
|
69
69
|
super(...arguments);
|
|
70
70
|
this.name = 'Text';
|
|
71
71
|
this.texts = {};
|
|
72
|
-
this._lastFontFamily = undefined;
|
|
73
72
|
}
|
|
74
73
|
init() {
|
|
75
74
|
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
@@ -81,13 +80,19 @@ let Text = class Text extends Renderer {
|
|
|
81
80
|
return;
|
|
82
81
|
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
83
82
|
const component = changed.component;
|
|
84
|
-
const
|
|
83
|
+
const styleWithoutFont = Object.assign({}, component.style);
|
|
84
|
+
const fontFamily = styleWithoutFont.fontFamily;
|
|
85
|
+
delete styleWithoutFont.fontFamily;
|
|
86
|
+
const text = new Text$3(component.text, styleWithoutFont);
|
|
85
87
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
|
|
86
88
|
this.texts[changed.gameObject.id] = {
|
|
87
89
|
text,
|
|
88
90
|
component: changed.component,
|
|
89
91
|
};
|
|
90
92
|
this.setSize(changed);
|
|
93
|
+
if (fontFamily) {
|
|
94
|
+
yield this.waitForFontResource(text, changed, fontFamily);
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
97
|
else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
93
98
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
|
|
@@ -97,6 +102,30 @@ let Text = class Text extends Renderer {
|
|
|
97
102
|
else {
|
|
98
103
|
this.change(changed);
|
|
99
104
|
this.setSize(changed);
|
|
105
|
+
const component = changed.component;
|
|
106
|
+
if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
|
|
107
|
+
const { text } = this.texts[changed.gameObject.id];
|
|
108
|
+
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
waitForFontResource(text, changed, fontFamily) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
if (!fontFamily) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
120
|
+
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
121
|
+
yield resource.getResource(fontName);
|
|
122
|
+
if (!this.validateAsyncId(changed.gameObject.id, asyncId))
|
|
123
|
+
return;
|
|
124
|
+
text.style.fontFamily = fontFamily;
|
|
125
|
+
this.setSize(changed);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
100
129
|
}
|
|
101
130
|
});
|
|
102
131
|
}
|
|
@@ -108,32 +137,6 @@ let Text = class Text extends Renderer {
|
|
|
108
137
|
else if (changed.prop.prop[0] === 'style') {
|
|
109
138
|
Object.assign(text.style, changed.component.style);
|
|
110
139
|
}
|
|
111
|
-
if (text.style.fontFamily && text.style.fontFamily !== this._lastFontFamily) {
|
|
112
|
-
this._lastFontFamily = text.style.fontFamily;
|
|
113
|
-
this.asyncChangeTextStyle(text, text.style);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
asyncChangeTextStyle(text, textStyle) {
|
|
117
|
-
if (textStyle.fontFamily) {
|
|
118
|
-
const fontFamily = textStyle.fontFamily;
|
|
119
|
-
textStyle.fontFamily = '';
|
|
120
|
-
this.asyncUpdateFontFamily(text, fontFamily);
|
|
121
|
-
}
|
|
122
|
-
Object.assign(text.style, textStyle);
|
|
123
|
-
}
|
|
124
|
-
asyncUpdateFontFamily(text, fontFamily) {
|
|
125
|
-
if (fontFamily) {
|
|
126
|
-
if (Array.isArray(fontFamily)) {
|
|
127
|
-
Promise.all(fontFamily.map(font => resource.getResource(font))).finally(() => {
|
|
128
|
-
text.style.fontFamily = fontFamily;
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
resource.getResource(fontFamily).finally(() => {
|
|
133
|
-
text.style.fontFamily = fontFamily;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
140
|
}
|
|
138
141
|
setSize(changed) {
|
|
139
142
|
const { transform } = changed.gameObject;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-text",
|
|
3
|
-
"version": "2.0.1-beta.
|
|
3
|
+
"version": "2.0.1-beta.19",
|
|
4
4
|
"description": "@eva/plugin-renderer-text",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-text.esm.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@eva/inspector-decorator": "^0.0.5",
|
|
22
|
-
"@eva/plugin-renderer": "2.0.1-beta.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.1-beta.
|
|
24
|
-
"@eva/eva.js": "2.0.1-beta.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.1-beta.19",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.1-beta.19",
|
|
24
|
+
"@eva/eva.js": "2.0.1-beta.19",
|
|
25
25
|
"pixi.js": "^8.8.1"
|
|
26
26
|
}
|
|
27
27
|
}
|