Skip to content

Commit 143986f

Browse files
committed
New plugin build
1 parent 0c9f5f2 commit 143986f

2 files changed

Lines changed: 115 additions & 162 deletions

File tree

plugins/spine/dist/SpinePlugin.js

Lines changed: 114 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -11350,8 +11350,13 @@ var SpineFile = new Class({
1135011350

1135111351
function SpineFile (loader, key, jsonURL, atlasURL, jsonXhrSettings, atlasXhrSettings)
1135211352
{
11353+
var i;
1135311354
var json;
1135411355
var atlas;
11356+
var files = [];
11357+
var cache = loader.cacheManager.custom.spine;
11358+
11359+
// atlas can be an array of atlas files, not just a single one
1135511360

1135611361
if (IsPlainObject(key))
1135711362
{
@@ -11366,22 +11371,60 @@ var SpineFile = new Class({
1136611371
xhrSettings: GetFastValue(config, 'jsonXhrSettings')
1136711372
});
1136811373

11369-
atlas = new TextFile(loader, {
11370-
key: key,
11371-
url: GetFastValue(config, 'atlasURL'),
11372-
extension: GetFastValue(config, 'atlasExtension', 'atlas'),
11373-
xhrSettings: GetFastValue(config, 'atlasXhrSettings')
11374-
});
11374+
atlasURL = GetFastValue(config, 'atlasURL');
11375+
11376+
if (Array.isArray(atlasURL))
11377+
{
11378+
for (i = 0; i < atlasURL.length; i++)
11379+
{
11380+
atlas = new TextFile(loader, {
11381+
key: key,
11382+
url: atlasURL[i],
11383+
extension: GetFastValue(config, 'atlasExtension', 'atlas'),
11384+
xhrSettings: GetFastValue(config, 'atlasXhrSettings')
11385+
});
11386+
11387+
files.push(atlas);
11388+
}
11389+
}
11390+
else
11391+
{
11392+
atlas = new TextFile(loader, {
11393+
key: key,
11394+
url: atlasURL,
11395+
extension: GetFastValue(config, 'atlasExtension', 'atlas'),
11396+
xhrSettings: GetFastValue(config, 'atlasXhrSettings')
11397+
});
11398+
11399+
files.push(atlas);
11400+
}
1137511401
}
1137611402
else
1137711403
{
1137811404
json = new JSONFile(loader, key, jsonURL, jsonXhrSettings);
11379-
atlas = new TextFile(loader, key, atlasURL, atlasXhrSettings);
11405+
11406+
if (Array.isArray(atlasURL))
11407+
{
11408+
for (i = 0; i < atlasURL.length; i++)
11409+
{
11410+
atlas = new TextFile(loader, key + '_' + i, atlasURL[i], atlasXhrSettings);
11411+
atlas.cache = cache;
11412+
11413+
files.push(atlas);
11414+
}
11415+
}
11416+
else
11417+
{
11418+
atlas = new TextFile(loader, key + '_0', atlasURL, atlasXhrSettings);
11419+
atlas.cache = cache;
11420+
11421+
files.push(atlas);
11422+
}
1138011423
}
11381-
11382-
atlas.cache = loader.cacheManager.custom.spine;
1138311424

11384-
MultiFile.call(this, loader, 'spine', key, [ json, atlas ]);
11425+
files.unshift(json);
11426+
11427+
MultiFile.call(this, loader, 'spine', key, files);
1138511428
},
1138611429

1138711430
/**
@@ -11471,153 +11514,39 @@ var SpineFile = new Class({
1147111514

1147211515
fileJSON.addToCache();
1147311516

11474-
var fileText = this.files[1];
11475-
11476-
fileText.addToCache();
11517+
var atlasCache;
11518+
var atlasKey = '';
11519+
var combinedAtlastData = '';
1147711520

11478-
for (var i = 2; i < this.files.length; i++)
11521+
for (var i = 1; i < this.files.length; i++)
1147911522
{
1148011523
var file = this.files[i];
1148111524

11482-
var key = file.key.substr(4).trim();
11525+
if (file.type === 'text')
11526+
{
11527+
atlasKey = file.key.substr(0, file.key.length - 2);
1148311528

11484-
this.loader.textureManager.addImage(key, file.data);
11529+
atlasCache = file.cache;
11530+
11531+
combinedAtlastData = combinedAtlastData.concat(file.data);
11532+
}
11533+
else
11534+
{
11535+
var key = file.key.substr(4).trim();
11536+
11537+
this.loader.textureManager.addImage(key, file.data);
11538+
}
1148511539

1148611540
file.pendingDestroy();
1148711541
}
1148811542

11489-
this.complete = true;
11490-
}
11491-
}
11543+
atlasCache.add(atlasKey, combinedAtlastData);
1149211544

11493-
});
11494-
11495-
/**
11496-
* Adds a Unity YAML based Texture Atlas, or array of atlases, to the current load queue.
11497-
*
11498-
* You can call this method from within your Scene's `preload`, along with any other files you wish to load:
11499-
*
11500-
* ```javascript
11501-
* function preload ()
11502-
* {
11503-
* this.load.unityAtlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.txt');
11504-
* }
11505-
* ```
11506-
*
11507-
* The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts,
11508-
* or if it's already running, when the next free load slot becomes available. This happens automatically if you
11509-
* are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued
11510-
* it means you cannot use the file immediately after calling this method, but must wait for the file to complete.
11511-
* The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the
11512-
* Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been
11513-
* loaded.
11514-
*
11515-
* If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring
11516-
* its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details.
11517-
*
11518-
* Phaser expects the atlas data to be provided in a YAML formatted text file as exported from Unity.
11519-
*
11520-
* Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle.
11521-
*
11522-
* The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load.
11523-
* The key should be unique both in terms of files being loaded and files already present in the Texture Manager.
11524-
* Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file
11525-
* then remove it from the Texture Manager first, before loading a new one.
11526-
*
11527-
* Instead of passing arguments you can pass a configuration object, such as:
11528-
*
11529-
* ```javascript
11530-
* this.load.unityAtlas({
11531-
* key: 'mainmenu',
11532-
* textureURL: 'images/MainMenu.png',
11533-
* atlasURL: 'images/MainMenu.txt'
11534-
* });
11535-
* ```
11536-
*
11537-
* See the documentation for `Phaser.Loader.FileTypes.SpineFileConfig` for more details.
11538-
*
11539-
* Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key:
11540-
*
11541-
* ```javascript
11542-
* this.load.unityAtlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json');
11543-
* // and later in your game ...
11544-
* this.add.image(x, y, 'mainmenu', 'background');
11545-
* ```
11546-
*
11547-
* To get a list of all available frames within an atlas please consult your Texture Atlas software.
11548-
*
11549-
* If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files
11550-
* key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and
11551-
* this is what you would use to retrieve the image from the Texture Manager.
11552-
*
11553-
* The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it.
11554-
*
11555-
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien"
11556-
* and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although
11557-
* this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL.
11558-
*
11559-
* Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image,
11560-
* then you can specify it by providing an array as the `url` where the second element is the normal map:
11561-
*
11562-
* ```javascript
11563-
* this.load.unityAtlas('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.txt');
11564-
* ```
11565-
*
11566-
* Or, if you are using a config object use the `normalMap` property:
11567-
*
11568-
* ```javascript
11569-
* this.load.unityAtlas({
11570-
* key: 'mainmenu',
11571-
* textureURL: 'images/MainMenu.png',
11572-
* normalMap: 'images/MainMenu-n.png',
11573-
* atlasURL: 'images/MainMenu.txt'
11574-
* });
11575-
* ```
11576-
*
11577-
* The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings.
11578-
* Normal maps are a WebGL only feature.
11579-
*
11580-
* Note: The ability to load this type of file will only be available if the Unity Atlas File type has been built into Phaser.
11581-
* It is available in the default build but can be excluded from custom builds.
11582-
*
11583-
* @method Phaser.Loader.LoaderPlugin#spine
11584-
* @fires Phaser.Loader.LoaderPlugin#addFileEvent
11585-
* @since 3.16.0
11586-
*
11587-
* @param {(string|Phaser.Loader.FileTypes.SpineFileConfig|Phaser.Loader.FileTypes.SpineFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them.
11588-
* @param {string|string[]} [textureURL] - The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `<key>.png`, i.e. if `key` was "alien" then the URL will be "alien.png".
11589-
* @param {string} [atlasURL] - The absolute or relative URL to load the texture atlas data file from. If undefined or `null` it will be set to `<key>.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt".
11590-
* @param {XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings.
11591-
* @param {XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the atlas data file. Used in replacement of the Loaders default XHR Settings.
11592-
*
11593-
* @return {Phaser.Loader.LoaderPlugin} The Loader instance.
11594-
FileTypesManager.register('spine', function (key, jsonURL, atlasURL, jsonXhrSettings, atlasXhrSettings)
11595-
{
11596-
var multifile;
11597-
11598-
// Supports an Object file definition in the key argument
11599-
// Or an array of objects in the key argument
11600-
// Or a single entry where all arguments have been defined
11601-
11602-
if (Array.isArray(key))
11603-
{
11604-
for (var i = 0; i < key.length; i++)
11605-
{
11606-
multifile = new SpineFile(this, key[i]);
11607-
11608-
this.addFile(multifile.files);
11545+
this.complete = true;
1160911546
}
1161011547
}
11611-
else
11612-
{
11613-
multifile = new SpineFile(this, key, jsonURL, atlasURL, jsonXhrSettings, atlasXhrSettings);
1161411548

11615-
this.addFile(multifile.files);
11616-
}
11617-
11618-
return this;
1161911549
});
11620-
*/
1162111550

1162211551
module.exports = SpineFile;
1162311552

@@ -11787,6 +11716,8 @@ var SpinePlugin = new Class({
1178711716

1178811717
this.skeletonRenderer = new runtime.SkeletonRenderer(gl);
1178911718

11719+
this.skeletonRenderer.premultipliedAlpha = true;
11720+
1179011721
this.shapes = new runtime.ShapeRenderer(gl);
1179111722

1179211723
this.debugRenderer = new runtime.SkeletonDebugRenderer(gl);
@@ -11822,7 +11753,7 @@ var SpinePlugin = new Class({
1182211753

1182311754
atlas = new Spine.TextureAtlas(atlasData, function (path)
1182411755
{
11825-
var glTexture = new Spine.webgl.GLTexture(gl, textures.get(path).getSourceImage());
11756+
var glTexture = new Spine.webgl.GLTexture(gl, textures.get(path).getSourceImage(), false);
1182611757

1182711758
spineTextures.add(key, glTexture);
1182811759

@@ -12024,7 +11955,9 @@ var ComponentsFlip = __webpack_require__(/*! ../../../../src/gameobjects/compone
1202411955
var ComponentsScrollFactor = __webpack_require__(/*! ../../../../src/gameobjects/components/ScrollFactor */ "../../../src/gameobjects/components/ScrollFactor.js");
1202511956
var ComponentsTransform = __webpack_require__(/*! ../../../../src/gameobjects/components/Transform */ "../../../src/gameobjects/components/Transform.js");
1202611957
var ComponentsVisible = __webpack_require__(/*! ../../../../src/gameobjects/components/Visible */ "../../../src/gameobjects/components/Visible.js");
11958+
var CounterClockwise = __webpack_require__(/*! ../../../../src/math/angle/CounterClockwise */ "../../../src/math/angle/CounterClockwise.js");
1202711959
var GameObject = __webpack_require__(/*! ../../../../src/gameobjects/GameObject */ "../../../src/gameobjects/GameObject.js");
11960+
var RadToDeg = __webpack_require__(/*! ../../../../src/math/RadToDeg */ "../../../src/math/RadToDeg.js");
1202811961
var SpineGameObjectRender = __webpack_require__(/*! ./SpineGameObjectRender */ "./gameobject/SpineGameObjectRender.js");
1202911962

1203011963
/**
@@ -12097,13 +12030,8 @@ var SpineGameObject = new Class({
1209712030

1209812031
var skeleton = data.skeleton;
1209912032

12100-
skeleton.setToSetupPose();
12101-
12102-
skeleton.updateWorldTransform();
12103-
1210412033
skeleton.setSkinByName('default');
12105-
12106-
this.skeleton = skeleton;
12034+
skeleton.setToSetupPose();
1210712035

1210812036
// AnimationState
1210912037
data = this.plugin.createAnimationState(skeleton);
@@ -12148,21 +12076,42 @@ var SpineGameObject = new Class({
1214812076
this.setAnimation(0, animationName, loop);
1214912077
}
1215012078

12079+
var renderer = this.scene.sys.renderer;
12080+
12081+
var height = renderer.height;
12082+
12083+
var oldScaleX = this.scaleX;
12084+
var oldScaleY = this.scaleY;
12085+
12086+
skeleton.x = this.x;
12087+
skeleton.y = height - this.y;
12088+
skeleton.scaleX = 1;
12089+
skeleton.scaleY = 1;
12090+
12091+
this.skeleton = skeleton;
12092+
1215112093
this.root = this.getRootBone();
12094+
12095+
if (this.root)
12096+
{
12097+
// - 90 degrees to account for the difference in Spine vs. Phaser rotation
12098+
this.root.rotation = RadToDeg(CounterClockwise(this.rotation - 1.5707963267948966));
12099+
}
1215212100

12153-
this.skeleton.scaleX = this.scaleX;
12154-
this.skeleton.scaleY = this.scaleY;
12101+
skeleton.updateWorldTransform();
1215512102

12156-
this.skeleton.updateWorldTransform();
12103+
var b = this.getBounds();
1215712104

12158-
var w = this.skeletonData.width;
12159-
var h = this.skeletonData.height;
12105+
this.width = b.size.x;
12106+
this.height = b.size.y;
1216012107

12161-
this.width = w;
12162-
this.height = h;
12108+
this.displayOriginX = this.x - b.offset.x;
12109+
this.displayOriginY = this.y - (height - (this.height + b.offset.y));
1216312110

12164-
this.displayOriginX = w / 2;
12165-
this.displayOriginY = h / 2;
12111+
skeleton.scaleX = oldScaleX;
12112+
skeleton.scaleY = oldScaleY;
12113+
12114+
skeleton.updateWorldTransform();
1216612115

1216712116
return this;
1216812117
},
@@ -12281,6 +12230,11 @@ var SpineGameObject = new Class({
1228112230
return this.skeleton.findSlotIndex(slotName);
1228212231
},
1228312232

12233+
// getBounds ( 2-tuple offset, 2-tuple size, float[] temp): void
12234+
// Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
12235+
// offset An output value, the distance from the skeleton origin to the bottom left corner of the AABB.
12236+
// size An output value, the width and height of the AABB.
12237+
1228412238
getBounds: function ()
1228512239
{
1228612240
return this.plugin.getBounds(this.skeleton);
@@ -12547,8 +12501,6 @@ var SpineGameObjectWebGLRenderer = function (renderer, src, interpolationPercent
1254712501
shader.setUniform4x4f(runtime.Shader.MVP_MATRIX, mvp.val);
1254812502

1254912503
batcher.begin(shader);
12550-
12551-
skeletonRenderer.premultipliedAlpha = true;
1255212504
}
1255312505

1255412506
if (renderer.nextTypeMatch)
@@ -12557,6 +12509,7 @@ var SpineGameObjectWebGLRenderer = function (renderer, src, interpolationPercent
1255712509
}
1255812510

1255912511
// Draw the current skeleton
12512+
skeletonRenderer.premultipliedAlpha = true;
1256012513
skeletonRenderer.draw(batcher, skeleton);
1256112514

1256212515
if (!renderer.nextTypeMatch)

plugins/spine/dist/SpinePlugin.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)