Exemplo n.º 1
0
        /// <summary>
        /// Gets the <see cref="IAddGrhDataTask"/>s for animated <see cref="GrhData"/>s.
        /// </summary>
        /// <param name="rootGrhDir">The root grh dir.</param>
        /// <returns>The <see cref="IAddGrhDataTask"/>s for animated <see cref="GrhData"/>s.</returns>
        static IEnumerable <IAddGrhDataTask> GetAnimatedTasks(string rootGrhDir)
        {
            if (log.IsInfoEnabled)
            {
                log.InfoFormat("Searching for automatic animated GrhDatas from root `{0}`.", rootGrhDir);
            }

            var ret = new List <IAddGrhDataTask>();

            // Find all directories that match the needed pattern
            var dirs = GetAnimatedDirectories(rootGrhDir);

            foreach (var dir in dirs)
            {
                // Grab the animation info from the directory
                var animInfo = AutomaticAnimatedGrhData.GetAutomaticAnimationInfo(dir);
                if (animInfo == null)
                {
                    continue;
                }

                // Get the virtual directory (remove the root)
                var partialDir = dir.Substring(rootGrhDir.Length);
                if (partialDir.StartsWith(Path.DirectorySeparatorChar.ToString()) ||
                    partialDir.StartsWith(Path.AltDirectorySeparatorChar.ToString()))
                {
                    partialDir = partialDir.Substring(1);
                }

                // Get the categorization
                var lastDirSep = partialDir.LastIndexOf(Path.DirectorySeparatorChar);
                if (lastDirSep < 0)
                {
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat("Animated GrhData found at `{0}`, but could not be created because it has no category.",
                                       dir);
                    }
                    continue;
                }

                var categoryStr = partialDir.Substring(0, lastDirSep);

                var categorization = new SpriteCategorization(new SpriteCategory(categoryStr), new SpriteTitle(animInfo.Title));

                // Ensure the GrhData doesn't already exist
                if (GrhInfo.GetData(categorization) != null)
                {
                    continue;
                }

                // Create the task
                ret.Add(new AddAnimatedGrhDataTask(categorization));
            }

            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Makes sure the path could be parsed correctly with the given parameters and works for all path separators.
        /// </summary>
        /// <param name="prefix">The prefix string (to ensure it is properly ignored).</param>
        /// <param name="title">The sprite title.</param>
        /// <param name="speed">The animation speed.</param>
        static void RunValidPathTest(string prefix, string title, string speed)
        {
            foreach (var pathSep in _pathSeps)
            {
                var path = string.Format("{0}{4}{1}{2}{1}frames{1}{3}", prefix, AutomaticAnimatedGrhData.DirectoryNameDelimiter,
                                         title, speed, pathSep);

                var v = AutomaticAnimatedGrhData.GetAutomaticAnimationInfo(path);
                Assert.IsNotNull(v);
                Assert.AreEqual(v.Speed.ToString(), speed, "Path sep: " + pathSep);
                Assert.AreEqual(v.Title, title, "Path sep: " + pathSep);
            }
        }