Ejemplo n.º 1
0
        List <ImageInfoBlock> praseMetaData(String metaData)
        {
            List <ImageInfoBlock> nodes = new List <ImageInfoBlock>();

            String[] lines = metaData.Split('\n');
            foreach (String line in lines)
            {
                if (Regex.IsMatch(line, "#.*") || line == "")
                {
                    continue;
                }
                Regex           reg    = new Regex("(\\s*)([^\\s]+)\\s*=\\s*(.*[^\\s])\\s*");
                MatchCollection matchs = reg.Matches(line);
                if (matchs.Count <= 0)
                {
                    throw new IOException("Malformed DMI");
                }
                String indent = matchs[0].Groups[1].Value;
                String key    = matchs[0].Groups[2].Value;
                String value  = matchs[0].Groups[3].Value;

                ImageInfoBlock block = new ImageInfoBlock();
                block.indent = (indent.Length != 0);
                block.key    = key;
                block.value  = value;
                nodes.Add(block);
            }
            return(nodes);
        }
Ejemplo n.º 2
0
        List<ImageInfoBlock> praseMetaData(String metaData)
        {
            List<ImageInfoBlock> nodes = new List<ImageInfoBlock>();
            String[] lines = metaData.Split('\n');
            foreach (String line in lines)
            {
                if (Regex.IsMatch(line, "#.*") || line == "")
                {
                    continue;
                }
                Regex reg = new Regex("(\\s*)([^\\s]+)\\s*=\\s*(.*[^\\s])\\s*");
                MatchCollection matchs = reg.Matches(line);
                if (matchs.Count <= 0)
                    throw new IOException("Malformed DMI");
                String indent = matchs[0].Groups[1].Value;
                String key = matchs[0].Groups[2].Value;
                String value = matchs[0].Groups[3].Value;

                ImageInfoBlock block = new ImageInfoBlock();
                block.indent = (indent.Length != 0);
                block.key = key;
                block.value = value;
                nodes.Add(block);
            }
            return nodes;
        }
Ejemplo n.º 3
0
        public void parse(FileStream source)
        {
            img        = new FreeImageBitmap(source);
            dmi_width  = img.Width;
            dmi_height = img.Height;
            MetadataModel         model    = img.Metadata.List[0];
            string                metaData = model.List[0].Value.ToString();
            List <ImageInfoBlock> nodes    = praseMetaData(metaData);


            String state_name = "";

            List <int> state_delay = new List <int>();

            int     state_frames     = 0;
            int     state_directions = 0;
            Boolean had_state        = false;

            this.states = new Dictionary <String, ImageState>();
            //  Enu<ImageInfoBlock> it = nodes.GetEnumerator();
            for (int i = 0; i < nodes.Count; i++)
            {
                ImageInfoBlock block = nodes[i];
                if (block.key == "dirs")
                {
                    Int32.TryParse(block.value, out state_directions);
                }
                else if (block.key == "frames")
                {
                    Int32.TryParse(block.value, out state_frames);
                }
                else if (block.key == "delay")
                {
                    foreach (String S in block.value.Split(','))
                    {
                        int x;
                        Int32.TryParse(S, out x);
                        state_delay.Add(x);
                    }
                }
                else if (block.key == "version")
                {
                    continue;
                }
                else if (block.key == "width")
                {
                    Int32.TryParse(block.value, out width);
                }
                else if (block.key == "height")
                {
                    Int32.TryParse(block.value, out height);
                }
                if (had_state)
                {
                    if (block.key == "state" || i == nodes.Count - 1)
                    {
                        if (state_frames == 0 || state_directions == 0)
                        {
                            throw new IOException(".DMI metadata malformed");
                        }
                        if (state_delay.Count == 0)
                        {
                            while (state_delay.Count < state_frames)
                            {
                                state_delay.Add(1);
                            }
                        }
                        if (state_delay.Count != state_frames)
                        {
                            throw new IOException(".DMI metadata malformed");
                        }
                        ImageState state = generateSpriteState(state_frames, state_directions, state_delay);

                        // intern state_name to make string comparison more efficient
                        if (!states.ContainsKey(state_name))
                        {
                            states.Add(state_name, state); // add state to the sprite
                        }
                        state_frames     = 0;
                        state_directions = 0;
                        state_delay.Clear();
                        had_state = false;
                    }
                }
                if (block.key == "state")
                {
                    state_name = block.value.Substring(1, block.value.Length - 2);
                    had_state  = true;
                }
            }
        }