コード例 #1
0
        private void Initialize(TextureAtlas textureAtlas)
        {
            image = new BitmapImage(new Uri(imagePath));

            List<String> animationNames = (from subTexture in textureAtlas.SubTextures select subTexture.Name.Substring(0, subTexture.Name.Length - 4)).ToList();
            HashSet<String> uniqueAnimationNames = new HashSet<String>(animationNames);
            foreach (String animationName in uniqueAnimationNames)
            {
                animations.Add
                (
                    new AnimationViewModel
                    (
                        animationName,
                        (from subTexture in textureAtlas.SubTextures where (subTexture.Name.Substring(0, subTexture.Name.Length - 4) == animationName) select subTexture).ToList(),
                        image
                    )
                );
            }
        }
コード例 #2
0
        public void LoadFile()
        {
            FileInfo info = new FileInfo(filePath);
            TextureAtlas textureAtlas = null;
            String atlasPath = String.Empty;
            if (info.Extension.ToLower().Contains("xml"))
                atlasPath = filePath;
            else
            {
                atlasPath = filePath.Replace(info.Extension, ".xml");
                //We're loading an image.  Look for the corresponding atlas in the same directory.
                if (!File.Exists(atlasPath))
                {
                    //Prompt for the atlas creation
                    CreateAtlasPromptViewModel vm = new CreateAtlasPromptViewModel(info.Name);
                    bool? rtn = windowManager.ShowDialog(vm);
                    if (rtn == true)
                    {
                        //Create an empty atlas file with the same name as the image in the same directory
                        textureAtlas = new TextureAtlas();
                        textureAtlas.ImagePath = info.Name; //Relative

                        try
                        {
                            using (FileStream stream = new FileStream(atlasPath, FileMode.OpenOrCreate))
                            {
                                XmlSerializer serializer = new XmlSerializer(typeof(TextureAtlas));
                                serializer.Serialize(stream, textureAtlas);
                            }
                        }
                        catch (Exception ex)
                        {
                            String debugMe = String.Empty;
                            return;
                        }
                    }
                    else
                        return;
                }
            }

            //Try to deserialize the atlas path
            //Check for the image path
            //Load image
            using (FileStream stream = new FileStream(atlasPath, FileMode.Open))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(TextureAtlas));
                textureAtlas = serializer.Deserialize(stream) as TextureAtlas;
            }

            String imagePath = textureAtlas.ImagePath;
            if(!Path.IsPathRooted(imagePath))
                imagePath = String.Format(@"{0}/{1}", info.Directory, imagePath);

            TextureAtlasViewModel textureAtlasViewModel = new TextureAtlasViewModel(textureAtlas, imagePath);
            FilePath = String.Empty;
            this.eventAggregator.Publish(new Events.AtlasLoadedEvent() { Atlas = textureAtlasViewModel });
        }
コード例 #3
0
 public TextureAtlasViewModel(TextureAtlas textureAtlas, String imagePath)
 {
     this.ImagePath = imagePath;
     Initialize(textureAtlas);
 }
コード例 #4
0
 public TextureAtlasViewModel(TextureAtlas textureAtlas)
 {
     this.ImagePath = textureAtlas.ImagePath;
     Initialize(textureAtlas);
 }