Beispiel #1
0
        public static void LoadCompact(string path)
        {
            var lines = GameData.Read(path);
            int i     = 0;

            while (lines != null && i < lines.Length)
            {
                string spriteName = lines[i++];

                if (string.IsNullOrWhiteSpace(spriteName) || spriteName.StartsWith("#"))
                {
                    continue;
                }

                var splitName = spriteName.Split(new[] { '=' });
                spriteName = splitName[0];
                string textureName = null;
                if (splitName.Length == 2)
                {
                    textureName = splitName[1];
                }

                Sprite sprite = new Sprite {
                    Animations = new SerializableDictionary <string, List <SpriteFrame> >(), texturePath = textureName
                };

                bool isSameSprite = true;
                while (isSameSprite)
                {
                    string animationDef = lines[i];

                    var parseResult = smartParse.Match(animationDef);

                    if (parseResult.Success)
                    {
                        string animationName = parseResult.Groups["animName"].Value;

                        SpriteFrame        seedFrame = parseSeed(parseResult.Groups["seed"].Value);
                        List <SpriteFrame> frames    = new List <SpriteFrame> {
                            seedFrame
                        };

                        string dupeParamsStr  = parseResult.Groups["dupeParams"].Value;
                        string delayParamsStr = parseResult.Groups["delayParams"].Value;
                        if (dupeParamsStr != string.Empty)
                        {
                            string[] dupeParams = dupeParamsStr.Split(new[] { ',' });
                            int      duration   = dupeParams[0].ToInt();
                            int      frameCount = dupeParams[1].ToInt();
                            seedFrame.Duration = duration;

                            for (int frameNum = 1; frameNum < frameCount; frameNum++)
                            {
                                SpriteFrame frame = createFrame(seedFrame, frameNum, duration);
                                frames.Add(frame);
                            }
                        }
                        else if (delayParamsStr != string.Empty)
                        {
                            string[] delayParams = delayParamsStr.Split(new[] { ',' });
                            int      frameCount  = delayParams.Length;
                            seedFrame.Duration = delayParams[0].ToInt();

                            for (int frameNum = 1; frameNum < frameCount; frameNum++)
                            {
                                SpriteFrame frame = createFrame(seedFrame, frameNum, delayParams[frameNum].ToInt());
                                frames.Add(frame);
                            }
                        }

                        sprite.Animations.Add(animationName, frames);
                    }

                    i++;

                    if (i >= lines.Length || !lines[i].StartsWith("\t"))
                    {
                        isSameSprite = false;
                        allSprites.Add(spriteName, sprite);
                    }
                }
            }
        }