public async Task Png384Dpi()
        {
            var fileName = Path.Combine(_artifacts, "png384.sprite");
            var imgFile  = fileName + ".png";
            var cssFile  = fileName + ".css";

            try
            {
                var doc = await SpriteDocument.FromFile(fileName);

                await _generator.Generate(doc);

                using (var image = Image.FromFile(imgFile))
                {
                    Assert.AreEqual(384, Math.Round(image.HorizontalResolution), "Not 384 DPI");
                    Assert.AreEqual(166, image.Height); // 16 + padding
                    Assert.AreEqual(36, image.Width);   // 16 * 6 + padding
                }

                string css = File.ReadAllText(cssFile);
                Assert.IsTrue(css.Contains(".png384.a"), "Sprite \"a.png\" not generated");
                Assert.IsTrue(css.Contains("url('png384.sprite.png')"), "Incorrect url value");
                Assert.IsTrue(css.Contains("display: inline-block"), "Incorrect custom style");
            }
            finally
            {
                File.Delete(imgFile);
                File.Delete(cssFile);
            }
        }
        public async Task Png96Dpi()
        {
            var fileName = Path.Combine(_artifacts, "png96.sprite");
            var imgFile  = fileName + ".jpg";
            var lessFile = fileName + ".less";

            try
            {
                var doc = await SpriteDocument.FromFile(fileName);

                await _generator.Generate(doc);

                using (var image = Image.FromFile(imgFile))
                {
                    Assert.AreEqual(56, image.Height); // 16 + padding
                    Assert.AreEqual(236, image.Width); // 16 * 6 + padding
                }

                string less = File.ReadAllText(lessFile);
                Assert.IsTrue(less.Contains(".png96-a()"), "Sprite \"a.png\" not generated");
                Assert.IsTrue(less.Contains("url('png96.sprite.jpg')"), "Incorrect url value");
                Assert.IsTrue(less.Contains("margin: 0"), "Incorrect custom style");
            }
            finally
            {
                File.Delete(imgFile);
                File.Delete(lessFile);
            }
        }
Exemple #3
0
        public Graphics(SpriteDocument document)
        {
            InitializeComponent();

            this.document = document;
            this.comboboxSprites.SelectedIndex = 0;
        }
        public async Task CacheBustHash()
        {
            var fileName = Path.Combine(_artifacts, "hash.sprite");
            var imgFile  = fileName + ".jpg";
            var cssFile  = fileName + ".css";

            try
            {
                var doc = await SpriteDocument.FromFile(fileName);

                await _generator.Generate(doc);

                using (HashAlgorithm hash = new SHA256Managed())
                {
                    string imgHash = Convert.ToBase64String(hash.ComputeHash(File.ReadAllBytes(imgFile)));
                    string css     = File.ReadAllText(cssFile);
                    Assert.IsTrue(css.Contains($"?hash={WebUtility.UrlEncode(imgHash)}"), "Sprite hash not generated");
                }
            }
            finally
            {
                File.Delete(imgFile);
                File.Delete(cssFile);
            }
        }
Exemple #5
0
        private void backgroundworkerCode_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Level          level    = this.levelLoaded;
            SpriteDocument document = this.documentLoaded;

            this.Invoke(new CodeCallback(this.SetLevelCode), new object[] { level });
            this.Invoke(new CounterCallback(this.SetCounter), new object[] { document, level });
        }
Exemple #6
0
        public Main()
        {
            InitializeComponent();

            this.document = new SpriteDocument();
            this.document.Load(Application.StartupPath + "/Options/Graphics.xml");

            this.Text = string.Format("Level2Pic v{0}", new Version(Application.ProductVersion).ToString(2));
        }
 public void FromJsonFail()
 {
     try
     {
         SpriteDocument.FromJSON("\"images\": {\"a\": \"dontexist.png\"}}");
     }
     catch (SpriteParseException ex)
     {
         Assert.IsNull(ex.FileName);
     }
 }
