using AcDream.Content.CharGen; using AcDream.Core.CharGen; using DatReaderWriter; using DatReaderWriter.Options; using Xunit.Abstractions; namespace AcDream.Content.Tests.CharGen; /// /// Installed-DAT gate for + /// together: for every one of the 13 /// installed heritages' genders, composes a "pick the first offered option /// everywhere, mid shade" selection and asserts it resolves with no missing /// PalSet or ClothingTable dat ids — the CC6a task's explicit acceptance /// bar ("every heritage/gender's default selection resolves to a complete /// description with no missing dat ids"). Also records (without asserting /// zero — see the class doc on 's /// deliberate scope cut) how many clothing slots have no /// ClothingBaseEffects entry for their own gender's body Setup, so a /// future session can see at a glance whether CC6a's decision to skip /// retail's Setup-substitution fallback chain ever actually costs /// coverage on the real dat. /// public sealed class ChargenAppearanceCatalogInstalledDatTests { private readonly ITestOutputHelper _out; public ChargenAppearanceCatalogInstalledDatTests(ITestOutputHelper output) => _out = output; private static string? ResolveDatDir() { string? fromEnv = Environment.GetEnvironmentVariable("ACDREAM_DAT_DIR"); if (!string.IsNullOrWhiteSpace(fromEnv) && Directory.Exists(fromEnv)) return fromEnv; string def = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Documents", "Asheron's Call"); return Directory.Exists(def) ? def : null; } [Fact] public void EveryHeritageGendersDefaultSelection_ResolvesWithNoMissingDatIds() { string? datDir = ResolveDatDir(); if (datDir is null) { _out.WriteLine("SKIP: installed retail DAT directory is unavailable."); return; } using var dats = new DatCollection(datDir, DatAccessType.Read); using var adapter = new DatCollectionAdapter(dats); ChargenOptions options = ChargenTableReader.Load(adapter); Assert.NotEmpty(options.HeritagesById); var catalog = new ChargenAppearanceCatalog(adapter); int composed = 0; int absentBaseEffectTotal = 0; var missingSummaries = new List(); foreach (ChargenHeritageOptions heritage in options.HeritagesById.Values) { foreach ((int genderKey, ChargenGenderOptions gender) in heritage.GendersByKey) { ChargenAppearanceSelection selection = MakeDefaultSelection(gender); bool ok = ChargenAppearanceFactory.TryCompose( options, heritage.HeritageId, genderKey, selection, catalog, catalog, out ChargenAppearanceResult result); Assert.True(ok, $"heritage=0x{heritage.HeritageId:X} gender={genderKey} failed to resolve heritage/gender"); composed++; if (result.MissingPalSetIds.Count > 0 || result.MissingClothingTableIds.Count > 0) { missingSummaries.Add( $"heritage={heritage.Name} gender={genderKey}: " + $"missingPalSets=[{string.Join(",", result.MissingPalSetIds.Select(id => $"0x{id:X8}"))}] " + $"missingClothingTables=[{string.Join(",", result.MissingClothingTableIds.Select(id => $"0x{id:X8}"))}]"); } absentBaseEffectTotal += result.ClothingTablesMissingBaseEffectForSetup.Count; if (result.ClothingTablesMissingBaseEffectForSetup.Count > 0) { _out.WriteLine( $"heritage={heritage.Name} gender={genderKey} setup=0x{result.SetupId:X8}: " + $"{result.ClothingTablesMissingBaseEffectForSetup.Count} clothing table(s) with no " + "ClothingBaseEffects entry for this body setup " + $"[{string.Join(",", result.ClothingTablesMissingBaseEffectForSetup.Select(id => $"0x{id:X8}"))}]"); } } } _out.WriteLine($"composed {composed} heritage/gender selections; {absentBaseEffectTotal} absent-base-effect slots total."); Assert.True( missingSummaries.Count == 0, "Missing dat ids found:\n" + string.Join('\n', missingSummaries)); Assert.True(composed >= 13, $"Expected at least 13 heritage/gender combinations, composed {composed}."); } /// /// "Pick the first offered option everywhere, mid shade" — CC6a's own /// default policy for exercising the factory end-to-end, NOT a claim /// about retail's own CharGenState default selection (that policy is /// CC3/CC6b's concern). Every index/shade starts at /// / /// and is only set when the gender's own list actually offers an /// option, so a heritage with e.g. no headgear choices exercises the /// factory's "slot not selected" path rather than an out-of-range index. /// private static ChargenAppearanceSelection MakeDefaultSelection(ChargenGenderOptions gender) { const double midShade = 0.5; ChargenAppearanceSelection selection = ChargenAppearanceSelection.Default; if (gender.HairStyles.Count > 0) selection = selection with { HairStyle = 0u }; if (gender.EyeStrips.Count > 0) selection = selection with { EyesStrip = 0u }; if (gender.NoseStrips.Count > 0) selection = selection with { NoseStrip = 0u }; if (gender.MouthStrips.Count > 0) selection = selection with { MouthStrip = 0u }; if (gender.HairColors.Count > 0) selection = selection with { HairColor = 0u, HairShade = midShade }; if (gender.EyeColors.Count > 0) selection = selection with { EyeColor = 0u }; if (gender.Headgears.Count > 0) selection = selection with { HeadgearStyle = 0u }; if (gender.Shirts.Count > 0) selection = selection with { ShirtStyle = 0u }; if (gender.Pants.Count > 0) selection = selection with { TrousersStyle = 0u }; if (gender.Footwear.Count > 0) selection = selection with { FootwearStyle = 0u }; if (gender.ClothingColors.Count > 0) { selection = selection with { HeadgearColor = 0u, HeadgearShade = midShade, ShirtColor = 0u, ShirtShade = midShade, TrousersColor = 0u, TrousersShade = midShade, FootwearColor = 0u, FootwearShade = midShade, }; } return selection with { SkinShade = midShade }; } }