diff --git a/src/dragonBones/animation/Animation.java b/src/dragonBones/animation/Animation.java index abc6e6d..a2ff911 100644 --- a/src/dragonBones/animation/Animation.java +++ b/src/dragonBones/animation/Animation.java @@ -2,6 +2,8 @@ import dragonBones.Armature; import dragonBones.Slot; +import dragonBones.cache.AnimationCacheManager; +import dragonBones.core.IAnimation; import dragonBones.core.IAnimationState; import dragonBones.objects.AnimationData; import dragonBones.utils.ArrayListUtils; @@ -15,7 +17,7 @@ * @see Animation * @see dragonBones.animation.AnimationState */ -public class Animation extends BaseAnimation +public class Animation implements IAnimation { public static final String NONE = "none"; public static final String SAME_LAYER = "sameLayer"; @@ -44,6 +46,13 @@ public class Animation extends BaseAnimation private int _animationStateCount; + public AnimationCacheManager animationCacheManager; + public IAnimationState ianimationState; + + public IAnimationState gotoAndPlay(String animationName, double fadeInTime, double duration) { + return gotoAndPlay(animationName, fadeInTime, duration, Double.NaN); + } + /** * Creates a new Animation instance and attaches it to the passed Armature. * @param armature An Armature to attach this Animation instance to. @@ -105,6 +114,11 @@ public IAnimationState gotoAndPlay(String animationName, double fadeInTime, doub return gotoAndPlay(animationName, fadeInTime, duration, playTimes, 0, null, SAME_LAYER_AND_GROUP, true, true); } + @Override + public void setAnimationCacheManager(AnimationCacheManager animationCacheManager) { + this.animationCacheManager = animationCacheManager; + } + /** * Fades the animation with name animation in over a period of time seconds and fades other animations out. * @param animationName The name of the AnimationData to play. @@ -370,6 +384,11 @@ public boolean hasAnimation(String animationName) return false; } + @Override + public IAnimationState getAnimationState() { + return this.getLastAnimationState(); + } + /** @private */ public void advanceTime(double passedTime) { diff --git a/src/dragonBones/animation/BaseAnimation.java b/src/dragonBones/animation/BaseAnimation.java deleted file mode 100644 index c24e384..0000000 --- a/src/dragonBones/animation/BaseAnimation.java +++ /dev/null @@ -1,20 +0,0 @@ -package dragonBones.animation; - -import dragonBones.cache.AnimationCacheManager; -import dragonBones.core.IAnimation; -import dragonBones.core.IAnimationState; - -abstract public class BaseAnimation implements IAnimation { - public AnimationCacheManager animationCacheManager; - public IAnimationState ianimationState; - - abstract public IAnimationState gotoAndPlay(String animationName, double fadeInTime, double duration, double playTimes); - - public IAnimationState gotoAndPlay(String animationName) { - return gotoAndPlay(animationName, -1, -1, Double.NaN); - } - - public IAnimationState gotoAndPlay(String animationName, double fadeInTime, double duration) { - return gotoAndPlay(animationName, fadeInTime, duration, Double.NaN); - } -} diff --git a/src/dragonBones/cache/AnimationCacheManager.java b/src/dragonBones/cache/AnimationCacheManager.java index 905fca8..88fa6a0 100644 --- a/src/dragonBones/cache/AnimationCacheManager.java +++ b/src/dragonBones/cache/AnimationCacheManager.java @@ -73,7 +73,7 @@ public void bindCacheUserArmatures(ArrayList armatures) public void bindCacheUserArmature(ICacheableArmature armature) { - armature.getAnimation().animationCacheManager = this; + armature.getAnimation().setAnimationCacheManager(this); Map slotDic = armature.getSlotDic(); // for each(cacheUser in armature._boneDic) @@ -126,7 +126,7 @@ public void generateAnimationCache(String animationName, boolean loop) return; } - IAnimationState animationState = cacheGeneratorArmature.getAnimation().ianimationState; + IAnimationState animationState = cacheGeneratorArmature.getAnimation().getAnimationState(); double passTime = 1 / frameRate; if (loop) diff --git a/src/dragonBones/core/IAnimation.java b/src/dragonBones/core/IAnimation.java index 65b0f3a..ee9cf74 100644 --- a/src/dragonBones/core/IAnimation.java +++ b/src/dragonBones/core/IAnimation.java @@ -1,5 +1,6 @@ package dragonBones.core; +import dragonBones.cache.AnimationCacheManager; import dragonBones.objects.AnimationData; import java.util.ArrayList; @@ -9,6 +10,8 @@ public interface IAnimation { boolean hasAnimation(String animationName); IAnimationState getAnimationState(); IAnimationState gotoAndPlay(String name); + IAnimationState gotoAndPlay(String animationName, double fadeInTime, double duration, double playTimes); + void setAnimationCacheManager(AnimationCacheManager animationCacheManager); void play(); void stop(); } diff --git a/src/dragonBones/fast/animation/FastAnimation.java b/src/dragonBones/fast/animation/FastAnimation.java index 1a6aa01..37daa73 100644 --- a/src/dragonBones/fast/animation/FastAnimation.java +++ b/src/dragonBones/fast/animation/FastAnimation.java @@ -1,6 +1,5 @@ package dragonBones.fast.animation; -import dragonBones.animation.BaseAnimation; import dragonBones.cache.AnimationCacheManager; import dragonBones.core.IAnimation; import dragonBones.core.IAnimationState; @@ -117,6 +116,11 @@ public IAnimationState gotoAndPlay(String animationName, double fadeInTime, doub return animationState; } + @Override + public void setAnimationCacheManager(AnimationCacheManager animationCacheManager) { + this.animationCacheManager = animationCacheManager; + } + public FastAnimationState gotoAndStop( String animationName, double time diff --git a/src/dragonBones/objects/DataParser.java b/src/dragonBones/objects/DataParser.java index 1033c9a..a87513a 100644 --- a/src/dragonBones/objects/DataParser.java +++ b/src/dragonBones/objects/DataParser.java @@ -1,6 +1,8 @@ package dragonBones.objects; import dragonBones.textures.TextureData; +import dragonBones.textures.TextureDataMap; +import flash.XML; import org.w3c.dom.Document; import java.util.Map; @@ -13,26 +15,28 @@ public DataParser() public static DragonBonesData parseData(Object rawData) { - if(rawData instanceof Document) + if(rawData instanceof XML) { - return XMLDataParser.parseDragonBonesData((Document)rawData); + return XMLDataParser.parseDragonBonesData((XML)rawData); } else { - return ObjectDataParser.parseDragonBonesData(rawData); + throw new Error("Not supported JSON/Object parsing"); + //return ObjectDataParser.parseDragonBonesData(rawData); } } //public static Map parseTextureAtlasData(Object textureAtlasData, double scale= 1) - public static Map parseTextureAtlasData(Object textureAtlasData, double scale) + public static TextureDataMap parseTextureAtlasData(Object textureAtlasData, double scale) { - if(textureAtlasData instanceof Document) + if(textureAtlasData instanceof XML) { - return XMLDataParser.parseTextureAtlasData((Document)textureAtlasData, scale); + return XMLDataParser.parseTextureAtlasData((XML)textureAtlasData, scale); } else { - return ObjectDataParser.parseTextureAtlasData(textureAtlasData, scale); + //return ObjectDataParser.parseTextureAtlasData(textureAtlasData, scale); + throw new Error("Not supported JSON/Object parsing"); } } } diff --git a/src/dragonBones/objects/XMLDataParser.java b/src/dragonBones/objects/XMLDataParser.java index 09e95a1..93e949b 100644 --- a/src/dragonBones/objects/XMLDataParser.java +++ b/src/dragonBones/objects/XMLDataParser.java @@ -33,7 +33,7 @@ final public class XMLDataParser public static TextureDataMap parseTextureAtlasData(XML rawData, double scale) { TextureDataMap textureAtlasData = new TextureDataMap(); - textureAtlasData.__name = getString(rawData, ConstValues.A_NAME); + textureAtlasData.name = getString(rawData, ConstValues.A_NAME); Rectangle subTextureFrame; for (XML subTextureXML : rawData.children(ConstValues.SUB_TEXTURE)) { diff --git a/src/dragonBones/textures/NativeTextureAtlas.java b/src/dragonBones/textures/NativeTextureAtlas.java index 2c692c9..caafa63 100644 --- a/src/dragonBones/textures/NativeTextureAtlas.java +++ b/src/dragonBones/textures/NativeTextureAtlas.java @@ -12,8 +12,6 @@ import dragonBones.objects.DataParser; -import java.util.Map; - //use namespace dragonBones_internal; /** @@ -24,7 +22,7 @@ public class NativeTextureAtlas implements ITextureAtlas /** * @private */ - protected Map _subTextureDataDic; + protected TextureDataMap _subTextureDataDic; /** * @private */ @@ -114,7 +112,7 @@ public void dispose() */ public Rectangle getRegion(String name) { - TextureData textureData = (TextureData)_subTextureDataDic.get(name); + TextureData textureData = (TextureData)_subTextureDataDic.data.get(name); if(textureData != null) { return textureData.region; @@ -125,7 +123,7 @@ public Rectangle getRegion(String name) public Rectangle getFrame(String name) { - TextureData textureData = (TextureData)_subTextureDataDic.get(name); + TextureData textureData = (TextureData)_subTextureDataDic.data.get(name); if(textureData != null) { return textureData.frame; @@ -137,9 +135,7 @@ public Rectangle getFrame(String name) protected void parseData(Object textureAtlasRawData) { _subTextureDataDic = DataParser.parseTextureAtlasData(textureAtlasRawData, _isDifferentConfig ? _scale : 1); - _name = (String)_subTextureDataDic.get("__name"); - - _subTextureDataDic.remove("__name"); + _name = (String)_subTextureDataDic.name; } public void movieClipToBitmapData() diff --git a/src/dragonBones/textures/StarlingTextureAtlas.java b/src/dragonBones/textures/StarlingTextureAtlas.java index dffdcc0..bd81888 100644 --- a/src/dragonBones/textures/StarlingTextureAtlas.java +++ b/src/dragonBones/textures/StarlingTextureAtlas.java @@ -9,7 +9,6 @@ import dragonBones.objects.DataParser; -import starling.textures.SubTexture; import starling.textures.Texture; import starling.textures.TextureAtlas; @@ -106,12 +105,11 @@ public StarlingTextureAtlas(Texture texture, Object textureAtlasRawData, boolean */ protected void parseData(Object textureAtlasRawData) { - Map textureAtlasData = DataParser.parseTextureAtlasData(textureAtlasRawData, _isDifferentConfig ? _scale : 1); - _name = (String) (Object)textureAtlasData.get("__name"); - textureAtlasData.remove("__name"); - for(String subTextureName : textureAtlasData.keySet()) + TextureDataMap textureAtlasData = DataParser.parseTextureAtlasData(textureAtlasRawData, _isDifferentConfig ? _scale : 1); + _name = textureAtlasData.name; + for(String subTextureName : textureAtlasData.data.keySet()) { - TextureData textureData = textureAtlasData.get(subTextureName); + TextureData textureData = textureAtlasData.data.get(subTextureName); //, textureData.rotated this.addRegion(subTextureName, textureData.region, textureData.frame); } diff --git a/src/dragonBones/textures/TextureDataMap.java b/src/dragonBones/textures/TextureDataMap.java index 1b1e1cd..67e61c5 100644 --- a/src/dragonBones/textures/TextureDataMap.java +++ b/src/dragonBones/textures/TextureDataMap.java @@ -4,6 +4,6 @@ import java.util.Map; public class TextureDataMap { - public String __name; + public String name; public Map data = new HashMap<>(); } diff --git a/src/flash/utils/ByteArray.java b/src/flash/utils/ByteArray.java index 9d22d7b..42f8314 100644 --- a/src/flash/utils/ByteArray.java +++ b/src/flash/utils/ByteArray.java @@ -5,6 +5,11 @@ public class ByteArray { private int length; private int position; + public ByteArray() { + this(new byte[0], 0, 0); + } + + public ByteArray(byte[] bytes) { this(bytes, 0, bytes.length); }