Esempio n. 1
0
        PlistDictionary LoadDictionaryContents(XmlReader reader, PlistDictionary dict)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.LocalName == "key");
            while (!reader.EOF && reader.NodeType == XmlNodeType.Element)
            {
                //string key = reader.ReadElementString ();
                string key = reader.ReadElementContentAsString();
                while (reader.NodeType != XmlNodeType.Element && reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        throw new Exception(String.Format("No value found for key {0}", key));
                    }
                }
                PlistObjectBase result = LoadFromNode(reader);
                if (result != null)
                {
                    dict.Add(key, result);
                }

                // when there is no whitespace between nodes, we might already be at
                // the next key element, so reading to next sibling would jump over
                // the next (current) key element
                if (!"key".Equals(reader.Name))
                {
                    reader.ReadToNextSibling("key");
                }
            }
            return(dict);
        }
Esempio n. 2
0
        public void RemoveSpriteFrames(string plistFileName)
        {
            PlistDocument document = CCContentManager.SharedContentManager.Load <PlistDocument>(plistFileName);

            PlistDictionary dict = document.Root.AsDictionary;

            RemoveSpriteFrames(dict);
        }
Esempio n. 3
0
 private CCLabelAtlas(string label, PlistDictionary fontPlistDict)
     : this(label, fontPlistDict["textureFilename"].AsString,
            (int)Math.Ceiling((double)fontPlistDict["itemWidth"].AsInt),
            (int)Math.Ceiling((double)fontPlistDict["itemHeight"].AsInt),
            (char)fontPlistDict["firstChar"].AsInt)
 {
     Debug.Assert(fontPlistDict["version"].AsInt == 1, "Unsupported version. Upgrade cocos2d version");
 }
Esempio n. 4
0
        public void AddSpriteFrames(string plistFileName, CCTexture2D pobTexture)
        {
            PlistDocument document = CCContentManager.SharedContentManager.Load <PlistDocument>(plistFileName);

            PlistDictionary dict = document.Root.AsDictionary;

            AddSpriteFrames(dict, pobTexture);
        }
Esempio n. 5
0
        void ParseVersion2(PlistDictionary animations)
        {
            CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

            foreach (var pElement in animations)
            {
                string          name          = pElement.Key;
                PlistDictionary animationDict = pElement.Value.AsDictionary;

                int  loops = animationDict["loops"].AsInt;
                bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].AsBool;

                PlistArray frameArray = animationDict["frames"].AsArray;

                if (frameArray == null)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.",
                        name);
                    continue;
                }

                // Array of AnimationFrames
                var array = new List <CCAnimationFrame>(frameArray.Count);

                foreach (PlistObjectBase pObj in frameArray)
                {
                    PlistDictionary entry = pObj.AsDictionary;

                    string        spriteFrameName = entry["spriteframe"].AsString;
                    CCSpriteFrame spriteFrame     = frameCache[spriteFrameName];

                    if (spriteFrame == null)
                    {
                        CCLog.Log(
                            "cocos2d: CCAnimationCache: Animation '{0}' refers to frame '{1}' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.",
                            name, spriteFrameName);

                        continue;
                    }

                    float           delayUnits = entry["delayUnits"].AsFloat;
                    PlistDictionary userInfo   = entry["notification"].AsDictionary;

                    var animFrame = new CCAnimationFrame(spriteFrame, delayUnits, userInfo);

                    array.Add(animFrame);
                }

                float delayPerUnit = animationDict["delayPerUnit"].AsFloat;
                var   animation    = new CCAnimation(array, delayPerUnit, (uint)loops);

                animation.RestoreOriginalFrame = restoreOriginalFrame;

                this.AddAnimation(animation, name);
            }
        }
