Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static fromLoader(source, imageUrl, name)
{
// console.log('added from loader...')
const resource = new ImageResource(source);
resource.url = imageUrl;
// console.log('base resource ' + resource.width);
const baseTexture = new BaseTexture(resource, {
scaleMode: settings.SCALE_MODE,
resolution: getResolutionOfUrl(imageUrl),
});
const texture = new Texture(baseTexture);
// No name, use imageUrl instead
if (!name)
{
name = imageUrl;
}
// lets also add the frame to pixi's global cache for fromFrame and fromImage functions
BaseTexture.addToCache(texture.baseTexture, name);
Texture.addToCache(texture, name);
// also add references by url if they are different.
if (name !== imageUrl)
static fromLoader(source, imageUrl, name)
{
const resource = new ImageResource(source);
resource.url = imageUrl;
const baseTexture = new BaseTexture(resource, {
scaleMode: settings.SCALE_MODE,
resolution: getResolutionOfUrl(imageUrl),
});
const texture = new Texture(baseTexture);
// No name, use imageUrl instead
if (!name)
{
name = imageUrl;
}
// lets also add the frame to pixi's global cache for 'fromLoader' function
BaseTexture.addToCache(texture.baseTexture, name);
Texture.addToCache(texture, name);
// also add references by url if they are different.
if (name !== imageUrl)
_updateResolution(resolutionFilename)
{
const scale = this.data.meta.scale;
// Use a defaultValue of `null` to check if a url-based resolution is set
let resolution = getResolutionOfUrl(resolutionFilename, null);
// No resolution found via URL
if (resolution === null)
{
// Use the scale value or default to 1
resolution = scale !== undefined ? parseFloat(scale) : 1;
}
// For non-1 resolutions, update baseTexture
if (resolution !== 1)
{
this.baseTexture.setResolution(resolution);
}
return resolution;
}
static registerFont(xml, textures)
{
const data = {};
const info = xml.getElementsByTagName('info')[0];
const common = xml.getElementsByTagName('common')[0];
const pages = xml.getElementsByTagName('page');
const res = getResolutionOfUrl(pages[0].getAttribute('file'), settings.RESOLUTION);
const pagesTextures = {};
data.font = info.getAttribute('face');
data.size = parseInt(info.getAttribute('size'), 10);
data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10) / res;
data.chars = {};
// Single texture, convert to list
if (textures instanceof Texture)
{
textures = [textures];
}
// Convert the input Texture, Textures or object
// into a page Texture lookup by "id"
for (let i = 0; i < pages.length; i++)
cacheId = source._pixiId;
}
let texture = TextureCache[cacheId];
// Strict-mode rejects invalid cacheIds
if (isFrame && strict && !texture)
{
throw new Error(`The cacheId "${cacheId}" does not exist in TextureCache.`);
}
if (!texture)
{
if (!options.resolution)
{
options.resolution = getResolutionOfUrl(source);
}
texture = new Texture(new BaseTexture(source, options));
texture.baseTexture.cacheId = cacheId;
BaseTexture.addToCache(texture.baseTexture, cacheId);
Texture.addToCache(texture, cacheId);
}
// lets assume its a base texture!
return texture;
}
static registerFont(xml, textures)
{
const data = {};
const info = xml.getElementsByTagName('info')[0];
const common = xml.getElementsByTagName('common')[0];
const pages = xml.getElementsByTagName('page');
const res = getResolutionOfUrl(pages[0].getAttribute('file'), settings.RESOLUTION);
const pagesTextures = {};
data.font = info.getAttribute('face');
data.size = parseInt(info.getAttribute('size'), 10);
data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10) / res;
data.chars = {};
// Single texture, convert to list
if (textures instanceof Texture)
{
textures = [textures];
}
// Convert the input Texture, Textures or object
// into a page Texture lookup by "id"
for (let i = 0; i < pages.length; i++)
static from(source, options = {})
{
let cacheId = null;
if (typeof source === 'string')
{
cacheId = source;
if (!options.resolution)
{
options.resolution = getResolutionOfUrl(source);
}
}
else
{
if (!source._pixiId)
{
source._pixiId = `pixiid_${uid()}`;
}
cacheId = source._pixiId;
}
let texture = TextureCache[cacheId];
if (!texture)
{