Skip to content

Commit

Permalink
Merge branch 'dev' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Aug 10, 2022
2 parents 4975264 + 3c205ce commit be10876
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 44 deletions.
13 changes: 11 additions & 2 deletions packages/assets/src/Assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,20 @@ export class AssetsClass

const out: Record<string, Record<string, any>> = {};

const promises = Object.keys(resolveResults).map((bundleId) =>
const keys = Object.keys(resolveResults);
let count = 0;
let total = 0;
const _onProgress = () =>
{
onProgress?.(++count / total);
};
const promises = keys.map((bundleId) =>
{
const resolveResult = resolveResults[bundleId];

return this._mapLoadToResolve(resolveResult, onProgress)
total += Object.keys(resolveResult).length;

return this._mapLoadToResolve(resolveResult, _onProgress)
.then((resolveResult) =>
{
out[bundleId] = resolveResult;
Expand Down
53 changes: 18 additions & 35 deletions packages/assets/src/loader/parsers/loadBitmapFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,13 @@ import type { Texture } from '@pixi/core';
import { extensions, ExtensionType } from '@pixi/core';
import { settings } from '@pixi/settings';
import type { BitmapFontData } from '@pixi/text-bitmap';
import { BitmapFont, TextFormat, XMLFormat, XMLStringFormat } from '@pixi/text-bitmap';
import { BitmapFont, TextFormat, XMLStringFormat } from '@pixi/text-bitmap';
import { dirname, extname, join } from '../../utils/path';

import type { Loader } from '../Loader';
import type { LoadAsset } from '../types';
import type { LoaderParser } from './LoaderParser';

async function _loadBitmap(src: string, data: BitmapFontData, loader: Loader): Promise<BitmapFont>
{
const pages = data.page;

const textureUrls = [];

for (let i = 0; i < pages.length; ++i)
{
const pageFile = pages[i].file;

const imagePath = join(dirname(src), pageFile);

textureUrls.push(imagePath);
}

const textures: Texture[] = Object.values(await loader.load(textureUrls));

return BitmapFont.install(data, textures, true);
}
const validExtensions = ['.xml', '.fnt'];

/** simple loader plugin for loading in bitmap fonts! */
Expand All @@ -41,35 +22,37 @@ export const loadBitmapFont = {

async testParse(data: string): Promise<boolean>
{
const isText = TextFormat.test(data);
const isXMLText = XMLStringFormat.test(data);

return isText || isXMLText;
return TextFormat.test(data) || XMLStringFormat.test(data);
},

async parse(asset: string, data: LoadAsset, loader: Loader): Promise<BitmapFont>
{
const isText = TextFormat.test(asset);
const fontData: BitmapFontData = TextFormat.test(asset)
? TextFormat.parse(asset)
: XMLStringFormat.parse(asset);

const { src } = data;
const { page: pages } = fontData;
const textureUrls = [];

if (isText)
for (let i = 0; i < pages.length; ++i)
{
const parsed = TextFormat.parse(asset);
const pageFile = pages[i].file;
const imagePath = join(dirname(src), pageFile);

return await _loadBitmap(data.src, parsed, loader);
textureUrls.push(imagePath);
}

return await _loadBitmap(data.src, XMLStringFormat.parse(asset), loader);
const textures: Texture[] = Object.values(await loader.load(textureUrls));

return BitmapFont.install(fontData, textures, true);
},

async load(url: string, _options: LoadAsset, loader: Loader): Promise<BitmapFont>
async load(url: string, _options: LoadAsset): Promise<string>
{
const response = await settings.ADAPTER.fetch(url);

const text = await response.text();

const data = new window.DOMParser().parseFromString(text, 'text/xml');

return await _loadBitmap(url, XMLFormat.parse(data), loader);
return response.text();
},

unload(bitmapFont: BitmapFont): void
Expand Down
2 changes: 1 addition & 1 deletion packages/assets/src/resolver/Resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Resolver
}

/**
* Set the base path to append to all urls when resolving
* Set the base path to prepend to all urls when resolving
* @example
* resolver.basePath = 'https://home.com/';
* resolver.add('foo', 'bar.ong');
Expand Down
6 changes: 5 additions & 1 deletion packages/assets/test/assets.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ describe('Assets', () =>
manifest: 'json/asset-manifest-2.json',
});

const assets = await Assets.loadBundle(['default', 'data']);
const progressMock = jest.fn();

const assets = await Assets.loadBundle(['default', 'data'], progressMock);

expect(progressMock).toHaveBeenCalledTimes(4);
expect(progressMock.mock.calls).toEqual([[0.25], [0.5], [0.75], [1]]);
expect(assets.default.bunny).toBeInstanceOf(Texture);
expect(assets.default['profile-abel']).toBeInstanceOf(Texture);
expect(assets.default.spritesheet).toBeInstanceOf(Spritesheet);
Expand Down
8 changes: 4 additions & 4 deletions packages/graphics/src/Graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,17 +714,17 @@ export class Graphics extends Container
return this.drawShape(new Ellipse(x, y, width, height));
}

public drawPolygon(...path: Array<number> | Array<Point>): this;
public drawPolygon(path: Array<number> | Array<Point> | Polygon): this;
public drawPolygon(...path: Array<number> | Array<IPointData>): this;
public drawPolygon(path: Array<number> | Array<IPointData> | Polygon): this;

/**
* Draws a polygon using the given path.
* @param {number[]|PIXI.Point[]|PIXI.Polygon} path - The path data used to construct the polygon.
* @param {number[]|PIXI.IPointData[]|PIXI.Polygon} path - The path data used to construct the polygon.
* @returns - This Graphics object. Good for chaining method calls
*/
public drawPolygon(...path: any[]): this
{
let points: Array<number> | Array<Point>;
let points: Array<number> | Array<IPointData>;
let closeStroke = true;// !!this._fillStyle;

const poly = path[0] as Polygon;
Expand Down
3 changes: 2 additions & 1 deletion packages/text-bitmap/src/BitmapText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ export class BitmapText extends Container

chars.push(charRenderData);

lastLineWidth = charRenderData.position.x + Math.max(charData.xAdvance, charData.texture.orig.width);
lastLineWidth = charRenderData.position.x
+ Math.max(charData.xAdvance - charData.xOffset, charData.texture.orig.width);
pos.x += charData.xAdvance + this._letterSpacing;
maxLineHeight = Math.max(maxLineHeight, (charData.yOffset + charData.texture.height));
prevCharCode = charCode;
Expand Down

0 comments on commit be10876

Please sign in to comment.