/// <summary>
        /// Checks which existing texture file closest resembles the specified <paramref name="matchTextureName"/>.
        /// </summary>
        /// <param name="matchTextureName">Name of the texture to to find the best match for.</param>
        /// <returns>
        /// Name of the texture file that best matches the specified <paramref name="matchTextureName"/>, or
        /// null if no decent matches were found.
        /// </returns>
        public string FindBestMatchTexture(string matchTextureName)
        {
            // Check that we even have this texture
            if (!Contains(matchTextureName))
            {
                return(null);
            }

            // Get the info for the texture to match against
            var target = this[matchTextureName];

            // Loop through every existing hash until we find one with the same size and hash, but the file exists
            foreach (var kvp in _textureHash)
            {
                var hashInfo = kvp.Value;
                if (hashInfo == target || hashInfo.FileSize != target.FileSize || hashInfo.Hash != target.Hash)
                {
                    continue;
                }

                var textureName = kvp.Key;
                var assetName   = new ContentAssetName(textureName);
                if (assetName.ContentExists())
                {
                    return(textureName);
                }
            }

            return(null);
        }
        /// <summary>
        /// Creates the <see cref="StationaryGrhData"/> frames for this <see cref="AutomaticAnimatedGrhData"/>.
        /// </summary>
        /// <param name="directory">The directory containing the frames.</param>
        /// <returns>An array of the <see cref="StationaryGrhData"/> frames.</returns>
        StationaryGrhData[] CreateFrames(string directory)
        {
            // Find all the valid content files
            var allFiles = Directory.GetFiles(directory, "*" + ContentPaths.ContentFileSuffix, SearchOption.TopDirectoryOnly);

            // Filter out the files with invalid naming conventions, and sort them so we animate in the correct order
            var files = SortAndFilterFrameFiles(allFiles);

            // Build the individual frames
            var frames = new StationaryGrhData[files.Length];

            for (var i = 0; i < frames.Length; i++)
            {
                var contentAssetName = ContentAssetName.FromAbsoluteFilePath(files[i], ContentPaths.Build.Grhs).Value;
                var textureAssetName = new TextureAssetName(contentAssetName);
                var frameGrhData     = new StationaryGrhData(this, textureAssetName);
                frames[i] = frameGrhData;
            }

            if (frames.Length == 0)
            {
                throw new Exception("Animation has no frames");
            }

            return(frames);
        }
Beispiel #3
0
        public void FromAbsoluteFilePathAlternateSeparatorDeepTest()
        {
            var n = ContentAssetName.FromAbsoluteFilePath(@"C:/whatever/path/to/mycontent/is/super/awesome",
                                                          @"C:/whatever/path/to");

            Assert.AreEqual(@"mycontent/is/super/awesome".Replace("/", ContentAssetName.PathSeparator), n.Value);
        }
Beispiel #4
0
        public void FromAbsoluteFilePathDeepTest()
        {
            var n = ContentAssetName.FromAbsoluteFilePath(@"C:\whatever\path\to\mycontent\is\super\awesome",
                                                          @"C:\whatever\path\to");

            Assert.AreEqual(@"mycontent\is\super\awesome".Replace("\\", ContentAssetName.PathSeparator), n.Value);
        }
        /// <summary>
        /// Loads an asset that has been created through the Content Pipeline.
        /// </summary>
        /// <param name="contentManager">The <see cref="IContentManager"/> to use to load the asset.</param>
        /// <param name="contentAssetName">The name of the asset to load.</param>
        /// <param name="level">The <see cref="ContentLevel"/> to load the asset into.</param>
        /// <returns>
        /// The asset loaded from the <paramref name="contentManager"/>, or null if the loading failed.
        /// </returns>
        public static Image LoadImage(this IContentManager contentManager, ContentAssetName contentAssetName, ContentLevel level)
        {
            if (contentManager == null || contentAssetName == null)
                return null;

            return contentManager.LoadImage(contentAssetName.Value, level);
        }
