Пример #1
0
        /// <summary>
        /// Adds a <see cref="GrhData"/> to the list of <see cref="GrhData"/>s at the index assigned to it.
        /// </summary>
        /// <param name="gd"><see cref="GrhData"/> to add.</param>
        /// <exception cref="ArgumentNullException"><paramref name="gd" /> is <c>null</c>.</exception>
        internal static void AddGrhData(GrhData gd)
        {
            if (gd == null)
            {
                throw new ArgumentNullException("gd");
            }

            var index = gd.GrhIndex;

            AssertGrhIndexIsFree(index, gd);

            _grhDatas[(int)index] = gd;

            // Make sure the GrhData is only in the list once
            Debug.Assert(GrhDatas.Where(x => x == gd).Count() == 1,
                         "The GrhData should be in the list only once. Somehow, its in there either more times, or not at all.");
        }
Пример #2
0
        /// <summary>
        /// Saves all of the GrhData information to the specified file.
        /// </summary>
        /// <param name="contentPath">ContentPath to save the GrhData to.</param>
        public static void Save(ContentPaths contentPath)
        {
            // Grab the GrhDatas by their type
            var gds = GrhDatas.Where(x => x != null).OrderBy(x => x.Categorization.ToString(), StringComparer.OrdinalIgnoreCase);
            var stationaryGrhDatas   = gds.OfType <StationaryGrhData>().ToImmutable();
            var animatedGrhDatas     = gds.OfType <AnimatedGrhData>().ToImmutable();
            var autoAnimatedGrhDatas = gds.OfType <AutomaticAnimatedGrhData>().ToImmutable();

            // Write
            var path = GetGrhDataFilePath(contentPath);

            using (IValueWriter writer = GenericValueWriter.Create(path, _rootNodeName, EncodingFormat))
            {
                writer.WriteManyNodes(_nonAnimatedGrhDatasNodeName, stationaryGrhDatas, ((w, item) => item.Write(w)));
                writer.WriteManyNodes(_animatedGrhDatasNodeName, animatedGrhDatas, ((w, item) => item.Write(w)));
                writer.WriteManyNodes(_autoAnimatedGrhDatasNodeName, autoAnimatedGrhDatas, ((w, item) => item.Write(w)));
            }
        }