/// <summary> /// Finds all of the <see cref="GrhData"/>s that reference a texture that does not exist. /// </summary> /// <returns>IEnumerable of all of the <see cref="GrhData"/>s that reference a texture that does not exist.</returns> public static IEnumerable <StationaryGrhData> FindMissingTextures() { var nonanimated = GrhDatas.OfType <StationaryGrhData>(); var invalidTextures = nonanimated.Where(x => !x.TextureName.ContentExists()); return(invalidTextures); }
/// <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.Count(x => x == gd) == 1, "The GrhData should be in the list only once. Somehow, its in there either more times, or not at all."); }
/// <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))); } }
/// <summary> /// Gets a <see cref="IContentManager"/>. /// </summary> /// <returns>A <see cref="IContentManager"/>.</returns> static IContentManager GetContentManager() { return(GrhDatas.OfType <StationaryGrhData>().First(x => x.ContentManager != null).ContentManager); }
/// <summary> /// Deletes a <see cref="GrhData"/>. /// </summary> /// <param name="grhData"><see cref="GrhData"/> to delete.</param> /// <exception cref="ArgumentNullException"><paramref name="grhData" /> is <c>null</c>.</exception> public static void Delete(GrhData grhData) { if (grhData == null) { throw new ArgumentNullException("grhData"); } var grhIndex = grhData.GrhIndex; if (grhIndex.IsInvalid) { return; } // Insure the index is valid if (!_grhDatas.CanGet((int)grhIndex)) { const string errmsg = "Attempted to delete GrhData `{0}`, but GrhIndex `{1}` could not be acquired."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, grhData, grhIndex); } Debug.Fail(string.Format(errmsg, grhData, grhIndex)); return; } // Make sure we are deleting the correct GrhData var i = (int)grhIndex; if (_grhDatas[i] != grhData) { const string errmsg = "Attempted to delete GrhData `{0}`, but GrhIndex `{1}` is already in use by" + " a different GrhData `{2}`. Most likely, the GrhData we tried to delete is already deleted, and" + " the GrhIndex has been recycled to a new GrhData. Stop trying to delete dead stuff, will ya!?"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, grhData, grhIndex, _grhDatas[i]); } Debug.Fail(string.Format(errmsg, grhData, grhIndex, _grhDatas[i])); return; } // Remove the GrhData from the collection _grhDatas.RemoveAt((int)grhIndex); // If a stationary GrhData and auto-size is set, delete the texture, too try { var sgd = grhData as StationaryGrhData; if (sgd != null && sgd.AutomaticSize) { // Make sure no other GrhData is using the texture var origTexture = sgd.GetOriginalTexture(); if (GrhDatas.OfType <StationaryGrhData>().All(x => origTexture != x.GetOriginalTexture())) { // Dispose of the texture then recycle the file origTexture.Dispose(); try { sgd.TextureName.RecycleFile(); } catch { } } } } catch (Exception ex) { const string errmsg = "Failed to recycle texture file for GrhData `{0}`. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, grhData, ex); } Debug.Fail(string.Format(errmsg, grhData, ex)); } }