Beispiel #6
0
        public void FromAbsoluteFilePathWithSuffixTest()
        {
            var n = ContentAssetName.FromAbsoluteFilePath(@"C:\whatever\path\to\mycontent" + ContentPaths.ContentFileSuffix,
                                                          @"C:\whatever\path\to");

            Assert.AreEqual("mycontent", n.Value);
        }
        /// <summary>
        /// Loads an asset that has been created through the Content Pipeline.
        /// </summary>
        /// <param name="contentManager">The <see cref="IContentManager"/> to use to load the asset.</param>
        /// <param name="contentAssetName">The name of the asset to load.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="level">The <see cref="ContentLevel"/> to load the asset into.</param>
        /// <returns>
        /// The asset loaded from the <paramref name="contentManager"/>, or null if the loading failed.
        /// </returns>
        public static Font LoadFont(this IContentManager contentManager, ContentAssetName contentAssetName, int fontSize,
                                    ContentLevel level)
        {
            if (contentManager == null || contentAssetName == null)
                return null;

            return contentManager.LoadFont(contentAssetName.Value, fontSize, level);
        }
Beispiel #8
0
        public void FromAbsoluteFilePathWithSuffixCapsTest()
        {
            var n =
                ContentAssetName.FromAbsoluteFilePath(
                    (@"C:\whatever\path\to\mycontent" + ContentPaths.ContentFileSuffix).ToUpper(), @"C:\whatever\path\to");

            Assert.AreEqual("mycontent", n.Value.ToLower());
        }
        /// <summary>
        ///   Updates the HashInfo for all of the files in the specified root directory.
        /// </summary>
        void UpdateHashes()
        {
            var files = GetFilesToHash(_rootTextureDir);

            foreach (var file in files)
            {
                try
                {
                    // Get the current info
                    var      contentAssetName = ContentAssetName.FromAbsoluteFilePath(file, _rootTextureDir).Value;
                    var      textureName      = new TextureAssetName(contentAssetName).Value;
                    HashInfo hashInfo         = null;
                    if (Contains(textureName))
                    {
                        hashInfo = this[textureName];
                    }

                    // Get the file size and last modified time
                    int  size;
                    long lastMod;
                    GetFileSizeAndLastModified(file, out size, out lastMod);

                    // If we already have the hash info, and the size and last modified time have not changed,
                    // we can skip updating the hash
                    if (hashInfo != null && hashInfo.FileSize == size && hashInfo.LastModifiedTime == lastMod)
                    {
                        continue;
                    }

                    // Get the new hash and add the new file or update the existing values
                    var hash = GetFileHash(file);
                    if (hashInfo == null)
                    {
                        hashInfo          = new HashInfo(hash, size, lastMod);
                        this[textureName] = hashInfo;
                    }
                    else
                    {
                        hashInfo.FileSize         = size;
                        hashInfo.Hash             = hash;
                        hashInfo.LastModifiedTime = lastMod;
                    }
                }
                catch (IOException)
                {
                }
                catch (UnauthorizedAccessException)
                {
                }
            }

            // Write the updates
            Save();
        }
Beispiel #10
0
        void NewTxt_TextChanged(object sender, EventArgs e)
        {
            var textureName = NewTxt.Text;

            var assetName = new ContentAssetName(NewTxt.Text);

            if (!string.IsNullOrEmpty(textureName) && assetName.ContentExists())
            {
                NewTxt.BackColor = EditorColors.Normal;

                var texture = _cm.LoadImage(assetName, ContentLevel.Temporary);
                var w       = (int)texture.Width;
                var h       = (int)texture.Height;

                Image previewImage = texture.ToBitmap(new Rectangle(0, 0, w, h), PreviewPic.Width, PreviewPic.Height);
                PreviewPic.Image = previewImage;
            }
            else
            {
                PreviewPic.Image = null;
                NewTxt.BackColor = EditorColors.Error;
            }
        }
Beispiel #11
0
 public static void Write(this IValueWriter writer, string name, ContentAssetName value)
 {
     writer.Write(name, value.Value);
 }
Beispiel #12
0
        public void GetAbsoluteFilePathTest()
        {
            var s = new ContentAssetName("myasset").GetAbsoluteFilePath(ContentPaths.Build);

            Assert.IsTrue(s.EndsWith("Content\\myasset" + ContentPaths.ContentFileSuffix, StringComparison.OrdinalIgnoreCase));
        }
        /// <summary>
        /// Checks which existing texture file closest resembles the specified <paramref name="matchTextureName"/>.
        /// </summary>
        /// <param name="matchTextureName">Name of the texture to to find the best match for.</param>
        /// <returns>
        /// Name of the texture file that best matches the specified <paramref name="matchTextureName"/>, or
        /// null if no decent matches were found.
        /// </returns>
        public string FindBestMatchTexture(string matchTextureName)
        {
            // Check that we even have this texture
            if (!Contains(matchTextureName))
                return null;

            // Get the info for the texture to match against
            var target = this[matchTextureName];

            // Loop through every existing hash until we find one with the same size and hash, but the file exists
            foreach (var kvp in _textureHash)
            {
                var hashInfo = kvp.Value;
                if (hashInfo == target || hashInfo.FileSize != target.FileSize || hashInfo.Hash != target.Hash)
                    continue;

                var textureName = kvp.Key;
                var assetName = new ContentAssetName(textureName);
                if (assetName.ContentExists())
                    return textureName;
            }

            return null;
        }
