Esempio n. 1
0
        private void ParseMapFile(InitializeParameters p)
        {
            // read file
            XResourceBundle r           = (XResourceBundle)this.Parent;
            string          mapFilePath = Path.ChangeExtension(this.Source, "xml");

            mapFilePath = Path.Combine(Directory.GetCurrentDirectory(), p.Content.RootDirectory, r.RootFolder.Replace('/', Path.DirectorySeparatorChar), mapFilePath);

            if (!File.Exists(mapFilePath))
            {
                throw new InvalidOperationException(string.Format("Could not find spritesheet map file: {0}", mapFilePath));
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(mapFilePath);

            foreach (XmlElement spriteNode in doc.DocumentElement.ChildNodes)
            {
                this.Map.Add(
                    Path.GetFileNameWithoutExtension(spriteNode.GetAttribute("n")),
                    new System.Drawing.RectangleF(
                        float.Parse(spriteNode.GetAttribute("x")),
                        float.Parse(spriteNode.GetAttribute("y")),
                        float.Parse(spriteNode.GetAttribute("w")),
                        float.Parse(spriteNode.GetAttribute("h"))
                        )
                    );
            }
        }
Esempio n. 2
0
        protected T LoadResource <T>(ContentManager content, string buildProcessor, string defaultInExtension, string defaultOutExtension, string importer = "")
        {
#if DEBUG
            Console.WriteLine("==> Loading resource {0} Source: {1}", this.Id, this.Source);
#endif

            XResourceBundle r = (XResourceBundle)this.Parent;

            string fileName = Path.Combine(r.RootFolder.Replace('/', Path.DirectorySeparatorChar), this.Source);

#if WINDOWS
            var inFile = fileName;
            if (string.IsNullOrEmpty(Path.GetExtension(fileName)))
            {
                inFile = Path.ChangeExtension(inFile, defaultInExtension);
            }
            inFile = Path.Combine(Directory.GetCurrentDirectory(), content.RootDirectory, inFile);

            var outFile = Path.ChangeExtension(Path.Combine(Directory.GetCurrentDirectory(), content.RootDirectory, fileName), defaultOutExtension);

            var outputPath = Path.GetDirectoryName(inFile);

            if (File.Exists(inFile) &&
                (!File.Exists(outFile) || File.GetLastWriteTimeUtc(inFile) > File.GetLastWriteTimeUtc(outFile)))
            {
                using (Lunohod.ContentLoading.ContentBuilder b = new ContentLoading.ContentBuilder(outputPath))
                {
                    b.Add(inFile, this.Source, importer, buildProcessor);
                    string error = b.Build();

                    if (!string.IsNullOrEmpty(error))
                    {
                        throw new InvalidOperationException(string.Format("Could not compile resource: {0}", this.Source));
                    }
                }
            }
#endif
            PerfMon.Start("LoadResource");

            var result = content.Load <T>(fileName);

            PerfMon.Stop("LoadResource");

            return(result);
        }