Example #1
0
        // This constructor populates a two dimensional list of brushes.
        // It does this by translating between the provided colour map and the collection of StarboundBrushes.
        // This layer contains the *raw* brush information as drawn on the colour map,
        // and is not responsible for any validity checking.
        // Also sets up the collision map
        public EditorMapLayer(string layerName, Bitmap colourMap, Dictionary <List <byte>, EditorBrush> brushMap,
                              EditorMapPart parent)
        {
            m_parent       = parent;
            ColourMap      = colourMap;
            m_name         = layerName;
            m_width        = colourMap.Width;
            m_height       = colourMap.Height;
            m_brushMap     = new EditorBrush[m_width, m_height];
            m_collisionMap = new HashSet <List <int> > [m_width, m_height];

            List <CollisionObjectBrush> brushObjList = new List <CollisionObjectBrush>();

            for (int x = 0; x < m_width; ++x)
            {
                for (int y = 0; y < m_height; ++y)
                {
                    Color       pixel = colourMap.GetPixel(x, y);
                    EditorBrush brush = null;

                    List <byte> rawPixelData
                        = new List <byte> {
                        pixel.R, pixel.G, pixel.B, pixel.A
                        };

                    if (brushMap.ContainsKey(rawPixelData))
                    {
                        brush            = brushMap[rawPixelData];
                        m_brushMap[x, y] = brush;
                    }

                    if (brush != null && brush.FrontAsset != null && brush.FrontAsset is StarboundObject)
                    {
                        // Add the object brush to a list, to process after all other tiles
                        var objBrush = new CollisionObjectBrush();
                        objBrush.m_brush = brush;
                        objBrush.m_x     = x;
                        objBrush.m_y     = y;

                        brushObjList.Add(objBrush);
                    }
                    else
                    {
                        SetCollisionAt(brush, x, y);
                    }
                }
            }

            parent.UpdateCompositeCollisionMap();

            foreach (CollisionObjectBrush objBrush in brushObjList)
            {
                SetCollisionAt(objBrush.m_brush, objBrush.m_x, objBrush.m_y);
            }
        }
        // This constructor populates a two dimensional list of brushes.
        // It does this by translating between the provided colour map and the collection of StarboundBrushes.
        // This layer contains the *raw* brush information as drawn on the colour map,
        // and is not responsible for any validity checking.
        // Also sets up the collision map
        public EditorMapLayer(string layerName, Bitmap colourMap, Dictionary<Color, EditorBrush> brushMap,
            EditorMapPart parent)
        {
            m_parent = parent;
            ColourMap = colourMap;
            m_name = layerName;
            m_width = colourMap.Width;
            m_height = colourMap.Height;
            m_brushMap = new EditorBrush[m_width, m_height];
            m_collisionMap = new HashSet<Vec2I>[m_width, m_height];
            m_undoManager = new UndoManager(this);

            List<CollisionObjectBrush> brushObjList = new List<CollisionObjectBrush>();

            for (int x = 0; x < m_width; ++x)
            {
                for (int y = 0; y < m_height; ++y)
                {
                    Color pixel = colourMap.GetPixel(x, y);
                    EditorBrush brush = null;

                    //List<byte> rawPixelData
                      //  = new List<byte> {pixel.R, pixel.G, pixel.B, pixel.A};

                    if (brushMap.ContainsKey(pixel))
                    {
                        brush = brushMap[pixel];
                        m_brushMap[x, y] = brush;
                    }

                    if (brush != null && brush.FrontAsset != null && brush.FrontAsset is StarboundObject)
                    {
                        // Add the object brush to a list, to process after all other tiles
                        var objBrush = new CollisionObjectBrush();
                        objBrush.m_brush = brush;
                        objBrush.m_x = x;
                        objBrush.m_y = y;

                        brushObjList.Add(objBrush);
                    }
                    else
                    {
                        SetCollisionAt(brush, x, y);
                    }
                }
            }

            parent.UpdateCompositeCollisionMap();

            foreach (CollisionObjectBrush objBrush in brushObjList)
            {
                SetCollisionAt(objBrush.m_brush, objBrush.m_x, objBrush.m_y);
            }
        }
        private bool CheckCollisionMapAtOffset(EditorMapPart part, int x, int y)
        {
            HashSet<Vec2I> collisions = part.GetCollisionsAt(x, y);

            if (collisions == null)
                return false;

            // Check each list of coordinates.
            // The collision is only valid if the list doesn't point to an object
            return (from coords in collisions
                    from layer in part.Layers
                    select layer.GetBrushAt(coords.x, coords.y)).Any(brush =>
                        brush != null &&
                        brush.FrontAsset != null &&
                        !(brush.FrontAsset is StarboundObject));
        }