Interface IContentManager
- Namespace
- BSGameLib.Game
- Assembly
- BSGameLib.Game.dll
Loads, caches and finds the textures and fonts a game uses, by file name. Games reach it through ContentManager.
public interface IContentManager : IDisposable
- Inherited Members
Properties
Fonts
The cached fonts. A font cached under more than one name is listed once.
IReadOnlyList<IFont> Fonts { get; }
Property Value
TextureCount
The number of textures in the cache.
int TextureCount { get; }
Property Value
Textures
The cached textures, by the name each was first requested under. Built on each read, so keep the result rather than reading it in a loop.
IReadOnlyDictionary<string, ITexture> Textures { get; }
Property Value
Methods
AddFont(string, IFont)
Caches font under key, and also under its FileName when it has one.
void AddFont(string key, IFont font)
Parameters
AddTexture(string, ITexture)
Caches texture under key, so later lookups by that name return it. Does nothing if the key is already cached.
void AddTexture(string key, ITexture texture)
Parameters
CreateTextureFromColorArray(Color[], int, int)
Creates a texture from colors, width pixels wide and height pixels high. The texture is not cached; AddTexture(string, ITexture) names it.
ITexture CreateTextureFromColorArray(Color[] colors, int width, int height)
Parameters
Returns
EnumerateFiles(string, bool)
Lists the files under path, relative to the root folder. Files in the overlay folders are listed too, and an overlay's file stands in for the root's file with the same relative path.
IEnumerable<FileInfo> EnumerateFiles(string path, bool recurseSubDirectories)
Parameters
Returns
FontExists(string)
Whether a font is cached under key, or under the file that key resolves to, at any size.
bool FontExists(string key)
Parameters
keystring
Returns
GetBMFont(string)
Returns the BMFont (.fnt) in fontFile, loading and caching it on first use. Returns null, and logs a warning, when the file does not exist or cannot be loaded.
IFont GetBMFont(string fontFile)
Parameters
fontFilestring
Returns
GetBMFontFromStream(string, Stream)
Returns the BMFont read from stream, cached under fontFile.
IFont GetBMFontFromStream(string fontFile, Stream stream)
Parameters
Returns
GetIndexedTextureAtlas(int, int, Color?, params string[])
Builds an indexed atlas whose sheets are loaded with a transparent color.
ITextureAtlas GetIndexedTextureAtlas(int width, int height, Color? colorKey, params string[] fileNames)
Parameters
Returns
Remarks
The same need as the keyed GetTexture(string, Color?), for art that arrives a sheet at a time. Sheets from the DirectDraw era carry no alpha at all and mark their transparency with a color, so an atlas built over them without a key draws every cell inside an opaque box. That stays invisible for as long as the cells being drawn are edge-to-edge art, and is obvious the moment one is drawn over something else.
GetIndexedTextureAtlas(int, int, params string[])
Returns an indexed atlas whose items are cells of width by height pixels, taken from the images in fileNames in order. Items are got by an int index. Returns null when fileNames is empty.
ITextureAtlas GetIndexedTextureAtlas(int width, int height, params string[] fileNames)
Parameters
Returns
GetRegionAtlas(string, Color?)
Loads a region atlas over an image, with a colour key if one is given, and returns it empty: the game adds the regions.
IRegionTextureAtlas GetRegionAtlas(string fileName, Color? colorKey = null)
Parameters
Returns
Remarks
Like GetTexture(string, Color?), the image is found through the root and the overlays, and the atlas is cached under the file it resolves to - a keyed atlas apart from an un-keyed one. Throws if the image file cannot be read.
GetRegionTextureAtlas(ITexture)
Returns a region atlas over texture. Regions are added to it with AddRegion(string, int, int, int, int).
IRegionTextureAtlas GetRegionTextureAtlas(ITexture texture)
Parameters
textureITexture
Returns
GetRegionTextureAtlas(string)
Returns a region atlas over the image in fileName, loading and caching the image on first use.
IRegionTextureAtlas GetRegionTextureAtlas(string fileName)
Parameters
fileNamestring
Returns
GetRegionTextureAtlasFromStream(string, Stream)
Returns a region atlas over the image decoded from stream, cached under fileName.
IRegionTextureAtlas GetRegionTextureAtlasFromStream(string fileName, Stream stream)
Parameters
Returns
GetSubTexture(ITexture, TextureRegion)
Returns a texture that shows region of parentTexture.
ITexture GetSubTexture(ITexture parentTexture, TextureRegion region)
Parameters
parentTextureITextureregionTextureRegion
Returns
GetSubTexture(string, TextureRegion)
Returns the part of the image in fileName that region covers.
ITexture GetSubTexture(string fileName, TextureRegion region)
Parameters
fileNamestringregionTextureRegion
Returns
GetSubTextureFromStream(string, Stream, TextureRegion)
Returns the part of the image decoded from stream that region covers.
ITexture GetSubTextureFromStream(string fileName, Stream stream, TextureRegion region)
Parameters
fileNamestringstreamStreamregionTextureRegion
Returns
GetTexture(string)
Returns the texture for fileName, loading and caching it on first use. Throws when the file cannot be read. A name containing | names an atlas or one of its regions, such as sheet.png|ATLAS.
ITexture GetTexture(string fileName)
Parameters
fileNamestring
Returns
GetTexture(string, Color?)
Loads a texture with a transparent color, as the original DirectDraw client did for every sprite, tile, object and effect sheet.
ITexture GetTexture(string fileName, Color? colorKey)
Parameters
Returns
Remarks
Cached separately from the un-keyed load of the same file, since they are different images.
GetTextureFromStream(string, Stream)
Returns a texture decoded from stream, cached under fileName.
ITexture GetTextureFromStream(string fileName, Stream stream)
Parameters
Returns
GetTrueTypeFont(string, int, bool, bool)
Loads a TrueType font at a size. Bold and italic are faked from the one face - see LoadTrueTypeFontFromFile. Each combination of size and style is its own font.
IFont GetTrueTypeFont(string fontFile, int size, bool bold = false, bool italic = false)
Parameters
Returns
GetTrueTypeFontFromStream(string, int, Stream, bool, bool)
Returns a TrueType font read from stream at size. Bold and italic are faked from the one face, as GetTrueTypeFont(string, int, bool, bool) describes.
IFont GetTrueTypeFontFromStream(string fontFile, int size, Stream stream, bool bold = false, bool italic = false)
Parameters
Returns
ResetRootPath()
Sets the root folder back to the working directory.
void ResetRootPath()
SetOverlayPaths(IEnumerable<string>)
Folders looked in before the root path, first to last, for every texture and font loaded by file name: a file found in one stands in for the root's file of the same name. For content a player or a mod replaces without touching what the game installed.
void SetOverlayPaths(IEnumerable<string> paths)
Parameters
pathsIEnumerable<string>
Remarks
Set it before loading. What is loaded is cached by file name, so a texture already loaded from the root stays the root's until it is unloaded.
SetRootPath(string)
Sets the folder that file names are resolved against. Content already cached stays as it was loaded.
void SetRootPath(string path)
Parameters
pathstring
TextureExists(string)
Whether a texture is cached under key, or under the file that key resolves to.
bool TextureExists(string key)
Parameters
keystring
Returns
UnloadFont(string)
Removes every font cached under key, at any size, and disposes each one.
void UnloadFont(string key)
Parameters
keystring
UnloadTexture(string)
Removes the texture cached under key, and disposes it if it is disposable. Does nothing if none is cached.
void UnloadTexture(string key)
Parameters
keystring