Esempio n. 6
0
        void ParseVersion1(PlistDictionary animations)
        {
            CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

            foreach (var pElement in animations)
            {
                PlistDictionary animationDict = pElement.Value.AsDictionary;

                PlistArray frameNames = animationDict["frames"].AsArray;
                float      delay      = animationDict["delay"].AsFloat;

                if (frameNames == null)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.",
                        pElement.Key);
                    continue;
                }

                var frames = new List <CCAnimationFrame>(frameNames.Count);

                foreach (PlistObjectBase pObj in frameNames)
                {
                    string        frameName   = pObj.AsString;
                    CCSpriteFrame spriteFrame = frameCache[frameName];

                    if (spriteFrame == null)
                    {
                        CCLog.Log(
                            "cocos2d: CCAnimationCache: Animation '{0}' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.",
                            pElement.Key, frameName);
                        continue;
                    }

                    var animFrame = new CCAnimationFrame(spriteFrame, 1, null);
                    frames.Add(animFrame);
                }

                if (frames.Count == 0)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: None of the frames for animation '{0}' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.",
                        pElement.Key);
                    continue;
                }
                else if (frames.Count != frameNames.Count)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '{0}' may be missing.",
                        pElement.Key);
                }

                CCAnimation animation = new CCAnimation(frames, delay, 1);

                this.AddAnimation(animation, pElement.Key);
            }
        }
Esempio n. 7
0
        public void AddAnimations(string plistFilename)
        {
            Debug.Assert(!string.IsNullOrEmpty(plistFilename), "Invalid texture file name");

            PlistDocument document = CCContentManager.SharedContentManager.Load <PlistDocument>(plistFilename);

            PlistDictionary dict = document.Root.AsDictionary;

            Debug.Assert(dict != null, "CCAnimationCache: File could not be found");

            this.AddAnimations(dict);
        }
Esempio n. 8
0
            protected PlistObjectBase ReadValue(ContentReader input)
            {
                var type = (ValueType)input.ReadByte();

                switch (type)
                {
                case ValueType.Array:
                    var count = input.ReadInt32();
                    var array = new PlistArray(count);
                    for (int i = 0; i < count; i++)
                    {
                        array.Add(ReadValue(input));
                    }
                    return(array);

                case ValueType.Bool:
                    return(new PlistBoolean(input.ReadBoolean()));

                case ValueType.Data:
                    count = input.ReadInt32();
                    return(new PlistData(input.ReadBytes(count)));

                case ValueType.Date:
                    return(new PlistDate(input.ReadObject <DateTime>()));

                case ValueType.Dictionary:
                    count = input.ReadInt32();
                    var dict = new PlistDictionary();
                    for (int i = 0; i < count; i++)
                    {
                        string key = stringPool[input.ReadInt32()];
                        dict.Add(key, ReadValue(input));
                    }
                    return(dict);

                case ValueType.Integer:
                    return(new PlistInteger(input.ReadInt32()));

                case ValueType.Null:
                    return(new PlistNull());

                case ValueType.Real:
                    return(new PlistReal(input.ReadSingle()));

                case ValueType.String:
                    return(new PlistString(stringPool[input.ReadInt32()]));

                default:
                    throw new InvalidOperationException();
                }
            }
Esempio n. 9
0
        void InitWithDictionary(PlistDictionary dict, CCTexture2D texture)
        {
            spriteFrames.Clear();
            spriteFramesAliases.Clear();

            if (plistType == PlistType.SpriteKit)
            {
                LoadAppleDictionary(dict, texture);
            }
            else
            {
                LoadCocos2DDictionary(dict, texture);
            }
        }
Esempio n. 10
0
        public void AddSpriteFrames(string plistFileName)
        {
            PlistDocument document = CCContentManager.SharedContentManager.Load <PlistDocument>(plistFileName);

            PlistDictionary dict         = document.Root.AsDictionary;
            string          texturePath  = "";
            PlistDictionary metadataDict = dict.ContainsKey("metadata") ? dict["metadata"].AsDictionary : null;

            if (metadataDict != null)
            {
                // try to read  texture file name from meta data
                if (metadataDict.ContainsKey("textureFileName"))
                {
                    texturePath = metadataDict["textureFileName"].AsString;
                }
            }

            if (!string.IsNullOrEmpty(texturePath))
            {
                // build texture path relative to plist file
                texturePath = CCFileUtils.FullPathFromRelativeFile(texturePath, plistFileName);
            }
            else
            {
                // build texture path by replacing file extension
                texturePath = plistFileName;

                // remove .xxx
                texturePath = CCFileUtils.RemoveExtension(texturePath);

                // append .png
                texturePath = texturePath + ".png";

                CCLog.Log("CocosSharp: CCSpriteFrameCache: Trying to use file {0} as texture", texturePath);
            }

            CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(texturePath);

            if (pTexture != null)
            {
                AddSpriteFrames(dict, pTexture);
            }
            else
            {
                CCLog.Log("CocosSharp: CCSpriteFrameCache: Couldn't load texture");
            }
        }
