Tanoda
FilePickerTextureMapper.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using TriLibCore.Interfaces;
4using TriLibCore.SFB;
5using TriLibCore.Utils;
6
7namespace TriLibCore.Mappers
8{
10 public class FilePickerTextureMapper : TextureMapper
11 {
13 public override TextureLoadingContext Map(AssetLoaderContext assetLoaderContext, ITexture texture)
14 {
15 if (string.IsNullOrEmpty(texture.Filename)) return null;
16 if (assetLoaderContext.CustomData is IEnumerable<ItemWithStream> itemsWithStream)
17 {
18 var shortFileName = FileUtils.GetShortFilename(texture.Filename).ToLowerInvariant();
19 foreach (var itemWithStream in itemsWithStream)
20 {
21 if (!itemWithStream.HasData) continue;
22 var checkingFileShortName = FileUtils.GetShortFilename(itemWithStream.Name).ToLowerInvariant();
23 if (shortFileName == checkingFileShortName)
24 {
25 var textureLoadingContext = new TextureLoadingContext
26 {
27 Context = assetLoaderContext,
28 Stream = itemWithStream.OpenStream(),
29 Texture = texture
30 };
31 return textureLoadingContext;
32 }
33 }
34 }
35 else
36 {
37 throw new Exception("Missing custom context data.");
38 }
39
40 return null;
41 }
42 }
43}
Represents a class used to load Textures from a list of selected files.
override TextureLoadingContext Map(AssetLoaderContext assetLoaderContext, ITexture texture)