public static void TestUpdateHeadPart2() { var patchMod = new SkyrimMod(PatchModKey, SkyrimRelease.SkyrimSE); var masterMod = new SkyrimMod(MasterModKey, SkyrimRelease.SkyrimSE); var oldHeadPart = masterMod.HeadParts.AddNew("oldHeadPart"); (oldHeadPart.Model ??= new()).File = Path.Join(MeshesPath, "mesh.nif"); var headPartFormLink = oldHeadPart.AsLink(); var linkCache = masterMod.ToImmutableLinkCache(); var newMeshPath = Path.Join(MeshesPath, "Player", "mesh.nif"); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>() { { newMeshPath, new MockFileData("") } }); HeadParts program = new(patchMod, linkCache, fileSystem : fileSystem); program.UpdateHeadPart(headPartFormLink, TexturePath, MeshesPath); Assert.Single(patchMod.HeadParts); var newHeadPart = patchMod.HeadParts.Single(); Assert.Equal(newMeshPath, newHeadPart.Model?.File); }
public void PlacedObjectInCell() { var mod = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE); var block = new CellBlock() { BlockNumber = 2, GroupType = GroupTypeEnum.InteriorCellBlock, }; var subBlock = new CellSubBlock() { BlockNumber = 4, GroupType = GroupTypeEnum.InteriorCellSubBlock, }; block.SubBlocks.Add(subBlock); mod.Cells.Records.Add(block); var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); subBlock.Cells.Add(cell1); subBlock.Cells.Add(cell2); var block2 = new CellBlock() { BlockNumber = 5, GroupType = GroupTypeEnum.InteriorCellBlock, }; var subBlock2 = new CellSubBlock() { BlockNumber = 8, GroupType = GroupTypeEnum.InteriorCellSubBlock, }; block2.SubBlocks.Add(subBlock2); mod.Cells.Records.Add(block2); var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); subBlock2.Cells.Add(cell3); var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); cell2.Persistent.Add(placedNpc); var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); cell2.Persistent.Add(placedObj); var cache = mod.ToImmutableLinkCache(); var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray(); contexts.Should().HaveCount(1); var mod2 = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE); var placedObjOverride = contexts[0].GetOrAddAsOverride(mod2); Assert.Equal(placedObj.FormKey, placedObjOverride.FormKey); mod2.Cells.Records.Should().HaveCount(1); mod2.Cells.Records.First().SubBlocks.Should().HaveCount(1); mod2.Cells.Records.First().SubBlocks.First().Cells.Should().HaveCount(1); mod2.Cells.Records.First().SubBlocks.First().Cells.First().Persistent.Should().HaveCount(1); Assert.Same(placedObjOverride, mod2.Cells.Records.First().SubBlocks.First().Cells.First().Persistent.First()); }
public void HasKeyword_ByEditorID_Empty() { SkyrimMod mod = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE); var npc = mod.Npcs.AddNew(); var cache = mod.ToImmutableLinkCache(); npc.HasKeyword(Utility.Edid1, cache).Should().BeFalse(); }
public void ParentRefs() { WarmupSkyrim.Init(); var mod = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE); var worldspace = mod.Worldspaces.AddNew(); var block = new WorldspaceBlock() { BlockNumberX = 2, BlockNumberY = 3, GroupType = GroupTypeEnum.ExteriorCellBlock, }; var subBlock = new WorldspaceSubBlock() { BlockNumberX = 4, BlockNumberY = 5, GroupType = GroupTypeEnum.ExteriorCellSubBlock, }; block.Items.Add(subBlock); worldspace.SubCells.Add(block); var cell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); subBlock.Items.Add(cell); var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); cell.Persistent.Add(placedNpc); var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); cell.Persistent.Add(placedObj); var cache = mod.ToImmutableLinkCache(); var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray(); contexts.Should().HaveCount(1); var baseContext = contexts[0]; var cellContext = baseContext.Parent; cellContext.Should().BeOfType(typeof(ModContext <ISkyrimMod, ISkyrimModGetter, ICell, ICellGetter>)); cellContext !.Record.Should().Be(cell); var subBlockContext = cellContext.Parent; subBlockContext !.Record.Should().Be(subBlock); var blockContext = subBlockContext.Parent; blockContext !.Record.Should().Be(block); var worldspaceContext = blockContext.Parent; worldspaceContext !.Record.Should().Be(worldspace); baseContext.IsUnderneath <IWorldspaceGetter>().Should().BeTrue(); baseContext.TryGetParent <IWorldspaceGetter>(out var worldParent).Should().BeTrue(); worldParent.Should().Be(worldspace); baseContext.TryGetParentContext <IWorldspace, IWorldspaceGetter>(out var worldParentContext).Should().BeTrue(); worldParentContext !.Record.Should().Be(worldspace); }
public static void FormLink() { var mod = new SkyrimMod(Utility.LightMasterModKey, SkyrimRelease.SkyrimLE); var light = mod.Lights.AddNew(); var cache = mod.ToImmutableLinkCache(); var link = new FormLink <ISkyrimMajorRecordGetter>(light.FormKey); var nullableLink = new FormLinkNullable <ISkyrimMajorRecordGetter>(light.FormKey); IFormLink <ISkyrimMajorRecordGetter> iLink = link; // Normal resolution link.TryResolve(cache, out var _); link.TryResolve(cache, out ISkyrimMajorRecordGetter _); link.Resolve(cache); link.TryResolve <ILightGetter>(cache, out var _); link.TryResolve(cache, out ILightGetter _); link.Resolve <ILightGetter>(cache); nullableLink.TryResolve(cache, out var _); nullableLink.TryResolve(cache, out ISkyrimMajorRecordGetter _); nullableLink.Resolve(cache); nullableLink.TryResolve <ILightGetter>(cache, out var _); nullableLink.TryResolve(cache, out ILightGetter _); nullableLink.Resolve <ILightGetter>(cache); iLink.TryResolve(cache, out var _); iLink.Resolve(cache); iLink.TryResolve <ISkyrimMajorRecordGetter, ILightGetter>(cache, out var _); iLink.TryResolve(cache, out ILightGetter _); iLink.Resolve <ISkyrimMajorRecordGetter, ILightGetter>(cache); // Context resolution // ToDo // Enable when generic querying is supported //link.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out var _); //link.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out IModContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter> _); //link.ResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache); link.TryResolveContext <ISkyrimMod, ILight, ILightGetter>(cache, out var _); link.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _); link.ResolveContext <ISkyrimMod, ILight, ILightGetter>(cache); //nullableLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out var _); //nullableLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out IModContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter> _); //nullableLink.ResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache); nullableLink.TryResolveContext <ISkyrimMod, ILight, ILightGetter>(cache, out var _); nullableLink.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _); nullableLink.ResolveContext <ISkyrimMod, ILight, ILightGetter>(cache); //iLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache, out var _); //iLink.ResolveContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache); iLink.TryResolveContext <ISkyrimMod, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache, out var _); iLink.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _); iLink.ResolveContext <ISkyrimMod, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache); }
public void HasKeyword_ByEditorID_Found() { SkyrimMod mod = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE); var npc = mod.Npcs.AddNew(); var cache = mod.ToImmutableLinkCache(); Keyword keyword = mod.Keywords.AddNew(); keyword.EditorID = Utility.Edid1; npc.Keywords = new ExtendedList <IFormLinkGetter <IKeywordGetter> >(); npc.Keywords.Add(keyword); npc.HasKeyword(Utility.Edid1, cache).Should().BeTrue(); }
public void TryResolveKeyword_ByEditorID_Found() { SkyrimMod mod = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE); var npc = mod.Npcs.AddNew(); var cache = mod.ToImmutableLinkCache(); Keyword keyword = mod.Keywords.AddNew(); keyword.EditorID = TestConstants.Edid1; npc.Keywords = new ExtendedList <IFormLinkGetter <IKeywordGetter> >(); npc.Keywords.Add(keyword); npc.TryResolveKeyword(TestConstants.Edid1, cache, out var kw).Should().BeTrue(); kw.Should().Be(keyword); }
public static void TestUpdateHeadPart() { var patchMod = new SkyrimMod(PatchModKey, SkyrimRelease.SkyrimSE); var masterMod = new SkyrimMod(MasterModKey, SkyrimRelease.SkyrimSE); var oldHeadPart = masterMod.HeadParts.AddNew("oldHeadPart"); var headPartFormLink = oldHeadPart.AsLink(); var linkCache = masterMod.ToImmutableLinkCache(); HeadParts program = new(patchMod, linkCache); program.UpdateHeadPart(headPartFormLink, TexturePath, MeshesPath); Assert.Empty(patchMod.TextureSets); }
public static void IKeyworded() { void TestFunction <T>() where T : IKeywordedGetter <IKeywordGetter> { } void TestFunction2 <T>() where T : IKeywordedGetter { } TestFunction <IWeaponGetter>(); TestFunction2 <IWeaponGetter>(); var mod = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE); IKeyworded <IKeywordGetter> keyworded = mod.Armors.AddNew(); keyworded.TryResolveKeyword(Utility.Form2, mod.ToImmutableLinkCache(), out var keyword); }
public void SetModKeys() { WarmupSkyrim.Init(); var mod = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE); var worldspace = mod.Worldspaces.AddNew(); var block = new WorldspaceBlock() { BlockNumberX = 2, BlockNumberY = 3, GroupType = GroupTypeEnum.ExteriorCellBlock, }; var subBlock = new WorldspaceSubBlock() { BlockNumberX = 4, BlockNumberY = 5, GroupType = GroupTypeEnum.ExteriorCellSubBlock, }; block.Items.Add(subBlock); worldspace.SubCells.Add(block); var cell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); subBlock.Items.Add(cell); var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); cell.Persistent.Add(placedNpc); var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); cell.Persistent.Add(placedObj); var cache = mod.ToImmutableLinkCache(); var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray(); contexts.Should().HaveCount(1); contexts[0].ModKey.Should().Be(TestConstants.PluginModKey); }
public void IPlacedInWorldspace() { WarmupSkyrim.Init(); var mod = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE); var worldspace = mod.Worldspaces.AddNew(); var block = new WorldspaceBlock() { BlockNumberX = 2, BlockNumberY = 3, GroupType = GroupTypeEnum.ExteriorCellBlock, }; var subBlock = new WorldspaceSubBlock() { BlockNumberX = 4, BlockNumberY = 5, GroupType = GroupTypeEnum.ExteriorCellSubBlock, }; block.Items.Add(subBlock); worldspace.SubCells.Add(block); var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); subBlock.Items.Add(cell1); subBlock.Items.Add(cell2); var block2 = new WorldspaceBlock() { BlockNumberX = 5, BlockNumberY = 6, GroupType = GroupTypeEnum.ExteriorCellBlock, }; var subBlock2 = new WorldspaceSubBlock() { BlockNumberX = 8, BlockNumberY = 9, GroupType = GroupTypeEnum.ExteriorCellSubBlock, }; block2.Items.Add(subBlock2); worldspace.SubCells.Add(block2); var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); subBlock2.Items.Add(cell3); var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); cell2.Persistent.Add(placedNpc); var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); cell2.Persistent.Add(placedObj); var cache = mod.ToImmutableLinkCache(); var contexts = mod.EnumerateMajorRecordContexts <IPlaced, IPlacedGetter>(linkCache: cache).ToArray(); Assert.Equal(2, contexts.Length); var mod2 = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE); var placedNpcOverride = contexts[0].GetOrAddAsOverride(mod2); var placedObjOverride = contexts[1].GetOrAddAsOverride(mod2); Assert.Equal(placedNpc.FormKey, placedNpcOverride.FormKey); Assert.Equal(placedObj.FormKey, placedObjOverride.FormKey); mod2.Worldspaces.Should().HaveCount(1); mod2.Worldspaces.First().SubCells.Should().HaveCount(1); mod2.Worldspaces.First().SubCells.First().Items.Should().HaveCount(1); mod2.Worldspaces.First().SubCells.First().Items.First().Items.Should().HaveCount(1); mod2.Worldspaces.First().SubCells.First().Items.First().Items.First().Persistent.Should().HaveCount(2); Assert.Same(placedNpcOverride, mod2.Worldspaces.First().SubCells.First().Items.First().Items.First().Persistent.First()); }
public void CellInWorldspace() { WarmupSkyrim.Init(); var mod = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE); var worldspace = mod.Worldspaces.AddNew(); var block = new WorldspaceBlock() { BlockNumberX = 2, BlockNumberY = 3, GroupType = GroupTypeEnum.ExteriorCellBlock, }; var subBlock = new WorldspaceSubBlock() { BlockNumberX = 4, BlockNumberY = 5, GroupType = GroupTypeEnum.ExteriorCellSubBlock, }; block.Items.Add(subBlock); worldspace.SubCells.Add(block); var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); subBlock.Items.Add(cell1); subBlock.Items.Add(cell2); var block2 = new WorldspaceBlock() { BlockNumberX = 5, BlockNumberY = 6, GroupType = GroupTypeEnum.ExteriorCellBlock, }; var subBlock2 = new WorldspaceSubBlock() { BlockNumberX = 8, BlockNumberY = 9, GroupType = GroupTypeEnum.ExteriorCellSubBlock, }; block2.Items.Add(subBlock2); worldspace.SubCells.Add(block2); var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE); subBlock2.Items.Add(cell3); var cache = mod.ToImmutableLinkCache(); var contexts = mod.EnumerateMajorRecordContexts <ICell, ICellGetter>(linkCache: cache).ToArray(); Assert.Equal(3, contexts.Length); Assert.Same(contexts[0].Record, cell1); Assert.Same(contexts[1].Record, cell2); Assert.Same(contexts[2].Record, cell3); var mod2 = new SkyrimMod(Utility.PluginModKey2, SkyrimRelease.SkyrimSE); var cell2Override = contexts[1].GetOrAddAsOverride(mod2); Assert.Equal(cell2.FormKey, cell2Override.FormKey); mod2.Worldspaces.Should().HaveCount(1); mod2.Worldspaces.First().SubCells.Should().HaveCount(1); mod2.Worldspaces.First().SubCells.First().Items.Should().HaveCount(1); mod2.Worldspaces.First().SubCells.First().Items.First().Items.Should().HaveCount(1); Assert.Same(cell2Override, mod2.Worldspaces.First().SubCells.First().Items.First().Items.First()); }
public static void FormLink() { var mod = new SkyrimMod(Utility.LightMasterModKey, SkyrimRelease.SkyrimLE); var light = mod.Lights.AddNew(); var cache = mod.ToImmutableLinkCache(); var link = new FormLink <ISkyrimMajorRecordGetter>(light.FormKey); var nullableLink = new FormLinkNullable <ISkyrimMajorRecordGetter>(light.FormKey); IFormLinkGetter <ISkyrimMajorRecordGetter> iLink = link; // Normal resolution link.TryResolve(cache, out var _); link.TryResolve <ISkyrimMajorRecordGetter>(cache, out var _); link.Resolve(cache); link.TryResolve <ILightGetter>(cache, out var _); link.TryResolve(cache, out ILightGetter _); link.Resolve <ILightGetter>(cache); nullableLink.TryResolve(cache, out var _); nullableLink.TryResolve <ISkyrimMajorRecordGetter>(cache, out var _); nullableLink.Resolve(cache); nullableLink.TryResolve <ILightGetter>(cache, out var _); nullableLink.TryResolve(cache, out ILightGetter _); nullableLink.Resolve <ILightGetter>(cache); iLink.TryResolve(cache, out var _); iLink.Resolve(cache); iLink.TryResolve <ISkyrimMajorRecordGetter, ILightGetter>(cache, out var _); iLink.TryResolve(cache, out ILightGetter _); iLink.Resolve <ISkyrimMajorRecordGetter, ILightGetter>(cache); // Context resolution link.TryResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache, out var _); link.TryResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache, out IModContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter> _); link.ResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache); link.TryResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache, out var _); link.TryResolveContext(cache, out IModContext <ISkyrimMod, ISkyrimModGetter, ILight, ILightGetter> _); link.ResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache); nullableLink.TryResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache, out var _); nullableLink.TryResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache, out IModContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter> _); nullableLink.ResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache); nullableLink.TryResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache, out var _); nullableLink.TryResolveContext(cache, out IModContext <ISkyrimMod, ISkyrimModGetter, ILight, ILightGetter> _); nullableLink.ResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache); iLink.TryResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache, out var _); iLink.ResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache); iLink.TryResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache, out var _); iLink.TryResolveContext(cache, out IModContext <ISkyrimMod, ISkyrimModGetter, ILight, ILightGetter> _); iLink.ResolveContext <ISkyrimMod, ISkyrimModGetter, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache); // Getter interface conversion IPerkGetter getter = new Perk(Utility.Form1, SkyrimRelease.SkyrimLE); Perk direct = new Perk(Utility.Form2, SkyrimRelease.SkyrimLE); IPerk setter = new Perk(Utility.Form2, SkyrimRelease.SkyrimLE); IFormLink <IPerkGetter> formLink = new FormLink <IPerkGetter>(); formLink = getter.AsLink(); formLink = direct.AsLink(); formLink = setter.AsLink(); formLink.SetTo(direct); formLink.SetTo(getter); formLink.SetTo(setter); formLink.SetTo(formLink); IObjectEffectGetter objGetter = null !; IFormLink <IEffectRecordGetter> aLink = new FormLink <IEffectRecordGetter>(); aLink.SetTo(objGetter); IFormLink <ISkyrimMajorRecordGetter> majRecordLink = new FormLink <ISkyrimMajorRecordGetter>(); IFormLink <IKeywordGetter> keywordLink = new FormLink <IKeywordGetter>(); majRecordLink.SetTo(keywordLink); majRecordLink.TryResolve <IKeywordGetter>(cache, out var keyw); }