Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add getLoader method to SpineLoader, export atlas and spine loaders #525

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions packages/loader-base/src/SpineLoaderAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import { AssetExtension, checkExtension, LoadAsset, Loader, LoaderParserPriority
import { BaseTexture, extensions, ExtensionType, settings, Texture, utils } from '@pixi/core';
import { makeSpineTextureAtlasLoaderFunctionFromPixiLoaderObject } from './atlasLoader';

type SPINEJSON = any;
type SPINEBINARY = ArrayBuffer;
/**
* @public
*/
export type SPINEJSON = any;

/**
* @public
*/
export type SPINEBINARY = ArrayBuffer;

function isJson(resource: unknown): resource is SPINEJSON {
return resource.hasOwnProperty('bones');
Expand All @@ -27,10 +34,11 @@ export abstract class SpineLoaderAbstract<SKD extends ISkeletonData> {

abstract parseData(parser: ISkeletonParser, atlas: TextureAtlas, dataToParse: any): ISpineResource<SKD>;

public installLoader(): any {
public getLoader(): AssetExtension<SPINEJSON | SPINEBINARY | ISpineResource<SKD>, ISpineMetadata> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const spineAdapter = this;
const spineLoaderExtension: AssetExtension<SPINEJSON | SPINEBINARY | ISpineResource<SKD>, ISpineMetadata> = {

return {
extension: ExtensionType.Asset,

loader: {
Expand Down Expand Up @@ -141,6 +149,10 @@ export abstract class SpineLoaderAbstract<SKD extends ISkeletonData> {
// },
},
} as AssetExtension<SPINEJSON | SPINEBINARY | ISpineResource<SKD>, ISpineMetadata>;
}

public installLoader(): any {
const spineLoaderExtension = this.getLoader();

extensions.add(spineLoaderExtension);

Expand Down
12 changes: 10 additions & 2 deletions packages/loader-base/src/atlasLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ import { type AssetExtension, LoaderParserPriority, LoadAsset, Loader, checkExte
import { BaseTexture, extensions, ExtensionType, settings, Texture, utils } from '@pixi/core';
import type { ISpineMetadata } from './SpineLoaderAbstract';

type RawAtlas = string;
/**
* Type of atlas file content.
* @public
*/
export type RawAtlas = string;

const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineMetadata> = {
/**
* This variable is used loader extension for atlas files loading.
* @public
*/
export const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineMetadata> = {
extension: ExtensionType.Asset,

// cache: {
Expand Down
1 change: 1 addition & 0 deletions packages/loader-uni/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// <reference path="../global.d.ts" />
import '@pixi-spine/loader-base'; // Side effect install atlas loader
import { SpineLoader } from './SpineLoader';
export { SpineLoader };
export * from './Spine';
export * from './versions';

Expand Down