public IImage ToItem(AGSSerializationContext context) { if (string.IsNullOrEmpty(ID)) { return(new EmptyImage(Width, Height)); } var loadConfig = LoadConfig.ToItem(context); var spriteSheet = SpriteSheet.ToItem(context); if (context.Textures.TryGetTexture(ID, out var texture)) { return(getImage(texture, spriteSheet, loadConfig)); } if (spriteSheet != null) { context.Factory.Graphics.LoadAnimationFromSpriteSheet(spriteSheet, null, loadConfig); if (context.Textures.TryGetTexture(ID, out texture)) { return(getImage(texture, spriteSheet, loadConfig)); } } try { texture = context.Factory.Graphics.LoadImage(ID, loadConfig).Texture; context.Textures.GetTexture(ID, _ => texture); return(getImage(texture, spriteSheet, loadConfig)); } catch (ArgumentException e) { Debug.WriteLine($"Failed to load image: {ID}. Exception: {e.ToString()}"); return(new EmptyImage(Width, Height)); } }