public StaticSpriteFont Load(AssetLoaderContext context, string assetName) { var fontData = context.Load <string>(assetName); return(StaticSpriteFont.FromBMFont(fontData, name => TextureGetter(context, name))); }
public SoundEffect Load(AssetLoaderContext context, string assetName) { using (var stream = context.Open(assetName)) { return(SoundEffect.FromStream(stream)); } }
public Texture2D Load(AssetLoaderContext context, string assetName) { using (var stream = context.Open(assetName)) { return(Texture2DExtensions.FromStream(stream, true)); } }
public TextureRegionAtlas Load(AssetLoaderContext context, string assetName) { var data = context.Load <string>(assetName); #if MONOGAME || FNA || STRIDE return(TextureRegionAtlas.Load(data, name => context.Load <Texture2D>(name))); #else return(TextureRegionAtlas.Load(data, name => context.Load <Texture2DWrapper>(name).Texture)); #endif }
public SpriteFontBase Load(AssetLoaderContext context, string assetName) { if (assetName.Contains(".fnt")) { return(context.Load <StaticSpriteFont>(assetName)); } else if (assetName.Contains(".ttf")) { return(context.Load <DynamicSpriteFont>(assetName)); } throw new Exception(string.Format("Can't load font '{0}'", assetName)); }
public FontSystem Load(AssetLoaderContext context, string assetName) { var parts = assetName.Split(':'); var fontType = FontType.Regular; var amount = 1; if (parts.Length > 1) { fontType = (FontType)Enum.Parse(typeof(FontType), parts[1]); if (fontType != FontType.Regular) { if (parts.Length < 3) { throw new Exception("Missing amount"); } amount = int.Parse(parts[2]); } } FontSystem fontSystem = null; switch (fontType) { case FontType.Regular: fontSystem = FontSystemFactory.Create(context.GraphicsDevice, 1024, 1024); break; case FontType.Blurry: fontSystem = FontSystemFactory.CreateBlurry(context.GraphicsDevice, 1024, 1024, amount); break; case FontType.Stroked: fontSystem = FontSystemFactory.CreateStroked(context.GraphicsDevice, 1024, 1024, amount); break; } var data = context.Load <byte[]>(parts[0]); fontSystem.AddFont(data); return(fontSystem); }
public Texture2DWrapper Load(AssetLoaderContext context, string assetName) #endif { ImageResult result = null; using (var stream = context.Open(assetName)) { if (stream.CanSeek) { result = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha); } else { // If stream doesnt provide seek functionaly, use MemoryStream instead using (var ms = new MemoryStream()) { stream.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); result = ImageResult.FromStream(ms, ColorComponents.RedGreenBlueAlpha); } } } // Premultiply Alpha var b = result.Data; for (var i = 0; i < result.Data.Length; i += 4) { var a = b[i + 3]; b[i] = ApplyAlpha(b[i], a); b[i + 1] = ApplyAlpha(b[i + 1], a); b[i + 2] = ApplyAlpha(b[i + 2], a); } #if MONOGAME || FNA || STRIDE var texture = CrossEngineStuff.CreateTexture(MyraEnvironment.GraphicsDevice, result.Width, result.Height); CrossEngineStuff.SetTextureData(texture, new Rectangle(0, 0, result.Width, result.Height), result.Data); return(texture); #else var texture = MyraEnvironment.Platform.CreateTexture(result.Width, result.Height); MyraEnvironment.Platform.SetTextureData(texture, new Rectangle(0, 0, result.Width, result.Height), result.Data); return(new Texture2DWrapper(result.Width, result.Height, texture)); #endif }
public TextureRegion Load(AssetLoaderContext context, string assetName) { if (assetName.Contains(":")) { // First part is texture region atlas name // Second part is texture region name var parts = assetName.Split(':'); var textureRegionAtlas = context.Load <TextureRegionAtlas>(parts[0]); return(textureRegionAtlas[parts[1]]); } // Ordinary texture #if MONOGAME || FNA || STRIDE var texture = context.Load <Texture2D>(assetName); return(new TextureRegion(texture, new Rectangle(0, 0, texture.Width, texture.Height))); #else var texture = context.Load <Texture2DWrapper>(assetName); return(new TextureRegion(texture.Texture, new Rectangle(0, 0, texture.Width, texture.Height))); #endif }
public DynamicSpriteFont Load(AssetLoaderContext context, string assetName) { var parts = assetName.Split(':'); if (parts.Length < 2) { throw new Exception("Missing font size"); } var fontSize = int.Parse(parts[parts.Length - 1]); var partsWithoutSize = new List <string>(); for (var i = 0; i < parts.Length - 1; ++i) { partsWithoutSize.Add(parts[i]); } var fontSystem = context.Load <FontSystem>(string.Join(":", partsWithoutSize)); return(fontSystem.GetFont(fontSize)); }
public FontSystem Load(AssetLoaderContext context, string assetName) { var parts = assetName.Split(':'); var fontType = FontType.Regular; var amount = 1; if (parts.Length > 1) { fontType = (FontType)Enum.Parse(typeof(FontType), parts[1]); if (fontType != FontType.Regular) { if (parts.Length < 3) { throw new Exception("Missing amount"); } amount = int.Parse(parts[2]); } } FontSystem fontSystem = null; #if MONOGAME || FNA || STRIDE switch (fontType) { case FontType.Regular: fontSystem = FontSystemFactory.Create(MyraEnvironment.GraphicsDevice, MyraEnvironment.FontAtlasSize, MyraEnvironment.FontAtlasSize); break; case FontType.Blurry: fontSystem = FontSystemFactory.CreateBlurry(MyraEnvironment.GraphicsDevice, amount, MyraEnvironment.FontAtlasSize, MyraEnvironment.FontAtlasSize); break; case FontType.Stroked: fontSystem = FontSystemFactory.CreateStroked(MyraEnvironment.GraphicsDevice, amount, MyraEnvironment.FontAtlasSize, MyraEnvironment.FontAtlasSize); break; } #else switch (fontType) { case FontType.Regular: fontSystem = FontSystemFactory.Create(MyraEnvironment.FontAtlasSize, MyraEnvironment.FontAtlasSize); break; case FontType.Blurry: fontSystem = FontSystemFactory.CreateBlurry(amount, MyraEnvironment.FontAtlasSize, MyraEnvironment.FontAtlasSize); break; case FontType.Stroked: fontSystem = FontSystemFactory.CreateStroked(amount, MyraEnvironment.FontAtlasSize, MyraEnvironment.FontAtlasSize); break; } #endif var data = context.Load <byte[]>(parts[0]); fontSystem.AddFont(data); return(fontSystem); }
public T Load <T>(string assetName) { var type = typeof(T); assetName = assetName.Replace('\\', SeparatorSymbol); Dictionary <string, object> cache; if (_cache.TryGetValue(type, out cache)) { object cached; if (cache.TryGetValue(assetName, out cached)) { // Found in cache return((T)cached); } } LoaderInfo loaderBase; if (!_loaders.TryGetValue(type, out loaderBase)) { // Try determine it using AssetLoader attribute var attr = type.FindAttribute <AssetLoaderAttribute>(); if (attr == null) { throw new Exception(string.Format("Unable to resolve AssetLoader for type {0}", type.Name)); } // Create loader loaderBase = new LoaderInfo(Activator.CreateInstance(attr.AssetLoaderType), attr.StoreInCache); // Save in the _loaders _loaders[type] = loaderBase; } var loader = (IAssetLoader <T>)loaderBase.Loader; var baseFolder = string.Empty; var assetFileName = assetName; var separatorIndex = assetName.LastIndexOf(SeparatorSymbol); if (separatorIndex != -1) { baseFolder = assetName.Substring(0, separatorIndex); assetFileName = assetName.Substring(separatorIndex + 1); } var context = new AssetLoaderContext(this, baseFolder); var result = loader.Load(context, assetFileName); if (loaderBase.StoreInCache) { // Store in cache if (cache == null) { cache = new Dictionary <string, object>(); _cache[type] = cache; } cache[assetName] = result; } return(result); }
private TextureWithOffset TextureGetter(AssetLoaderContext context, string name) { var textureRegion = context.Load <TextureRegion>(name); return(new TextureWithOffset(textureRegion.Texture, textureRegion.Bounds.Location)); }
public Texture2D Load(AssetLoaderContext context, string assetName)