Esempio n. 11
0
        public void AddSpriteFrames(Stream plist, CCTexture2D pobTexture)
        {
            PlistDocument document = new PlistDocument();

            try
            {
                document.LoadFromXmlFile(plist);
            }
            catch (Exception)
            {
                throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from stream"));
            }

            PlistDictionary dict = document.Root.AsDictionary;

            AddSpriteFrames(dict, pobTexture);
        }
Esempio n. 12
0
        public CCSpriteSheet(Stream stream, CCTexture2D texture)
        {
            var document = new PlistDocument();

            try
            {
                document.LoadFromXmlFile(stream);
            }
            catch (Exception)
            {
                throw (new Microsoft.Xna.Framework.Content.ContentLoadException(
                           "Failed to load the sprite sheet definition file from stream"));
            }

            PlistDictionary dict = document.Root.AsDictionary;

            InitWithDictionary(dict, texture);
        }
Esempio n. 13
0
        public void RemoveSpriteFrames(PlistDictionary dictionary)
        {
            PlistDictionary framesDict   = dictionary["frames"].AsDictionary;
            var             keysToRemove = new List <string>();

            foreach (var pair in framesDict)
            {
                if (spriteFrames.ContainsKey(pair.Key))
                {
                    keysToRemove.Add(pair.Key);
                }
            }

            foreach (string key in keysToRemove)
            {
                spriteFrames.Remove(key);
            }
        }
Esempio n. 14
0
        internal void AddAnimations(PlistDictionary animationDict)
        {
            PlistDictionary animations = animationDict["animations"].AsDictionary;

            if (animations == null)
            {
                CCLog.Log("CocosSharp: CCAnimationCache: No animations were found in provided dictionary.");
                return;
            }

            PlistDictionary properties = animationDict["properties"].AsDictionary;

            if (properties != null)
            {
                int        version      = properties["format"].AsInt;
                PlistArray spritesheets = properties["spritesheets"].AsArray;

                foreach (PlistObjectBase pObj in spritesheets)
                {
                    string name = pObj.AsString;
                    CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames(name);
                }

                switch (version)
                {
                case 1:
                    ParseVersion1(animations);
                    break;

                case 2:
                    ParseVersion2(animations);
                    break;

                default:
                    Debug.Assert(false, "Invalid animation format");
                    break;
                }
            }
        }
Esempio n. 15
0
        PlistDictionary ParseBinaryDictionary(int objRef)
        {
            var buffer = new PlistDictionary(true);

            List <int> refs     = new List <int>();
            int        refCount = 0;

            byte dictByte = objectTable[offsetTable[objRef]];

            int refStartPosition;

            refCount = GetCount(offsetTable[objRef], out refStartPosition);

            if (refCount < 15)
            {
                refStartPosition = offsetTable[objRef] + 1;
            }
            else
            {
                refStartPosition = offsetTable[objRef] + 2 + RegulateNullBytes(BitConverter.GetBytes(refCount), 1).Length;
            }

            for (int i = refStartPosition; i < refStartPosition + refCount * 2 * objRefSize; i += objRefSize)
            {
                byte[] refBuffer = objectTable.GetRange(i, objRefSize).ToArray();
                Array.Reverse(refBuffer);
                refs.Add(BitConverter.ToInt32(RegulateNullBytes(refBuffer, 4), 0));
            }

            for (int i = 0; i < refCount; i++)
            {
                var key = ((PlistString)ParseBinary(refs [i])).AsString;
                var val = ParseBinary(refs [i + refCount]);
                buffer.Add(key, val);
            }

            return(buffer);
        }
