Repository navigation
Expand file tree
/
Copy pathJsExtension.js
More file actions
778 lines (707 loc) · 24.8 KB
/
Copy pathJsExtension.js
File metadata and controls
778 lines (707 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
//@ts-check
/// <reference path="../JsExtensionTypes.d.ts" />
/**
* This is a declaration of an extension for GDevelop 5.
*
* ℹ️ Changes in this file are watched and automatically imported if the editor
* is running. You can also manually run `node import-GDJS-Runtime.js` (in newIDE/app/scripts).
*
* The file must be named "JsExtension.js", otherwise GDevelop won't load it.
* ⚠️ If you make a change and the extension is not loaded, open the developer console
* and search for any errors.
*
* More information on https://github.com/4ian/GDevelop/blob/master/newIDE/README-extensions.md
*/
/** @type {ExtensionModule} */
module.exports = {
createExtension: function (_, gd) {
const extension = new gd.PlatformExtension();
extension
.setExtensionInformation(
'BitmapText',
_('Bitmap Text'),
_(
'Displays a text using a "Bitmap Font" (an image representing characters). This is more performant than a traditional Text object and it allows for complete control on the characters aesthetic.'
),
'Aurélien Vivet',
'Open source (MIT License)'
)
.setExtensionHelpPath('/objects/bitmap_text')
.setCategory('Text');
extension
.addInstructionOrExpressionGroupMetadata(_('Bitmap Text'))
.setIcon('JsPlatform/Extensions/bitmapfont32.png');
const bitmapTextObject = new gd.ObjectJsImplementation();
bitmapTextObject.updateProperty = function (
objectContent,
propertyName,
newValue
) {
if (propertyName in objectContent) {
if (typeof objectContent[propertyName] === 'boolean')
objectContent[propertyName] = newValue === '1';
else if (typeof objectContent[propertyName] === 'number')
objectContent[propertyName] = parseFloat(newValue);
else objectContent[propertyName] = newValue;
return true;
}
return false;
};
bitmapTextObject.getProperties = function (objectContent) {
const objectProperties = new gd.MapStringPropertyDescriptor();
objectProperties
.getOrCreate('text')
.setValue(objectContent.text)
.setType('textarea')
.setLabel(_('Text'));
objectProperties
.getOrCreate('opacity')
.setValue(objectContent.opacity.toString())
.setType('number')
.setLabel(_('Opacity (0-255)'))
.setGroup(_('Appearance'));
objectProperties
.getOrCreate('align')
.setValue(objectContent.align)
.setType('choice')
.addExtraInfo('left')
.addExtraInfo('center')
.addExtraInfo('right')
.setLabel(_('Alignment, when multiple lines are displayed'))
.setGroup(_('Appearance'));
objectProperties
.getOrCreate('bitmapFontResourceName')
.setValue(objectContent.bitmapFontResourceName)
.setType('resource')
.addExtraInfo('bitmapFont') //fnt or xml files
.setLabel(_('Bitmap Font'))
.setGroup(_('Font'));
objectProperties
.getOrCreate('textureAtlasResourceName')
.setValue(objectContent.textureAtlasResourceName)
.setType('resource')
.addExtraInfo('image')
.setLabel(_('Bitmap atlas image'))
.setGroup(_('Font'));
objectProperties
.getOrCreate('scale')
.setValue(objectContent.scale.toString())
.setType('number')
.setLabel(_('Text scale'))
.setGroup(_('Appearance'));
objectProperties
.getOrCreate('tint')
.setValue(objectContent.tint)
.setType('color')
.setLabel(_('Font tint'))
.setGroup(_('Font'));
objectProperties
.getOrCreate('wordWrap')
.setValue(objectContent.wordWrap ? 'true' : 'false')
.setType('boolean')
.setLabel(_('Word wrapping'))
.setGroup(_('Appearance'));
return objectProperties;
};
bitmapTextObject.setRawJSONContent(
JSON.stringify({
text:
'This text use the default bitmap font.\nUse a custom Bitmap Font to create your own texts.',
opacity: 255,
scale: 1,
fontSize: 20,
tint: '255;255;255',
bitmapFontResourceName: '',
textureAtlasResourceName: '',
align: 'left',
wordWrap: true,
})
);
bitmapTextObject.updateInitialInstanceProperty = function (
objectContent,
instance,
propertyName,
newValue,
project,
layout
) {
return false;
};
bitmapTextObject.getInitialInstanceProperties = function (
content,
instance,
project,
layout
) {
var instanceProperties = new gd.MapStringPropertyDescriptor();
return instanceProperties;
};
const object = extension
.addObject(
'BitmapTextObject',
_('Bitmap Text'),
_(
'Displays a text using a "Bitmap Font" (an image representing characters). This is more performant than a traditional Text object and it allows for complete control on the characters aesthetic.'
),
'JsPlatform/Extensions/bitmapfont32.png',
bitmapTextObject
)
.setIncludeFile('Extensions/BitmapText/bitmaptextruntimeobject.js')
.addIncludeFile(
'Extensions/BitmapText/bitmaptextruntimeobject-pixi-renderer.js'
)
.setCategoryFullName(_('Text'))
.addDefaultBehavior('TextContainerCapability::TextContainerBehavior')
.addDefaultBehavior('EffectCapability::EffectBehavior')
.addDefaultBehavior('OpacityCapability::OpacityBehavior')
.addDefaultBehavior('ScalableCapability::ScalableBehavior');
// Deprecated
object
.addExpressionAndConditionAndAction(
'string',
'Text',
_('Text'),
_('the text'),
_('the text'),
'',
'res/conditions/text24_black.png'
)
.setHidden()
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.useStandardParameters('string', gd.ParameterOptions.makeNewOptions())
.setFunctionName('setText')
.setGetter('getText');
object
.addStrExpression(
'Text',
_('Text'),
_('Return the text.'),
'',
'res/conditions/text24_black.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.setFunctionName('getText');
// Deprecated
object
.addExpressionAndConditionAndAction(
'number',
'Opacity',
_('Opacity'),
_('the opacity, between 0 (fully transparent) and 255 (opaque)'),
_('the opacity'),
'',
'res/conditions/opacity24.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.useStandardParameters(
'number',
gd.ParameterOptions.makeNewOptions().setDescription(
_('Opacity (0-255)')
)
)
.setFunctionName('setOpacity')
.setGetter('getOpacity')
.setHidden();
object
.addExpressionAndCondition(
'number',
'FontSize',
_('Font size'),
_('the font size, defined in the Bitmap Font'),
_('the font size'),
'',
'res/conditions/characterSize24.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.useStandardParameters('number', gd.ParameterOptions.makeNewOptions())
.setFunctionName('getFontSize');
// Deprecated
object
.addExpressionAndConditionAndAction(
'number',
'Scale',
_('Scale'),
_('the scale (1 by default)'),
_('the scale'),
'',
'res/actions/scale24_black.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.useStandardParameters(
'number',
gd.ParameterOptions.makeNewOptions().setDescription(
_('Scale (1 by default)')
)
)
.setHidden()
.setFunctionName('setScale')
.setGetter('getScale');
object
.addExpressionAndCondition(
'string',
'FontName',
_('Font name'),
_('the font name (defined in the Bitmap font)'),
_('the font name'),
'',
'res/conditions/font24.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.useStandardParameters('string', gd.ParameterOptions.makeNewOptions())
.setFunctionName('getFontName');
object
.addAction(
'SetTint',
_('Tint'),
_('Set the tint of the Bitmap Text object.'),
_('Set tint of _PARAM0_ to _PARAM1_'),
'',
'res/actions/color24.png',
'res/actions/color.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.addParameter('color', _('Color'), '', false)
.getCodeExtraInformation()
.setFunctionName('setTint');
// Deprecated
object
.addAction(
'SetBitmapFontAndTextureAtlasResourceName',
_('Bitmap files resources'),
_('Change the Bitmap Font and/or the atlas image used by the object.'),
_(
'Set the bitmap font of _PARAM0_ to _PARAM1_ and the atlas to _PARAM2_'
),
'',
'res/actions/font24.png',
'res/actions/font.png'
)
.setHidden()
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.addParameter(
'bitmapFontResource',
_('Bitmap font resource name'),
'',
false
)
.setParameterLongDescription(
'The resource name of the font file, without quotes.'
)
.addParameter('string', _('Texture atlas resource name'), '', false)
.setParameterLongDescription(
'The resource name of the image exported with the font, with quotes.'
)
.getCodeExtraInformation()
.setFunctionName('setBitmapFontAndTextureAtlasResourceName');
object
.addAction(
'SetBitmapFontAndTextureAtlasResourceName2',
_('Bitmap files resources'),
_('Change the Bitmap Font and/or the atlas image used by the object.'),
_(
'Set the bitmap font of _PARAM0_ to _PARAM1_ and the atlas to _PARAM2_'
),
'',
'res/actions/font24.png',
'res/actions/font.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.addParameter(
'bitmapFontResource',
_('Bitmap font resource name'),
'',
false
)
.addParameter(
'imageResource',
_('Texture atlas resource name'),
'',
false
)
.getCodeExtraInformation()
.setFunctionName('setBitmapFontAndTextureAtlasResourceName');
object
.addExpressionAndCondition(
'string',
'Alignment',
_('Alignment'),
_('the text alignment'),
_('the text alignment'),
'',
'res/actions/textAlign24.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.useStandardParameters(
'string',
gd.ParameterOptions.makeNewOptions().setDescription(
_('Alignment ("left", "right" or "center")')
)
)
.setFunctionName('getAlignment');
object
.addAction(
'SetAlignment',
_('Alignment'),
_('Change the alignment of a Bitmap text object.'),
_('Set the alignment of _PARAM0_ to _PARAM1_'),
'',
'res/actions/textAlign24.png',
'res/actions/textAlign.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.addParameter(
'stringWithSelector',
_('Alignment'),
'["left", "center", "right"]',
false
)
.getCodeExtraInformation()
.setFunctionName('setAlignment');
object
.addCondition(
'WordWrap',
_('Word wrap'),
_('Check if word wrap is enabled.'),
_('_PARAM0_ word wrap is enabled'),
'',
'res/conditions/wordWrap24_black.png',
'res/conditions/wordWrap_black.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.getCodeExtraInformation()
.setFunctionName('getWordWrap');
object
.addAction(
'SetWordWrap',
_('Word wrap'),
_('De/activate word wrapping.'),
_('Activate word wrap of _PARAM0_: _PARAM1_'),
'',
'res/actions/wordWrap24_black.png',
'res/actions/wordWrap_black.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.addParameter('yesorno', _('Activate word wrap'), '', false)
.getCodeExtraInformation()
.setFunctionName('setWordWrap');
object
.addExpressionAndConditionAndAction(
'number',
'WrappingWidth',
_('Wrapping width'),
_('the width, in pixels, after which the text is wrapped on next line'),
_('the wrapping width'),
'',
'res/actions/scaleWidth24_black.png'
)
.addParameter('object', _('Bitmap text'), 'BitmapTextObject', false)
.useStandardParameters('number', gd.ParameterOptions.makeNewOptions())
.setFunctionName('setWrappingWidth')
.setGetter('getWrappingWidth');
return extension;
},
/**
* You can optionally add sanity tests that will check the basic working
* of your extension behaviors/objects by instantiating behaviors/objects
* and setting the property to a given value.
*
* If you don't have any tests, you can simply return an empty array.
*
* But it is recommended to create tests for the behaviors/objects properties you created
* to avoid mistakes.
*/
runExtensionSanityTests: function (gd, extension) {
return [];
},
/**
* Register editors for objects.
*
* ℹ️ Run `node import-GDJS-Runtime.js` (in newIDE/app/scripts) if you make any change.
*/
registerEditorConfigurations: function (objectsEditorService) {
objectsEditorService.registerEditorConfiguration(
'BitmapText::BitmapTextObject',
objectsEditorService.getDefaultObjectJsImplementationPropertiesEditor({
helpPagePath: '/objects/bitmap_text',
})
);
},
/**
* Register renderers for instance of objects on the scene editor.
*
* ℹ️ Run `node import-GDJS-Runtime.js` (in newIDE/app/scripts) if you make any change.
*/
registerInstanceRenderers: function (objectsRenderingService) {
const RenderedInstance = objectsRenderingService.RenderedInstance;
const PIXI = objectsRenderingService.PIXI;
/** The bitmap font used in case another font can't be loaded. */
let defaultBitmapFont = null;
const defaultBitmapFontInstallKey = 'GD-DEFAULT-BITMAP-FONT';
/**
* Map counting the number of "reference" to a bitmap font. This is useful
* to uninstall a bitmap font when not used anymore.
*/
const bitmapFontUsageCount = {};
/**
* We patch the installed font to use a name that is unique for each font data and texture,
* to avoid conflicts between different font files using the same font name (by default, the
* font name used by Pixi is the one inside the font data, but this name is not necessarily unique.
* For example, 2 resources can use the same font, or we can have multiple objects with the same
* font data and different textures).
*/
const patchBitmapFont = (bitmapFont, bitmapFontInstallKey) => {
const defaultName = bitmapFont.font;
bitmapFont.font = bitmapFontInstallKey;
PIXI.BitmapFont.available[bitmapFontInstallKey] = bitmapFont;
delete PIXI.BitmapFont.available[defaultName];
return PIXI.BitmapFont.available[bitmapFontInstallKey];
};
/**
* Return a default bitmap font to be used in case another font can't be loaded.
*/
const getDefaultBitmapFont = () => {
if (defaultBitmapFont) return defaultBitmapFont;
const defaultBitmapFontStyle = new PIXI.TextStyle({
fontFamily: 'Arial',
fontSize: 20,
padding: 5,
align: 'left',
fill: '#ffffff',
wordWrap: true,
lineHeight: 20,
});
defaultBitmapFont = patchBitmapFont(
PIXI.BitmapFont.from(
defaultBitmapFontStyle.fontFamily,
defaultBitmapFontStyle,
{
chars: [
[' ', '~'], // All the printable ASCII characters
],
}
),
defaultBitmapFontInstallKey
);
return defaultBitmapFont;
};
/**
* Given a bitmap font resource name and a texture atlas resource name, returns the PIXI.BitmapFont
* for it.
* The font must be released with `releaseBitmapFont` when not used anymore - so that it can be removed
* from memory when not used by any instance.
*
* @param pixiResourcesLoader
* @param project
* @param bitmapFontResourceName
* @param textureAtlasResourceName
*/
const obtainBitmapFont = (
pixiResourcesLoader,
project,
bitmapFontResourceName,
textureAtlasResourceName
) => {
const bitmapFontInstallKey =
bitmapFontResourceName + '@' + textureAtlasResourceName;
if (PIXI.BitmapFont.available[bitmapFontInstallKey]) {
// Return the existing BitmapFont that is already in memory and already installed.
bitmapFontUsageCount[bitmapFontInstallKey] =
(bitmapFontUsageCount[bitmapFontInstallKey] || 0) + 1;
return Promise.resolve(PIXI.BitmapFont.available[bitmapFontInstallKey]);
}
// Get the atlas texture, the bitmap font data and install the font:
const texture = pixiResourcesLoader.getPIXITexture(
project,
textureAtlasResourceName
);
const loadBitmapFont = () =>
pixiResourcesLoader
.getBitmapFontData(project, bitmapFontResourceName)
.then((fontData) => {
if (!texture.valid)
throw new Error(
'Tried to install a BitmapFont with an invalid texture.'
);
const bitmapFont = patchBitmapFont(
PIXI.BitmapFont.install(fontData, texture),
bitmapFontInstallKey
);
bitmapFontUsageCount[bitmapFontInstallKey] =
(bitmapFontUsageCount[bitmapFontInstallKey] || 0) + 1;
return bitmapFont;
})
.catch((err) => {
console.warn('Unable to load font data:', err);
console.info(
'Is the texture atlas properly set for the Bitmap Text object? The default font will be used instead.'
);
const bitmapFont = getDefaultBitmapFont();
return bitmapFont;
});
if (!texture.valid) {
// Post pone texture update if texture is not loaded.
// (otherwise, the bitmap font would not get updated when the
// texture is loaded and updated).
return new Promise((resolve) => {
texture.once('update', () => {
resolve(loadBitmapFont());
});
});
} else {
// We're ready to load the bitmap font now, as the texture
// is already loaded.
return loadBitmapFont();
}
};
/**
* When a font is not used by an object anymore (object destroyed or font changed),
* call this function to decrease the internal count of objects using the font.
*
* Fonts are unloaded when not used anymore.
*/
const releaseBitmapFont = (bitmapFontInstallKey) => {
if (bitmapFontInstallKey === defaultBitmapFontInstallKey) {
// Never uninstall the default bitmap font.
return;
}
if (!bitmapFontUsageCount[bitmapFontInstallKey]) {
console.error(
'BitmapFont with name ' +
bitmapFontInstallKey +
' was tried to be released but was never marked as used.'
);
return;
}
bitmapFontUsageCount[bitmapFontInstallKey]--;
if (bitmapFontUsageCount[bitmapFontInstallKey] === 0) {
PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
console.info(
'Uninstalled BitmapFont "' + bitmapFontInstallKey + '" from memory.'
);
}
};
/**
* Return the path to the thumbnail of the specified object.
* This is called to update the PIXI object on the scene editor
*/
class RenderedBitmapTextInstance extends RenderedInstance {
static getThumbnail(project, resourcesLoader, objectConfiguration) {
return 'JsPlatform/Extensions/bitmapfont24.png';
}
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
pixiResourcesLoader
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
pixiResourcesLoader
);
// We'll track changes of the font to trigger the loading of the new font.
this._currentBitmapFontResourceName = '';
this._currentTextureAtlasResourceName = '';
this._pixiObject = new PIXI.BitmapText('', {
// Use a default font. The proper font will be loaded in `update` method.
fontName: getDefaultBitmapFont().font,
});
this._pixiObject.anchor.x = 0.5;
this._pixiObject.anchor.y = 0.5;
this._pixiContainer.addChild(this._pixiObject);
this.update();
}
update() {
const properties = this._associatedObjectConfiguration.getProperties();
// Update the rendered text properties (note: Pixi is only
// applying changes if there were changed).
const rawText = properties.get('text').getValue();
this._pixiObject.text = rawText;
const opacity = +properties.get('opacity').getValue();
this._pixiObject.alpha = opacity / 255;
const align = properties.get('align').getValue();
this._pixiObject.align = align;
const color = properties.get('tint').getValue();
this._pixiObject.tint = objectsRenderingService.rgbOrHexToHexNumber(
color
);
const scale = +(properties.get('scale').getValue() || 1);
this._pixiObject.scale.set(scale);
// Track the changes in font to load the new requested font.
const bitmapFontResourceName = properties
.get('bitmapFontResourceName')
.getValue();
const textureAtlasResourceName = properties
.get('textureAtlasResourceName')
.getValue();
if (
this._currentBitmapFontResourceName !== bitmapFontResourceName ||
this._currentTextureAtlasResourceName !== textureAtlasResourceName
) {
// Release the old font (if it was installed).
releaseBitmapFont(this._pixiObject.fontName);
// Temporarily go back to the default font, as the PIXI.BitmapText
// object does not support being displayed with a font not installed at all.
// It will be replaced as soon as the proper font is loaded.
this._pixiObject.fontName = getDefaultBitmapFont().font;
this._currentBitmapFontResourceName = bitmapFontResourceName;
this._currentTextureAtlasResourceName = textureAtlasResourceName;
obtainBitmapFont(
this._pixiResourcesLoader,
this._project,
this._currentBitmapFontResourceName,
this._currentTextureAtlasResourceName
).then((bitmapFont) => {
this._pixiObject.fontName = bitmapFont.font;
this._pixiObject.fontSize = bitmapFont.size;
this._pixiObject.dirty = true;
});
}
// Set up the wrapping width if enabled.
const wordWrap = properties.get('wordWrap').getValue() === 'true';
if (wordWrap && this._instance.hasCustomSize()) {
this._pixiObject.maxWidth =
this.getCustomWidth() / this._pixiObject.scale.x;
this._pixiObject.dirty = true;
} else {
this._pixiObject.maxWidth = 0;
this._pixiObject.dirty = true;
}
this._pixiObject.position.x =
this._instance.getX() + (this._pixiObject.textWidth * scale) / 2;
this._pixiObject.position.y =
this._instance.getY() + (this._pixiObject.textHeight * scale) / 2;
this._pixiObject.rotation = RenderedInstance.toRad(
this._instance.getAngle()
);
}
onRemovedFromScene() {
RenderedInstance.prototype.onRemovedFromScene.call(this);
const fontName = this._pixiObject.fontName;
this._pixiObject.destroy();
releaseBitmapFont(fontName);
}
/**
* Return the width of the instance, when it's not resized.
*/
getDefaultWidth() {
return this._pixiObject.width;
}
/**
* Return the height of the instance, when it's not resized.
*/
getDefaultHeight() {
return this._pixiObject.height;
}
}
objectsRenderingService.registerInstanceRenderer(
'BitmapText::BitmapTextObject',
RenderedBitmapTextInstance
);
},
};