Skip to content

Commit

Permalink
🐛 Update DragonBones and fix issues with skeleton import
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoMyzrailGorynych committed Nov 25, 2019
1 parent 4d0554b commit 0e3b557
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion DragonBonesJS
Submodule DragonBonesJS updated 117 files
1 change: 1 addition & 0 deletions app/data/DragonBones.min.js

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/js/3rdparty/DragonBones.min.js

This file was deleted.

1 change: 1 addition & 0 deletions src/pug/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ html
void e;
}
script(src="node_modules/pixi.js/dist/pixi.min.js")
script(src="data/DragonBones.min.js")
script.
/* So that WebGL contexts are taken from one page,
even if PIXI was called from the background page,
Expand Down
44 changes: 26 additions & 18 deletions src/riotTags/textures-panel.tag
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,11 @@ textures-panel.panel.view
from: 'dragonbones',
uid: uid
})
this.skelGenPreview(dest, dest + '_prev.png', 64)
this.skelGenPreview(dest, dest + '_prev.png', [64, 128])
.then(dataUrl => {
this.updateList();
this.update();
});
this.skelGenPreview(dest, dest + '[email protected]', 128);
});
};
/**
Expand Down Expand Up @@ -324,32 +323,41 @@ textures-panel.panel.view
* @param {Number} size Size of the square thumbnail, in pixels
* @returns {Promise} Resolves after creating a thumbnail. On success, passes data-url of the created thumbnail.
*/
this.skelGenPreview = (source, destFile, size) => {
this.skelGenPreview = (source, destFile, sizes) => {
const loader = new PIXI.loaders.Loader(),
dbf = dragonBones.PixiFactory.factory;
const slice = source.replace('_ske.json', '');
const slice = 'file://' + source.replace('_ske.json', '');
return new Promise((resolve, reject) => {
loader.add(`${slice}_ske.json`, `${slice}_ske.json`)
.add(`${slice}_tex.json`, `${slice}_tex.json`)
.add(`${slice}_tex.png`, `${slice}_tex.png`);
loader.load(() => {
const app = new PIXI.Application();
dbf.parseDragonBonesData(loader.resources[`${slice}_ske.json`].data);
dbf.parseTextureAtlasData(loader.resources[`${slice}_tex.json`].data, loader.resources[`${slice}_tex.png`].texture);
const skel = dbf.buildArmatureDisplay('Armature', loader.resources[`${slice}_ske.json`].data.name);
const base64 = app.renderer.plugins.extract.base64(skel)
var data = base64.replace(/^data:image\/\w+;base64,/, '');;
var buf = new Buffer(data, 'base64');
var stream = fs.createWriteStream(destFile);
stream.on('finish', () => {
setTimeout(() => { // WHY THE HECK I EVER NEED THIS?!
resolve(destFile);
}, 100);
});
stream.on('error', err => {
reject(err);
});
stream.end(buf);
const promises = sizes.map(size => new Promise((resolve, reject) => {
const app = new PIXI.Application();
const base64 = app.renderer.plugins.extract.base64(skel)
const data = base64.replace(/^data:image\/\w+;base64,/, '');;
const buf = new Buffer(data, 'base64');
const stream = fs.createWriteStream(destFile);
stream.on('finish', () => {
setTimeout(() => { // WHY THE HECK I EVER NEED THIS?!
resolve(destFile);
}, 100);
});
stream.on('error', err => {
reject(err);
});
stream.end(buf);
}));
Promise.all(promises)
.then(() => {
delete dbf._dragonBonesDataMap[loader.resources[`${slice}_ske.json`].data.name];
delete dbf._textureAtlasDataMap[loader.resources[`${slice}_ske.json`].data.name];
})
.then(resolve)
.catch(reject);
});
});
};
Expand Down

0 comments on commit 0e3b557

Please sign in to comment.