Esempio n. 16
0
        internal void AddSpriteFrames(PlistDictionary pobDictionary, CCTexture2D pobTexture)
        {
            /*
             * Supported Zwoptex Formats:
             *
             * ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
             * ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
             * ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
             * ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
             */

            PlistDictionary metadataDict = null;

            if (pobDictionary.ContainsKey("metadata"))
            {
                metadataDict = pobDictionary["metadata"].AsDictionary;
            }

            PlistDictionary framesDict = null;

            if (pobDictionary.ContainsKey("frames"))
            {
                framesDict = pobDictionary["frames"].AsDictionary;
            }

            int format = 0;

            // get the format
            if (metadataDict != null)
            {
                format = metadataDict["format"].AsInt;
            }

            // check the format
            if (format < 0 || format > 3)
            {
                throw (new NotSupportedException("PList format " + format + " is not supported."));
            }

            foreach (var pair in framesDict)
            {
                PlistDictionary frameDict   = pair.Value.AsDictionary;
                CCSpriteFrame   spriteFrame = null;

                if (format == 0)
                {
                    float x = 0f, y = 0f, w = 0f, h = 0f;
                    x = frameDict["x"].AsFloat;
                    y = frameDict["y"].AsFloat;
                    w = frameDict["width"].AsFloat;
                    h = frameDict["height"].AsFloat;
                    float ox = 0f, oy = 0f;
                    ox = frameDict["offsetX"].AsFloat;
                    oy = frameDict["offsetY"].AsFloat;
                    int ow = 0, oh = 0;
                    ow = frameDict["originalWidth"].AsInt;
                    oh = frameDict["originalHeight"].AsInt;
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        CCLog.Log(
                            "cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag");
                    }
                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);
                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        new CCSize(ow, oh),
                        pobTexture,
                        new CCRect(x, y, w, h),
                        new CCSize(ow, oh),
                        false,
                        new CCPoint(ox, oy)
                        );
                }
                else if (format == 1 || format == 2)
                {
                    CCRect frame   = CCRect.Parse(frameDict["frame"].AsString);
                    bool   rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        if (frameDict.ContainsKey("rotated"))
                        {
                            rotated = frameDict["rotated"].AsBool;
                        }
                    }

                    CCPoint offset     = CCPoint.Parse(frameDict["offset"].AsString);
                    CCSize  sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString);

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        sourceSize,
                        pobTexture,
                        frame,
                        sourceSize,
                        rotated,
                        offset
                        );
                }
                else if (format == 3)
                {
                    // get values
                    CCSize  spriteSize       = CCSize.Parse(frameDict["spriteSize"].AsString);
                    CCPoint spriteOffset     = CCPoint.Parse(frameDict["spriteOffset"].AsString);
                    CCSize  spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString);
                    CCRect  textureRect      = CCRect.Parse(frameDict["textureRect"].AsString);
                    bool    textureRotated   = false;
                    if (frameDict.ContainsKey("textureRotated"))
                    {
                        textureRotated = frameDict["textureRotated"].AsBool;
                    }

                    // get aliases
                    PlistArray aliases  = frameDict["aliases"].AsArray;
                    string     frameKey = pair.Key;

                    foreach (PlistObjectBase item2 in aliases)
                    {
                        string oneAlias = item2.AsString;
                        if (spriteFramesAliases.ContainsKey(oneAlias))
                        {
                            if (spriteFramesAliases[oneAlias] != null)
                            {
                                CCLog.Log("CocosSharp: WARNING: an alias with name {0} already exists", oneAlias);
                            }
                        }
                        if (!spriteFramesAliases.ContainsKey(oneAlias))
                        {
                            spriteFramesAliases.Add(oneAlias, frameKey);
                        }
                    }

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        spriteSourceSize,
                        pobTexture,
                        new CCRect(textureRect.Origin.X, textureRect.Origin.Y, spriteSize.Width, spriteSize.Height),
                        spriteSourceSize,
                        textureRotated,
                        spriteOffset
                        );
                }

                // add sprite frame
                string key = pair.Key;
                if (!AllowFrameOverwrite && spriteFrames.ContainsKey(key))
                {
                    CCLog.Log("Frame named " + key + " already exists in the animation cache. Not overwriting existing record.");
                }
                else if (AllowFrameOverwrite || !spriteFrames.ContainsKey(key))
                {
                    spriteFrames[key] = spriteFrame;
                }
            }
        }
