This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

261
node_modules/pixi.js/lib/spritesheet/Spritesheet.d.ts generated vendored Normal file
View File

@@ -0,0 +1,261 @@
import { Texture } from '../rendering/renderers/shared/texture/Texture';
import type { PointData } from '../maths/point/PointData';
import type { TextureSource } from '../rendering/renderers/shared/texture/sources/TextureSource';
import type { BindableTexture, TextureBorders } from '../rendering/renderers/shared/texture/Texture';
import type { Dict } from '../utils/types';
/**
* Represents the JSON data for a spritesheet atlas.
* @memberof assets
*/
export interface SpritesheetFrameData {
/** The frame rectangle of the texture. */
frame: {
x: number;
y: number;
w: number;
h: number;
};
/** Whether the texture is trimmed. */
trimmed?: boolean;
/** Whether the texture is rotated. */
rotated?: boolean;
/** The source size of the texture. */
sourceSize?: {
w: number;
h: number;
};
/** The sprite source size. */
spriteSourceSize?: {
h?: number;
w?: number;
x: number;
y: number;
};
/** The anchor point of the texture. */
anchor?: PointData;
/** The 9-slice borders of the texture. */
borders?: TextureBorders;
}
/**
* Atlas format.
* @memberof assets
*/
export interface SpritesheetData {
/** The frames of the atlas. */
frames: Dict<SpritesheetFrameData>;
/** The animations of the atlas. */
animations?: Dict<string[]>;
/** The meta data of the atlas. */
meta: {
app?: string;
format?: string;
frameTags?: {
from: number;
name: string;
to: number;
direction: string;
}[];
image?: string;
layers?: {
blendMode: string;
name: string;
opacity: number;
}[];
scale: number | string;
size?: {
h: number;
w: number;
};
slices?: {
color: string;
name: string;
keys: {
frame: number;
bounds: {
x: number;
y: number;
w: number;
h: number;
};
}[];
}[];
related_multi_packs?: string[];
version?: string;
};
}
/**
* Utility class for maintaining reference to a collection
* of Textures on a single Spritesheet.
*
* To access a sprite sheet from your code you may pass its JSON data file to Pixi's loader:
*
* ```js
* import { Assets } from 'pixi.js';
*
* const sheet = await Assets.load('images/spritesheet.json');
* ```
*
* Alternately, you may circumvent the loader by instantiating the Spritesheet directly:
*
* ```js
* import { Spritesheet } from 'pixi.js';
*
* const sheet = new Spritesheet(texture, spritesheetData);
* await sheet.parse();
* console.log('Spritesheet ready to use!');
* ```
*
* With the `sheet.textures` you can create Sprite objects, and `sheet.animations` can be used to create an AnimatedSprite.
*
* Here's an example of a sprite sheet JSON data file:
* ```json
* {
* "frames": {
* "enemy1.png":
* {
* "frame": {"x":103,"y":1,"w":32,"h":32},
* "spriteSourceSize": {"x":0,"y":0,"w":32,"h":32},
* "sourceSize": {"w":32,"h":32},
* "anchor": {"x":16,"y":16}
* },
* "enemy2.png":
* {
* "frame": {"x":103,"y":35,"w":32,"h":32},
* "spriteSourceSize": {"x":0,"y":0,"w":32,"h":32},
* "sourceSize": {"w":32,"h":32},
* "anchor": {"x":16,"y":16}
* },
* "button.png":
* {
* "frame": {"x":1,"y":1,"w":100,"h":100},
* "spriteSourceSize": {"x":0,"y":0,"w":100,"h":100},
* "sourceSize": {"w":100,"h":100},
* "anchor": {"x":0,"y":0},
* "borders": {"left":35,"top":35,"right":35,"bottom":35}
* }
* },
*
* "animations": {
* "enemy": ["enemy1.png","enemy2.png"]
* },
*
* "meta": {
* "image": "sheet.png",
* "format": "RGBA8888",
* "size": {"w":136,"h":102},
* "scale": "1"
* }
* }
* ```
* Sprite sheets can be packed using tools like {@link https://codeandweb.com/texturepacker|TexturePacker},
* {@link https://renderhjs.net/shoebox/|Shoebox} or {@link https://github.com/krzysztof-o/spritesheet.js|Spritesheet.js}.
* Default anchor points (see {@link Texture#defaultAnchor}), default 9-slice borders
* (see {@link Texture#defaultBorders}) and grouping of animation sprites are currently only
* supported by TexturePacker.
*
* Alternative ways for loading spritesheet image if you need more control:
*
* ```js
* import { Assets } from 'pixi.js';
*
* const sheetTexture = await Assets.load('images/spritesheet.png');
* Assets.add({
* alias: 'atlas',
* src: 'images/spritesheet.json',
* data: {texture: sheetTexture} // using of preloaded texture
* });
* const sheet = await Assets.load('atlas')
* ```
*
* or:
*
* ```js
* import { Assets } from 'pixi.js';
*
* Assets.add({
* alias: 'atlas',
* src: 'images/spritesheet.json',
* data: {imageFilename: 'my-spritesheet.2x.avif'} // using of custom filename located in "images/my-spritesheet.2x.avif"
* });
* const sheet = await Assets.load('atlas')
* ```
* @memberof assets
*/
export declare class Spritesheet<S extends SpritesheetData = SpritesheetData> {
/** The maximum number of Textures to build per process. */
static readonly BATCH_SIZE = 1000;
/** For multi-packed spritesheets, this contains a reference to all the other spritesheets it depends on. */
linkedSheets: Spritesheet<S>[];
/** Reference to the source texture. */
textureSource: TextureSource;
/**
* A map containing all textures of the sprite sheet.
* Can be used to create a {@link Sprite|Sprite}:
* @example
* import { Sprite } from 'pixi.js';
*
* new Sprite(sheet.textures['image.png']);
*/
textures: Record<keyof S['frames'], Texture>;
/**
* A map containing the textures for each animation.
* Can be used to create an {@link AnimatedSprite|AnimatedSprite}:
* @example
* import { AnimatedSprite } from 'pixi.js';
*
* new AnimatedSprite(sheet.animations['anim_name']);
*/
animations: Record<keyof NonNullable<S['animations']>, Texture[]>;
/**
* Reference to the original JSON data.
* @type {object}
*/
data: S;
/** The resolution of the spritesheet. */
resolution: number;
/**
* Reference to original source image from the Loader. This reference is retained so we
* can destroy the Texture later on. It is never used internally.
*/
private _texture;
/**
* Map of spritesheet frames.
* @type {object}
*/
private _frames;
/** Collection of frame names. */
private _frameKeys;
/** Current batch index being processed. */
private _batchIndex;
/**
* Callback when parse is completed.
* @type {Function}
*/
private _callback;
/**
* @param texture - Reference to the source BaseTexture object.
* @param {object} data - Spritesheet image data.
*/
constructor(texture: BindableTexture, data: S);
/**
* Parser spritesheet from loaded data. This is done asynchronously
* to prevent creating too many Texture within a single process.
*/
parse(): Promise<Record<string, Texture>>;
/**
* Process a batch of frames
* @param initialFrameIndex - The index of frame to start.
*/
private _processFrames;
/** Parse animations config. */
private _processAnimations;
/** The parse has completed. */
private _parseComplete;
/** Begin the next batch of textures. */
private _nextBatch;
/**
* Destroy Spritesheet and don't use after this.
* @param {boolean} [destroyBase=false] - Whether to destroy the base texture as well
*/
destroy(destroyBase?: boolean): void;
}

