diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js index 4368ee5..4eb829c 100644 --- a/packages/text-bitmap/src/BitmapFontLoader.js +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -1,4 +1,3 @@ -import { TextureCache } from '@pixi/utils'; import { LoaderResource } from '@pixi/loaders'; import BitmapText from './BitmapText'; @@ -114,6 +113,19 @@ const pages = resource.data.getElementsByTagName('page'); const textures = []; + + // Handle completed, when the number of textures + // load is the same number as references in the fnt file + const completed = () => + { + if (textures.length === pages.length) + { + BitmapFontLoader.parse(resource, textures); + next(); + } + }; + + // Standard loading options for images const loadOptions = { crossOrigin: resource.crossOrigin, loadType: LoaderResource.LOAD_TYPE.IMAGE, @@ -121,44 +133,27 @@ parentResource: resource, }; - for (let x = 0; x < pages.length; ++x) + for (let i = 0; i < pages.length; ++i) { - const textureUrl = xmlUrl + pages[x].getAttribute('file'); + const url = xmlUrl + pages[i].getAttribute('file'); - if (TextureCache[textureUrl]) + // texture is not loaded, we'll attempt to add + // it to the load and add the texture to the list + if (!this.resources[url]) { - textures.push(TextureCache[textureUrl]); + this.add(url, loadOptions, (resource) => + { + textures.push(resource.texture); + completed(); + }); } else { - // load the texture for the font - this.add(`${resource.name}_image${x}`, textureUrl, loadOptions, () => - { - const nextTextures = []; - - for (let x = 0; x < pages.length; ++x) - { - const nextTextureUrl = xmlUrl + pages[x].getAttribute('file'); - - if (TextureCache[nextTextureUrl]) - { - nextTextures.push(TextureCache[nextTextureUrl]); - } - else - { - return; - } - } - BitmapFontLoader.parse(resource, nextTextures); - next(); - }); + // incase the image is loaded outside + // using the same loader, texture will be available + textures.push(this.resources[url].texture); + completed(); } } - - if (textures.length === pages.length) - { - BitmapFontLoader.parse(resource, textures); - next(); - } } } diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js index 4368ee5..4eb829c 100644 --- a/packages/text-bitmap/src/BitmapFontLoader.js +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -1,4 +1,3 @@ -import { TextureCache } from '@pixi/utils'; import { LoaderResource } from '@pixi/loaders'; import BitmapText from './BitmapText'; @@ -114,6 +113,19 @@ const pages = resource.data.getElementsByTagName('page'); const textures = []; + + // Handle completed, when the number of textures + // load is the same number as references in the fnt file + const completed = () => + { + if (textures.length === pages.length) + { + BitmapFontLoader.parse(resource, textures); + next(); + } + }; + + // Standard loading options for images const loadOptions = { crossOrigin: resource.crossOrigin, loadType: LoaderResource.LOAD_TYPE.IMAGE, @@ -121,44 +133,27 @@ parentResource: resource, }; - for (let x = 0; x < pages.length; ++x) + for (let i = 0; i < pages.length; ++i) { - const textureUrl = xmlUrl + pages[x].getAttribute('file'); + const url = xmlUrl + pages[i].getAttribute('file'); - if (TextureCache[textureUrl]) + // texture is not loaded, we'll attempt to add + // it to the load and add the texture to the list + if (!this.resources[url]) { - textures.push(TextureCache[textureUrl]); + this.add(url, loadOptions, (resource) => + { + textures.push(resource.texture); + completed(); + }); } else { - // load the texture for the font - this.add(`${resource.name}_image${x}`, textureUrl, loadOptions, () => - { - const nextTextures = []; - - for (let x = 0; x < pages.length; ++x) - { - const nextTextureUrl = xmlUrl + pages[x].getAttribute('file'); - - if (TextureCache[nextTextureUrl]) - { - nextTextures.push(TextureCache[nextTextureUrl]); - } - else - { - return; - } - } - BitmapFontLoader.parse(resource, nextTextures); - next(); - }); + // incase the image is loaded outside + // using the same loader, texture will be available + textures.push(this.resources[url].texture); + completed(); } } - - if (textures.length === pages.length) - { - BitmapFontLoader.parse(resource, textures); - next(); - } } } diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js index 8afdcd0..aa2177c 100644 --- a/packages/text-bitmap/test/BitmapFontLoader.js +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -330,11 +330,9 @@ it('should properly register bitmap font having more than one texture', function (done) { - Loader.registerPlugin(BitmapFontLoader); - const loader = new Loader(); - loader.add(`${__dirname}/resources/split_font.fnt`); + loader.add(path.join(this.resources, 'split_font.fnt')); loader.load(() => { const font = BitmapText.fonts.split_font; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js index 4368ee5..4eb829c 100644 --- a/packages/text-bitmap/src/BitmapFontLoader.js +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -1,4 +1,3 @@ -import { TextureCache } from '@pixi/utils'; import { LoaderResource } from '@pixi/loaders'; import BitmapText from './BitmapText'; @@ -114,6 +113,19 @@ const pages = resource.data.getElementsByTagName('page'); const textures = []; + + // Handle completed, when the number of textures + // load is the same number as references in the fnt file + const completed = () => + { + if (textures.length === pages.length) + { + BitmapFontLoader.parse(resource, textures); + next(); + } + }; + + // Standard loading options for images const loadOptions = { crossOrigin: resource.crossOrigin, loadType: LoaderResource.LOAD_TYPE.IMAGE, @@ -121,44 +133,27 @@ parentResource: resource, }; - for (let x = 0; x < pages.length; ++x) + for (let i = 0; i < pages.length; ++i) { - const textureUrl = xmlUrl + pages[x].getAttribute('file'); + const url = xmlUrl + pages[i].getAttribute('file'); - if (TextureCache[textureUrl]) + // texture is not loaded, we'll attempt to add + // it to the load and add the texture to the list + if (!this.resources[url]) { - textures.push(TextureCache[textureUrl]); + this.add(url, loadOptions, (resource) => + { + textures.push(resource.texture); + completed(); + }); } else { - // load the texture for the font - this.add(`${resource.name}_image${x}`, textureUrl, loadOptions, () => - { - const nextTextures = []; - - for (let x = 0; x < pages.length; ++x) - { - const nextTextureUrl = xmlUrl + pages[x].getAttribute('file'); - - if (TextureCache[nextTextureUrl]) - { - nextTextures.push(TextureCache[nextTextureUrl]); - } - else - { - return; - } - } - BitmapFontLoader.parse(resource, nextTextures); - next(); - }); + // incase the image is loaded outside + // using the same loader, texture will be available + textures.push(this.resources[url].texture); + completed(); } } - - if (textures.length === pages.length) - { - BitmapFontLoader.parse(resource, textures); - next(); - } } } diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js index 8afdcd0..aa2177c 100644 --- a/packages/text-bitmap/test/BitmapFontLoader.js +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -330,11 +330,9 @@ it('should properly register bitmap font having more than one texture', function (done) { - Loader.registerPlugin(BitmapFontLoader); - const loader = new Loader(); - loader.add(`${__dirname}/resources/split_font.fnt`); + loader.add(path.join(this.resources, 'split_font.fnt')); loader.load(() => { const font = BitmapText.fonts.split_font; diff --git a/packages/text-bitmap/test/resources/font1.fnt b/packages/text-bitmap/test/resources/font1.fnt index 74496bb..a3a7b77 100644 --- a/packages/text-bitmap/test/resources/font1.fnt +++ b/packages/text-bitmap/test/resources/font1.fnt @@ -1,8 +1,8 @@ - + - +