Esempio n. 17
0
        PlistObjectBase LoadFromNode(XmlReader reader)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            bool isEmpty = reader.IsEmptyElement;

            switch (reader.LocalName)
            {
            case "dict":
                var dict = new PlistDictionary(true);
                if (!isEmpty)
                {
                    if (reader.ReadToDescendant("key"))
                    {
                        dict = LoadDictionaryContents(reader, dict);
                    }
                    reader.ReadEndElement();
                }
                return(dict);

            case "array":
                if (isEmpty)
                {
                    return(new PlistArray());
                }

                //advance to first node
                reader.ReadStartElement();
                while (reader.Read() && reader.NodeType != XmlNodeType.Element)
                {
                    ;
                }

                // HACK: plist data in iPods is not even valid in some cases! Way to go Apple!
                // This hack checks to see if they really meant for this array to be a dict.
                if (reader.LocalName == "key")
                {
                    var ret = LoadDictionaryContents(reader, new PlistDictionary(true));
                    reader.ReadEndElement();
                    return(ret);
                }

                var arr = new PlistArray();
                do
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        var val = LoadFromNode(reader);
                        if (val != null)
                        {
                            arr.Add(val);
                        }
                    }
                } while (reader.Read() && reader.NodeType != XmlNodeType.EndElement);
                reader.ReadEndElement();
                return(arr);

            case "string":
                return(new PlistString(reader.ReadElementContentAsString()));

            case "integer":
                return(new PlistInteger(reader.ReadElementContentAsInt()));

            case "real":
                return(new PlistReal(reader.ReadElementContentAsFloat()));

            case "false":
                reader.ReadStartElement();
                if (!isEmpty)
                {
                    reader.ReadEndElement();
                }
                return(new PlistBoolean(false));

            case "true":
                reader.ReadStartElement();
                if (!isEmpty)
                {
                    reader.ReadEndElement();
                }
                return(new PlistBoolean(true));

            case "data":
                return(new PlistData(reader.ReadElementContentAsString()));

            case "date":
#if NETFX_CORE
                return(new PlistDate(DateTime.Parse(reader.ReadElementContentAsString())));
#else
                return(new PlistDate(reader.ReadElementContentAsDateTime()));
