From d8b9028210aa7ffe4c21098a222fc02f36a66467 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Fri, 15 Dec 2023 18:03:29 -0400 Subject: [PATCH] [ts][player] Added scale parameter to config. --- spine-ts/spine-player/src/Player.ts | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/spine-ts/spine-player/src/Player.ts b/spine-ts/spine-player/src/Player.ts index 8de7eecb8..9274eae3a 100644 --- a/spine-ts/spine-player/src/Player.ts +++ b/spine-ts/spine-player/src/Player.ts @@ -40,6 +40,9 @@ export interface SpinePlayerConfig { /* The URL of the skeleton binary file (.skel). Undefined if jsonUrl is given. */ binaryUrl?: string + /* The scale when loading the skeleton data. Default: 1 */ + scale?: number + /* The URL of the skeleton atlas file (.atlas). Atlas page images are automatically resolved. */ atlasUrl?: string @@ -284,6 +287,7 @@ export class SpinePlayer implements Disposable { if (!config) throw new Error("A configuration object must be passed to to new SpinePlayer()."); if ((config as any).skelUrl) config.binaryUrl = (config as any).skelUrl; if (!config.jsonUrl && !config.binaryUrl) throw new Error("A URL must be specified for the skeleton JSON or binary file."); + if (!config.scale) config.scale = 1; if (!config.atlasUrl) throw new Error("A URL must be specified for the atlas file."); if (!config.backgroundColor) config.backgroundColor = config.alpha ? "00000000" : "000000"; if (!config.fullScreenBackgroundColor) config.fullScreenBackgroundColor = config.backgroundColor; @@ -460,29 +464,25 @@ export class SpinePlayer implements Disposable { // Load skeleton data. let skeletonData: SkeletonData; - if (config.jsonUrl) { - try { - let jsonData = this.assetManager!.remove(config.jsonUrl); - if (!jsonData) throw new Error("Empty JSON data."); + try { + let loader: any, data: any, attachmentLoader = new AtlasAttachmentLoader(atlas); + if (config.jsonUrl) { + data = this.assetManager!.remove(config.jsonUrl); + if (!data) throw new Error("Empty JSON data."); if (config.jsonField) { - jsonData = jsonData[config.jsonField]; - if (!jsonData) throw new Error("JSON field does not exist: " + config.jsonField); + data = data[config.jsonField]; + if (!data) throw new Error("JSON field does not exist: " + config.jsonField); } - let json = new SkeletonJson(new AtlasAttachmentLoader(atlas)); - skeletonData = json.readSkeletonData(jsonData); - } catch (e) { - this.showError(`Error: Could not load skeleton JSON.\n${(e as any).message}`, e as any); - return; - } - } else { - let binaryData = this.assetManager!.remove(config.binaryUrl!); - let binary = new SkeletonBinary(new AtlasAttachmentLoader(atlas)); - try { - skeletonData = binary.readSkeletonData(binaryData); - } catch (e) { - this.showError(`Error: Could not load skeleton binary.\n${(e as any).message}`, e as any); - return; + loader = new SkeletonJson(attachmentLoader); + } else { + data = this.assetManager!.remove(config.binaryUrl!); + loader = new SkeletonBinary(attachmentLoader); } + loader.scale = config.scale; + skeletonData = loader.readSkeletonData(data); + } catch (e) { + this.showError(`Error: Could not load skeleton data.\n${(e as any).message}`, e as any); + return; } this.skeleton = new Skeleton(skeletonData); let stateData = new AnimationStateData(skeletonData);