From f66354dfcde6948af9efe6cbfdd6376aa1bc6cbe Mon Sep 17 00:00:00 2001 From: Daniel Sperl Date: Mon, 13 May 2019 16:23:04 +0200 Subject: [PATCH] added compatibility with new Animate CC 'optimized' export (refs #4) --- .../extensions/animate/AnimAssetManager.as | 2 +- .../extensions/animate/AnimationAtlas.as | 107 +++++++++++++++--- src/starling/extensions/animate/LoopMode.as | 14 +++ src/starling/extensions/animate/Symbol.as | 28 ++--- src/starling/extensions/animate/SymbolType.as | 14 +++ 5 files changed, 134 insertions(+), 31 deletions(-) diff --git a/src/starling/extensions/animate/AnimAssetManager.as b/src/starling/extensions/animate/AnimAssetManager.as index 56a5442..0f40022 100644 --- a/src/starling/extensions/animate/AnimAssetManager.as +++ b/src/starling/extensions/animate/AnimAssetManager.as @@ -100,7 +100,7 @@ class AnimationAtlasFactory extends JsonFactory assets.addAsset(baseName, new JsonTextureAtlas(texture, json)); }, 100); } - else if (json.ANIMATION && json.SYMBOL_DICTIONARY) + else if ((json.ANIMATION && json.SYMBOL_DICTIONARY) || (json.AN && json.SD)) { helper.addPostProcessor(function(assets:AssetManager):void { diff --git a/src/starling/extensions/animate/AnimationAtlas.as b/src/starling/extensions/animate/AnimationAtlas.as index 531047a..c209f71 100644 --- a/src/starling/extensions/animate/AnimationAtlas.as +++ b/src/starling/extensions/animate/AnimationAtlas.as @@ -32,6 +32,7 @@ package starling.extensions.animate public function AnimationAtlas(data:Object, atlas:TextureAtlas) { + data = normalizeJsonKeys(data); parseData(data); _atlas = atlas; @@ -130,25 +131,25 @@ package starling.extensions.animate _symbolData = new Dictionary(); // the actual symbol dictionary - for each (var symbolData:Object in data.SYMBOL_DICTIONARY.Symbols) - _symbolData[symbolData.SYMBOL_name] = preprocessSymbolData(symbolData); + for each (var symbolData:Object in data.symbolDictionary.symbols) + _symbolData[symbolData.symbolName] = preprocessSymbolData(symbolData); // the main animation - var defaultSymbolData:Object = preprocessSymbolData(data.ANIMATION); - _defaultSymbolName = defaultSymbolData.SYMBOL_name; + var defaultSymbolData:Object = preprocessSymbolData(data.animation); + _defaultSymbolName = defaultSymbolData.symbolName; _symbolData[_defaultSymbolName] = defaultSymbolData; // a purely internal symbol for bitmaps - simplifies their handling _symbolData[Symbol.BITMAP_SYMBOL_NAME] = { - SYMBOL_name: Symbol.BITMAP_SYMBOL_NAME, - TIMELINE: { LAYERS: [] } + symbolName: Symbol.BITMAP_SYMBOL_NAME, + timeline: { layers: [] } }; } private static function preprocessSymbolData(symbolData:Object):Object { - var timeLineData:Object = symbolData.TIMELINE; - var layerDates:Array = timeLineData.LAYERS; + var timeLineData:Object = symbolData.timeline; + var layerDates:Array = timeLineData.layers; // In Animate CC, layers are sorted front to back. // In Starling, it's the other way round - so we simply reverse the layer data. @@ -167,7 +168,7 @@ package starling.extensions.animate for (var l:int=0; l i ? layer.getChildAt(i) as Symbol : null; var newSymbol:Symbol = null; - var symbolName:String = elementData.SYMBOL_name; + var symbolName:String = elementData.symbolName; if (!_atlas.hasSymbol(symbolName)) symbolName = BITMAP_SYMBOL_NAME; @@ -118,7 +118,7 @@ package starling.extensions.animate layer.addChildAt(newSymbol, i); } - newSymbol.setTransformationMatrix(elementData.Matrix3D); + newSymbol.setTransformationMatrix(elementData.matrix3D); newSymbol.setBitmap(elementData.bitmap); newSymbol.setColor(elementData.color); newSymbol.setLoop(elementData.loop); @@ -157,7 +157,7 @@ package starling.extensions.animate for (var i:int = 0; i<_numLayers; ++i) { var layer:Sprite = new Sprite(); - layer.name = getLayerData(i).Layer_name; + layer.name = getLayerData(i).layerName; _layers.addChild(layer); } } @@ -179,8 +179,8 @@ package starling.extensions.animate addChild(_bitmap); } - _bitmap.x = data.Position.x; - _bitmap.y = data.Position.y; + _bitmap.x = data.position.x; + _bitmap.y = data.position.y; } else if (_bitmap) { @@ -211,13 +211,13 @@ package starling.extensions.animate private function setLoop(data:String):void { - if (data) _loopMode = data; + if (data) _loopMode = LoopMode.parse(data); else _loopMode = LoopMode.LOOP; } private function setType(data:String):void { - if (data) _type = data; + if (data) _type = SymbolType.parse(data); } private function getNumFrames():int @@ -226,7 +226,7 @@ package starling.extensions.animate for (var i:int=0; i<_numLayers; ++i) { - var frameDates:Array = getLayerData(i).Frames as Array; + var frameDates:Array = getLayerData(i).frames as Array; var numFrameDates:int = frameDates ? frameDates.length : 0; var layerNumFrames:int = numFrameDates ? frameDates[0].index : 0; @@ -246,7 +246,7 @@ package starling.extensions.animate for (var i:int=0; i<_numLayers; ++i) { - var frameDates:Array = getLayerData(i).Frames as Array; + var frameDates:Array = getLayerData(i).frames as Array; var numFrameDates:int = frameDates ? frameDates.length : 0; for (var j:int=0; j