#endif
            default:
                throw new XmlException(String.Format("Plist Node `{0}' is not supported", reader.LocalName));
            }
        }
        CCParticleSystemConfig(PlistDictionary dictionary, string directoryName, bool loadingAsync)
        {
            ParticleSystemType = CCParticleSystemType.Cocos2D;

            MaxParticles = dictionary ["maxParticles"].AsInt;
            Duration     = dictionary["duration"].AsFloat;
            Life         = dictionary["particleLifespan"].AsFloat;
            LifeVar      = dictionary["particleLifespanVariance"].AsFloat;

            Angle    = dictionary["angle"].AsFloat;
            AngleVar = dictionary["angleVariance"].AsFloat;

            CCBlendFunc blendFunc = new CCBlendFunc();

            blendFunc.Source      = dictionary["blendFuncSource"].AsInt;
            blendFunc.Destination = dictionary["blendFuncDestination"].AsInt;
            BlendFunc             = blendFunc;

            CCColor4F startColor = new CCColor4F();

            startColor.R = dictionary["startColorRed"].AsFloat;
            startColor.G = dictionary["startColorGreen"].AsFloat;
            startColor.B = dictionary["startColorBlue"].AsFloat;
            startColor.A = dictionary["startColorAlpha"].AsFloat;
            StartColor   = startColor;

            CCColor4F startColorVar = new CCColor4F();

            startColorVar.R = dictionary["startColorVarianceRed"].AsFloat;
            startColorVar.G = dictionary["startColorVarianceGreen"].AsFloat;
            startColorVar.B = dictionary["startColorVarianceBlue"].AsFloat;
            startColorVar.A = dictionary["startColorVarianceAlpha"].AsFloat;
            StartColorVar   = startColorVar;

            CCColor4F endColor = new CCColor4F();

            endColor.R = dictionary["finishColorRed"].AsFloat;
            endColor.G = dictionary["finishColorGreen"].AsFloat;
            endColor.B = dictionary["finishColorBlue"].AsFloat;
            endColor.A = dictionary["finishColorAlpha"].AsFloat;
            EndColor   = endColor;

            CCColor4F endColorVar = new CCColor4F();

            endColorVar.R = dictionary["finishColorVarianceRed"].AsFloat;
            endColorVar.G = dictionary["finishColorVarianceGreen"].AsFloat;
            endColorVar.B = dictionary["finishColorVarianceBlue"].AsFloat;
            endColorVar.A = dictionary["finishColorVarianceAlpha"].AsFloat;
            EndColorVar   = endColorVar;

            StartSize    = dictionary["startParticleSize"].AsFloat;
            StartSizeVar = dictionary["startParticleSizeVariance"].AsFloat;
            EndSize      = dictionary["finishParticleSize"].AsFloat;
            EndSizeVar   = dictionary["finishParticleSizeVariance"].AsFloat;

            CCPoint position;

            position.X = dictionary["sourcePositionx"].AsFloat;
            position.Y = dictionary["sourcePositiony"].AsFloat;
            Position   = position;

            CCPoint positionVar;

            positionVar.X = dictionary["sourcePositionVariancex"].AsFloat;
            positionVar.Y = dictionary["sourcePositionVariancey"].AsFloat;
            PositionVar   = positionVar;

            StartSpin    = dictionary["rotationStart"].AsFloat;
            StartSpinVar = dictionary["rotationStartVariance"].AsFloat;
            EndSpin      = dictionary["rotationEnd"].AsFloat;
            EndSpinVar   = dictionary["rotationEndVariance"].AsFloat;

            EmitterMode = (CCEmitterMode)dictionary["emitterType"].AsInt;

            if (EmitterMode == CCEmitterMode.Gravity)
            {
                CCPoint gravity;
                gravity.X = dictionary["gravityx"].AsFloat;
                gravity.Y = dictionary["gravityy"].AsFloat;
                Gravity   = gravity;

                GravitySpeed              = dictionary["speed"].AsFloat;
                GravitySpeedVar           = dictionary["speedVariance"].AsFloat;
                GravityRadialAccel        = dictionary["radialAcceleration"].AsFloat;
                GravityRadialAccelVar     = dictionary["radialAccelVariance"].AsFloat;
                GravityTangentialAccel    = dictionary["tangentialAcceleration"].AsFloat;
                GravityTangentialAccelVar = dictionary["tangentialAccelVariance"].AsFloat;
                GravityRotationIsDir      = dictionary["rotationIsDir"].AsBool;
            }

            else if (EmitterMode == CCEmitterMode.Radius)
            {
                RadialStartRadius        = dictionary["maxRadius"].AsFloat;
                RadialStartRadiusVar     = dictionary["maxRadiusVariance"].AsFloat;
                RadialEndRadius          = dictionary["minRadius"].AsFloat;
                RadialEndRadiusVar       = 0.0f;
                RadialRotatePerSecond    = dictionary["rotatePerSecond"].AsFloat;
                RadialRotatePerSecondVar = dictionary["rotatePerSecondVariance"].AsFloat;
            }
            else
            {
                Debug.Assert(false, "Invalid emitterType in config file");
                return;
            }

            TextureName = dictionary["textureFileName"].AsString;
            TextureData = dictionary["textureImageData"].AsString;

            if (!loadingAsync)
            {
                LoadParticleTexture();
            }
        }