Beispiel #14
0
        public void FromAbsoluteFilePathTrailingSlashTest()
        {
            var n = ContentAssetName.FromAbsoluteFilePath(@"C:\whatever\path\to\mycontent", @"C:\whatever\path\to\");

            Assert.AreEqual("mycontent", n.Value);
        }
Beispiel #15
0
        public void FromAbsoluteFilePathAlternateSeparatorTest()
        {
            var n = ContentAssetName.FromAbsoluteFilePath(@"C:/whatever/path/to/mycontent", @"C:/whatever/path/to");

            Assert.AreEqual("mycontent", n.Value);
        }
Beispiel #16
0
        public void FromAbsoluteFilePathCapsTest()
        {
            var n = ContentAssetName.FromAbsoluteFilePath(@"C:\whatever\path\to\mycontent".ToUpper(), @"C:\whatever\path\to");

            Assert.AreEqual("mycontent", n.Value.ToLower());
        }
Beispiel #17
0
        void NewTxt_TextChanged(object sender, EventArgs e)
        {
            var textureName = NewTxt.Text;

            var assetName = new ContentAssetName(NewTxt.Text);
            if (!string.IsNullOrEmpty(textureName) && assetName.ContentExists())
            {
                NewTxt.BackColor = EditorColors.Normal;

                var texture = _cm.LoadImage(assetName, ContentLevel.Temporary);
                var w = (int)texture.Width;
                var h = (int)texture.Height;

                Image previewImage = texture.ToBitmap(new Rectangle(0, 0, w, h), PreviewPic.Width, PreviewPic.Height);
                PreviewPic.Image = previewImage;
            }
            else
            {
                PreviewPic.Image = null;
                NewTxt.BackColor = EditorColors.Error;
            }
        }
Beispiel #18
0
        public void SanitizeSuffixedSeparatorTest()
        {
            const string s = @"asdf\";

            Assert.AreEqual("asdf", ContentAssetName.Sanitize(s));
        }
Beispiel #19
0
        public void SanitizeSeparatorTest()
        {
            const string s = @"asdf\basdf\wer\asdf";

            Assert.AreEqual(s.Replace("\\", ContentAssetName.PathSeparator), ContentAssetName.Sanitize(s));
        }
 /// <summary>
 /// Gets the sanitized text for this <see cref="AutoValidateTextBox"/>. This should always be used when
 /// you want to make use of the contents of the <see cref="AutoValidateTextBox"/>. The sanitized
 /// text is only guaranteed to be valid if IsValid is true.
 /// </summary>
 /// <param name="text">The text to sanitize.</param>
 /// <returns>
 /// The sanitized text for this <see cref="AutoValidateTextBox"/>.
 /// </returns>
 public override string GetSanitizedText(string text)
 {
     return(ContentAssetName.Sanitize(text));
 }
Beispiel #21
0
        public void SanitizeAlternateSeparatorTest()
        {
            const string s = @"asdf/basdf/wer/asdf";

            Assert.AreEqual(s.Replace("/", ContentAssetName.PathSeparator), ContentAssetName.Sanitize(s));
        }
Beispiel #22
0
        public void SanitizePrefixedAndSuffixedAlternateSeparatorTest()
        {
            const string s = @"/asdf/";

            Assert.AreEqual("asdf", ContentAssetName.Sanitize(s));
        }
 public void GetAbsoluteFilePathTest()
 {
     var s = new ContentAssetName("myasset").GetAbsoluteFilePath(ContentPaths.Build);
     Assert.IsTrue(s.EndsWith("Content\\myasset" + ContentPaths.ContentFileSuffix, StringComparison.OrdinalIgnoreCase));
 }