164
node_modules/pixi.js/lib/spritesheet/Spritesheet.js generated vendored Normal file
View File

@@ -0,0 +1,164 @@
'use strict';
var Rectangle = require('../maths/shapes/Rectangle.js');
var Texture = require('../rendering/renderers/shared/texture/Texture.js');
"use strict";
const _Spritesheet = class _Spritesheet {
/**
* @param texture - Reference to the source BaseTexture object.
* @param {object} data - Spritesheet image data.
*/
constructor(texture, data) {
/** For multi-packed spritesheets, this contains a reference to all the other spritesheets it depends on. */
this.linkedSheets = [];
this._texture = texture instanceof Texture.Texture ? texture : null;
this.textureSource = texture.source;
this.textures = {};
this.animations = {};
this.data = data;
const metaResolution = parseFloat(data.meta.scale);
if (metaResolution) {
this.resolution = metaResolution;
texture.source.resolution = this.resolution;
} else {
this.resolution = texture.source._resolution;
}
this._frames = this.data.frames;
this._frameKeys = Object.keys(this._frames);
this._batchIndex = 0;
this._callback = null;
}
/**
* Parser spritesheet from loaded data. This is done asynchronously
* to prevent creating too many Texture within a single process.
*/
parse() {
return new Promise((resolve) => {
this._callback = resolve;
this._batchIndex = 0;
if (this._frameKeys.length <= _Spritesheet.BATCH_SIZE) {
this._processFrames(0);
this._processAnimations();
this._parseComplete();
} else {
this._nextBatch();
}
});
}
/**
* Process a batch of frames
* @param initialFrameIndex - The index of frame to start.
*/
_processFrames(initialFrameIndex) {
let frameIndex = initialFrameIndex;
const maxFrames = _Spritesheet.BATCH_SIZE;
while (frameIndex - initialFrameIndex < maxFrames && frameIndex < this._frameKeys.length) {
const i = this._frameKeys[frameIndex];
const data = this._frames[i];
const rect = data.frame;
if (rect) {
let frame = null;
let trim = null;
const sourceSize = data.trimmed !== false && data.sourceSize ? data.sourceSize : data.frame;
const orig = new Rectangle.Rectangle(
0,
0,
Math.floor(sourceSize.w) / this.resolution,
Math.floor(sourceSize.h) / this.resolution
);
if (data.rotated) {
frame = new Rectangle.Rectangle(
Math.floor(rect.x) / this.resolution,
Math.floor(rect.y) / this.resolution,
Math.floor(rect.h) / this.resolution,
Math.floor(rect.w) / this.resolution
);
} else {
frame = new Rectangle.Rectangle(
Math.floor(rect.x) / this.resolution,
Math.floor(rect.y) / this.resolution,
Math.floor(rect.w) / this.resolution,
Math.floor(rect.h) / this.resolution
);
}
if (data.trimmed !== false && data.spriteSourceSize) {
trim = new Rectangle.Rectangle(
Math.floor(data.spriteSourceSize.x) / this.resolution,
Math.floor(data.spriteSourceSize.y) / this.resolution,
Math.floor(rect.w) / this.resolution,
Math.floor(rect.h) / this.resolution
);
}
this.textures[i] = new Texture.Texture({
source: this.textureSource,
frame,
orig,
trim,
rotate: data.rotated ? 2 : 0,
defaultAnchor: data.anchor,
defaultBorders: data.borders,
label: i.toString()
});
}
frameIndex++;
}
}
/** Parse animations config. */
_processAnimations() {
const animations = this.data.animations || {};
for (const animName in animations) {
this.animations[animName] = [];
for (let i = 0; i < animations[animName].length; i++) {
const frameName = animations[animName][i];
this.animations[animName].push(this.textures[frameName]);
}
}
}
/** The parse has completed. */
_parseComplete() {
const callback = this._callback;
this._callback = null;
this._batchIndex = 0;
callback.call(this, this.textures);
}
/** Begin the next batch of textures. */
_nextBatch() {
this._processFrames(this._batchIndex * _Spritesheet.BATCH_SIZE);
this._batchIndex++;
setTimeout(() => {
if (this._batchIndex * _Spritesheet.BATCH_SIZE < this._frameKeys.length) {
this._nextBatch();
} else {
this._processAnimations();
this._parseComplete();
}
}, 0);
}
/**
* Destroy Spritesheet and don't use after this.
* @param {boolean} [destroyBase=false] - Whether to destroy the base texture as well
*/
destroy(destroyBase = false) {
for (const i in this.textures) {
this.textures[i].destroy();
}
this._frames = null;
this._frameKeys = null;
this.data = null;
this.textures = null;
if (destroyBase) {
this._texture?.destroy();
this.textureSource.destroy();
}
this._texture = null;
this.textureSource = null;
this.linkedSheets = [];
}
};
/** The maximum number of Textures to build per process. */
_Spritesheet.BATCH_SIZE = 1e3;
let Spritesheet = _Spritesheet;
exports.Spritesheet = Spritesheet;
//# sourceMappingURL=Spritesheet.js.map