Esempio n. 19
0
        void LoadCocos2DDictionary(PlistDictionary dict, CCTexture2D texture)
        {
            PlistDictionary metadataDict = null;

            if (dict.ContainsKey("metadata"))
            {
                metadataDict = dict["metadata"].AsDictionary;
            }

            PlistDictionary framesDict = null;

            if (dict.ContainsKey("frames"))
            {
                framesDict = dict["frames"].AsDictionary;
            }

            // get the format
            int format = 0;

            if (metadataDict != null)
            {
                format = metadataDict["format"].AsInt;
            }

            // check the format
            if (format < 0 || format > 3)
            {
                throw (new NotSupportedException("PList format " + format + " is not supported."));
            }

            foreach (var pair in framesDict)
            {
                PlistDictionary frameDict   = pair.Value.AsDictionary;
                CCSpriteFrame   spriteFrame = null;

                if (format == 0)
                {
                    float x = 0f, y = 0f, w = 0f, h = 0f;
                    x = frameDict["x"].AsFloat;
                    y = frameDict["y"].AsFloat;
                    w = frameDict["width"].AsFloat;
                    h = frameDict["height"].AsFloat;
                    float ox = 0f, oy = 0f;
                    ox = frameDict["offsetX"].AsFloat;
                    oy = frameDict["offsetY"].AsFloat;
                    int ow = 0, oh = 0;
                    ow = frameDict["originalWidth"].AsInt;
                    oh = frameDict["originalHeight"].AsInt;
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        CCLog.Log(
                            "cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag");
                    }
                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        new CCSize(ow, oh),
                        texture,
                        new CCRect(x + ox, y + oy, w, h),
                        false
                        );
                }
                else if (format == 1 || format == 2)
                {
                    var  frame   = CCRect.Parse(frameDict["frame"].AsString);
                    bool rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        if (frameDict.ContainsKey("rotated"))
                        {
                            rotated = frameDict["rotated"].AsBool;
                        }
                    }

                    var offset     = CCPoint.Parse(frameDict["offset"].AsString);
                    var sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString);

                    frame.Origin += offset;

                    // create frame
                    spriteFrame = new CCSpriteFrame(sourceSize, texture, frame, rotated);
                }
                else if (format == 3)
                {
                    var spriteSize       = CCSize.Parse(frameDict["spriteSize"].AsString);
                    var spriteOffset     = CCPoint.Parse(frameDict["spriteOffset"].AsString);
                    var spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString);
                    var textureRect      = CCRect.Parse(frameDict["textureRect"].AsString);

                    bool textureRotated = false;

                    if (frameDict.ContainsKey("textureRotated"))
                    {
                        textureRotated = frameDict["textureRotated"].AsBool;
                    }

                    // get aliases
                    var aliases = frameDict["aliases"].AsArray;

                    for (int i = 0; i < aliases.Count; i++)
                    {
                        string oneAlias = aliases[i].AsString;

                        if (spriteFramesAliases.ContainsKey(oneAlias))
                        {
                            if (spriteFramesAliases[oneAlias] != null)
                            {
                                CCLog.Log("CocosSharp: WARNING: an alias with name {0} already exists", oneAlias);
                            }
                        }

                        if (!spriteFramesAliases.ContainsKey(oneAlias))
                        {
                            spriteFramesAliases.Add(oneAlias, pair.Key);
                        }
                    }

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        spriteSourceSize,
                        texture,
                        new CCRect(textureRect.Origin.X + spriteOffset.X, textureRect.Origin.Y + spriteOffset.Y, spriteSize.Width, spriteSize.Height),
                        textureRotated
                        );
                }

                spriteFrame.TextureFilename = pair.Key;
                spriteFrames[pair.Key]      = spriteFrame;
            }
            AutoCreateAliasList();
        }
Esempio n. 20
0
        void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture)
        {
            var version = dict.ContainsKey("version") ? dict ["version"].AsInt : 0;

            if (version != 1)
            {
                throw (new NotSupportedException("Binary PList version " + version + " is not supported."));
            }


            var images = dict.ContainsKey("images") ? dict ["images"].AsArray : null;

            foreach (var imageEntry in images)
            {
                // we only support one image for now
                var imageDict = imageEntry.AsDictionary;

                var path = imageDict ["path"].AsString;

                path = Path.Combine(plistFilePath, CCFileUtils.RemoveExtension(path));

                if (!CCTextureCache.SharedTextureCache.Contains(path))
                {
                    texture = CCTextureCache.SharedTextureCache.AddImage(path);
                }
                else
                {
                    texture = CCTextureCache.SharedTextureCache[path];
                }



                // size not used right now
                //var size = CCSize.Parse(imageDict ["size"].AsString);

                var subImages = imageDict ["subimages"].AsArray;

                foreach (var subImage in subImages)
                {
                    CCSpriteFrame spriteFrame = null;

                    var subImageDict  = subImage.AsDictionary;
                    var name          = subImageDict ["name"].AsString;
                    var alias         = subImageDict ["alias"].AsString;
                    var isFullyOpaque = true;

                    if (subImageDict.ContainsKey("isFullyOpaque"))
                    {
                        isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool;
                    }

                    var textureRect  = CCRect.Parse(subImageDict ["textureRect"].AsString);
                    var spriteOffset = CCPoint.Parse(subImageDict ["spriteOffset"].AsString);

                    // We are going to override the sprite offset for now to be 0,0
                    // It seems the offset is calculated off of the original size but if
                    // we pass this offset it throws our center position calculations off.
                    spriteOffset = CCPoint.Zero;

                    var textureRotated = false;
                    if (subImageDict.ContainsKey("textureRotated"))
                    {
                        textureRotated = subImageDict ["textureRotated"].AsBool;
                    }
                    var spriteSourceSize = CCSize.Parse(subImageDict ["spriteSourceSize"].AsString);
                    var frameRect        = textureRect;
                    if (textureRotated)
                    {
                        frameRect = new CCRect(textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width);
                    }

                    #if DEBUG
                    CCLog.Log("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize);
                    #endif

                    frameRect.Origin += spriteOffset;

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        spriteSourceSize,
                        texture,
                        frameRect,
                        textureRotated
                        );

                    spriteFrame.TextureFilename = name;
                    spriteFrames [name]         = spriteFrame;
                }
            }
            AutoCreateAliasList();
        }
