Exemple #1
0
    public void drawSong(Song song)
    {
        Debug.Log("Drawing the song from memory...");

        GameObject spawnedCellBlock = null;
        CellBlock  actualCellBlock  = null;
        Row        row;
        Block      block;

        int numRows = song.getRows().Count;
        int rowSize = 10;

        for (int i = 0; i < numRows; i++)
        {
            row = song.GetRowByIndex(i);
            if (row != null)
            {
                for (int j = 0; j < rowSize; j++)
                {
                    block = row.GetBlockByIndex(j);
                    if (block != null)
                    {
                        //Debug.Log($"found a block with pos x: {block.x} y: {block.y} z: {block.z}");
                        Vector3 cellBlockPos = new Vector3(block.x, block.y, block.z);
                        instantiateCellBlock(actualCellBlock, cellBlockPos, spawnedCellBlock, block.getMaterial(), i, j);
                    }
                }
            }
        }
    }
        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());
        }
Exemple #3
0
 void OnTriggerExit(Collider target)
 {
     if (target.gameObject.tag.Equals("Block"))
     {
         CellBlock c = target.gameObject.GetComponent <CellBlock>();
         ToggleCellLight(c, false);
     }
 }
Exemple #4
0
    private void instantiateCellBlock(CellBlock cellblock, Vector3 pos, GameObject spawnedCellBlock, string materialName, int row, int rowIndex)
    {
        spawnedCellBlock = Instantiate(cellBlockPrefab, pos, cellBlockPrefab.transform.rotation);
        spawnedCellBlock.GetComponent <Renderer>().material = Resources.Load($"Materials/Blocks/{materialName}", typeof(Material)) as Material;
        spawnedCellBlock.transform.SetParent(cellBlockParent, true);

        cellblock          = spawnedCellBlock.GetComponent <CellBlock>();
        cellblock.row      = row;
        cellblock.rowIndex = rowIndex;
    }
Exemple #5
0
    void OnTriggerEnter(Collider target)
    {
        if (target.gameObject.tag.Equals("Block"))
        {
            // get cellblock from target collider
            CellBlock c = target.gameObject.GetComponent <CellBlock>();
            ToggleCellLight(c, true);

            // only play sound if this is a new row
            if (c.row > currentRow)
            {
                currentRow = c.row;
                Debug.Log(currentRow);

                // get all music blocks in current row and play simultaneously
                Block[] blocks = MC.getDataJockey().GetAllBlocksInRow(c.row);
                Block   loop   = CheckForLoop(blocks);

                if (loop != null)
                {
                    Debug.Log("Found a loop block!");

                    // IF the loop has been set to complete and this is a NEW loop block, start a new loop
                    if (loopCompleted && loop != loopTail && loop != loopHead)
                    {
                        ResetLoop();
                    }

                    if (loopTail == null)
                    {
                        loopTail = loop;
                    }

                    // the loop is only complete IF :
                    // current loop block is not loop head or tail

                    if (!loopCompleted && loop != loopTail && loopHead == null)
                    {
                        Debug.Log("Returning to loop tail...");
                        loopHead = loop;

                        // take the music wall back to position of previous loop block
                        transform.position = new Vector3(loopTail.x, transform.position.y, transform.position.z);
                        currentRow         = -1;
                        // loop is now complete
                        loopCompleted = true;
                    }
                }

                PlayNotes(blocks);
            }
        }
    }
        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);
        }
Exemple #7
0
    // turn on light/emission when block is triggered
    void ToggleCellLight(CellBlock block, bool on)
    {
        Light light = block.GetComponent <Light>();

        light.enabled = on;

        Material mat = block.GetComponent <Renderer>().material;

        light.color = mat.color;

        if (on)
        {
            mat.EnableKeyword("_EMISSION");
        }
        else
        {
            mat.DisableKeyword("_EMISSION");
        }
    }
Exemple #8
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());
        }
Exemple #9
0
    public Block placeCellBlock(Vector3 cellBlockPosition, int row, int rowIndex)
    {
        CellBlock  actualCellBlock  = null;
        GameObject spawnedCellBlock = null;
        string     materialName     = currentlySelected.getMaterial();
        string     audioClipName    = currentlySelected.getAudio();

        Debug.Log($"Placing cell block of type {materialName} with audio file {audioClipName}");
        cellBlockPosition.y += cellBlockPrefab.transform.localScale.y / 2 + 0.1f;
        instantiateCellBlock(actualCellBlock, cellBlockPosition, spawnedCellBlock, materialName, row, rowIndex);

        Block saveBlock = new Block(cellBlockPosition.x, cellBlockPosition.y, cellBlockPosition.z, rowIndex, materialName, audioClipName);


        // hack; ugh throwing up
        if (audioClipName.Equals("loop"))
        {
            saveBlock.isLoopBlock = true;
        }

        return(saveBlock);
    }
Exemple #10
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());
        }
Exemple #11
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());
        }
Exemple #12
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);
                            }
                        }
                    }
                }
            }
        }