[Phaser] Adds Asset Pack support (#2337)

* [Phaser] Adds Asset Pack support.

In Phaser you can use an Asset Pack manifest json file for loading the assets.

This PR adds Asset Pack support to the SpinePlugin.

* [Phaser] Update SpinePlugin.ts. Fixes code indentation.

Fixes code indentation of the previous commit.

* [Phaser] Uses typescript interface for loader file configurations.
This commit is contained in:
Phaser Editor 2D 2023-09-04 04:43:00 -04:00 committed by GitHub
parent c2f7c7e0fc
commit 4892bceb66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -255,8 +255,24 @@ enum SpineSkeletonDataFileType {
binary
}
interface SpineSkeletonDataFileConfig {
key: string;
url: string;
type: "spineJson" | "spineBinary";
xhrSettings?: Phaser.Types.Loader.XHRSettingsObject
}
class SpineSkeletonDataFile extends Phaser.Loader.MultiFile {
constructor (loader: Phaser.Loader.LoaderPlugin, key: string, url: string, public fileType: SpineSkeletonDataFileType, xhrSettings: Phaser.Types.Loader.XHRSettingsObject) {
constructor (loader: Phaser.Loader.LoaderPlugin, key: string | SpineSkeletonDataFileConfig, url?: string, public fileType?: SpineSkeletonDataFileType, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject) {
if (typeof key !== "string") {
const config = key;
key = config.key;
url = config.url;
fileType = config.type === "spineJson" ? SpineSkeletonDataFileType.json : SpineSkeletonDataFileType.binary;
xhrSettings = config.xhrSettings;
}
let file = null;
let isJson = fileType == SpineSkeletonDataFileType.json;
if (isJson) {
@ -286,8 +302,24 @@ class SpineSkeletonDataFile extends Phaser.Loader.MultiFile {
}
}
interface SpineAtlasFileConfig {
key: string;
url: string;
premultipliedAlpha?: boolean;
xhrSettings?: Phaser.Types.Loader.XHRSettingsObject;
}
class SpineAtlasFile extends Phaser.Loader.MultiFile {
constructor (loader: Phaser.Loader.LoaderPlugin, key: string, url: string, public premultipliedAlpha: boolean = true, xhrSettings: Phaser.Types.Loader.XHRSettingsObject) {
constructor (loader: Phaser.Loader.LoaderPlugin, key: string | SpineAtlasFileConfig, url?: string, public premultipliedAlpha: boolean = true, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject) {
if (typeof key !== "string") {
const config = key;
key = config.key;
url = config.url;
premultipliedAlpha = config.premultipliedAlpha ?? true;
xhrSettings = config.xhrSettings;
}
super(loader, SPINE_ATLAS_FILE_TYPE, key, [
new Phaser.Loader.FileTypes.TextFile(loader, {
key: key,
@ -296,6 +328,8 @@ class SpineAtlasFile extends Phaser.Loader.MultiFile {
extension: "atlas"
})
]);
this.premultipliedAlpha = premultipliedAlpha;
}
onFileComplete (file: Phaser.Loader.File) {