Example #1
0
    /// <summary>
    /// Submit changes you've made to the dungeons' to the ROM in memory.
    ///
    /// Note: Sprite writing NOT done.
    /// </summary>
    public void writeToRom()
    {
        SortedList <ushort, List <i_torch> >  l_torch  = new SortedList <ushort, List <i_torch> >();
        SortedList <ushort, List <i_block> >  l_block  = new SortedList <ushort, List <i_block> >();
        SortedList <ushort, List <i_sprite> > l_sprite = new SortedList <ushort, List <i_sprite> >();

        ushort roomNo = 0;

        foreach (List <dungeon_object> l in master_list)
        {
            foreach (dungeon_object o in l)
            {
                switch (o.objectTypeIdentifier)
                {
                case (int)(objectType.torch):
                    if (!l_torch.ContainsKey(roomNo))
                    {
                        l_torch.Add(roomNo, new List <i_torch>());
                    }
                    i_torch t = new i_torch(o.rawX, o.rawY, Convert.ToBoolean(o.BG_number));
                    l_torch[roomNo].Add(t);
                    break;

                case (int)(objectType.block):
                    if (!l_block.ContainsKey(roomNo))
                    {
                        l_block.Add(roomNo, new List <i_block>());
                    }
                    i_block b = new i_block(roomNo, o.rawX, o.rawY);
                    l_block[roomNo].Add(b);
                    break;

                case (int)(objectType.chest):
                    throw new NotImplementedException();

                case (int)(objectType.sprite):
                    if (!l_sprite.ContainsKey(roomNo))
                    {
                        l_sprite.Add(roomNo, new List <i_sprite>());
                    }
                    i_sprite s = new i_sprite(true, (byte)o.spriteID, o.rawX, o.rawY, Convert.ToBoolean(o.BG_number));
                    l_sprite[roomNo].Add(s);
                    break;
                }
            }
            roomNo++;
        }

        dung.block.writeAllBlocks(l_block);
        dung.torches.writeAllTorches(l_torch);
        dung.sprite.writeAllSprites(l_sprite);
    }
Example #2
0
    /// <summary>
    /// Read the rom data to generate a Linked List of block objects
    /// </summary>
    public SortedList <ushort, List <i_block> > readBlocks()
    {
        byte[] allData = null;

        //Merge all data into one array because I want to keep things simple and readable.
        for (int i = 0; i < numberOfPointers; i++)
        {
            byte[] b = ROM.Read(primaryPointer_address[i], dataSize[i]);
            if (allData == null)
            {
                allData = b;
            }
            else
            {
                allData = allData.Concat(b).ToArray();
            }
        }

        SortedList <ushort, List <i_block> > allDungeonBlocks = new SortedList <ushort, List <i_block> >();

        for (ushort i = 0; i <= Dungeon.maxRoomNo; i++)
        {
            allDungeonBlocks.Add(i, new List <i_block>());
        }

        //now read every 4 byte pair and create
        for (int i = 0; i < allData.Length; i += bytesPerBlock)
        {
            /*
             * Skip adding the block if the room number is the value of 0xFFFF
             * The game doesn't have unused/empty data, but for the purposes of this
             * editor, we'll use 0xFFFF.
             */
            if (!i_block.isNulledOut(allData[i + 0], allData[i + 1]))
            {
                i_block blocky = new i_block(allData[i + 0], allData[i + 1], allData[i + 2], allData[i + 3]);

                if (!allDungeonBlocks.ContainsKey(blocky.room))
                {
                    allDungeonBlocks.Add(blocky.room, new List <i_block>());
                }
                allDungeonBlocks[blocky.room].Add(blocky);
            }
        }
        return(allDungeonBlocks);
    }