Ejemplo n.º 1
0
        private void LoadFonts(IODataPack ioDataPack) {
            XElement xml = ioDataPack.Xml;
            IOContent contentType = ioDataPack.Type;
            IOOperation operation = ioDataPack.Operation;

            int fileCount = xml.Elements("font").Count();
            int filesLoaded = 0;
            double progress = (double)filesLoaded / (double)fileCount * 100;

            OnStart(this, new IOEventArgs(0, ioDataPack.Operation, ioDataPack.Type));
            foreach (XElement element in xml.Elements("font")) {
                SpriteFont font = Game.Content.Load<SpriteFont>(element.Element("resource").Value);
                int id = Convert.ToInt32(element.Element("id").Value);
                string name = element.Element("name").Value;
                fonts.Add(new FontPack(font, id, name));
                links.Add(id, fonts.Count - 1);
                links.Add(name, fonts.Count - 1);
                filesLoaded++;
                progress = (double)filesLoaded / (double)fileCount * 100;
                OnProgress(this, new IOEventArgs(progress, ioDataPack.Operation, ioDataPack.Type));
            }
            OnComplete(this, new IOEventArgs(progress, ioDataPack.Operation, ioDataPack.Type));
        }
        /// <summary>
        /// Creates texturepacks and adds them to the packs list.
        /// </summary>
        private void LoadTexturePacks(IODataPack ioDataPack) {
            XElement xml = ioDataPack.Xml;
            IOContent contentType = ioDataPack.Type;
            IOOperation operation = ioDataPack.Operation;

            int totalFiles = FileCount(xml);
            int loadedFiles = 0;
            int progress = 0;
            OnStart(this, new IOEventArgs(progress, operation, contentType));
            IEnumerable<XElement> xmlPacks = from element in xml.Elements() select element;
            
            foreach (XElement xmlData in xmlPacks) {
                int id = Convert.ToInt32(xmlData.Element("id").Value);
                int count = Convert.ToInt32(xmlData.Element("frames").Value);
                string folder = xmlData.Element("folder").Value;
                string name = xmlData.Element("name").Value;
                packs.Add(CreateTexturePack(id, name, folder, count, ref loadedFiles, ref totalFiles, contentType, operation));
                links.Add(name, packs.Count-1);
                links.Add(id, packs.Count-1);
                OnNewPack(this, new IOEventArgs(progress, operation, contentType));
            }
            OnComplete(this, new IOEventArgs(progress, operation, contentType));
        }