using System.Reflection; using EvilEngine.Conversion; using EvilEngine.Formats; using EvilEngine.Formats.Textures; namespace EvilEngine.Host.Tests; public sealed class SourceTextureTests { private static readonly string Installed = typeof(SourceTextureTests).Assembly .GetCustomAttributes() .Single(attribute => attribute.Key == "AdapterOutputRoot").Value!; private static (Texture Texture, byte[] Bytes) Convert(string id) { var path = Environment.GetEnvironmentVariable("EVIL_GMOD"); Assert.SkipWhen(path is null, "Set EVIL_GMOD to a Garry's Mod install to convert its textures."); var host = new EngineHost(); host.Adapters.LoadAll([Installed]); var mount = host.Mounts.Open(Assert.Single(host.Mounts.Probe(path!))); host.Conversion.AddNamespace(ContentNamespace.For(mount)); var result = host.Conversion.Get(ContentKind.Texture, ContentId.Parse(id)); Assert.True(result.Succeeded, string.Join('\n', result.Diagnostics)); Assert.Equal("source.vtf", result.Content!.Converter); return (TextureFile.Read(result.Content.Data, id), result.Content.Data.ToArray()); } [Fact] public void ConvertsTheOilDrumTheSameEachTime() { var (texture, bytes) = Convert("gmod:materials/models/props_c17/oil_drum001h"); Assert.Equal(bytes, Convert("gmod:materials/models/props_c17/oil_drum001h").Bytes); Assert.Equal((TextureFormat.Bc1RgbaUnorm, 512, 512, 1, 10), (texture.Format, texture.Width, texture.Height, texture.Layers, texture.Levels.Count)); } [Fact] public void ConvertsGarrysModsDefaultCubeMapWithoutItsSphereMap() { var (texture, _) = Convert("gmod:materials/engine/defaultcubemap"); Assert.True(texture.Cube); Assert.Equal(TextureMipFilter.None, texture.Sampling.Mips); Assert.Equal((TextureWrap.Clamp, TextureWrap.Clamp), (texture.Sampling.WrapU, texture.Sampling.WrapV)); } [Fact] public void ConvertsAParticleSheetWithItsSequences() { var (texture, _) = Convert("gmod:materials/particle/smoke1/smoke1"); Assert.NotNull(texture.Sheet); Assert.All(texture.Sheet, sequence => Assert.True(sequence.Clamp)); } }