Exemplo n.º 1
0
        public static void ScanDirectory(string path)
        {
            PicRef.Prepare();

            if (!Endogine.Files.FileFinder.ContainsRoot(path))
            {
                DirectoryInfo di = new DirectoryInfo(path);
                if (!di.Exists)
                {
                    di = new DirectoryInfo(Endogine.AppSettings.BaseDirectory + "\\" + path);
                    if (!di.Exists)
                    {
                        throw new Exception("ScanDirectory: " + path + " doesn't exists");
                    }
                }
                path = di.FullName;
            }
            if (!path.EndsWith("\\"))
            {
                path += "\\";
            }

            FileInfo[] files = Endogine.Files.FileFinder.GetFiles(path + "*.xml");
            foreach (FileInfo file in files)
            {
                //Find files with the same name, but a different file extension - those are probably media files.
                //TODO: Not only bitmaps - this goes for all types of media, they come in media+resource pairs.
                string     mediaFile          = file.FullName.Remove(file.FullName.Length - 3, 3) + "*";
                FileInfo[] probableMediaFiles = Endogine.Files.FileFinder.GetFiles(mediaFile);

                foreach (FileInfo probableFile in probableMediaFiles)
                {
                    if (probableFile.Name.EndsWith("xml"))
                    {
                        continue;
                    }
                    PicRef.LoadPicRef(probableFile.FullName);
                    break;
                }
            }

            FileInfo[] filesGif = Endogine.Files.FileFinder.GetFiles(path + "*.gif");
            foreach (FileInfo file in filesGif)
            {
                //TODO: check if already loaded (had xml fork)
                PicRef.LoadPicRef(file.FullName);
            }
        }
Exemplo n.º 2
0
 public static void AddPicture(PicRef p)
 {
     PicRef.Prepare();
     PicRef._pictures.Add(p.OriginalName, p);
     PicRef._originalsToMerged.Add(p.OriginalName, p.Member.Name);
 }
Exemplo n.º 3
0
        public static void LoadPicRef(string bitmapFilename)
        {
            FileInfo bitmapFile = new FileInfo(bitmapFilename);

            PicRef.Prepare();

            if (_originalsToMerged.ContainsValue(bitmapFile.FullName))
            {
                return;
            }
//				throw new Exception("This tiled bitmap has already been loaded: "+bitmapFile.FullName);

            //For now, load the bitmap immediately. The retrieval process for each PicRef seems to be very slow.
            MemberSpriteBitmap mb = new MemberSpriteBitmap(bitmapFilename);

            XmlDocument doc     = new XmlDocument();
            string      xmlFile = bitmapFile.FullName.Substring(0, bitmapFile.FullName.Length - bitmapFile.Extension.Length) + ".xml";

            if (File.Exists(xmlFile))
            {
                doc.Load(xmlFile);
                if (doc["root"]["Files"] != null)
                {
                    List <string> fileOrder = new List <string>();
                    foreach (XmlNode node in doc["root"]["Files"])
                    {
                        string originalFile = node.Attributes["value"].InnerXml;
                        fileOrder.Add(originalFile);
                        //remove file extension:
                        int index = originalFile.LastIndexOf(".");
                        if (index > 0)
                        {
                            originalFile = originalFile.Remove(index, originalFile.Length - index);
                        }
                        //							if (_originalsToMerged.Contains(originalFile)
                        //if (originalFile == "object01_0000")
                        //	EH.Put("Jks");
                        //_originalsToMerged.Add(originalFile, bitmapFile.FullName);

                        PicRef picture = new PicRef(originalFile, mb);
                        picture.SourceRectangle = new ERectangle(node["Rect"].Attributes["value"].InnerXml);
                        picture.Offset          = new EPoint(node["Offset"].Attributes["value"].InnerXml);
                    }

                    //TODO: ATM, nothing is done with the animation information in here.
                    //Should be stored in a global animation collection -
                    //accessed by [
                    if (doc["root"]["Animations"] != null)
                    {
                        foreach (XmlNode node in doc["root"]["Animations"])
                        {
                            System.Collections.ArrayList anim = Endogine.Animation.AnimationHelpers.ParseAnimationString(node.Attributes["value"].InnerXml);
                            List <string> animPics            = new List <string>();
                            foreach (int frame in anim)
                            {
                                animPics.Add(fileOrder[frame]);
                            }
                            EH.Instance.CastLib.FrameSets.AddFrameSet(node.Name, animPics);
                        }
                    }
                }
            }
        }