Exemple #8
0
        public Information(Level level, SpriteDocument document)
        {
            InitializeComponent();

            this.lvwColumnSorter = new Classes.ListViewColumnSorter();
            this.listviewCount.ListViewItemSorter = lvwColumnSorter;
            this.documentLoaded = document;
            this.levelLoaded    = level;
            this.tabcontrolMain.TabPages.Remove(this.tabpageInternet);
            this.Text = string.Format("{0} Properties", level.Name);
            this.SetLevelInfo(level);
        }
 public static async Task GenerateSpriteAsync(SpriteDocument doc)
 {
     try
     {
         await _generator.Generate(doc);
     }
     catch (FileNotFoundException ex)
     {
         MessageBox.Show(ex.Message, Vsix.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
         ProjectHelpers.DTE.ItemOperations.OpenFile(doc.FileName);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
 public static async Task GenerateSpriteAsync(string fileName)
 {
     try
     {
         SpriteDocument doc = await SpriteDocument.FromFile(fileName);
         await GenerateSpriteAsync(doc);
     }
     catch (SpriteParseException ex)
     {
         MessageBox.Show(ex.Message, Vsix.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
         ProjectHelpers.DTE.ItemOperations.OpenFile(fileName);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
        private async void Execute(object sender, EventArgs e)
        {
            var    files  = GetFiles();
            var    folder = Path.GetDirectoryName(files.First());
            string spriteFile;

            if (GetFileName(folder, out spriteFile))
            {
                var doc = new SpriteDocument(spriteFile, files);
                doc.Stylesheet = Stylesheet.Css;

                await doc.Save();

                ProjectHelpers.DTE.ItemOperations.OpenFile(doc.FileName);
                await SpriteService.GenerateSprite(doc);
            }
        }
Exemple #12
0
        private void SetCounter(SpriteDocument document, Level level)
        {
            // Has it been set already?
            if (this.listviewCount.Items.Count == 0)
            {
                foreach (KeyValuePair <int, int> sprite in level.Count)
                {
                    ListViewItem spriteItem = new ListViewItem();

                    spriteItem.Text = this.documentLoaded.Sprites[sprite.Key].Name;
                    spriteItem.SubItems.Add(sprite.Value.ToString("N"));
                    spriteItem.SubItems.Add(((float)sprite.Value / 5400F).ToString("0.##%"));

                    this.listviewCount.Items.Add(spriteItem);
                }
            }
        }
        public async Task CreateDocument()
        {
            var img      = Path.Combine(_artifacts, "images/96dpi/a.png");
            var original = new SpriteDocument(_fileName, new[] { img });

            original.Output = ImageType.Jpg;
            await original.Save();

            var read = await SpriteDocument.FromFile(_fileName);

            Assert.AreEqual(original.Orientation, read.Orientation);
            Assert.AreEqual(original.FileName, read.FileName);
            Assert.AreEqual(original.Output, read.Output);
            Assert.AreEqual(original.Images.Count(), read.Images.Count());

            var input = new FileInfo(Path.Combine(_artifacts, "images/96dpi/a.png")).FullName;

            Assert.AreEqual(input, read.ToAbsoluteImages().First().Value);
        }
        private void Execute(object sender, EventArgs e)
        {
            IEnumerable <string> files = GetFiles();
            string folder = Path.GetDirectoryName(files.First());

            if (GetFileName(folder, out string spriteFile))
            {
                var doc = new SpriteDocument(spriteFile, files)
                {
                    Stylesheet = Stylesheet.Css
                };

                ThreadHelper.JoinableTaskFactory.Run(async() =>
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    await doc.Save();
                    ProjectHelpers.DTE.ItemOperations.OpenFile(doc.FileName);
                    await SpriteService.GenerateSpriteAsync(doc);
                });
            }
        }
Exemple #15
0
        public Information(Classes.Dapper dapper, SpriteDocument document)
        {
            InitializeComponent();

            this.lvwColumnSorter = new Classes.ListViewColumnSorter();
            this.listviewCount.ListViewItemSorter = lvwColumnSorter;
            this.documentLoaded = document;
            this.levelLoaded    = new Level(dapper.Code);
            this.Text           = string.Format("{0} Properties", this.levelLoaded.Name);
            this.SetLevelInfo(this.levelLoaded);

            // Set the Pouetpu-Games information
            this.labelAverageRatingValue.Text          = string.Format("{0:P} ({1:N}/20)", dapper.Ratings, dapper.Ratings * 20);
            this.labelDatePublishedValue.Text          = dapper.Published.ToLongDateString();
            this.labelStatusValue.Text                 = dapper.Status;
            this.labelViewsValue.Text                  = string.Format("{0:N} view(s)", dapper.Views);
            this.labelVotesValue.Text                  = string.Format("{0:N} vote(s)", dapper.Votes);
            this.linkAuthorValue.Links[0].LinkData     = dapper.AuthorUri.ToString();
            this.linkAuthorValue.Text                  = dapper.Author;
            this.linkOnlineNameValue.Links[0].LinkData = dapper.Uri.ToString();
            this.linkOnlineNameValue.Text              = dapper.Name;
            this.textboxDescription.Text               = dapper.Description;
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            Microsoft.VisualStudio.Text.SnapshotPoint position = dragDropInfo.VirtualBufferPosition.Position;
            var doc = SpriteDocument.FromJSON(_view.TextBuffer.CurrentSnapshot.GetText(), _documentFileName);

            string ident = SpriteHelpers.GetIdentifier(_draggedFileName);
            string file  = SpriteHelpers.MakeRelative(_documentFileName, _draggedFileName);

            if (doc.Images.ContainsKey(ident))
            {
                ident += "_" + Guid.NewGuid().ToString().Replace("-", string.Empty);
            }

            doc.Images.Add(new KeyValuePair <string, string>(ident, file));

            using (Microsoft.VisualStudio.Text.ITextEdit edit = _view.TextBuffer.CreateEdit())
            {
                edit.Replace(0, _view.TextBuffer.CurrentSnapshot.Length, doc.ToJsonString());
                edit.Apply();
            }

            return(DragDropPointerEffects.Copy);
        }
Exemple #17
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            var _artifacts = new DirectoryInfo(".\\").FullName;

            var spritesDirName = "Sprites";

            if (!Directory.Exists(spritesDirName))
            {
                Directory.CreateDirectory(spritesDirName);
            }

            var _fileName = Path.Combine(_artifacts, spritesDirName, $"{txtSpriteName.Text}.sprite");

            var images = new List <string>();

            foreach (FileInfoDisplayName f in lbTarget.Items)
            {
                images.Add(f.File.FullName);
            }

            var document = new SpriteDocument(_fileName, images);

            document.Orientation             = ImageSprites.Orientation.Horizontal;
            document.Padding                 = 20;
            document.Output                  = ImageType.Png;
            document.Stylesheet              = Stylesheet.Css;
            document.CustomStyles["display"] = "block";
            document.CustomStyles.Add("margin", "0");

            var task = Task.Run(() => _generator.Generate(document));

            task.Wait();

            var documentTask = Task.Run(() => document.Save());

            documentTask.Wait();
        }
Exemple #18
0
 public void SetUp()
 {
     document = new SpriteDocument();
 }
 public async Task FromFileFail()
 {
     await SpriteDocument.FromFile("doesntexist.json");
 }