Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        public void Cell()
        {
            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 mod2     = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var contexts = mod.EnumerateMajorRecordContexts <ICell, ICellGetter>(linkCache: null !).ToArray();

            contexts.Should().HaveCount(3);
            Assert.Same(contexts[0].Record, cell1);
            Assert.Same(contexts[1].Record, cell2);
            Assert.Same(contexts[2].Record, cell3);
            var cell2Override = contexts[1].GetOrAddAsOverride(mod2);

            Assert.Equal(cell2.FormKey, cell2Override.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);
        }
Esempio n. 3
0
        public void Typed_Blocked()
        {
            var mod      = new OblivionMod(TestConstants.PluginModKey);
            var npc1     = mod.Npcs.AddNew();
            var cell     = new Cell(mod.GetNextFormKey());
            var subBlock = new CellSubBlock()
            {
                BlockNumber = 1,
                Cells       =
                {
                    cell
                }
            };
            var cell2     = new Cell(mod.GetNextFormKey());
            var subBlock2 = new CellSubBlock()
            {
                BlockNumber = 2,
                Cells       =
                {
                    cell2
                }
            };
            var block = new CellBlock()
            {
                BlockNumber = 1,
                SubBlocks   =
                {
                    subBlock,
                    subBlock2,
                }
            };

            mod.Cells.Records.Add(block);
            mod.Remove(cell2);
            Assert.Single(mod.Cells.Records);
            Assert.Single(mod.Cells.Records.First().SubBlocks);
            Assert.Same(subBlock, mod.Cells.Records.First().SubBlocks.First());
            Assert.Single(mod.Cells.Records.First().SubBlocks.First().Cells);
            Assert.Same(cell, mod.Cells.Records.First().SubBlocks.First().Cells.First());
            Assert.Single(mod.Npcs);
            Assert.Same(npc1, mod.Npcs.First());
        }
Esempio n. 4
0
        public void Typeless_Blocked()
        {
            var mod      = new OblivionMod(Utility.PluginModKey);
            var cell     = new Cell(mod.GetNextFormKey());
            var subBlock = new CellSubBlock()
            {
                BlockNumber = 1,
                Cells       =
                {
                    cell
                }
            };
            var cell2     = new Cell(mod.GetNextFormKey());
            var subBlock2 = new CellSubBlock()
            {
                BlockNumber = 2,
                Cells       =
                {
                    cell2
                }
            };
            var block = new CellBlock()
            {
                BlockNumber = 1,
                SubBlocks   =
                {
                    subBlock,
                    subBlock2,
                }
            };

            mod.Cells.Records.Add(block);
            mod.Remove(cell2.FormKey);
            Assert.Single(mod.Cells.Records);
            Assert.Single(mod.Cells.Records.First().SubBlocks);
            Assert.Same(subBlock, mod.Cells.Records.First().SubBlocks.First());
            Assert.Single(mod.Cells.Records.First().SubBlocks.First().Cells);
            Assert.Same(cell, mod.Cells.Records.First().SubBlocks.First().Cells.First());
        }
Esempio n. 5
0
        public void Typeless_Deep()
        {
            var mod     = new OblivionMod(TestConstants.PluginModKey);
            var placed1 = new PlacedObject(mod.GetNextFormKey());
            var placed2 = new PlacedObject(mod.GetNextFormKey());
            var cell    = new Cell(mod.GetNextFormKey());

            cell.Temporary.Add(placed1);
            cell.Temporary.Add(placed2);
            var subBlock = new CellSubBlock()
            {
                BlockNumber = 1,
                Cells       =
                {
                    cell
                }
            };
            var block = new CellBlock()
            {
                BlockNumber = 1,
                SubBlocks   =
                {
                    subBlock,
                }
            };

            mod.Cells.Records.Add(block);
            mod.Remove(placed2.FormKey);
            Assert.Single(mod.Cells.Records);
            Assert.Single(mod.Cells.Records.First().SubBlocks);
            Assert.Same(subBlock, mod.Cells.Records.First().SubBlocks.First());
            Assert.Single(mod.Cells.Records.First().SubBlocks.First().Cells);
            Assert.Same(cell, mod.Cells.Records.First().SubBlocks.First().Cells.First());
            Assert.Single(mod.Cells.Records.First().SubBlocks.First().Cells.First().Temporary);
            Assert.Same(placed1, mod.Cells.Records.First().SubBlocks.First().Cells.First().Temporary.First());
        }