File diff suppressed because one or more lines are too long

162
node_modules/pixi.js/lib/spritesheet/Spritesheet.mjs generated vendored Normal file
View File

@@ -0,0 +1,162 @@
import { Rectangle } from '../maths/shapes/Rectangle.mjs';
import { Texture } from '../rendering/renderers/shared/texture/Texture.mjs';
"use strict";
const _Spritesheet = class _Spritesheet {
/**
* @param texture - Reference to the source BaseTexture object.
* @param {object} data - Spritesheet image data.
*/
constructor(texture, data) {
/** For multi-packed spritesheets, this contains a reference to all the other spritesheets it depends on. */
this.linkedSheets = [];
this._texture = texture instanceof Texture ? texture : null;
this.textureSource = texture.source;
this.textures = {};
this.animations = {};
this.data = data;
const metaResolution = parseFloat(data.meta.scale);
if (metaResolution) {
this.resolution = metaResolution;
texture.source.resolution = this.resolution;
} else {
this.resolution = texture.source._resolution;
}
this._frames = this.data.frames;
this._frameKeys = Object.keys(this._frames);
this._batchIndex = 0;
this._callback = null;
}
/**
* Parser spritesheet from loaded data. This is done asynchronously
* to prevent creating too many Texture within a single process.
*/
parse() {
return new Promise((resolve) => {
this._callback = resolve;
this._batchIndex = 0;
if (this._frameKeys.length <= _Spritesheet.BATCH_SIZE) {
this._processFrames(0);
this._processAnimations();
this._parseComplete();
} else {
this._nextBatch();
}
});
}
/**
* Process a batch of frames
* @param initialFrameIndex - The index of frame to start.
*/
_processFrames(initialFrameIndex) {
let frameIndex = initialFrameIndex;
const maxFrames = _Spritesheet.BATCH_SIZE;
while (frameIndex - initialFrameIndex < maxFrames && frameIndex < this._frameKeys.length) {
const i = this._frameKeys[frameIndex];
const data = this._frames[i];
const rect = data.frame;
if (rect) {
let frame = null;
let trim = null;
const sourceSize = data.trimmed !== false && data.sourceSize ? data.sourceSize : data.frame;
const orig = new Rectangle(
0,
0,
Math.floor(sourceSize.w) / this.resolution,
Math.floor(sourceSize.h) / this.resolution
);
if (data.rotated) {
frame = new Rectangle(
Math.floor(rect.x) / this.resolution,
Math.floor(rect.y) / this.resolution,
Math.floor(rect.h) / this.resolution,
Math.floor(rect.w) / this.resolution
);
} else {
frame = new Rectangle(
Math.floor(rect.x) / this.resolution,
Math.floor(rect.y) / this.resolution,
Math.floor(rect.w) / this.resolution,
Math.floor(rect.h) / this.resolution
);
}
if (data.trimmed !== false && data.spriteSourceSize) {
trim = new Rectangle(
Math.floor(data.spriteSourceSize.x) / this.resolution,
Math.floor(data.spriteSourceSize.y) / this.resolution,
Math.floor(rect.w) / this.resolution,
Math.floor(rect.h) / this.resolution
);
}
this.textures[i] = new Texture({
source: this.textureSource,
frame,
orig,
trim,
rotate: data.rotated ? 2 : 0,
defaultAnchor: data.anchor,
defaultBorders: data.borders,
label: i.toString()
});
}
frameIndex++;
}
}
/** Parse animations config. */
_processAnimations() {
const animations = this.data.animations || {};
for (const animName in animations) {
this.animations[animName] = [];
for (let i = 0; i < animations[animName].length; i++) {
const frameName = animations[animName][i];
this.animations[animName].push(this.textures[frameName]);
}
}
}
/** The parse has completed. */
_parseComplete() {
const callback = this._callback;
this._callback = null;
this._batchIndex = 0;
callback.call(this, this.textures);
}
/** Begin the next batch of textures. */
_nextBatch() {
this._processFrames(this._batchIndex * _Spritesheet.BATCH_SIZE);
this._batchIndex++;
setTimeout(() => {
if (this._batchIndex * _Spritesheet.BATCH_SIZE < this._frameKeys.length) {
this._nextBatch();
} else {
this._processAnimations();
this._parseComplete();
}
}, 0);
}
/**
* Destroy Spritesheet and don't use after this.
* @param {boolean} [destroyBase=false] - Whether to destroy the base texture as well
*/
destroy(destroyBase = false) {
for (const i in this.textures) {
this.textures[i].destroy();
}
this._frames = null;
this._frameKeys = null;
this.data = null;
this.textures = null;
if (destroyBase) {
this._texture?.destroy();
this.textureSource.destroy();
}
this._texture = null;
this.textureSource = null;
this.linkedSheets = [];
}
};
/** The maximum number of Textures to build per process. */
_Spritesheet.BATCH_SIZE = 1e3;
let Spritesheet = _Spritesheet;
export { Spritesheet };
//# sourceMappingURL=Spritesheet.mjs.map

