From 84c2648affa1ad5e76fa4ca3c57b6af7f910d04b Mon Sep 17 00:00:00 2001 From: bchevalier Date: Fri, 17 Jul 2015 19:03:29 +0900 Subject: [PATCH] * Timeline now export frames correctly --- HISTORY.md | 3 ++ README.md | 2 +- lib/Gordon/parser.js | 6 ++- lib/SwfObjectProcessor/generateChildren.js | 63 +++++++++++----------- package.json | 2 +- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index bc2c78e..027ced3 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,8 @@ # Release history +## v0.1.9 +Fixed export of drawings that last several frames + ## v0.1.8 Fixed badly handled case when only one frame has to be prerendered and exported into an atlas diff --git a/README.md b/README.md index 1039f77..7270c76 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ For use as an api: ## Use Command line: - `jeff -src mySwf.swf` + `jeff -s mySwf.swf` API: ``` diff --git a/lib/Gordon/parser.js b/lib/Gordon/parser.js index 973e606..aaa5d2a 100644 --- a/lib/Gordon/parser.js +++ b/lib/Gordon/parser.js @@ -171,7 +171,7 @@ SwfParser.prototype = { var timeline = []; var sprite = { type: 'sprite', - frameCount: frameCount, //maybe useless since it is equal to timeline.length + frameCount: frameCount, id: id, timeline: timeline }; @@ -195,7 +195,9 @@ SwfParser.prototype = { else { this._handleUnhandledTag(handle, code, stream, stream.offset, len, frm); } if (this.aborting) return null; }while (code); - if (numTags > 0) timeline.push(frm); + if (code !== 0) { + timeline.push(frm); + } }while (code); this.onData(sprite); this._dictionary[id] = sprite; diff --git a/lib/SwfObjectProcessor/generateChildren.js b/lib/SwfObjectProcessor/generateChildren.js index 3333e81..6ba65c8 100644 --- a/lib/SwfObjectProcessor/generateChildren.js +++ b/lib/SwfObjectProcessor/generateChildren.js @@ -234,47 +234,50 @@ function generateChildren(symbol, symbols) { var depths = {}; // Contains element mapped by depth var depth, d, depthArray, nDepths; var timeline = symbol.swfObject.timeline; - var duration = timeline.length; + // var duration = timeline.length; + var duration = symbol.duration; for (f = 0; f < duration; f += 1) { - var displayList = timeline[f].displayList; - var morphedShapeReplacements = []; - for (d = 0, depthArray = Object.keys(displayList), nDepths = depthArray.length; d < nDepths; d += 1) { - depth = depthArray[d]; - objectData = displayList[depth]; - if (objectData === null) { - objectLayerData[depth] = null; - continue; - } + if (timeline[f] !== undefined) { + var displayList = timeline[f].displayList; + var morphedShapeReplacements = []; + for (d = 0, depthArray = Object.keys(displayList), nDepths = depthArray.length; d < nDepths; d += 1) { + depth = depthArray[d]; + objectData = displayList[depth]; + if (objectData === null) { + objectLayerData[depth] = null; + continue; + } - // objects are not redefined every frame - // In objectData, if an object remains unchanged from a frame A to a frame B then it does not appear in frame B - if (!objectLayerData[depth]) { + // objects are not redefined every frame + // In objectData, if an object remains unchanged from a frame A to a frame B then it does not appear in frame B + if (!objectLayerData[depth]) { - // no object was previously defined for the given depth - objectLayerData[depth] = objectData; - } else { + // no object was previously defined for the given depth + objectLayerData[depth] = objectData; + } else { - for (var a = 0, attributeArray = Object.keys(objectData), nAttributes = attributeArray.length; a < nAttributes; a += 1) { - var attribute = attributeArray[a]; + for (var a = 0, attributeArray = Object.keys(objectData), nAttributes = attributeArray.length; a < nAttributes; a += 1) { + var attribute = attributeArray[a]; - // the object attribute has changed - objectLayerData[depth][attribute] = objectData[attribute]; + // the object attribute has changed + objectLayerData[depth][attribute] = objectData[attribute]; + } } - } - // Testing for special case when object is a morphing - objectData = objectLayerData[depth]; - var childSymbol = symbols[objectData.id]; + // Testing for special case when object is a morphing + objectData = objectLayerData[depth]; + var childSymbol = symbols[objectData.id]; - if (childSymbol && childSymbol.isMorphing) { - var ratio = objectData.ratio || 0; + if (childSymbol && childSymbol.isMorphing) { + var ratio = objectData.ratio || 0; - // Creating a new graphic that correspond to interpolation of the morphing with respect to the given ratio - var morphedShapeId = createMorphedShape(symbols, childSymbol, symbols[objectData.id].swfObject, ratio); + // Creating a new graphic that correspond to interpolation of the morphing with respect to the given ratio + var morphedShapeId = createMorphedShape(symbols, childSymbol, symbols[objectData.id].swfObject, ratio); - // Replacing symbol id - morphedShapeReplacements.push({ depth: depth, morphId: morphedShapeId, originalId: childSymbol.id }); + // Replacing symbol id + morphedShapeReplacements.push({ depth: depth, morphId: morphedShapeId, originalId: childSymbol.id }); + } } } diff --git a/package.json b/package.json index 4d9a00c..b8ca5c1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jeff", "description": "Extracts Json meta-data and images from a SWF Flash file.", - "version": "0.1.8", + "version": "0.1.9", "private": false, "author": { "name": "Brice Chevalier",