Esempio n. 21
0
        PlistType GetPlistType(PlistDictionary dict)
        {
            var isSpriteKit = dict.ContainsKey("format") ? dict ["format"].AsString == "APPL" : false;

            return(isSpriteKit ? PlistType.SpriteKit : PlistType.Cocos2D);
        }
Esempio n. 22
0
 internal CCSpriteSheet(PlistDictionary dictionary, CCTexture2D texture)
 {
     InitWithDictionary(dictionary, texture);
 }
Esempio n. 23
0
        void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture)
        {
            var version = dict.ContainsKey("version") ? dict ["version"].AsInt : 0;

            if (version != 1)
            {
                throw (new NotSupportedException("Binary PList version " + version + " is not supported."));
            }


            var images = dict.ContainsKey("images") ? dict ["images"].AsArray : null;

            foreach (var imageEntry in images)
            {
                // we only support one image for now
                var imageDict = imageEntry.AsDictionary;

                var path = imageDict ["path"].AsString;

                path = Path.Combine(plistFilePath, CCFileUtils.RemoveExtension(path));

                if (!CCTextureCache.SharedTextureCache.Contains(path))
                {
                    texture = CCTextureCache.SharedTextureCache.AddImage(path);
                }
                else
                {
                    // Fix for SpriteKit texture atlases
                    // Backgrounds.1.png
                    // Example is that after stripping the extension when passing the value in
                    // the ".1" is considered an extension so it is stripped as well resulting
                    // in the texture not being found.  So we try with the texture key first and
                    // only if it is not found then we check for extension and continue with normal
                    // processing.
                    if (Path.HasExtension(path))
                    {
                        var extension = Path.GetExtension(path);
                        var sequence  = 0;
                        if (Int32.TryParse(extension.Substring(1), out sequence))
                        {
                            path = imageDict ["path"].AsString;
                            path = Path.Combine(plistFilePath, path);
                        }
                    }
                    texture = CCTextureCache.SharedTextureCache [path];
                }



                // size not used right now
                //var size = CCSize.Parse(imageDict ["size"].AsString);

                var subImages = imageDict ["subimages"].AsArray;

                foreach (var subImage in subImages)
                {
                    CCSpriteFrame spriteFrame = null;

                    var subImageDict  = subImage.AsDictionary;
                    var name          = subImageDict ["name"].AsString;
                    var alias         = subImageDict ["alias"].AsString;
                    var isFullyOpaque = true;

                    if (subImageDict.ContainsKey("isFullyOpaque"))
                    {
                        isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool;
                    }

                    var textureRect  = CCRect.Parse(subImageDict ["textureRect"].AsString);
                    var spriteOffset = CCPoint.Parse(subImageDict ["spriteOffset"].AsString);

                    // We are going to override the sprite offset for now to be 0,0
                    // It seems the offset is calculated off of the original size but if
                    // we pass this offset it throws our center position calculations off.
                    spriteOffset = CCPoint.Zero;

                    var textureRotated = false;
                    if (subImageDict.ContainsKey("textureRotated"))
                    {
                        textureRotated = subImageDict ["textureRotated"].AsBool;
                    }
                    var spriteSourceSize = CCSize.Parse(subImageDict ["spriteSourceSize"].AsString);
                    var frameRect        = textureRect;
                    if (textureRotated)
                    {
                        frameRect = new CCRect(textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width);
                    }

                    #if DEBUG
                    CCLog.Log("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize);
                    #endif

                    frameRect.Origin += spriteOffset;

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        spriteSourceSize,
                        texture,
                        frameRect,
                        textureRotated
                        );

                    spriteFrame.TextureFilename = name;
                    spriteFrames [name]         = spriteFrame;
                }
            }
            AutoCreateAliasList();
        }