File diff suppressed because one or more lines are too long

2
node_modules/pixi.js/lib/spritesheet/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from './Spritesheet';
export * from './spritesheetAsset';

10
node_modules/pixi.js/lib/spritesheet/index.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
'use strict';
var Spritesheet = require('./Spritesheet.js');
var spritesheetAsset = require('./spritesheetAsset.js');
"use strict";
exports.Spritesheet = Spritesheet.Spritesheet;
exports.spritesheetAsset = spritesheetAsset.spritesheetAsset;
//# sourceMappingURL=index.js.map

1
node_modules/pixi.js/lib/spritesheet/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}

5
node_modules/pixi.js/lib/spritesheet/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,5 @@
export { Spritesheet } from './Spritesheet.mjs';
export { spritesheetAsset } from './spritesheetAsset.mjs';
"use strict";
//# sourceMappingURL=index.mjs.map

1
node_modules/pixi.js/lib/spritesheet/index.mjs.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}

1
node_modules/pixi.js/lib/spritesheet/init.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export {};

8
node_modules/pixi.js/lib/spritesheet/init.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
'use strict';
var Extensions = require('../extensions/Extensions.js');
var spritesheetAsset = require('./spritesheetAsset.js');
"use strict";
Extensions.extensions.add(spritesheetAsset.spritesheetAsset);
//# sourceMappingURL=init.js.map