Esempio n. 6
0
        internal static IEnumerable <IModContext <IFallout4Mod, IMajorRecordCommon, IMajorRecordCommonGetter> > EnumerateMajorRecordContexts(
            this IListGroupGetter <ICellBlockGetter> cellBlocks,
            ILinkCache linkCache,
            Type type,
            ModKey modKey,
            IModContext?parent,
            bool throwIfUnknown)
        {
            foreach (var readOnlyBlock in cellBlocks.Records)
            {
                var blockNum     = readOnlyBlock.BlockNumber;
                var blockContext = new ModContext <ICellBlockGetter>(
                    modKey: modKey,
                    parent: parent,
                    record: readOnlyBlock);
                foreach (var readOnlySubBlock in readOnlyBlock.SubBlocks)
                {
                    var subBlockNum     = readOnlySubBlock.BlockNumber;
                    var subBlockContext = new ModContext <ICellSubBlockGetter>(
                        modKey: modKey,
                        parent: blockContext,
                        record: readOnlySubBlock);
                    foreach (var readOnlyCell in readOnlySubBlock.Cells)
                    {
                        Func <IFallout4Mod, ICellGetter, bool, string?, ICell> cellGetter = (mod, copyCell, dup, edid) =>
                        {
                            var formKey        = copyCell.FormKey;
                            var retrievedBlock = mod.Cells.Records.FirstOrDefault(x => x.BlockNumber == blockNum);
                            if (retrievedBlock == null)
                            {
                                retrievedBlock = new CellBlock()
                                {
                                    BlockNumber = blockNum,
                                    GroupType   = GroupTypeEnum.InteriorCellBlock,
                                };
                                mod.Cells.Records.Add(retrievedBlock);
                            }
                            var subBlock = retrievedBlock.SubBlocks.FirstOrDefault(x => x.BlockNumber == subBlockNum);
                            if (subBlock == null)
                            {
                                subBlock = new CellSubBlock()
                                {
                                    BlockNumber = subBlockNum,
                                    GroupType   = GroupTypeEnum.InteriorCellSubBlock,
                                };
                                retrievedBlock.SubBlocks.Add(subBlock);
                            }
                            var cell = subBlock.Cells.FirstOrDefault(cell => cell.FormKey == formKey);
                            if (cell == null)
                            {
                                if (dup)
                                {
                                    cell = copyCell.Duplicate(mod.GetNextFormKey(edid), CellCopyMask);
                                }
                                else
                                {
                                    cell = copyCell.DeepCopy(CellCopyMask);
                                }
                                subBlock.Cells.Add(cell);
                            }
                            return(cell);
                        };

                        if (LoquiRegistration.TryGetRegister(type, out var regis) &&
                            regis.ClassType == typeof(Cell))
                        {
                            yield return(new ModContext <IFallout4Mod, IMajorRecordCommon, IMajorRecordCommonGetter>(
                                             modKey: modKey,
                                             record: readOnlyCell,
                                             getOrAddAsOverride: (m, r) => cellGetter(m, (ICellGetter)r, false, default(string?)),
                                             duplicateInto: (m, r, e) => cellGetter(m, (ICellGetter)r, true, e),
                                             parent: subBlockContext));
                        }
                        else
                        {
                            foreach (var con in CellCommon.Instance.EnumerateMajorRecordContexts(
                                         readOnlyCell,
                                         linkCache,
                                         type,
                                         modKey,
                                         subBlockContext,
                                         throwIfUnknown,
                                         (m, c) => cellGetter(m, c, false, default(string?)),
                                         (m, c, e) => cellGetter(m, c, true, e)))
                            {
                                yield return(con);
                            }
                        }
                    }
                }
            }
        }