mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[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:
parent
c2f7c7e0fc
commit
4892bceb66
@ -255,8 +255,24 @@ enum SpineSkeletonDataFileType {
|
|||||||
binary
|
binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SpineSkeletonDataFileConfig {
|
||||||
|
key: string;
|
||||||
|
url: string;
|
||||||
|
type: "spineJson" | "spineBinary";
|
||||||
|
xhrSettings?: Phaser.Types.Loader.XHRSettingsObject
|
||||||
|
}
|
||||||
|
|
||||||
class SpineSkeletonDataFile extends Phaser.Loader.MultiFile {
|
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 file = null;
|
||||||
let isJson = fileType == SpineSkeletonDataFileType.json;
|
let isJson = fileType == SpineSkeletonDataFileType.json;
|
||||||
if (isJson) {
|
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 {
|
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, [
|
super(loader, SPINE_ATLAS_FILE_TYPE, key, [
|
||||||
new Phaser.Loader.FileTypes.TextFile(loader, {
|
new Phaser.Loader.FileTypes.TextFile(loader, {
|
||||||
key: key,
|
key: key,
|
||||||
@ -296,6 +328,8 @@ class SpineAtlasFile extends Phaser.Loader.MultiFile {
|
|||||||
extension: "atlas"
|
extension: "atlas"
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
this.premultipliedAlpha = premultipliedAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
onFileComplete (file: Phaser.Loader.File) {
|
onFileComplete (file: Phaser.Loader.File) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user