1
node_modules/pixi.js/lib/spritesheet/init.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"init.js","sources":["../../src/spritesheet/init.ts"],"sourcesContent":["import { extensions } from '../extensions/Extensions';\nimport { spritesheetAsset } from './spritesheetAsset';\n\nextensions.add(spritesheetAsset);\n"],"names":["extensions","spritesheetAsset"],"mappings":";;;;;;AAGAA,qBAAA,CAAW,IAAIC,iCAAgB,CAAA;;"}

6
node_modules/pixi.js/lib/spritesheet/init.mjs generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import { extensions } from '../extensions/Extensions.mjs';
import { spritesheetAsset } from './spritesheetAsset.mjs';
"use strict";
extensions.add(spritesheetAsset);
//# sourceMappingURL=init.mjs.map

1
node_modules/pixi.js/lib/spritesheet/init.mjs.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"init.mjs","sources":["../../src/spritesheet/init.ts"],"sourcesContent":["import { extensions } from '../extensions/Extensions';\nimport { spritesheetAsset } from './spritesheetAsset';\n\nextensions.add(spritesheetAsset);\n"],"names":[],"mappings":";;;;AAGA,UAAA,CAAW,IAAI,gBAAgB,CAAA"}

View File

@@ -0,0 +1,71 @@
import { LoaderParserPriority } from '../assets/loader/parsers/LoaderParser';
import { ExtensionType } from '../extensions/Extensions';
import { Texture } from '../rendering/renderers/shared/texture/Texture';
import { Spritesheet } from './Spritesheet';
import type { Loader } from '../assets/loader/Loader';
import type { ResolvedAsset } from '../assets/types';
import type { SpritesheetData } from './Spritesheet';
export interface SpriteSheetJson extends SpritesheetData {
meta: {
image: string;
scale: string;
related_multi_packs?: string[];
};
}
/**
* Asset extension for loading spritesheets
* @example
* import { Assets } from 'pixi.js';
*
* Assets.load({
* alias: 'spritesheet',
* src: 'path/to/spritesheet.json',
* data: {
* ignoreMultiPack: true,
* }
* })
* @type {AssetExtension}
* @memberof assets
*/
export declare const spritesheetAsset: {
extension: ExtensionType.Asset;
/** Handle the caching of the related Spritesheet Textures */
cache: {
test: (asset: Spritesheet) => boolean;
getCacheableAssets: (keys: string[], asset: Spritesheet) => Record<string, any>;
};
/** Resolve the resolution of the asset. */
resolver: {
extension: {
type: ExtensionType.ResolveParser;
name: string;
};
test: (value: string) => boolean;
parse: (value: string) => {
resolution: number;
format: string;
src: string;
};
};
/**
* Loader plugin that parses sprite sheets!
* once the JSON has been loaded this checks to see if the JSON is spritesheet data.
* If it is, we load the spritesheets image and parse the data into Spritesheet
* All textures in the sprite sheet are then added to the cache
*/
loader: {
name: string;
extension: {
type: ExtensionType.LoadParser;
priority: LoaderParserPriority;
name: string;
};
testParse(asset: SpriteSheetJson, options: ResolvedAsset): Promise<boolean>;
parse<T>(asset: SpriteSheetJson, options: ResolvedAsset<{
texture?: Texture;
imageFilename?: string;
ignoreMultiPack?: boolean;
}>, loader?: Loader): Promise<Spritesheet>;
unload(spritesheet: Spritesheet, _resolvedAsset: ResolvedAsset<any>, loader: Loader): Promise<void>;
};
};

View File

@@ -0,0 +1,151 @@
'use strict';
var LoaderParser = require('../assets/loader/parsers/LoaderParser.js');
var Resolver = require('../assets/resolver/Resolver.js');
var copySearchParams = require('../assets/utils/copySearchParams.js');
var Extensions = require('../extensions/Extensions.js');
var Texture = require('../rendering/renderers/shared/texture/Texture.js');
var path = require('../utils/path.js');
var Spritesheet = require('./Spritesheet.js');
"use strict";
const validImages = [
"jpg",
"png",
"jpeg",
"avif",
"webp",
"basis",
"etc2",
"bc7",
"bc6h",
"bc5",
"bc4",
"bc3",
"bc2",
"bc1",
"eac",
"astc"
];
function getCacheableAssets(keys, asset, ignoreMultiPack) {
const out = {};
keys.forEach((key) => {
out[key] = asset;
});
Object.keys(asset.textures).forEach((key) => {
out[key] = asset.textures[key];
});
if (!ignoreMultiPack) {
const basePath = path.path.dirname(keys[0]);
asset.linkedSheets.forEach((item, i) => {
const out2 = getCacheableAssets([`${basePath}/${asset.data.meta.related_multi_packs[i]}`], item, true);
Object.assign(out, out2);
});
}
return out;
}
const spritesheetAsset = {
extension: Extensions.ExtensionType.Asset,
/** Handle the caching of the related Spritesheet Textures */
cache: {
test: (asset) => asset instanceof Spritesheet.Spritesheet,
getCacheableAssets: (keys, asset) => getCacheableAssets(keys, asset, false)
},
/** Resolve the resolution of the asset. */
resolver: {
extension: {
type: Extensions.ExtensionType.ResolveParser,
name: "resolveSpritesheet"
},
test: (value) => {
const tempURL = value.split("?")[0];
const split = tempURL.split(".");
const extension = split.pop();
const format = split.pop();
return extension === "json" && validImages.includes(format);
},
parse: (value) => {
const split = value.split(".");
return {
resolution: parseFloat(Resolver.Resolver.RETINA_PREFIX.exec(value)?.[1] ?? "1"),
format: split[split.length - 2],
src: value
};
}
},
/**
* Loader plugin that parses sprite sheets!
* once the JSON has been loaded this checks to see if the JSON is spritesheet data.
* If it is, we load the spritesheets image and parse the data into Spritesheet
* All textures in the sprite sheet are then added to the cache
*/
loader: {
name: "spritesheetLoader",
extension: {
type: Extensions.ExtensionType.LoadParser,
priority: LoaderParser.LoaderParserPriority.Normal,
name: "spritesheetLoader"
},
async testParse(asset, options) {
return path.path.extname(options.src).toLowerCase() === ".json" && !!asset.frames;
},
async parse(asset, options, loader) {
const {
texture: imageTexture,
// if user need to use preloaded texture
imageFilename
// if user need to use custom filename (not from jsonFile.meta.image)
} = options?.data ?? {};
let basePath = path.path.dirname(options.src);
if (basePath && basePath.lastIndexOf("/") !== basePath.length - 1) {
basePath += "/";
}
let texture;
if (imageTexture instanceof Texture.Texture) {
texture = imageTexture;
} else {
const imagePath = copySearchParams.copySearchParams(basePath + (imageFilename ?? asset.meta.image), options.src);
const assets = await loader.load([imagePath]);
texture = assets[imagePath];
}
const spritesheet = new Spritesheet.Spritesheet(
texture.source,
asset
);
await spritesheet.parse();
const multiPacks = asset?.meta?.related_multi_packs;
if (Array.isArray(multiPacks)) {
const promises = [];
for (const item of multiPacks) {
if (typeof item !== "string") {
continue;
}
let itemUrl = basePath + item;
if (options.data?.ignoreMultiPack) {
continue;
}
itemUrl = copySearchParams.copySearchParams(itemUrl, options.src);
promises.push(loader.load({
src: itemUrl,
data: {
ignoreMultiPack: true
}
}));
}
const res = await Promise.all(promises);
spritesheet.linkedSheets = res;
res.forEach((item) => {
item.linkedSheets = [spritesheet].concat(spritesheet.linkedSheets.filter((sp) => sp !== item));
});
}
return spritesheet;
},
async unload(spritesheet, _resolvedAsset, loader) {
await loader.unload(spritesheet.textureSource._sourceOrigin);
spritesheet.destroy(false);
}
}
};
exports.spritesheetAsset = spritesheetAsset;
//# sourceMappingURL=spritesheetAsset.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,149 @@
import { LoaderParserPriority } from '../assets/loader/parsers/LoaderParser.mjs';
import { Resolver } from '../assets/resolver/Resolver.mjs';
import { copySearchParams } from '../assets/utils/copySearchParams.mjs';
import { ExtensionType } from '../extensions/Extensions.mjs';
import { Texture } from '../rendering/renderers/shared/texture/Texture.mjs';
import { path } from '../utils/path.mjs';
import { Spritesheet } from './Spritesheet.mjs';
"use strict";
const validImages = [
"jpg",
"png",
"jpeg",
"avif",
"webp",
"basis",
"etc2",
"bc7",
"bc6h",
"bc5",
"bc4",
"bc3",
"bc2",
"bc1",
"eac",
"astc"
];
function getCacheableAssets(keys, asset, ignoreMultiPack) {
const out = {};
keys.forEach((key) => {
out[key] = asset;
});
Object.keys(asset.textures).forEach((key) => {
out[key] = asset.textures[key];
});
if (!ignoreMultiPack) {
const basePath = path.dirname(keys[0]);
asset.linkedSheets.forEach((item, i) => {
const out2 = getCacheableAssets([`${basePath}/${asset.data.meta.related_multi_packs[i]}`], item, true);
Object.assign(out, out2);
});
}
return out;
}
const spritesheetAsset = {
extension: ExtensionType.Asset,
/** Handle the caching of the related Spritesheet Textures */
cache: {
test: (asset) => asset instanceof Spritesheet,
getCacheableAssets: (keys, asset) => getCacheableAssets(keys, asset, false)
},
/** Resolve the resolution of the asset. */
resolver: {
extension: {
type: ExtensionType.ResolveParser,
name: "resolveSpritesheet"
},
test: (value) => {
const tempURL = value.split("?")[0];
const split = tempURL.split(".");
const extension = split.pop();
const format = split.pop();
return extension === "json" && validImages.includes(format);
},
parse: (value) => {
const split = value.split(".");
return {
resolution: parseFloat(Resolver.RETINA_PREFIX.exec(value)?.[1] ?? "1"),
format: split[split.length - 2],
src: value
};
}
},
/**
* Loader plugin that parses sprite sheets!
* once the JSON has been loaded this checks to see if the JSON is spritesheet data.
* If it is, we load the spritesheets image and parse the data into Spritesheet
* All textures in the sprite sheet are then added to the cache
*/
loader: {
name: "spritesheetLoader",
extension: {
type: ExtensionType.LoadParser,
priority: LoaderParserPriority.Normal,
name: "spritesheetLoader"
},
async testParse(asset, options) {
return path.extname(options.src).toLowerCase() === ".json" && !!asset.frames;
},
async parse(asset, options, loader) {
const {
texture: imageTexture,
// if user need to use preloaded texture
imageFilename
// if user need to use custom filename (not from jsonFile.meta.image)
} = options?.data ?? {};
let basePath = path.dirname(options.src);
if (basePath && basePath.lastIndexOf("/") !== basePath.length - 1) {
basePath += "/";
}
let texture;
if (imageTexture instanceof Texture) {
texture = imageTexture;
} else {
const imagePath = copySearchParams(basePath + (imageFilename ?? asset.meta.image), options.src);
const assets = await loader.load([imagePath]);
texture = assets[imagePath];
}
const spritesheet = new Spritesheet(
texture.source,
asset
);
await spritesheet.parse();
const multiPacks = asset?.meta?.related_multi_packs;
if (Array.isArray(multiPacks)) {
const promises = [];
for (const item of multiPacks) {
if (typeof item !== "string") {
continue;
}
let itemUrl = basePath + item;
if (options.data?.ignoreMultiPack) {
continue;
}
itemUrl = copySearchParams(itemUrl, options.src);
promises.push(loader.load({
src: itemUrl,
data: {
ignoreMultiPack: true
}
}));
}
const res = await Promise.all(promises);
spritesheet.linkedSheets = res;
res.forEach((item) => {
item.linkedSheets = [spritesheet].concat(spritesheet.linkedSheets.filter((sp) => sp !== item));
});
}
return spritesheet;
},
async unload(spritesheet, _resolvedAsset, loader) {
await loader.unload(spritesheet.textureSource._sourceOrigin);
spritesheet.destroy(false);
}
}
};
export { spritesheetAsset };
//# sourceMappingURL=spritesheetAsset.mjs.map

File diff suppressed because one or more lines are too long